[pypy-commit] pypy reflex-support: (cfbolz, wlav) 64bit support

wlav noreply at buildbot.pypy.org
Tue Jul 12 15:29:20 CEST 2011


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r45513:dfa7b7d296fa
Date: 2011-07-12 06:24 -0700
http://bitbucket.org/pypy/pypy/changeset/dfa7b7d296fa/

Log:	(cfbolz, wlav) 64bit support

diff --git a/pypy/module/cppyy/capi/reflex_capi.py b/pypy/module/cppyy/capi/reflex_capi.py
--- a/pypy/module/cppyy/capi/reflex_capi.py
+++ b/pypy/module/cppyy/capi/reflex_capi.py
@@ -107,6 +107,10 @@
     "cppyy_call_h",
     [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.SHORT,
     compilation_info=eci)
+c_call_i = rffi.llexternal(
+    "cppyy_call_l",
+    [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.INT,
+    compilation_info=eci)
 c_call_l = rffi.llexternal(
     "cppyy_call_l",
     [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.LONG,
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
@@ -100,7 +100,8 @@
             address[i] = buf.getitem(i)
 
 
-class PtrTypeConverter(TypeConverter):
+class PtrTypeConverterMixin(object):
+    _mixin_ = True
     _immutable_ = True
 
     def __init__(self, space, array_size):
@@ -204,12 +205,61 @@
         address = self._get_raw_address(space, w_obj, offset)
         address[0] = self._from_space(space, w_value)
 
+class IntConverter(TypeConverter):
+    _immutable = True
+    libffitype = libffi.types.sint
+
+    def _unwrap_object(self, space, w_obj):
+        return rffi.cast(rffi.INT, space.c_int_w(w_obj))
+
+    def convert_argument(self, space, w_obj):
+        arg = self._unwrap_object(space, w_obj)
+        x = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
+        x[0] = arg
+        return rffi.cast(rffi.VOIDP, x)
+
+    def convert_argument_libffi(self, space, w_obj, argchain):
+        argchain.arg(self._unwrap_object(space, w_obj))
+
+    def from_memory(self, space, w_obj, offset):
+        address = self._get_raw_address(space, w_obj, offset)
+        intptr = rffi.cast(rffi.INTP, address)
+        return space.wrap(intptr[0])
+
+    def to_memory(self, space, w_obj, w_value, offset):
+        address = self._get_raw_address(space, w_obj, offset)
+        intptr = rffi.cast(rffi.INTP, address)
+        intptr[0] = self._unwrap_object(space, w_value)
+
+class UnsignedIntConverter(TypeConverter):
+    _immutable = True
+    libffitype = libffi.types.uint
+
+    def _unwrap_object(self, space, w_obj):
+        return rffi.cast(rffi.UINT, space.uint_w(w_obj))
+
+    def convert_argument(self, space, w_obj):
+        arg = self._unwrap_object(space, w_obj)
+        x = lltype.malloc(rffi.UINTP.TO, 1, flavor='raw')
+        x[0] = arg
+        return rffi.cast(rffi.VOIDP, x)
+
+    def from_memory(self, space, w_obj, offset):
+        address = self._get_raw_address(space, w_obj, offset)
+        ulongptr = rffi.cast(rffi.UINTP, address)
+        return space.wrap(ulongptr[0])
+
+    def to_memory(self, space, w_obj, w_value, offset):
+        address = self._get_raw_address(space, w_obj, offset)
+        ulongptr = rffi.cast(rffi.UINTP, address)
+        ulongptr[0] = self._unwrap_object(space, w_value)
+
 class LongConverter(TypeConverter):
     _immutable = True
     libffitype = libffi.types.slong
 
     def _unwrap_object(self, space, w_obj):
-        return space.c_int_w(w_obj)
+        return space.int_w(w_obj)
 
     def convert_argument(self, space, w_obj):
         arg = self._unwrap_object(space, w_obj)
@@ -228,7 +278,7 @@
     def to_memory(self, space, w_obj, w_value, offset):
         address = self._get_raw_address(space, w_obj, offset)
         longptr = rffi.cast(rffi.LONGP, address)
-        longptr[0] = space.c_int_w(w_value)
+        longptr[0] = self._unwrap_object(space, w_value)
 
 class UnsignedLongConverter(TypeConverter):
     _immutable = True
@@ -251,7 +301,7 @@
     def to_memory(self, space, w_obj, w_value, offset):
         address = self._get_raw_address(space, w_obj, offset)
         ulongptr = rffi.cast(rffi.ULONGP, address)
-        ulongptr[0] = space.c_uint_w(w_value)
+        ulongptr[0] = self._unwrap_object(space, w_value)
 
 class ShortConverter(LongConverter):
     _immutable = True
@@ -287,7 +337,7 @@
     def to_memory(self, space, w_obj, w_value, offset):
         address = self._get_raw_address(space, w_obj, offset)
         floatptr = rffi.cast(rffi.FLOATP, address)
-        floatptr[0] = r_singlefloat(space.float_w(w_value))
+        floatptr[0] = self._unwrap_object(space, w_value)
 
 class DoubleConverter(TypeConverter):
     _immutable = True
@@ -312,7 +362,7 @@
     def to_memory(self, space, w_obj, w_value, offset):
         address = self._get_raw_address(space, w_obj, offset)
         doubleptr = rffi.cast(rffi.DOUBLEP, address)
-        doubleptr[0] = space.float_w(w_value)
+        doubleptr[0] = self._unwrap_object(space, w_value)
 
 
 class CStringConverter(TypeConverter):
@@ -327,43 +377,63 @@
 class ShortArrayConverter(ArrayTypeConverterMixin, TypeConverter):
     _immutable_=True
     typecode = 'h'
-    typesize = 2
+    typesize = rffi.sizeof(rffi.SHORT)
+
+class IntArrayConverter(ArrayTypeConverterMixin, TypeConverter):
+    _immutable_=True
+    typecode = 'i'
+    typesize = rffi.sizeof(rffi.INT)
+
+class UnsignedIntArrayConverter(ArrayTypeConverterMixin, TypeConverter):
+    _immutable_=True
+    typecode = 'I'
+    typesize = rffi.sizeof(rffi.UINT)
 
 class LongArrayConverter(ArrayTypeConverterMixin, TypeConverter):
     _immutable_=True
     typecode = 'l'
-    typesize = 4
+    typesize = rffi.sizeof(rffi.LONG)
 
 class FloatArrayConverter(ArrayTypeConverterMixin, TypeConverter):
     _immutable_=True
     typecode = 'f'
-    typesize = 4
+    typesize = rffi.sizeof(rffi.FLOAT)
 
 class DoubleArrayConverter(ArrayTypeConverterMixin, TypeConverter):
     _immutable_=True
     typecode = 'd'
-    typesize = 8
+    typesize = rffi.sizeof(rffi.DOUBLE)
 
 
-class ShortPtrConverter(PtrTypeConverter):
+class ShortPtrConverter(PtrTypeConverterMixin, TypeConverter):
     _immutable_=True
     typecode = 'h'
-    typesize = 2
+    typesize = rffi.sizeof(rffi.SHORT)
 
-class LongPtrConverter(PtrTypeConverter):
+class IntPtrConverter(PtrTypeConverterMixin, TypeConverter):
+    _immutable_=True
+    typecode = 'i'
+    typesize = rffi.sizeof(rffi.INT)
+
+class UnsignedIntPtrConverter(PtrTypeConverterMixin, TypeConverter):
+    _immutable_=True
+    typecode = 'I'
+    typesize = rffi.sizeof(rffi.UINT)
+
+class LongPtrConverter(PtrTypeConverterMixin, TypeConverter):
     _immutable_=True
     typecode = 'l'
-    typesize = 4
+    typesize = rffi.sizeof(rffi.LONG)
 
-class FloatPtrConverter(PtrTypeConverter):
+class FloatPtrConverter(PtrTypeConverterMixin, TypeConverter):
     _immutable_=True
     typecode = 'f'
-    typesize = 4
+    typesize = rffi.sizeof(rffi.FLOAT)
 
-class DoublePtrConverter(PtrTypeConverter):
+class DoublePtrConverter(PtrTypeConverterMixin, TypeConverter):
     _immutable_=True
     typecode = 'd'
-    typesize = 8
+    typesize = rffi.sizeof(rffi.DOUBLE)
 
 
 class InstancePtrConverter(TypeConverter):
@@ -474,12 +544,12 @@
 _converters["unsigned short int"]       = ShortConverter
 _converters["unsigned short int*"]      = ShortPtrConverter
 _converters["unsigned short int[]"]     = ShortArrayConverter
-_converters["int"]                      = LongConverter
-_converters["int*"]                     = LongPtrConverter
-_converters["int[]"]                    = LongArrayConverter
-_converters["unsigned int"]             = UnsignedLongConverter
-_converters["unsigned int*"]            = LongPtrConverter
-_converters["unsigned int[]"]           = LongArrayConverter
+_converters["int"]                      = IntConverter
+_converters["int*"]                     = IntPtrConverter
+_converters["int[]"]                    = IntArrayConverter
+_converters["unsigned int"]             = UnsignedIntConverter
+_converters["unsigned int*"]            = UnsignedIntPtrConverter
+_converters["unsigned int[]"]           = UnsignedIntArrayConverter
 _converters["long int"]                 = LongConverter
 _converters["long int*"]                = LongPtrConverter
 _converters["long int[]"]               = LongArrayConverter
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
@@ -33,7 +33,7 @@
 
     def execute(self, space, func, cppthis, num_args, args):
         lresult = capi.c_call_l(func.cpptype.handle, func.method_index, cppthis, num_args, args)
-        address = rffi.cast(rffi.UINT, lresult)
+        address = rffi.cast(rffi.ULONG, lresult)
         arr = space.interp_w(W_Array, unpack_simple_shape(space, space.wrap(self.typecode)))
         return arr.fromaddress(space, address, sys.maxint)
 
@@ -72,6 +72,32 @@
         result = capi.c_call_h(func.cpptype.handle, func.method_index, cppthis, num_args, args)
         return space.wrap(result)
 
+class IntExecutor(FunctionExecutor):
+    _immutable_ = True
+    libffitype = libffi.types.sint
+
+    def _wrap_result(self, space, result):
+        return space.wrap(result)
+
+    def execute(self, space, func, cppthis, num_args, args):
+        result = capi.c_call_i(func.cpptype.handle, func.method_index, cppthis, num_args, args)
+        return self._wrap_result(space, result)
+
+# TODO: check whether the following is correct (return type cast):
+#   def execute_libffi(self, space, libffifunc, argchain):
+#       return space.wrap(libffifunc.call(argchain, rffi.INT))
+
+class UnsignedIntExecutor(FunctionExecutor):
+    _immutable_ = True
+    libffitype = libffi.types.uint
+
+    def _wrap_result(self, space, result):
+        return space.wrap(result)
+
+    def execute(self, space, func, cppthis, num_args, args):
+        result = capi.c_call_i(func.cpptype.handle, func.method_index, cppthis, num_args, args)
+        return self._wrap_result(space, result)
+
 class LongExecutor(FunctionExecutor):
     _immutable_ = True
     libffitype = libffi.types.slong
@@ -86,6 +112,13 @@
     def execute_libffi(self, space, libffifunc, argchain):
         return space.wrap(libffifunc.call(argchain, lltype.Signed))
 
+class ConstIntRefExecutor(LongExecutor):
+    _immutable_ = True
+
+    def _wrap_result(self, space, result):
+        intptr = rffi.cast(rffi.INTP, result)
+        return space.wrap(intptr[0])
+
 class ConstLongRefExecutor(LongExecutor):
     _immutable_ = True
 
@@ -125,6 +158,14 @@
     _immutable_ = True
     typecode = 'h'
 
+class IntPtrExecutor(PtrTypeExecutor):
+    _immutable_ = True
+    typecode = 'i'
+
+class UnsignedIntPtrExecutor(PtrTypeExecutor):
+    _immutable_ = True
+    typecode = 'I'
+
 class LongPtrExecutor(PtrTypeExecutor):
     _immutable_ = True
     typecode = 'l'
@@ -226,12 +267,12 @@
 _executors["short int*"]          = ShortPtrExecutor
 _executors["unsigned short int"]  = ShortExecutor
 _executors["unsigned short int*"] = ShortPtrExecutor
-_executors["int"]                 = LongExecutor
-_executors["int*"]                = LongPtrExecutor
-_executors["const int&"]          = ConstLongRefExecutor
-_executors["int&"]                = ConstLongRefExecutor
-_executors["unsigned int"]        = LongExecutor
-_executors["unsigned int*"]       = LongPtrExecutor
+_executors["int"]                 = IntExecutor
+_executors["int*"]                = IntPtrExecutor
+_executors["const int&"]          = ConstIntRefExecutor
+_executors["int&"]                = ConstIntRefExecutor
+_executors["unsigned int"]        = UnsignedIntExecutor
+_executors["unsigned int*"]       = UnsignedIntPtrExecutor
 _executors["long int"]            = LongExecutor
 _executors["long int*"]           = LongPtrExecutor
 _executors["unsigned long int"]   = LongExecutor
diff --git a/pypy/module/cppyy/include/capi.h b/pypy/module/cppyy/include/capi.h
--- a/pypy/module/cppyy/include/capi.h
+++ b/pypy/module/cppyy/include/capi.h
@@ -25,6 +25,7 @@
     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[]);
+    int    cppyy_call_i(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[]);
diff --git a/pypy/module/cppyy/src/reflexcwrapper.cxx b/pypy/module/cppyy/src/reflexcwrapper.cxx
--- a/pypy/module/cppyy/src/reflexcwrapper.cxx
+++ b/pypy/module/cppyy/src/reflexcwrapper.cxx
@@ -151,6 +151,11 @@
     return cppyy_call_T<short>(handle, method_index, self, numargs, args);
 }
 
+int cppyy_call_i(cppyy_typehandle_t handle, int method_index,
+                  cppyy_object_t self, int numargs, void* args[]) {
+    return cppyy_call_T<int>(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);
diff --git a/pypy/module/cppyy/test/advancedcpp.cxx b/pypy/module/cppyy/test/advancedcpp.cxx
--- a/pypy/module/cppyy/test/advancedcpp.cxx
+++ b/pypy/module/cppyy/test/advancedcpp.cxx
@@ -25,6 +25,15 @@
 int a_ns::d_ns::e_class::f_class::s_f = 66;
 
 
+// for template testing
+template class T1<int>;
+template class T2<T1<int> >;
+template class T3<int, double>;
+template class T3<T1<int>, T2<T1<int> > >;
+template class a_ns::T4<int>;
+template class a_ns::T4<a_ns::T4<T3<int, double> > >;
+
+
 // helpers for checking pass-by-ref
 void set_int_through_ref(int& i, int val)             { i = val; }
 int pass_int_through_const_ref(const int& i)          { return i; }
diff --git a/pypy/module/cppyy/test/advancedcpp.h b/pypy/module/cppyy/test/advancedcpp.h
--- a/pypy/module/cppyy/test/advancedcpp.h
+++ b/pypy/module/cppyy/test/advancedcpp.h
@@ -176,12 +176,12 @@
 
 } // namespace a_ns
 
-template class T1<int>;
-template class T2<T1<int> >;
-template class T3<int, double>;
-template class T3<T1<int>, T2<T1<int> > >;
-template class a_ns::T4<int>;
-template class a_ns::T4<a_ns::T4<T3<int, double> > >;
+extern template class T1<int>;
+extern template class T2<T1<int> >;
+extern template class T3<int, double>;
+extern template class T3<T1<int>, T2<T1<int> > >;
+extern template class a_ns::T4<int>;
+extern template class a_ns::T4<a_ns::T4<T3<int, double> > >;
 
 
 //===========================================================================
diff --git a/pypy/module/cppyy/test/stltypes.cxx b/pypy/module/cppyy/test/stltypes.cxx
--- a/pypy/module/cppyy/test/stltypes.cxx
+++ b/pypy/module/cppyy/test/stltypes.cxx
@@ -1,1 +1,16 @@
 #include "stltypes.h"
+
+#define STLTYPES_EXPLICIT_INSTANTIATION(STLTYPE, TTYPE)                         \
+template class std::STLTYPE< TTYPE >;                                           \
+template class __gnu_cxx::__normal_iterator<TTYPE*, std::STLTYPE< TTYPE > >;    \
+template class __gnu_cxx::__normal_iterator<const TTYPE*, std::STLTYPE< TTYPE > >;\
+namespace __gnu_cxx {                                                           \
+template bool operator==(const std::STLTYPE< TTYPE >::iterator&,                \
+                         const std::STLTYPE< TTYPE >::iterator&);               \
+template bool operator!=(const std::STLTYPE< TTYPE >::iterator&,                \
+                         const std::STLTYPE< TTYPE >::iterator&);               \
+}
+
+//- explicit instantiations of used types
+STLTYPES_EXPLICIT_INSTANTIATION(vector, int)
+STLTYPES_EXPLICIT_INSTANTIATION(vector, just_a_class)
diff --git a/pypy/module/cppyy/test/stltypes.h b/pypy/module/cppyy/test/stltypes.h
--- a/pypy/module/cppyy/test/stltypes.h
+++ b/pypy/module/cppyy/test/stltypes.h
@@ -3,14 +3,14 @@
 #include <string>
 #include <vector>
 
-#define STLTYPES_EXPLICIT_INSTANTIATION(STLTYPE, TTYPE)                         \
-template class std::STLTYPE< TTYPE >;                                           \
-template class __gnu_cxx::__normal_iterator<TTYPE*, std::STLTYPE< TTYPE > >;    \
-template class __gnu_cxx::__normal_iterator<const TTYPE*, std::STLTYPE< TTYPE > >;\
+#define STLTYPES_EXPLICIT_INSTANTIATION_DECL(STLTYPE, TTYPE)                    \
+extern template class std::STLTYPE< TTYPE >;                                    \
+extern template class __gnu_cxx::__normal_iterator<TTYPE*, std::STLTYPE< TTYPE > >;\
+extern template class __gnu_cxx::__normal_iterator<const TTYPE*, std::STLTYPE< TTYPE > >;\
 namespace __gnu_cxx {                                                           \
-template bool operator==(const std::STLTYPE< TTYPE >::iterator&,                \
+extern template bool operator==(const std::STLTYPE< TTYPE >::iterator&,         \
                          const std::STLTYPE< TTYPE >::iterator&);               \
-template bool operator!=(const std::STLTYPE< TTYPE >::iterator&,                \
+extern template bool operator!=(const std::STLTYPE< TTYPE >::iterator&,         \
                          const std::STLTYPE< TTYPE >::iterator&);               \
 }
 
@@ -23,5 +23,5 @@
 
 
 //- explicit instantiations of used types
-STLTYPES_EXPLICIT_INSTANTIATION(vector, int)
-STLTYPES_EXPLICIT_INSTANTIATION(vector, just_a_class)
+STLTYPES_EXPLICIT_INSTANTIATION_DECL(vector, int)
+STLTYPES_EXPLICIT_INSTANTIATION_DECL(vector, just_a_class)
diff --git a/pypy/module/cppyy/test/test_cppyy.py b/pypy/module/cppyy/test/test_cppyy.py
--- a/pypy/module/cppyy/test/test_cppyy.py
+++ b/pypy/module/cppyy/test/test_cppyy.py
@@ -40,7 +40,7 @@
         """Test passing of an int, returning of an int, and overloading on a
             differening number of arguments."""
 
-        import sys
+        import sys, math
         t = self.example01
 
         res = t.invoke(t.get_overload("staticAddOneToInt"), 1)
@@ -51,14 +51,15 @@
         assert res == 4
         res = t.invoke(t.get_overload("staticAddOneToInt"), -1)
         assert res == 0
-        res = t.invoke(t.get_overload("staticAddOneToInt"), sys.maxint-1)
-        assert res == sys.maxint
-        res = t.invoke(t.get_overload("staticAddOneToInt"), sys.maxint)
-        assert res == -sys.maxint-1
+        maxint32 = int(math.pow(2,31)-1)
+        res = t.invoke(t.get_overload("staticAddOneToInt"), maxint32-1)
+        assert res == maxint32
+        res = t.invoke(t.get_overload("staticAddOneToInt"), maxint32)
+        assert res == -maxint32-1
 
         raises(TypeError, 't.invoke(t.get_overload("staticAddOneToInt"), 1, [])')
         raises(TypeError, 't.invoke(t.get_overload("staticAddOneToInt"), 1.)')
-        raises(OverflowError, 't.invoke(t.get_overload("staticAddOneToInt"), sys.maxint+1)')
+        raises(OverflowError, 't.invoke(t.get_overload("staticAddOneToInt"), maxint32+1)')
 
 
     def test_example01static_double(self):
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
@@ -30,7 +30,7 @@
         lib2 = cppyy.load_lib(self.shared_lib)
         assert self.datatypes is lib2
 
-    def test1_instance_data_read_access( self ):
+    def test1_instance_data_read_access(self):
         """Test read access to instance public data and verify values"""
 
         import cppyy, sys
diff --git a/pypy/module/cppyy/test/test_pythonify.py b/pypy/module/cppyy/test/test_pythonify.py
--- a/pypy/module/cppyy/test/test_pythonify.py
+++ b/pypy/module/cppyy/test/test_pythonify.py
@@ -41,7 +41,7 @@
 
     def test03_calling_static_functions(self):
         """Test calling of static methods."""
-        import cppyy, sys
+        import cppyy, sys, math
         example01_class = cppyy.gbl.example01
         res = example01_class.staticAddOneToInt(1)
         assert res == 2
@@ -52,14 +52,15 @@
         assert res == 4
         res = example01_class.staticAddOneToInt(-1)
         assert res == 0
-        res = example01_class.staticAddOneToInt(sys.maxint-1)
-        assert res == sys.maxint
-        res = example01_class.staticAddOneToInt(sys.maxint)
-        assert res == -sys.maxint-1
+        maxint32 = int(math.pow(2,31)-1)
+        res = example01_class.staticAddOneToInt(maxint32-1)
+        assert res == maxint32
+        res = example01_class.staticAddOneToInt(maxint32)
+        assert res == -maxint32-1
 
         raises(TypeError, 'example01_class.staticAddOneToInt(1, [])')
         raises(TypeError, 'example01_class.staticAddOneToInt(1.)')
-        raises(OverflowError, 'example01_class.staticAddOneToInt(sys.maxint+1)')
+        raises(OverflowError, 'example01_class.staticAddOneToInt(maxint32+1)')
         res = example01_class.staticAddToDouble(0.09)
         assert res == 0.09 + 0.01
 


More information about the pypy-commit mailing list