[pypy-commit] pypy reflex-support: CINT back-end support for test_datatypes.py

wlav noreply at buildbot.pypy.org
Tue Aug 16 23:20:03 CEST 2011


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r46553:e77abeca9517
Date: 2011-08-16 14:26 -0700
http://bitbucket.org/pypy/pypy/changeset/e77abeca9517/

Log:	CINT back-end support for test_datatypes.py

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
@@ -344,6 +344,8 @@
     def convert_argument(self, space, w_obj, address):
         x = rffi.cast(rffi.FLOATP, address)
         x[0] = self._unwrap_object(space, w_obj)
+        typecode = _direct_ptradd(address, capi.c_function_arg_typeoffset())
+        typecode[0] = 'f'
 
     def convert_argument_libffi(self, space, w_obj, argchain):
         from pypy.rlib.rarithmetic import r_singlefloat
diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py
--- a/pypy/module/cppyy/executor.py
+++ b/pypy/module/cppyy/executor.py
@@ -332,7 +332,9 @@
 _executors["short int*"]          = ShortPtrExecutor
 _executors["short*"]              = _executors["short int*"]
 _executors["unsigned short int"]  = ShortExecutor
+_executors["unsigned short"]      = _executors["unsigned short int"]
 _executors["unsigned short int*"] = ShortPtrExecutor
+_executors["unsigned short*"]     = _executors["unsigned short int*"]
 _executors["int"]                 = IntExecutor
 _executors["int*"]                = IntPtrExecutor
 _executors["const int&"]          = ConstIntRefExecutor
diff --git a/pypy/module/cppyy/src/cintcwrapper.cxx b/pypy/module/cppyy/src/cintcwrapper.cxx
--- a/pypy/module/cppyy/src/cintcwrapper.cxx
+++ b/pypy/module/cppyy/src/cintcwrapper.cxx
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <iostream>
 #include <map>
+#include <sstream>
 #include <string>
 #include <utility>
 
@@ -74,6 +75,19 @@
 }
 
 
+static inline void fixup_args(G__param* libp) {
+    for (int i = 0; i < libp->paran; ++i) {
+        libp->para[i].ref = libp->para[i].obj.i;
+        if (libp->para[i].type == 'f') {
+            assert(sizeof(float) <= sizeof(long));
+            long val = libp->para[i].obj.i;
+            void* pval = (void*)&val;
+            libp->para[i].obj.d = *(float*)pval;
+        }
+    }
+}
+
+
 /* name to handle --------------------------------------------------------- */
 cppyy_typehandle_t cppyy_get_typehandle(const char* class_name) {
     ClassRefIndices_t::iterator icr = g_classref_indices.find(class_name);
@@ -124,8 +138,7 @@
     G__InterfaceMethod meth = (G__InterfaceMethod)m->InterfaceMethod();
     G__param* libp = (G__param*)((char*)args - offsetof(G__param, para));
     assert(libp->paran == numargs);
-    for (int i = 0; i < numargs; ++i)
-        libp->para[i].ref = libp->para[i].obj.i;
+    fixup_args(libp);
 
     // TODO: access to store_struct_offset won't work on Windows
     G__setgvp((long)self);
@@ -150,8 +163,7 @@
     G__InterfaceMethod meth = (G__InterfaceMethod)m->InterfaceMethod();
     G__param* libp = (G__param*)((char*)args - offsetof(G__param, para));
     assert(libp->paran == numargs);
-    for (int i = 0; i < numargs; ++i)
-        libp->para[i].ref = libp->para[i].obj.i;
+    fixup_args(libp);
 
     // TODO: access to store_struct_offset won't work on Windows
     G__setgvp((long)self);
@@ -372,13 +384,21 @@
 char* cppyy_data_member_type(cppyy_typehandle_t handle, int data_member_index) {
     TClassRef cr = type_from_handle(handle);
     TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At(data_member_index);
-    return cppstring_to_cstring(m->GetFullTypeName());
+    std::string fullType = m->GetFullTypeName();
+    if ((int)m->GetArrayDim() > 1 || (!m->IsBasic() && m->IsaPointer()))
+        fullType.append("*");
+    else if ((int)m->GetArrayDim() == 1) {
+        std::ostringstream s;
+        s << '[' << m->GetMaxIndex(0) << ']' << std::ends;
+        fullType.append(s.str());
+    }
+    return cppstring_to_cstring(fullType);
 }
 
 size_t cppyy_data_member_offset(cppyy_typehandle_t handle, int data_member_index) {
     TClassRef cr = type_from_handle(handle);
     TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At(data_member_index);
-    return m->GetOffset();
+    return m->GetOffsetCint();
 }
 
 
diff --git a/pypy/module/cppyy/test/datatypes_LinkDef.h b/pypy/module/cppyy/test/datatypes_LinkDef.h
new file mode 100644
--- /dev/null
+++ b/pypy/module/cppyy/test/datatypes_LinkDef.h
@@ -0,0 +1,14 @@
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ struct cppyy_test_pod;
+#pragma link C++ class cppyy_test_data;
+#pragma link C++ function get_pod_address(cppyy_test_data&);
+#pragma link C++ function get_int_address(cppyy_test_data&);
+#pragma link C++ function get_double_address(cppyy_test_data&);
+#pragma link C++ variable N;
+
+#endif


More information about the pypy-commit mailing list