Commits

wlav committed 2d45870

integer and floating point array return types and data member access

  • Participants
  • Parent commits d300522
  • Branches reflex-support

Comments (0)

Files changed (3)

File pypy/module/cppyy/converter.py

     typecode = 'l'
     typesize = 4
 
+class FloatArrayConverter(ArrayTypeConverter):
+    _immutable_ = True
+    typecode = 'f'
+    typesize = 4
+
+class DoubleArrayConverter(ArrayTypeConverter):
+    _immutable_ = True
+    typecode = 'd'
+    typesize = 8
+
 
 class ShortPtrConverter(PtrTypeConverter):
     _immutable_ = True
     typecode = 'l'
     typesize = 4
 
+class FloatPtrConverter(PtrTypeConverter):
+    _immutable_ = True
+    typecode = 'f'
+    typesize = 4
+
+class DoublePtrConverter(PtrTypeConverter):
+    _immutable_ = True
+    typecode = 'd'
+    typesize = 8
+
 
 class InstancePtrConverter(TypeConverter):
     _immutable_ = True
 _converters["unsigned long int*"]       = LongPtrConverter
 _converters["unsigned long int[]"]      = LongArrayConverter
 _converters["float"]                    = FloatConverter
+_converters["float*"]                   = FloatPtrConverter
+_converters["float[]"]                  = FloatArrayConverter
 _converters["double"]                   = DoubleConverter
+_converters["double*"]                  = DoublePtrConverter
+_converters["double[]"]                 = DoubleArrayConverter
 _converters["const char*"]              = CStringConverter

File pypy/module/cppyy/executor.py

         raise FastCallNotPossible
 
 
-class ArrayExecutor(FunctionExecutor):
+class PtrTypeExecutor(FunctionExecutor):
     _immutable_ = True
+    typecode = ''
+
+    def execute(self, space, func, cppthis, num_args, args):
+        lresult = capi.c_call_l(func.cpptype.handle, func.method_index, cppthis, num_args, args)
+        spresult = rffi.cast(rffi.SHORTP, lresult)
+        arr = space.interp_w(W_Array, unpack_simple_shape(space, space.wrap(self.typecode)))
+        return arr.fromaddress(space, spresult, sys.maxint)
 
 
 class VoidExecutor(FunctionExecutor):
         libffifunc.call(argchain, lltype.Void)
         return space.w_None
 
+
 class BoolExecutor(FunctionExecutor):
     _immutable_ = True
     def execute(self, space, func, cppthis, num_args, args):
         return space.wrap(result)
 
 
-class ShortArrayExecutor(ArrayExecutor):
+class ShortPtrExecutor(PtrTypeExecutor):
     _immutable_ = True
-    def execute(self, space, func, cppthis, num_args, args):
-        lresult = capi.c_call_l(func.cpptype.handle, func.method_index, cppthis, num_args, args)
-        spresult = rffi.cast(rffi.SHORTP, lresult)
-        arr = space.interp_w(W_Array, unpack_simple_shape(space, space.wrap('h')))
-        return arr.fromaddress(space, spresult, sys.maxint)
+    typecode = 'h'
+
+class LongPtrExecutor(PtrTypeExecutor):
+    _immutable_ = True
+    typecode = 'l'
+
+class FloatPtrExecutor(PtrTypeExecutor):
+    _immutable_ = True
+    typecode = 'f'
+
+class DoublePtrExecutor(PtrTypeExecutor):
+    _immutable_ = True
+    typecode = 'd'
 
 
 class InstancePtrExecutor(FunctionExecutor):
 _executors["char"]                = CharExecutor
 _executors["unsigned char"]       = CharExecutor
 _executors["short int"]           = ShortExecutor
-_executors["short int*"]          = ShortArrayExecutor
+_executors["short int*"]          = ShortPtrExecutor
 _executors["unsigned short int"]  = ShortExecutor
+_executors["unsigned short int*"] = ShortPtrExecutor
 _executors["int"]                 = LongExecutor
+_executors["int*"]                = LongPtrExecutor
 _executors["unsigned int"]        = LongExecutor
+_executors["unsigned int*"]       = LongPtrExecutor
 _executors["long int"]            = LongExecutor
+_executors["long int*"]           = LongPtrExecutor
 _executors["unsigned long int"]   = LongExecutor
+_executors["unsigned long int*"]  = LongPtrExecutor
 _executors["float"]               = FloatExecutor
+_executors["float*"]              = FloatPtrExecutor
 _executors["double"]              = DoubleExecutor
+_executors["double*"]             = DoublePtrExecutor
 _executors["char*"]               = CStringExecutor

File pypy/module/cppyy/test/test_datatypes.py

             assert c.get_short_array()[i]   ==  -1*i
             assert c.m_short_array2[i]      ==  -2*i
             assert c.get_short_array2()[i]  ==  -2*i
-            """
             assert c.m_ushort_array[i]      ==   3*i
             assert c.get_ushort_array()[i]  ==   3*i
             assert c.m_ushort_array2[i]     ==   4*i
             assert round(c.m_float_array2[i]  + 14.*i, 5) == 0
             assert round(c.m_double_array[i]  + 15.*i, 8) == 0
             assert round(c.m_double_array2[i] + 16.*i, 8) == 0
-            """
 
-        """
         # out-of-bounds checks
         raises(IndexError, c.m_short_array.__getitem__,  self.N)
         raises(IndexError, c.m_ushort_array.__getitem__, self.N)
         raises(IndexError, c.m_ulong_array.__getitem__,  self.N)
         raises(IndexError, c.m_float_array.__getitem__,  self.N)
         raises(IndexError, c.m_double_array.__getitem__, self.N)
-        """
 
         c.destruct()