commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 03/07: runtime: mods for pmt's NIL.


From: git
Subject: [Commit-gnuradio] [gnuradio] 03/07: runtime: mods for pmt's NIL.
Date: Mon, 30 Jun 2014 02:29:28 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

trondeau pushed a commit to branch master
in repository gnuradio.

commit 3d8a19b55a15a285d5a95d1e786cb93e26cb4f3a
Author: Tom Rondeau <address@hidden>
Date:   Fri Jun 27 15:09:56 2014 -0400

    runtime: mods for pmt's NIL.
---
 gnuradio-runtime/include/pmt/pmt.h           |  3 ++-
 gnuradio-runtime/lib/pmt/pmt.cc              |  9 +++++++--
 gnuradio-runtime/python/pmt/__init__.py      |  5 ++++-
 gnuradio-runtime/python/pmt/pmt_to_python.py | 11 +++++++----
 gnuradio-runtime/swig/pmt_swig.i             |  6 ++++--
 5 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/gnuradio-runtime/include/pmt/pmt.h 
b/gnuradio-runtime/include/pmt/pmt.h
index 5929975..3e17571 100644
--- a/gnuradio-runtime/include/pmt/pmt.h
+++ b/gnuradio-runtime/include/pmt/pmt.h
@@ -249,7 +249,8 @@ PMT_API std::complex<double> to_complex(pmt_t z);
  * ------------------------------------------------------------------------
  */
 
-extern PMT_API const pmt_t PMT_NIL;    //< the empty list
+#define PMT_NIL get_PMT_NIL()
+PMT_API pmt_t get_PMT_NIL();
 
 //! Return true if \p x is the empty list, otherwise return false.
 PMT_API bool is_null(const pmt_t& x);
diff --git a/gnuradio-runtime/lib/pmt/pmt.cc b/gnuradio-runtime/lib/pmt/pmt.cc
index 8315100..082b98a 100644
--- a/gnuradio-runtime/lib/pmt/pmt.cc
+++ b/gnuradio-runtime/lib/pmt/pmt.cc
@@ -160,9 +160,14 @@ _any(pmt_t x)
 
 const pmt_t PMT_T = pmt_t(new pmt_bool());     // singleton
 const pmt_t PMT_F = pmt_t(new pmt_bool());     // singleton
-const pmt_t PMT_NIL = pmt_t(new pmt_null());   // singleton
 const pmt_t PMT_EOF = cons(PMT_NIL, PMT_NIL);           // singleton
 
+pmt_t get_PMT_NIL()
+{
+  static pmt_t NIL = pmt_t(new pmt_null());
+  return NIL;
+}
+
 ////////////////////////////////////////////////////////////////////////////
 //                           Booleans
 ////////////////////////////////////////////////////////////////////////////
@@ -1388,7 +1393,7 @@ list_has(pmt_t list, const pmt_t& item)
     pmt_t right = cdr(list);
     if(equal(left,item))
         return true;
-    return list_has(right, item);   
+    return list_has(right, item);
   } else {
     if(is_null(list))
         return false;
diff --git a/gnuradio-runtime/python/pmt/__init__.py 
b/gnuradio-runtime/python/pmt/__init__.py
index 00940e4..1c7db73 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 8973b88..e08b726 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'))),
@@ -116,7 +120,7 @@ type_mappings = ( #python type, check pmt type, to python, 
from python
 
 def pmt_to_python(p):
     for python_type, pmt_check, to_python, from_python in type_mappings:
-        if pmt_check(p): 
+        if pmt_check(p):
             try:
                 return to_python(p)
             except:
@@ -129,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))
-
diff --git a/gnuradio-runtime/swig/pmt_swig.i b/gnuradio-runtime/swig/pmt_swig.i
index 5ea612b..e54b544 100644
--- a/gnuradio-runtime/swig/pmt_swig.i
+++ b/gnuradio-runtime/swig/pmt_swig.i
@@ -83,9 +83,11 @@ namespace pmt{
 
   extern const pmt_t PMT_T;
   extern const pmt_t PMT_F;
-  extern const pmt_t PMT_NIL;
   extern const pmt_t PMT_EOF;
 
+  pmt_t get_PMT_NIL();
+  #define PMT_NIL get_PMT_NIL()
+
   bool is_bool(pmt_t obj);
   bool is_true(pmt_t obj);
   bool is_false(pmt_t obj);
@@ -219,7 +221,7 @@ namespace pmt{
   void c64vector_set(pmt_t v, size_t k, std::complex<double> x);
 
   %apply size_t & INOUT { size_t &len };
-  const void *uniform_vector_elements(pmt_t v, size_t &len);  
+  const void *uniform_vector_elements(pmt_t v, size_t &len);
 
   const std::vector<uint8_t>  u8vector_elements(pmt_t v);
   const std::vector<int8_t>   s8vector_elements(pmt_t v);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]