Author: Armin Rigo <[email protected]>
Branch: py3.5-newtext
Changeset: r90129:3ad4f6634212
Date: 2017-02-14 18:57 +0100
http://bitbucket.org/pypy/pypy/changeset/3ad4f6634212/

Log:    hg merge be088827c1c4

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
@@ -225,6 +225,9 @@
 class NumericTypeConverterMixin(object):
     _mixin_ = True
 
+    def _wrap_object(self, space, obj):
+        return getattr(space, self.wrapper)(obj)
+
     def convert_argument_libffi(self, space, w_obj, address, call_local):
         x = rffi.cast(self.c_ptrtype, address)
         x[0] = self._unwrap_object(space, w_obj)
@@ -236,7 +239,7 @@
     def from_memory(self, space, w_obj, w_pycppclass, offset):
         address = self._get_raw_address(space, w_obj, offset)
         rffiptr = rffi.cast(self.c_ptrtype, address)
-        return space.wrap(rffiptr[0])
+        return self._wrap_object(space, rffiptr[0])
 
     def to_memory(self, space, w_obj, w_value, offset):
         address = self._get_raw_address(space, w_obj, offset)
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
@@ -81,7 +81,7 @@
     _mixin_ = True
 
     def _wrap_object(self, space, obj):
-        return space.wrap(obj)
+        return getattr(space, self.wrapper)(obj)
 
     def execute(self, space, cppmethod, cppthis, num_args, args):
         result = self.c_stubcall(space, cppmethod, cppthis, num_args, args)
@@ -105,7 +105,7 @@
         self.do_assign = True
 
     def _wrap_object(self, space, obj):
-        return space.wrap(rffi.cast(self.c_type, obj))
+        return getattr(space, self.wrapper)(rffi.cast(self.c_type, obj))
 
     def _wrap_reference(self, space, rffiptr):
         if self.do_assign:
diff --git a/pypy/module/cppyy/ffitypes.py b/pypy/module/cppyy/ffitypes.py
--- a/pypy/module/cppyy/ffitypes.py
+++ b/pypy/module/cppyy/ffitypes.py
@@ -41,6 +41,17 @@
         self.c_size_t    = nt.new_primitive_type(space, 'size_t')
         self.c_ptrdiff_t = nt.new_primitive_type(space, 'ptrdiff_t')
 
+class BaseIntTypeMixin(object):
+    _mixin_     = True
+    _immutable_fields_ = ['wrapper']
+
+    wrapper     = 'newint'
+
+class BaseLongTypeMixin(object):
+    _mixin_     = True
+    _immutable_fields_ = ['wrapper']
+
+    wrapper     = 'newlong'
 
 class BoolTypeMixin(object):
     _mixin_     = True
@@ -69,6 +80,7 @@
 
     c_type      = rffi.CHAR
     c_ptrtype   = rffi.CCHARP           # there's no such thing as rffi.CHARP
+    wrapper     = 'newbytes'
 
     def _unwrap_object(self, space, w_value):
         # allow int to pass to char and make sure that str is of length 1
@@ -90,7 +102,7 @@
         state = space.fromcache(State)
         return state.c_char
 
-class ShortTypeMixin(object):
+class ShortTypeMixin(BaseIntTypeMixin):
     _mixin_     = True
     _immutable_fields_ = ['c_type', 'c_ptrtype']
 
@@ -104,7 +116,7 @@
         state = space.fromcache(State)
         return state.c_short
 
-class UShortTypeMixin(object):
+class UShortTypeMixin(BaseIntTypeMixin):
     _mixin_     = True
     _immutable_fields_ = ['c_type', 'c_ptrtype']
 
@@ -118,7 +130,7 @@
         state = space.fromcache(State)
         return state.c_ushort
 
-class IntTypeMixin(object):
+class IntTypeMixin(BaseIntTypeMixin):
     _mixin_     = True
     _immutable_fields_ = ['c_type', 'c_ptrtype']
 
@@ -132,7 +144,7 @@
         state = space.fromcache(State)
         return state.c_int
 
-class UIntTypeMixin(object):
+class UIntTypeMixin(BaseLongTypeMixin):
     _mixin_     = True
     _immutable_fields_ = ['c_type', 'c_ptrtype']
 
@@ -146,7 +158,7 @@
         state = space.fromcache(State)
         return state.c_uint
 
-class LongTypeMixin(object):
+class LongTypeMixin(BaseLongTypeMixin):
     _mixin_     = True
     _immutable_fields_ = ['c_type', 'c_ptrtype']
 
@@ -160,7 +172,9 @@
         state = space.fromcache(State)
         return state.c_long
 
-class ULongTypeMixin(object):
+# TODO: check ULong limits; actually, they fail if this is
+#  an BaseLongTypeMixin (i.e. use of space.ewlong) ... why??
+class ULongTypeMixin(BaseIntTypeMixin):
     _mixin_     = True
     _immutable_fields_ = ['c_type', 'c_ptrtype']
 
@@ -174,7 +188,7 @@
         state = space.fromcache(State)
         return state.c_ulong
 
-class LongLongTypeMixin(object):
+class LongLongTypeMixin(BaseLongTypeMixin):
     _mixin_     = True
     _immutable_fields_ = ['c_type', 'c_ptrtype']
 
@@ -188,7 +202,7 @@
         state = space.fromcache(State)
         return state.c_llong
 
-class ULongLongTypeMixin(object):
+class ULongLongTypeMixin(BaseLongTypeMixin):
     _mixin_     = True
     _immutable_fields_ = ['c_type', 'c_ptrtype']
 
@@ -226,6 +240,7 @@
 
     c_type      = rffi.DOUBLE
     c_ptrtype   = rffi.DOUBLEP
+    wrapper     = 'newfloat'
     typecode    = 'd'
 
     def _unwrap_object(self, space, w_obj):
diff --git a/pypy/module/cppyy/interp_cppyy.py 
b/pypy/module/cppyy/interp_cppyy.py
--- a/pypy/module/cppyy/interp_cppyy.py
+++ b/pypy/module/cppyy/interp_cppyy.py
@@ -2,7 +2,7 @@
 
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.gateway import interp2app, unwrap_spec
-from pypy.interpreter.typedef import TypeDef, GetSetProperty, 
interp_attrproperty
+from pypy.interpreter.typedef import TypeDef, GetSetProperty, 
interp_attrproperty, interp_attrproperty_w
 from pypy.interpreter.baseobjspace import W_Root
 
 from rpython.rtyper.lltypesystem import rffi, lltype, llmemory
@@ -982,7 +982,7 @@
 
 W_CPPClass.typedef = TypeDef(
     'CPPClass',
-    type_name = interp_attrproperty('name', W_CPPClass),
+    type_name = interp_attrproperty('name', W_CPPClass, wrapfn="newtext"),
     get_base_names = interp2app(W_CPPClass.get_base_names),
     get_method_names = interp2app(W_CPPClass.get_method_names),
     get_overload = interp2app(W_CPPClass.get_overload, unwrap_spec=['self', 
str]),
@@ -1009,7 +1009,7 @@
 
 W_ComplexCPPClass.typedef = TypeDef(
     'ComplexCPPClass',
-    type_name = interp_attrproperty('name', W_CPPClass),
+    type_name = interp_attrproperty('name', W_CPPClass, wrapfn="newtext"),
     get_base_names = interp2app(W_ComplexCPPClass.get_base_names),
     get_method_names = interp2app(W_ComplexCPPClass.get_method_names),
     get_overload = interp2app(W_ComplexCPPClass.get_overload, 
unwrap_spec=['self', str]),
@@ -1186,7 +1186,7 @@
 
 W_CPPInstance.typedef = TypeDef(
     'CPPInstance',
-    cppclass = interp_attrproperty('cppclass', cls=W_CPPInstance),
+    cppclass = interp_attrproperty_w('cppclass', cls=W_CPPInstance),
     _python_owns = GetSetProperty(W_CPPInstance.fget_python_owns, 
W_CPPInstance.fset_python_owns),
     __init__ = interp2app(W_CPPInstance.instance__init__),
     __eq__ = interp2app(W_CPPInstance.instance__eq__),
diff --git a/pypy/module/cppyy/test/test_fragile.py 
b/pypy/module/cppyy/test/test_fragile.py
--- a/pypy/module/cppyy/test/test_fragile.py
+++ b/pypy/module/cppyy/test/test_fragile.py
@@ -288,6 +288,8 @@
     def test14_double_enum_trouble(self):
         """Test a redefinition of enum in a derived class"""
 
+        return # don't bother; is fixed in cling-support
+
         import cppyy
 
         M = cppyy.gbl.fragile.M
diff --git a/pypy/module/cppyy/test/test_stltypes.py 
b/pypy/module/cppyy/test/test_stltypes.py
--- a/pypy/module/cppyy/test/test_stltypes.py
+++ b/pypy/module/cppyy/test/test_stltypes.py
@@ -261,6 +261,8 @@
     def test03_string_with_null_character(self):
         """Test that strings with NULL do not get truncated"""
 
+        return # don't bother; is fixed in cling-support
+
         import cppyy
         std = cppyy.gbl.std
         stringy_class = cppyy.gbl.stringy_class
diff --git a/pypy/module/cppyy/test/test_zjit.py 
b/pypy/module/cppyy/test/test_zjit.py
--- a/pypy/module/cppyy/test/test_zjit.py
+++ b/pypy/module/cppyy/test/test_zjit.py
@@ -71,6 +71,10 @@
     typename = "int"
     def __init__(self, val):
         self.val = val
+class FakeLong(FakeBase):
+    typename = "long"
+    def __init__(self, val):
+        self.val = val
 class FakeFloat(FakeBase):
     typename = "float"
     def __init__(self, val):
@@ -145,16 +149,7 @@
     def issequence_w(self, w_obj):
         return True
 
-    @specialize.argtype(1)
     def wrap(self, obj):
-        if isinstance(obj, int):
-            return FakeInt(obj)
-        if isinstance(obj, float):
-            return FakeFloat(obj)
-        if isinstance(obj, str):
-            return FakeString(obj)
-        if isinstance(obj, rffi.r_int):
-            return FakeInt(int(obj))
         assert 0
 
     @specialize.argtype(1)
@@ -163,11 +158,11 @@
 
     @specialize.argtype(1)
     def newint(self, obj):
-        return FakeInt(obj)
+        return FakeInt(rarithmetic.intmask(obj))
 
     @specialize.argtype(1)
     def newlong(self, obj):
-        return FakeInt(obj)
+        return FakeLong(rarithmetic.intmask(obj))
 
     @specialize.argtype(1)
     def newfloat(self, obj):
@@ -207,7 +202,9 @@
         return w_obj.val
 
     def uint_w(self, w_obj):
-        assert isinstance(w_obj, FakeInt)
+        if isinstance(w_obj, FakeInt):
+            return rarithmetic.r_uint(w_obj.val)
+        assert isinstance(w_obj, FakeLong)
         return rarithmetic.r_uint(w_obj.val)
 
     def str_w(self, w_obj):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to