diff options
Diffstat (limited to 'gnuradio-runtime/python/pmt')
-rw-r--r-- | gnuradio-runtime/python/pmt/__init__.py | 5 | ||||
-rw-r--r-- | gnuradio-runtime/python/pmt/pmt_to_python.py | 16 |
2 files changed, 16 insertions, 5 deletions
diff --git a/gnuradio-runtime/python/pmt/__init__.py b/gnuradio-runtime/python/pmt/__init__.py index 00940e4cc1..1c7db73322 100644 --- a/gnuradio-runtime/python/pmt/__init__.py +++ b/gnuradio-runtime/python/pmt/__init__.py @@ -48,6 +48,9 @@ except ImportError: __path__.append(os.path.join(dirname, "..", "..", "swig")) from pmt_swig import * +# due to changes in the PMT_NIL singleton for static builds, we force +# this into Python here. +PMT_NIL = get_PMT_NIL() + from pmt_to_python import pmt_to_python as to_python from pmt_to_python import python_to_pmt as to_pmt - diff --git a/gnuradio-runtime/python/pmt/pmt_to_python.py b/gnuradio-runtime/python/pmt/pmt_to_python.py index 3344eba163..e08b7265de 100644 --- a/gnuradio-runtime/python/pmt/pmt_to_python.py +++ b/gnuradio-runtime/python/pmt/pmt_to_python.py @@ -21,6 +21,10 @@ try: import pmt_swig as pmt except: import pmt import numpy +# SWIG isn't taking in the #define PMT_NIL; +# getting the singleton locally. +PMT_NIL = pmt.get_PMT_NIL() + #define missing def pmt_to_tuple(p): elems = list() @@ -41,7 +45,7 @@ def pmt_to_vector(p): return v def pmt_from_vector(p): - v = pmt.make_vector(len(p), pmt.PMT_NIL) + v = pmt.make_vector(len(p), PMT_NIL) for i, elem in enumerate(p): pmt.vector_set(v, i, python_to_pmt(elem)) return v @@ -99,7 +103,7 @@ def uvector_to_numpy(uvector): raise ValueError("unsupported uvector data type for conversion to numpy array %s"%(uvector)) type_mappings = ( #python type, check pmt type, to python, from python - (None, pmt.is_null, lambda x: None, lambda x: pmt.PMT_NIL), + (None, pmt.is_null, lambda x: None, lambda x: PMT_NIL), (bool, pmt.is_bool, pmt.to_bool, pmt.from_bool), (str, pmt.is_symbol, pmt.symbol_to_string, pmt.string_to_symbol), (unicode, lambda x: False, None, lambda x: pmt.string_to_symbol(x.encode('utf-8'))), @@ -110,12 +114,17 @@ type_mappings = ( #python type, check pmt type, to python, from python (tuple, pmt.is_tuple, pmt_to_tuple, pmt_from_tuple), (list, pmt.is_vector, pmt_to_vector, pmt_from_vector), (dict, pmt.is_dict, pmt_to_dict, pmt_from_dict), + (tuple, pmt.is_pair, lambda x: (pmt_to_python(pmt.car(x)), pmt_to_python(pmt.cdr(x))), lambda x: pmt.cons(python_to_pmt(x[0]), python_to_pmt(x[1]))), (numpy.ndarray, pmt.is_uniform_vector, uvector_to_numpy, numpy_to_uvector), ) def pmt_to_python(p): for python_type, pmt_check, to_python, from_python in type_mappings: - if pmt_check(p): return to_python(p) + if pmt_check(p): + try: + return to_python(p) + except: + pass raise ValueError("can't convert %s type to pmt (%s)"%(type(p),p)) def python_to_pmt(p): @@ -124,4 +133,3 @@ def python_to_pmt(p): if p == None: return from_python(p) elif isinstance(p, python_type): return from_python(p) raise ValueError("can't convert %s type to pmt (%s)"%(type(p),p)) - |