Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r62599:6f7196e584fc
Date: 2013-03-20 16:18 -0700
http://bitbucket.org/pypy/pypy/changeset/6f7196e584fc/

Log:    initial/experimental support for accessing macro's (CINT-only)

diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -581,6 +581,14 @@
         Py_DecRef(space, rffi.cast(PyObject, rffi.cast(rffi.VOIDPP, arg)[0]))
 
 
+class MacroConverter(TypeConverter):
+    def from_memory(self, space, w_obj, w_pycppclass, offset):
+        # TODO: get the actual type info from somewhere ...
+        address = self._get_raw_address(space, w_obj, offset)
+        longptr = rffi.cast(rffi.LONGP, address)
+        return space.wrap(longptr[0])
+
+
 _converters = {}         # builtin and custom types
 _a_converters = {}       # array and ptr versions of above
 def get_converter(space, name, default):
@@ -660,6 +668,8 @@
 
 _converters["PyObject*"]                         = PyObjectConverter
 
+_converters["#define"]                           = MacroConverter
+
 # add basic (builtin) converters
 def _build_basic_converters():
     "NOT_RPYTHON"
diff --git a/pypy/module/cppyy/test/test_cint.py 
b/pypy/module/cppyy/test/test_cint.py
--- a/pypy/module/cppyy/test/test_cint.py
+++ b/pypy/module/cppyy/test/test_cint.py
@@ -507,3 +507,19 @@
         gROOT.SetDirLevel(3)
         assert 3 == TROOT.GetDirLevel()
         TROOT.SetDirLevel(old)
+
+    def test07_macro(self):
+        """Test access to cpp macro's"""
+
+        from cppyy import gbl
+
+        assert gbl.NULL == 0
+
+        gbl.gROOT.ProcessLine('#define aap "aap"')
+        gbl.gROOT.ProcessLine('#define noot 1')
+        gbl.gROOT.ProcessLine('#define mies 2.0')
+
+        # TODO: macro's assumed to always be of long type ...
+        #assert gbl.aap  == "aap"
+        assert gbl.noot == 1
+        #assert gbl.mies == 2.0
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to