[pypy-svn] pypy reflex-support: integer and floating point array return types and data member access
wlav
commits-noreply at bitbucket.org
Sat Feb 5 00:06:37 CET 2011
Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r41621:2d45870d5299
Date: 2011-02-04 15:05 -0800
http://bitbucket.org/pypy/pypy/changeset/2d45870d5299/
Log: integer and floating point array return types and data member access
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
@@ -25,8 +25,15 @@
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):
@@ -40,6 +47,7 @@
libffifunc.call(argchain, lltype.Void)
return space.w_None
+
class BoolExecutor(FunctionExecutor):
_immutable_ = True
def execute(self, space, func, cppthis, num_args, args):
@@ -100,13 +108,21 @@
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):
@@ -146,12 +162,19 @@
_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
diff --git a/pypy/module/cppyy/test/test_datatypes.py b/pypy/module/cppyy/test/test_datatypes.py
--- a/pypy/module/cppyy/test/test_datatypes.py
+++ b/pypy/module/cppyy/test/test_datatypes.py
@@ -66,7 +66,6 @@
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
@@ -93,9 +92,7 @@
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)
@@ -105,7 +102,6 @@
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()
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
@@ -261,6 +261,16 @@
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
@@ -279,6 +289,16 @@
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
@@ -364,5 +384,9 @@
_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
More information about the Pypy-commit
mailing list