[pypy-commit] pypy cling-support: from Aditi: test_cppyy.py now succeeds

wlav pypy.commits at gmail.com
Thu Jun 30 18:55:22 EDT 2016


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: cling-support
Changeset: r85477:107dd38e12c9
Date: 2016-06-30 15:52 -0700
http://bitbucket.org/pypy/pypy/changeset/107dd38e12c9/

Log:	from Aditi: test_cppyy.py now succeeds

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
@@ -255,6 +255,8 @@
     def convert_argument(self, space, w_obj, address, call_local):
         x = rffi.cast(self.c_ptrtype, address)
         x[0] = self._unwrap_object(space, w_obj)
+        ba = rffi.cast(rffi.CCHARP, address)
+        ba[capi.c_function_arg_typeoffset(space)] = self.typecode
 
 class FloatTypeConverterMixin(NumericTypeConverterMixin):
     _mixin_ = True
@@ -337,7 +339,7 @@
     _immutable_fields_ = ['libffitype', 'typecode']
 
     libffitype = jit_libffi.types.pointer
-    typecode = 'F'
+    typecode = 'f'
 
     def convert_argument_libffi(self, space, w_obj, address, call_local):
         from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
@@ -356,7 +358,7 @@
     _immutable_fields_ = ['libffitype', 'typecode']
 
     libffitype = jit_libffi.types.pointer
-    typecode = 'D'
+    typecode = 'd'
 
 
 class CStringConverter(TypeConverter):
@@ -713,17 +715,18 @@
     "NOT_RPYTHON"
     # signed types (use strtoll in setting of default in __init__)
     type_info = (
-        (rffi.SHORT,      ("short", "short int")),
-        (rffi.INT,        ("int",)),
+        (rffi.SHORT,      ("short", "short int"),      'h'),
+        (rffi.INT,        ("int",),                    'i'),
     )
 
     # constref converters exist only b/c the stubs take constref by value, whereas
     # libffi takes them by pointer (hence it needs the fast-path in testing); note
     # that this is list is not complete, as some classes are specialized
 
-    for c_type, names in type_info:
+    for c_type, names, c_tc in type_info:
         class BasicConverter(ffitypes.typeid(c_type), IntTypeConverterMixin, TypeConverter):
             _immutable_ = True
+            typecode = c_tc
             def __init__(self, space, default):
                 self.default = rffi.cast(self.c_type, capi.c_strtoll(space, default))
         class ConstRefConverter(ConstRefNumericTypeConverterMixin, BasicConverter):
@@ -734,40 +737,35 @@
             _converters["const "+name+"&"] = ConstRefConverter
 
     type_info = (
-        (rffi.LONG,       ("long", "long int")),
-        (rffi.LONGLONG,   ("long long", "long long int", "Long64_t")),
+        (rffi.LONG,       ("long", "long int"),                        'l'),
+        (rffi.LONGLONG,   ("long long", "long long int", "Long64_t"),  'k'),
     )
 
-    for c_type, names in type_info:
+    for c_type, names, c_tc in type_info:
         class BasicConverter(ffitypes.typeid(c_type), IntTypeConverterMixin, TypeConverter):
             _immutable_ = True
+            typecode = c_tc
             def __init__(self, space, default):
                 self.default = rffi.cast(self.c_type, capi.c_strtoll(space, default))
-
         class ConstRefConverter(ConstRefNumericTypeConverterMixin, BasicConverter):
             _immutable_ = True
             libffitype = jit_libffi.types.pointer
-            typecode = 'r'
-            def convert_argument(self, space, w_obj, address, call_local):
-                x = rffi.cast(self.c_ptrtype, address)
-                x[0] = self._unwrap_object(space, w_obj)
-                ba = rffi.cast(rffi.CCHARP, address)
-                ba[capi.c_function_arg_typeoffset(space)] = self.typecode
         for name in names:
             _converters[name] = BasicConverter
             _converters["const "+name+"&"] = ConstRefConverter
 
     # unsigned integer types (use strtoull in setting of default in __init__)
     type_info = (
-        (rffi.USHORT,     ("unsigned short", "unsigned short int")),
-        (rffi.UINT,       ("unsigned", "unsigned int")),
-        (rffi.ULONG,      ("unsigned long", "unsigned long int")),
-        (rffi.ULONGLONG,  ("unsigned long long", "unsigned long long int", "ULong64_t")),
+        (rffi.USHORT,     ("unsigned short", "unsigned short int"),                            'H'),
+        (rffi.UINT,       ("unsigned", "unsigned int"),                                        'I'),
+        (rffi.ULONG,      ("unsigned long", "unsigned long int"),                              'L'),
+        (rffi.ULONGLONG,  ("unsigned long long", "unsigned long long int", "ULong64_t"),       'K'),
     )
 
-    for c_type, names in type_info:
+    for c_type, names, c_tc in type_info:
         class BasicConverter(ffitypes.typeid(c_type), IntTypeConverterMixin, TypeConverter):
             _immutable_ = True
+            typecode = c_tc
             def __init__(self, space, default):
                 self.default = rffi.cast(self.c_type, capi.c_strtoull(space, default))
         class ConstRefConverter(ConstRefNumericTypeConverterMixin, BasicConverter):
@@ -776,6 +774,7 @@
         for name in names:
             _converters[name] = BasicConverter
             _converters["const "+name+"&"] = ConstRefConverter
+
 _build_basic_converters()
 
 # create the array and pointer converters; all real work is in the mixins
@@ -789,6 +788,8 @@
         ('I', rffi.sizeof(rffi.UINT),   ("unsigned int", "unsigned")),
         ('l', rffi.sizeof(rffi.LONG),   ("long int", "long")),
         ('L', rffi.sizeof(rffi.ULONG),  ("unsigned long int", "unsigned long")),
+        ('k', rffi.sizeof(rffi.LONGLONG),("long long", "long long int", "Long64_t")),
+        ('K', rffi.sizeof(rffi.ULONGLONG),("unsigned long long", "unsigned long long int", "ULong64_t")),
         ('f', rffi.sizeof(rffi.FLOAT),  ("float",)),
         ('d', rffi.sizeof(rffi.DOUBLE), ("double",)),
     )
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
@@ -318,8 +318,8 @@
         (rffi.UINT,       capi.c_call_l,   ("unsigned", "unsigned int")),
         (rffi.LONG,       capi.c_call_l,   ("long", "long int")),
         (rffi.ULONG,      capi.c_call_l,   ("unsigned long", "unsigned long int")),
-        (rffi.LONGLONG,   capi.c_call_ll,  ("long long", "long long int")),
-        (rffi.ULONGLONG,  capi.c_call_ll,  ("unsigned long long", "unsigned long long int")),
+        (rffi.LONGLONG,   capi.c_call_ll,  ("long long", "long long int", "Long64_t")),
+        (rffi.ULONGLONG,  capi.c_call_ll,  ("unsigned long long", "unsigned long long int", "ULong64_t")),
         (rffi.FLOAT,      capi.c_call_f,   ("float",)),
         (rffi.DOUBLE,     capi.c_call_d,   ("double",)),
     )
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
@@ -341,9 +341,33 @@
    std::vector<TParameter>& args = *(std::vector<TParameter>*)args_;
    for ( std::vector<TParameter>::size_type i = 0; i < args.size(); ++i ) {
       switch ( args[i].fTypeCode ) {
+      case 'b':          /* bool */
+         vargs[i] = (void*)&args[i].fValue.fBool;
+         break;
+      case 'h':          /* short */
+         vargs[i] = (void*)&args[i].fValue.fShort;
+         break;
+      case 'H':          /* unsigned short */
+         vargs[i] = (void*)&args[i].fValue.fUShort;
+         break;
+      case 'i':          /* int */
+         vargs[i] = (void*)&args[i].fValue.fInt;
+         break;
+      case 'I':          /* unsigned int */
+         vargs[i] = (void*)&args[i].fValue.fUInt;
+         break;
       case 'l':          /* long */
          vargs[i] = (void*)&args[i].fValue.fLong;
          break;
+      case 'L':          /* unsigned long */
+         vargs[i] = (void*)&args[i].fValue.fULong;
+         break;
+      case 'k':          /* long long */
+         vargs[i] = (void*)&args[i].fValue.fLongLong;
+         break;
+      case 'K':          /* unsigned long long */
+         vargs[i] = (void*)&args[i].fValue.fULongLong;
+         break;
       case 'f':          /* double */
          vargs[i] = (void*)&args[i].fValue.fFloat;
          break;
@@ -353,9 +377,7 @@
       case 'D':          /* long double */
          vargs[i] = (void*)&args[i].fValue.fLongDouble;
          break;
-      case 'k':          /* long long */
-      case 'K':          /* unsigned long long */
-      case 'U':          /* unsigned long */
+      case 'o':
       case 'p':          /* void* */
          vargs[i] = (void*)&args[i].fValue.fVoidp;
          break;
@@ -519,6 +541,8 @@
 // scope reflection information ----------------------------------------------
 Bool_t Cppyy::IsNamespace( TCppScope_t scope ) {
 // Test if this scope represents a namespace.
+   if ( scope == GLOBAL_HANDLE )
+      return kTRUE;
    TClassRef& cr = type_from_handle( scope );
    if ( cr.GetClass() )
       return cr->Property() & kIsNamespace;
@@ -665,7 +689,7 @@
    return (TCppIndex_t)0;
 }
 
-Cppyy::TCppIndex_t Cppyy::GetMethodIndexAt( TCppScope_t scope, TCppIndex_t imeth)
+Cppyy::TCppIndex_t Cppyy::GetMethodIndexAt( TCppScope_t scope, TCppIndex_t imeth )
 {
    TClassRef& cr = type_from_handle (scope);
    if (cr.GetClass())
@@ -865,21 +889,8 @@
    TClassRef& cr = type_from_handle( scope );
    if ( cr.GetClass() && cr->GetListOfDataMembers() )
       return cr->GetListOfDataMembers()->GetSize();
-   else if ( scope == (TCppScope_t)GLOBAL_HANDLE ) {
-      std::cerr << " global data should be retrieved lazily " << std::endl;
-      TCollection* vars = gROOT->GetListOfGlobals( kTRUE );
-      if ( g_globalvars.size() != (GlobalVars_t::size_type)vars->GetSize() ) {
-         g_globalvars.clear();
-         g_globalvars.reserve(vars->GetSize());
 
-         TIter ivar(vars);
-
-         TGlobal* var = 0;
-         while ( (var = (TGlobal*)ivar.Next()) )
-            g_globalvars.push_back( var );
-      }
-      return (TCppIndex_t)g_globalvars.size();
-   }
+// global vars (and unknown classes) are always resolved lazily, so report as '0'
    return (TCppIndex_t)0;
 }
 


More information about the pypy-commit mailing list