[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Discuss-gnuradio] PMT Pairs/Dictionaries type checking bug
From: |
Martin Braun |
Subject: |
Re: [Discuss-gnuradio] PMT Pairs/Dictionaries type checking bug |
Date: |
Thu, 10 Mar 2016 19:14:53 -0800 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 |
Yeah, we had some discussions about making the dicts more explicit, but
eventually didn't. So this code is currently all you can do.
Cheers,
M
On 03/10/2016 06:59 PM, Jacob Gilbert wrote:
> Looks like this is known to at least some other folks. Here is a fix
> borrowed from:
> https://github.com/gnuradio/gnuradio/blob/master/gr-uhd/lib/usrp_block_impl.cc#L459
>
> void block::msg_handler(pmt::pmt_t msg)
> {
> try {
> pmt::pmt_t keys = pmt::dict_keys(msg);
> } catch (const pmt::wrong_type &e) {
> msg = pmt::dict_add(pmt::make_dict(), pmt::car(msg), pmt::cdr(msg));
> }
>
> <<< rest of message handler here... input msg will be a dictionary >>>
> }
>
>
> On Thu, Mar 10, 2016 at 9:26 AM, Jacob Gilbert
> <address@hidden <mailto:address@hidden>> wrote:
>
> It appears that PMT dictionaries and pairs are treated identically
> when it comes to using the pmt::is_<type>() checking functions.
>
> Example:
>
> pmt::pmt_t test_pair = pmt::cons(pmt::mp("pair"), pmt::mp(1));
> pmt::pmt_t test_dict = pmt::dict_add(pmt::make_dict(),
> pmt::mp("dict"), pmt::mp(1));
>
> if (pmt::is_pair(test_pair)) std::cout << "Pair is a pair" <<
> std::endl;
> if (pmt::is_pair(test_dict)) std::cout << "Dict is a pair" <<
> std::endl;
> if (pmt::is_dict(test_pair)) std::cout << "Pair is a dict" <<
> std::endl;
> if (pmt::is_dict(test_dict)) std::cout << "Dict is a dict" <<
> std::endl;
>
> output is:
>
> Pair is a pair
> Dict is a pair
> Pair is a dict
> Dict is a dict
>
> Naturally this causes issues if you attempt to use these PMTs (eg:
> get the keys from a pair). I'm not sure if this is an issue with GNU
> Radio or with some external PMT handling library, but at a minimum
> it seems like the doxygen
>
> (http://gnuradio.org/doc/doxygen/namespacepmt.html#a936ecb38da9a2a1bb107c090e194700f)
>
>
> "PMT_API bool pmt::is_pair (const pmt_t &obj) Return true if obj
> is a pair, else false."
>
> should be updated to reflect this issue for both pmt::is_pair() and
> pmt::is_dict().
>
> Jacob
>
>
>
>
> _______________________________________________
> Discuss-gnuradio mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
>