[pypy-svn] r76481 - in pypy/branch/reflex-support/pypy/module/cppyy: . include src test
wlav at codespeak.net
wlav at codespeak.net
Thu Aug 5 00:10:48 CEST 2010
Author: wlav
Date: Thu Aug 5 00:10:46 2010
New Revision: 76481
Modified:
pypy/branch/reflex-support/pypy/module/cppyy/capi.py
pypy/branch/reflex-support/pypy/module/cppyy/converter.py
pypy/branch/reflex-support/pypy/module/cppyy/executor.py
pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h
pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx
pypy/branch/reflex-support/pypy/module/cppyy/test/test_datatypes.py
Log:
Executors and converters for more integer types
Modified: pypy/branch/reflex-support/pypy/module/cppyy/capi.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/capi.py (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/capi.py Thu Aug 5 00:10:46 2010
@@ -54,6 +54,10 @@
"cppyy_call_c",
[C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.CHAR,
compilation_info=eci)
+c_call_h = rffi.llexternal(
+ "cppyy_call_h",
+ [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.SHORT,
+ compilation_info=eci)
c_call_l = rffi.llexternal(
"cppyy_call_l",
[C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.LONG,
Modified: pypy/branch/reflex-support/pypy/module/cppyy/converter.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/converter.py (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/converter.py Thu Aug 5 00:10:46 2010
@@ -12,14 +12,18 @@
obj = space.interpclass_w(space.findattr(w_obj, space.wrap("_cppinstance")))
return lltype.direct_ptradd(obj.rawobject, offset)
+ def _is_abstract(self):
+ raise NotImplementedError(
+ "abstract base class (actual: %s)" % type(self).__name__)
+
def convert_argument(self, space, w_obj):
- raise NotImplementedError("abstract base class")
+ self._is_abstract()
def from_memory(self, space, w_obj, offset):
- raise NotImplementedError("abstract base class")
+ self._is_abstract()
def to_memory(self, space, w_obj, w_value, offset):
- raise NotImplementedError("abstract base class")
+ self._is_abstract()
def free_argument(self, arg):
lltype.free(arg, flavor='raw')
@@ -73,13 +77,36 @@
fieldptr = self._get_fieldptr(space, w_obj, offset)
fieldptr[0] = self._from_space(space, w_value)
-class IntConverter(TypeConverter):
+class LongConverter(TypeConverter):
def convert_argument(self, space, w_obj):
arg = space.c_int_w(w_obj)
x = lltype.malloc(rffi.LONGP.TO, 1, flavor='raw')
x[0] = arg
return rffi.cast(rffi.VOIDP, x)
+ def from_memory(self, space, w_obj, offset):
+ fieldptr = self._get_fieldptr(space, w_obj, offset)
+ longptr = rffi.cast(rffi.LONGP, fieldptr)
+ return space.wrap(longptr[0])
+
+ def to_memory(self, space, w_obj, w_value, offset):
+ fieldptr = self._get_fieldptr(space, w_obj, offset)
+ longptr = rffi.cast(rffi.LONGP, fieldptr)
+ longptr[0] = space.c_int_w(w_value)
+
+class ShortConverter(LongConverter):
+ def from_memory(self, space, w_obj, offset):
+ fieldptr = self._get_fieldptr(space, w_obj, offset)
+ intptr = rffi.cast(rffi.SHORTP, fieldptr)
+ return space.wrap(intptr[0])
+
+ def to_memory(self, space, w_obj, w_value, offset):
+ import struct
+ fieldptr = self._get_fieldptr(space, w_obj, offset)
+ pack = struct.pack('h', space.unwrap(w_value)) # unchecked
+ fieldptr[0] = pack[0]
+ fieldptr[1] = pack[1]
+
class FloatConverter(TypeConverter):
def convert_argument(self, space, w_obj):
arg = space.float_w(w_obj)
@@ -173,7 +200,12 @@
_converters["bool"] = BoolConverter()
_converters["char"] = CharConverter()
_converters["unsigned char"] = CharConverter()
-_converters["int"] = IntConverter()
+_converters["short int"] = ShortConverter()
+_converters["unsigned short int"] = ShortConverter()
+_converters["int"] = LongConverter()
+_converters["unsigned int"] = LongConverter()
+_converters["long int"] = LongConverter()
+_converters["unsigned long int"] = LongConverter()
_converters["float"] = FloatConverter()
_converters["double"] = DoubleConverter()
_converters["const char*"] = CStringConverter()
Modified: pypy/branch/reflex-support/pypy/module/cppyy/executor.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/executor.py (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/executor.py Thu Aug 5 00:10:46 2010
@@ -7,7 +7,8 @@
class FunctionExecutor(object):
def execute(self, space, func, cppthis, num_args, args):
- raise NotImplementedError("abstract base class")
+ raise NotImplementedError(
+ "abstract base class (actual: %s)" % type(self).__name__)
class VoidExecutor(FunctionExecutor):
@@ -15,6 +16,7 @@
capi.c_call_v(func.cpptype.handle, func.method_index, cppthis, num_args, args)
return space.w_None
+
class BoolExecutor(FunctionExecutor):
def execute(self, space, func, cppthis, num_args, args):
result = capi.c_call_b(func.cpptype.handle, func.method_index, cppthis, num_args, args)
@@ -25,6 +27,11 @@
result = capi.c_call_c(func.cpptype.handle, func.method_index, cppthis, num_args, args)
return space.wrap(result)
+class ShortExecutor(FunctionExecutor):
+ def execute(self, space, func, cppthis, num_args, args):
+ result = capi.c_call_h(func.cpptype.handle, func.method_index, cppthis, num_args, args)
+ return space.wrap(result)
+
class LongExecutor(FunctionExecutor):
def execute(self, space, func, cppthis, num_args, args):
result = capi.c_call_l(func.cpptype.handle, func.method_index, cppthis, num_args, args)
@@ -81,8 +88,12 @@
_executors["bool"] = BoolExecutor()
_executors["char"] = CharExecutor()
_executors["unsigned char"] = CharExecutor()
+_executors["short int"] = ShortExecutor()
+_executors["unsigned short int"] = ShortExecutor()
_executors["int"] = LongExecutor()
+_executors["unsigned int"] = LongExecutor()
_executors["long int"] = LongExecutor()
+_executors["unsigned long int"] = LongExecutor()
_executors["float"] = FloatExecutor()
_executors["double"] = DoubleExecutor()
_executors["char*"] = CStringExecutor()
Modified: pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h Thu Aug 5 00:10:46 2010
@@ -18,6 +18,7 @@
void cppyy_call_v(cppyy_typehandle_t handle, int method_index, cppyy_object_t self, int numargs, void* args[]);
int cppyy_call_b(cppyy_typehandle_t handle, int method_index, cppyy_object_t self, int numargs, void* args[]);
char cppyy_call_c(cppyy_typehandle_t handle, int method_index, cppyy_object_t self, int numargs, void* args[]);
+ short cppyy_call_h(cppyy_typehandle_t handle, int method_index, cppyy_object_t self, int numargs, void* args[]);
long cppyy_call_l(cppyy_typehandle_t handle, int method_index, cppyy_object_t self, int numargs, void* args[]);
double cppyy_call_f(cppyy_typehandle_t handle, int method_index, cppyy_object_t self, int numargs, void* args[]);
double cppyy_call_d(cppyy_typehandle_t handle, int method_index, cppyy_object_t self, int numargs, void* args[]);
Modified: pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx Thu Aug 5 00:10:46 2010
@@ -58,6 +58,11 @@
return cppyy_call_T<char>(handle, method_index, self, numargs, args);
}
+short cppyy_call_h(cppyy_typehandle_t handle, int method_index,
+ cppyy_object_t self, int numargs, void* args[]) {
+ return cppyy_call_T<short>(handle, method_index, self, numargs, args);
+}
+
long cppyy_call_l(cppyy_typehandle_t handle, int method_index,
cppyy_object_t self, int numargs, void* args[]) {
return cppyy_call_T<long>(handle, method_index, self, numargs, args);
Modified: pypy/branch/reflex-support/pypy/module/cppyy/test/test_datatypes.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/test/test_datatypes.py (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/test/test_datatypes.py Thu Aug 5 00:10:46 2010
@@ -72,7 +72,6 @@
raises(TypeError, 'c.set_uchar("string")')
# TODO: raises(TypeError, 'c.set_uchar(-1)')
- """
# integer types
names = ['short', 'ushort', 'int', 'uint', 'long', 'ulong']
for i in range(len(names)):
@@ -82,7 +81,6 @@
for i in range(len(names)):
exec 'c.set_%s = %d' % (names[i],2*i)
assert eval('c.m_%s' % names[i]) == i
- """
# float types through functions
c.set_float( 0.123 ); assert round(c.get_float() - 0.123, 5) == 0
More information about the Pypy-commit
mailing list