[pypy-commit] pypy space-newtext: annotator fixes

wlav pypy.commits at gmail.com
Tue Nov 22 17:10:02 EST 2016


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: space-newtext
Changeset: r88555:8dfca1a083c6
Date: 2016-11-22 14:08 -0800
http://bitbucket.org/pypy/pypy/changeset/8dfca1a083c6/

Log:	annotator fixes

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
@@ -217,9 +217,6 @@
 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)
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
@@ -78,8 +78,8 @@
 class NumericExecutorMixin(object):
     _mixin_ = True
 
-    def _wrap_object(self, space, obj):
-        return getattr(space, self.wrapper)(obj)
+    #def _wrap_object(self, space, 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)
@@ -102,8 +102,8 @@
         self.item = self._unwrap_object(space, w_item)
         self.do_assign = True
 
-    def _wrap_object(self, space, obj):
-        return getattr(space, self.wrapper)(rffi.cast(self.c_type, obj))
+    #def _wrap_object(self, space, 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
@@ -2,6 +2,7 @@
 
 from rpython.rtyper.lltypesystem import rffi
 from rpython.rlib.rarithmetic import r_singlefloat
+from rpython.rlib.rbigint import rbigint
 from rpython.rlib import jit_libffi, rfloat
 
 # Mixins to share between converter and executor classes (in converter.py and
@@ -9,18 +10,6 @@
 # sets of jit_libffi, rffi, and different space unwrapping calls. To get the
 # right mixin, a non-RPython function typeid() is used.
 
-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
     _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
@@ -29,6 +18,9 @@
     c_type      = rffi.UCHAR
     c_ptrtype   = rffi.UCHARP
 
+    def _wrap_object(self, space, obj):
+        return space.newbool(bool(ord(rffi.cast(rffi.CHAR, obj))))
+
     def _unwrap_object(self, space, w_obj):
         arg = space.c_int_w(w_obj)
         if arg != False and arg != True:
@@ -36,9 +28,6 @@
                         "boolean value should be bool, or integer 1 or 0")
         return arg
 
-    def _wrap_object(self, space, obj):
-        return space.newbool(bool(ord(rffi.cast(rffi.CHAR, obj))))
-
 class CharTypeMixin(object):
     _mixin_     = True
     _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
@@ -46,7 +35,9 @@
     libffitype  = jit_libffi.types.schar
     c_type      = rffi.CHAR
     c_ptrtype   = rffi.CCHARP           # there's no such thing as rffi.CHARP
-    wrapper     = 'newbytes'
+
+    def _wrap_object(self, space, obj):
+        return space.newbytes(obj)
 
     def _unwrap_object(self, space, w_value):
         # allow int to pass to char and make sure that str is of length 1
@@ -64,6 +55,15 @@
                         "char expected, got string of size %d", len(value))
         return value[0] # turn it into a "char" to the annotator
 
+class BaseIntTypeMixin(object):
+    _mixin_     = True
+
+    def _wrap_object(self, space, obj):
+        return space.newint(rffi.cast(rffi.INT, obj))
+
+    def _unwrap_object(self, space, w_obj):
+        return rffi.cast(self.c_type, space.c_int_w(w_obj))
+
 class ShortTypeMixin(BaseIntTypeMixin):
     _mixin_     = True
     _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
@@ -72,9 +72,6 @@
     c_type      = rffi.SHORT
     c_ptrtype   = rffi.SHORTP
 
-    def _unwrap_object(self, space, w_obj):
-        return rffi.cast(rffi.SHORT, space.int_w(w_obj))
-
 class UShortTypeMixin(BaseIntTypeMixin):
     _mixin_     = True
     _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
@@ -83,9 +80,6 @@
     c_type      = rffi.USHORT
     c_ptrtype   = rffi.USHORTP
 
-    def _unwrap_object(self, space, w_obj):
-        return rffi.cast(self.c_type, space.int_w(w_obj))
-
 class IntTypeMixin(BaseIntTypeMixin):
     _mixin_     = True
     _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
@@ -94,10 +88,7 @@
     c_type      = rffi.INT
     c_ptrtype   = rffi.INTP
 
-    def _unwrap_object(self, space, w_obj):
-        return rffi.cast(self.c_type, space.c_int_w(w_obj))
-
-class UIntTypeMixin(BaseLongTypeMixin):
+class UIntTypeMixin(object):
     _mixin_     = True
     _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
 
@@ -105,10 +96,13 @@
     c_type      = rffi.UINT
     c_ptrtype   = rffi.UINTP
 
+    def _wrap_object(self, space, obj):
+        return space.newlong_from_rarith_int(obj)
+
     def _unwrap_object(self, space, w_obj):
         return rffi.cast(self.c_type, space.uint_w(w_obj))
 
-class LongTypeMixin(BaseLongTypeMixin):
+class LongTypeMixin(object):
     _mixin_     = True
     _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
 
@@ -116,12 +110,13 @@
     c_type      = rffi.LONG
     c_ptrtype   = rffi.LONGP
 
+    def _wrap_object(self, space, obj):
+        return space.newlong(obj)
+
     def _unwrap_object(self, space, w_obj):
         return space.int_w(w_obj)
 
-# TODO: check ULong limits; actually, they fail if this is
-#  an BaseLongTypeMixin (i.e. use of space.ewlong) ... why??
-class ULongTypeMixin(BaseIntTypeMixin):
+class ULongTypeMixin(object):
     _mixin_     = True
     _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
 
@@ -129,10 +124,13 @@
     c_type      = rffi.ULONG
     c_ptrtype   = rffi.ULONGP
 
+    def _wrap_object(self, space, obj):
+        return space.newlong_from_rarith_int(obj)
+
     def _unwrap_object(self, space, w_obj):
         return space.uint_w(w_obj)
 
-class LongLongTypeMixin(BaseLongTypeMixin):
+class LongLongTypeMixin(object):
     _mixin_     = True
     _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
 
@@ -140,10 +138,13 @@
     c_type      = rffi.LONGLONG
     c_ptrtype   = rffi.LONGLONGP
 
+    def _wrap_object(self, space, obj):
+        return space.newlong_from_rarith_int(obj)
+
     def _unwrap_object(self, space, w_obj):
         return space.r_longlong_w(w_obj)
 
-class ULongLongTypeMixin(BaseLongTypeMixin):
+class ULongLongTypeMixin(object):
     _mixin_     = True
     _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
 
@@ -151,6 +152,9 @@
     c_type      = rffi.ULONGLONG
     c_ptrtype   = rffi.ULONGLONGP
 
+    def _wrap_object(self, space, obj):
+        return space.newlong_from_rarith_int(obj)
+
     def _unwrap_object(self, space, w_obj):
         return space.r_ulonglong_w(w_obj)
 
@@ -176,9 +180,11 @@
     libffitype  = jit_libffi.types.double
     c_type      = rffi.DOUBLE
     c_ptrtype   = rffi.DOUBLEP
-    wrapper     = 'newfloat'
     typecode    = 'd'
 
+    def _wrap_object(self, space, obj):
+        return space.newfloat(obj)
+
     def _unwrap_object(self, space, w_obj):
         return space.float_w(w_obj)
 
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
@@ -1,7 +1,7 @@
 import py, os, sys
 from rpython.jit.metainterp.test.support import LLJitMixin
 from rpython.rlib.objectmodel import specialize, instantiate
-from rpython.rlib import rarithmetic, jit
+from rpython.rlib import rarithmetic, rbigint, jit
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rtyper import llinterp
 from pypy.interpreter.baseobjspace import InternalSpaceCache, W_Root
@@ -158,11 +158,20 @@
 
     @specialize.argtype(1)
     def newint(self, obj):
-        return FakeInt(rarithmetic.intmask(obj))
+        if not isinstance(obj, int):
+            return FakeLong(rbigint.rbigint.fromrarith_int(obj))
+        return FakeInt(obj)
 
     @specialize.argtype(1)
     def newlong(self, obj):
-        return FakeLong(rarithmetic.intmask(obj))
+        return FakeLong(rbigint.rbigint.fromint(obj))
+
+    @specialize.argtype(1)
+    def newlong_from_rarith_int(self, obj):
+        return FakeLong(rbigint.rbigint.fromrarith_int(obj))
+
+    def newlong_from_rbigint(self, val):
+        return FakeLong(obj)
 
     @specialize.argtype(1)
     def newfloat(self, obj):
@@ -202,10 +211,8 @@
         return w_obj.val
 
     def uint_w(self, w_obj):
-        if isinstance(w_obj, FakeInt):
-            return rarithmetic.r_uint(w_obj.val)
         assert isinstance(w_obj, FakeLong)
-        return rarithmetic.r_uint(w_obj.val)
+        return rarithmetic.r_uint(w_obj.val.touint())
 
     def str_w(self, w_obj):
         assert isinstance(w_obj, FakeString)


More information about the pypy-commit mailing list