[pypy-commit] pypy cling-support: take care of special case global pointers
wlav
pypy.commits at gmail.com
Thu Jul 28 14:40:52 EDT 2016
Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: cling-support
Changeset: r85897:3a3e429e58c8
Date: 2016-07-28 11:37 -0700
http://bitbucket.org/pypy/pypy/changeset/3a3e429e58c8/
Log: take care of special case global pointers
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
@@ -517,8 +517,7 @@
def from_memory(self, space, w_obj, w_pycppclass, offset):
address = rffi.cast(capi.C_OBJECT, self._get_raw_address(space, w_obj, offset))
from pypy.module.cppyy import interp_cppyy
- return interp_cppyy.wrap_cppobject(space, address, self.cppclass,
- do_cast=False, is_ref=True)
+ return interp_cppyy.wrap_cppobject(space, address, self.cppclass, do_cast=False)
def to_memory(self, space, w_obj, w_value, offset):
address = rffi.cast(rffi.VOIDPP, self._get_raw_address(space, w_obj, offset))
@@ -549,6 +548,11 @@
r = rffi.cast(rffi.VOIDPP, call_local)
w_obj._rawobject = rffi.cast(capi.C_OBJECT, r[0])
+ def from_memory(self, space, w_obj, w_pycppclass, offset):
+ address = rffi.cast(capi.C_OBJECT, self._get_raw_address(space, w_obj, offset))
+ from pypy.module.cppyy import interp_cppyy
+ return interp_cppyy.wrap_cppobject(space, address, self.cppclass,
+ do_cast=False, is_ref=True)
class StdStringConverter(InstanceConverter):
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -956,6 +956,7 @@
TGlobal* gbl = g_globalvars[ idata ];
std::string fullType = gbl->GetFullTypeName();
if ( fullType[fullType.size()-1] == '*' && \
+ !dynamic_cast<TGlobalMappedFunction*>(gbl) && \
fullType.find( "char", 0, 4 ) == std::string::npos )
fullType.append( "*" );
else if ( (int)gbl->GetArrayDim() > 1 )
diff --git a/pypy/module/cppyy/test/advancedcpp.cxx b/pypy/module/cppyy/test/advancedcpp.cxx
--- a/pypy/module/cppyy/test/advancedcpp.cxx
+++ b/pypy/module/cppyy/test/advancedcpp.cxx
@@ -73,7 +73,8 @@
// a couple of globals for access testing
double my_global_double = 12.;
double my_global_array[500];
-
+static double sd = 1234.;
+double* my_global_ptr = &sd;
// for life-line and identity testing
int some_class_with_data::some_data::s_num_data = 0;
diff --git a/pypy/module/cppyy/test/advancedcpp.h b/pypy/module/cppyy/test/advancedcpp.h
--- a/pypy/module/cppyy/test/advancedcpp.h
+++ b/pypy/module/cppyy/test/advancedcpp.h
@@ -276,7 +276,7 @@
//===========================================================================
extern double my_global_double; // a couple of globals for access testing
extern double my_global_array[500];
-
+extern double* my_global_ptr;
//===========================================================================
class some_class_with_data { // for life-line and identity testing
diff --git a/pypy/module/cppyy/test/advancedcpp.xml b/pypy/module/cppyy/test/advancedcpp.xml
--- a/pypy/module/cppyy/test/advancedcpp.xml
+++ b/pypy/module/cppyy/test/advancedcpp.xml
@@ -34,9 +34,12 @@
<class name="some_class_with_data::some_data" />
<class name="some_comparable" />
- <function name="operator=="/>
- <function name="operator!="/>
+ <function name="operator==" />
+ <function name="operator!=" />
+ <variable name="my_global_double" />
+ <variable name="my_global_array" />
+ <variable name="my_global_ptr" />
<class name="ref_tester" />
<class name="std::vector<ref_tester>" />
diff --git a/pypy/module/cppyy/test/test_advancedcpp.py b/pypy/module/cppyy/test/test_advancedcpp.py
--- a/pypy/module/cppyy/test/test_advancedcpp.py
+++ b/pypy/module/cppyy/test/test_advancedcpp.py
@@ -669,3 +669,14 @@
assert cppyy.gbl.overload_one_way().gime() == 1
assert cppyy.gbl.overload_the_other_way().gime() == "aap"
+
+ def test22_access_to_global_variables(self):
+ """Access global_variables_and_pointers"""
+
+ import cppyy
+
+ assert cppyy.gbl.my_global_double == 12.
+ assert len(cppyy.gbl.my_global_array) == 500
+ # TODO: currently fails b/c double** not understood as &double*
+ #assert cppyy.gbl.my_global_ptr[0] == 1234.
+
More information about the pypy-commit
mailing list