|
From: | Dave NotTelling |
Subject: | Re: [Discuss-gnuradio] PMT Oddities |
Date: | Tue, 13 Dec 2016 17:51:22 -0500 |
Here is a full example:[code]#!/usr/bin/pythonimport pmtd = pmt.make_dict()d = pmt.dict_add(d, pmt.intern('a'), pmt.intern('a'))d = pmt.dict_add(d, pmt.intern('b'), pmt.intern('b'))d = pmt.dict_add(d, pmt.intern('c'), pmt.intern('c'))a = pmt.cons(d, pmt.make_u8vector(10, 10))print 'dict_keys with a populated dictionary'print pmt.dict_keys(a)a = pmt.cons(pmt.make_dict(), pmt.make_u8vector(10, 10))print 'dict_keys with an empty dictionary'print pmt.dict_keys(a)[/code]You end up with the following output:[output]dict_keys with a populated dictionary((c . c))dict_keys with an empty dictionaryTraceback (most recent call last):File "test.py", line 18, in <module>print pmt.dict_keys(a)File "/usr/local/lib/python2.7/dist-packages/pmt/pmt_swig.py" , line 3010, in dict_keys return _pmt_swig.dict_keys(dict)RuntimeError: pmt_car: wrong_type : ()[/output]The first call to dict_keys(a) returns the last element in the dictionary. The second call errors out. Both should error out correct?On Fri, Dec 9, 2016 at 9:11 PM, Dave NotTelling <address@hidden> wrote:I understand that it should bomb, but it doesn't if there are elements in the dictionary of the pair generated by cons. that's the problem. calling dict_keys should die on both tests, but returns just fine on the first test.On Dec 9, 2016 1:35 PM, "Martin Braun" <address@hidden> wrote:On 12/05/2016 01:56 PM, Dave NotTelling wrote:It's supposed to bomb -- pmt.cons() does not return a dict. That's
> Marcus & Martin:
>
> I tried the dict_keys() method of checking, but even that can
> fail. Here is an example:
>
> [code]
>
> import pmt
>
> d = pmt.make_dict()
> d = pmt.dict_add(d, pmt.intern('a'), pmt.intern('a'))
> d = pmt.dict_add(d, pmt.intern('b'), pmt.intern('b'))
> d = pmt.dict_add(d, pmt.intern('c'), pmt.intern('c'))
>
> a = pmt.cons(d, pmt.make_u8vector(10, 10))
>
> print pmt.dict_keys(a)
>
> [/code]
>
> You end up with: ((c . c))
>
> The dict_keys() method will bomb if there are no elements in the dictionary:
>
> print pmt.dict_keys(pmt.cons(pmt.make_dict(), pmt.make_u8vector(10, 10)))
exactly how you can test for dicts.
See:
https://github.com/gnuradio/gnuradio/blob/1e8562c8d5430667b4 8fced2d2e50ab5771dfb5e/gr-uhd/ lib/usrp_block_impl.cc#L486-L4 94
-- M
_______________________________________________
Discuss-gnuradio mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
[Prev in Thread] | Current Thread | [Next in Thread] |