Author: Carl Friedrich Bolz <cfb...@gmx.de>
Branch: space-newtext
Changeset: r88258:6d72a3ca1108
Date: 2016-11-07 18:40 +0100
http://bitbucket.org/pypy/pypy/changeset/6d72a3ca1108/

Log:    _rawffi

diff --git a/pypy/module/_rawffi/alt/interp_ffitype.py 
b/pypy/module/_rawffi/alt/interp_ffitype.py
--- a/pypy/module/_rawffi/alt/interp_ffitype.py
+++ b/pypy/module/_rawffi/alt/interp_ffitype.py
@@ -37,7 +37,7 @@
 
     def descr_sizeof(self, space):
         try:
-            return space.wrap(self.sizeof())
+            return space.newint(self.sizeof())
         except ValueError:
             raise oefmt(space.w_ValueError,
                         "Operation not permitted on an incomplete type")
@@ -49,7 +49,7 @@
         return intmask(self.get_ffitype().c_alignment)
 
     def repr(self, space):
-        return space.wrap(self.__repr__())
+        return space.newtext(self.__repr__())
 
     def __repr__(self):
         name = self.name
diff --git a/pypy/module/_rawffi/alt/interp_funcptr.py 
b/pypy/module/_rawffi/alt/interp_funcptr.py
--- a/pypy/module/_rawffi/alt/interp_funcptr.py
+++ b/pypy/module/_rawffi/alt/interp_funcptr.py
@@ -114,7 +114,7 @@
         try:
             return func_caller.do_and_wrap(self.w_restype)
         except StackCheckError as e:
-            raise OperationError(space.w_ValueError, space.wrap(e.message))
+            raise OperationError(space.w_ValueError, space.newtext(e.message))
         #return self._do_call(space, argchain)
 
     def free_temp_buffers(self, space):
@@ -129,7 +129,7 @@
         """
         Return the physical address in memory of the function
         """
-        return space.wrap(rffi.cast(rffi.LONG, self.func.funcsym))
+        return space.newint(rffi.cast(rffi.LONG, self.func.funcsym))
 
 
 class PushArgumentConverter(FromAppLevelConverter):
@@ -213,7 +213,7 @@
         # the correct value, and to be sure to handle the signed/unsigned case
         # correctly, we need to cast the result to the correct type.  After
         # that, we cast it back to LONG, because this is what we want to pass
-        # to space.wrap in order to get a nice applevel <int>.
+        # to space.newint in order to get a nice applevel <int>.
         #
         restype = w_ffitype.get_ffitype()
         call = self.func.call
@@ -337,11 +337,11 @@
         except KeyError:
             raise oefmt(space.w_ValueError,
                         "No symbol %s found in library %s", name, self.name)
-        return space.wrap(address_as_uint)
+        return space.newint(address_as_uint)
 
 @unwrap_spec(name='str_or_None', mode=int)
 def descr_new_cdll(space, w_type, name, mode=-1):
-    return space.wrap(W_CDLL(space, name, mode))
+    return W_CDLL(space, name, mode)
 
 
 W_CDLL.typedef = TypeDef(
@@ -358,7 +358,7 @@
 
 @unwrap_spec(name='str_or_None', mode=int)
 def descr_new_windll(space, w_type, name, mode=-1):
-    return space.wrap(W_WinDLL(space, name, mode))
+    return W_WinDLL(space, name, mode)
 
 
 W_WinDLL.typedef = TypeDef(
@@ -372,7 +372,7 @@
 
 def get_libc(space):
     try:
-        return space.wrap(W_CDLL(space, get_libc_name(), -1))
+        return W_CDLL(space, get_libc_name(), -1)
     except OSError as e:
         raise wrap_oserror(space, e)
 
diff --git a/pypy/module/_rawffi/alt/interp_struct.py 
b/pypy/module/_rawffi/alt/interp_struct.py
--- a/pypy/module/_rawffi/alt/interp_struct.py
+++ b/pypy/module/_rawffi/alt/interp_struct.py
@@ -176,7 +176,7 @@
 
     def getaddr(self, space):
         addr = rffi.cast(rffi.ULONG, self.rawmem)
-        return space.wrap(addr)
+        return space.newint(addr)
 
     @unwrap_spec(name=str)
     def getfield(self, space, name):
diff --git a/pypy/module/_rawffi/alt/type_converter.py 
b/pypy/module/_rawffi/alt/type_converter.py
--- a/pypy/module/_rawffi/alt/type_converter.py
+++ b/pypy/module/_rawffi/alt/type_converter.py
@@ -202,7 +202,7 @@
             return self._longlong(w_ffitype)
         elif w_ffitype.is_signed():
             intval = self.get_signed(w_ffitype)
-            return space.wrap(intval)
+            return space.newint(intval)
         elif (w_ffitype is app_types.ulonglong or
               w_ffitype is app_types.ulong or (libffi.IS_32_BIT and
                                                w_ffitype is app_types.uint)):
@@ -216,19 +216,19 @@
             # and app-evel <long>.  This is why we need to treat it separately
             # than the other unsigned types.
             uintval = self.get_unsigned(w_ffitype)
-            return space.wrap(uintval)
+            return space.newint(uintval)
         elif w_ffitype.is_unsigned(): # note that ulong is handled just before
             intval = self.get_unsigned_which_fits_into_a_signed(w_ffitype)
-            return space.wrap(intval)
+            return space.newint(intval)
         elif w_ffitype.is_pointer():
             uintval = self.get_pointer(w_ffitype)
-            return space.wrap(uintval)
+            return space.newint(uintval)
         elif w_ffitype.is_char():
             ucharval = self.get_char(w_ffitype)
-            return space.wrap(chr(ucharval))
+            return space.newbytes(chr(ucharval))
         elif w_ffitype.is_unichar():
             wcharval = self.get_unichar(w_ffitype)
-            return space.wrap(unichr(wcharval))
+            return space.newunicode(unichr(wcharval))
         elif w_ffitype.is_double():
             return self._float(w_ffitype)
         elif w_ffitype.is_singlefloat():
@@ -253,10 +253,10 @@
         # depending on whether longlongs are supported
         if w_ffitype is app_types.slonglong:
             longlongval = self.get_longlong(w_ffitype)
-            return self.space.wrap(longlongval)
+            return self.space.newint(longlongval)
         elif w_ffitype is app_types.ulonglong:
             ulonglongval = self.get_ulonglong(w_ffitype)
-            return self.space.wrap(ulonglongval)
+            return self.space.newint(ulonglongval)
         else:
             self.error(w_ffitype)
 
@@ -264,13 +264,13 @@
         # a separate function, which can be seen by the jit or not,
         # depending on whether floats are supported
         floatval = self.get_float(w_ffitype)
-        return self.space.wrap(floatval)
+        return self.space.newfloat(floatval)
 
     def _singlefloat(self, w_ffitype):
         # a separate function, which can be seen by the jit or not,
         # depending on whether singlefloats are supported
         singlefloatval = self.get_singlefloat(w_ffitype)
-        return self.space.wrap(float(singlefloatval))
+        return self.space.newfloat(float(singlefloatval))
 
     def error(self, w_ffitype):
         raise oefmt(self.space.w_TypeError,
diff --git a/pypy/module/_rawffi/array.py b/pypy/module/_rawffi/array.py
--- a/pypy/module/_rawffi/array.py
+++ b/pypy/module/_rawffi/array.py
@@ -49,16 +49,16 @@
                 w_item = items_w[num]
                 unwrap_value(space, write_ptr, result.ll_buffer, num,
                              self.itemcode, w_item)
-        return space.wrap(result)
+        return result
 
     def descr_repr(self, space):
-        return space.wrap("<_rawffi.Array '%s' (%d, %d)>" % (self.itemcode,
-                                                             self.size,
-                                                             self.alignment))
+        return space.newtext("<_rawffi.Array '%s' (%d, %d)>" % (self.itemcode,
+                                                                self.size,
+                                                                
self.alignment))
 
     @unwrap_spec(address=r_uint, length=int)
     def fromaddress(self, space, address, length):
-        return space.wrap(W_ArrayInstance(space, self, length, address))
+        return W_ArrayInstance(space, self, length, address)
 
 PRIMITIVE_ARRAY_TYPES = {}
 for _code in TYPEMAP:
@@ -94,8 +94,8 @@
 
     def descr_repr(self, space):
         addr = rffi.cast(lltype.Unsigned, self.ll_buffer)
-        return space.wrap("<_rawffi array %x of length %d>" % (addr,
-                                                               self.length))
+        return space.newtext("<_rawffi array %x of length %d>" % (addr,
+                                                                  self.length))
 
     # This only allows non-negative indexes.  Arrays of shape 'c' also
     # support simple slices.
@@ -137,13 +137,13 @@
             return self.getitem(space, num)
 
     def getlength(self, space):
-        return space.wrap(self.length)
+        return space.newint(self.length)
 
     @unwrap_spec(num=int)
     def descr_itemaddress(self, space, num):
         itemsize = self.shape.size
         ptr = rffi.ptradd(self.ll_buffer, itemsize * num)
-        return space.wrap(rffi.cast(lltype.Unsigned, ptr))
+        return space.newint(rffi.cast(lltype.Unsigned, ptr))
 
     def getrawsize(self):
         itemsize = self.shape.size
@@ -155,9 +155,9 @@
         letter = self.shape.itemcode
         if letter != 'c':
             raise oefmt(space.w_TypeError, "only 'c' arrays support slicing")
-        w_start = space.getattr(w_slice, space.wrap('start'))
-        w_stop = space.getattr(w_slice, space.wrap('stop'))
-        w_step = space.getattr(w_slice, space.wrap('step'))
+        w_start = space.getattr(w_slice, space.newtext('start'))
+        w_stop = space.getattr(w_slice, space.newtext('stop'))
+        w_step = space.getattr(w_slice, space.newtext('step'))
 
         if space.is_w(w_start, space.w_None):
             start = 0
diff --git a/pypy/module/_rawffi/callback.py b/pypy/module/_rawffi/callback.py
--- a/pypy/module/_rawffi/callback.py
+++ b/pypy/module/_rawffi/callback.py
@@ -45,7 +45,7 @@
                     space, rffi.cast(rffi.SIZE_T, ll_args[i]))
             else:
                 # XXX other types?
-                args_w[i] = space.wrap(rffi.cast(rffi.ULONG, ll_args[i]))
+                args_w[i] = space.newint(rffi.cast(rffi.ULONG, ll_args[i]))
         w_res = space.call(w_callable, space.newtuple(args_w))
         if callback_ptr.result is not None: # don't return void
             ptr = ll_res
@@ -60,8 +60,8 @@
                         break
             unwrap_value(space, write_ptr, ptr, 0, letter, w_res)
     except OperationError as e:
-        tbprint(space, space.wrap(e.get_traceback()),
-                space.wrap(e.errorstr(space)))
+        tbprint(space, e.get_traceback(),
+                space.newtext(e.errorstr(space)))
         # force the result to be zero
         if callback_ptr.result is not None:
             resshape = letter2tp(space, callback_ptr.result)
diff --git a/pypy/module/_rawffi/interp_rawffi.py 
b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -163,10 +163,13 @@
         and restype
         """
         resshape = unpack_resshape(space, w_restype)
-        w = space.wrap
+        if resshape is None:
+            w_resshape = space.w_None
+        else:
+            w_resshape = resshape
         argtypes_w = space.fixedview(w_argtypes)
         w_argtypes = space.newtuple(argtypes_w)
-        w_key = space.newtuple([w_name, w_argtypes, w(resshape)])
+        w_key = space.newtuple([w_name, w_argtypes, w_resshape])
         try:
             return space.getitem(self.w_cache, w_key)
         except OperationError as e:
@@ -222,7 +225,7 @@
                                         self.cdll.getaddressindll(name))
         except KeyError:
             raise oefmt(space.w_ValueError, "Cannot find symbol %s", name)
-        return space.wrap(address_as_uint)
+        return space.newint(address_as_uint)
 
 @unwrap_spec(name='str_or_None')
 def descr_new_cdll(space, w_type, name):
@@ -232,7 +235,7 @@
         raise wrap_dlopenerror(space, e, name)
     except OSError as e:
         raise wrap_oserror(space, e)
-    return space.wrap(W_CDLL(space, name, cdll))
+    return W_CDLL(space, name, cdll)
 
 W_CDLL.typedef = TypeDef(
     'CDLL',
@@ -301,8 +304,8 @@
 
 def segfault_exception(space, reason):
     w_mod = space.getbuiltinmodule("_rawffi")
-    w_exception = space.getattr(w_mod, space.wrap("SegfaultException"))
-    return OperationError(w_exception, space.wrap(reason))
+    w_exception = space.getattr(w_mod, space.newtext("SegfaultException"))
+    return OperationError(w_exception, space.newtext(reason))
 
 class W_DataShape(W_Root):
     _array_shapes = None
@@ -322,8 +325,8 @@
 
     @unwrap_spec(n=int)
     def descr_size_alignment(self, space, n=1):
-        return space.newtuple([space.wrap(self.size * n),
-                               space.wrap(self.alignment)])
+        return space.newtuple([space.newint(self.size * n),
+                               space.newint(self.alignment)])
 
 
 class W_DataInstance(W_Root):
@@ -339,7 +342,7 @@
         self._ll_buffer = self.ll_buffer
 
     def getbuffer(self, space):
-        return space.wrap(rffi.cast(lltype.Unsigned, self.ll_buffer))
+        return space.newint(rffi.cast(lltype.Unsigned, self.ll_buffer))
 
     def buffer_advance(self, n):
         self.ll_buffer = rffi.ptradd(self.ll_buffer, n)
@@ -347,8 +350,8 @@
     def byptr(self, space):
         from pypy.module._rawffi.array import ARRAY_OF_PTRS
         array = ARRAY_OF_PTRS.allocate(space, 1)
-        array.setitem(space, 0, space.wrap(self))
-        return space.wrap(array)
+        array.setitem(space, 0, self)
+        return array
 
     def free(self, space):
         if not self._ll_buffer:
@@ -433,10 +436,13 @@
         if letter == c:
             if c in TYPEMAP_PTR_LETTERS:
                 res = func(add_arg, argdesc, rffi.VOIDP)
-                return space.wrap(rffi.cast(lltype.Unsigned, res))
+                return space.newint(rffi.cast(lltype.Unsigned, res))
+            elif c == 'c':
+                return space.newbytes(func(add_arg, argdesc, ll_type))
             elif c == 'f' or c == 'd' or c == 'g':
-                return space.wrap(float(func(add_arg, argdesc, ll_type)))
+                return space.newfloat(float(func(add_arg, argdesc, ll_type)))
             else:
+                # YYY hard
                 return space.wrap(func(add_arg, argdesc, ll_type))
     raise oefmt(space.w_TypeError, "cannot directly read value")
 
@@ -455,7 +461,7 @@
             self.narrow_integer = 
is_narrow_integer_type(resshape.itemcode.lower())
 
     def getbuffer(self, space):
-        return space.wrap(rffi.cast(lltype.Unsigned, self.ptr.funcsym))
+        return space.newint(rffi.cast(lltype.Unsigned, self.ptr.funcsym))
 
     def byptr(self, space):
         from pypy.module._rawffi.array import ARRAY_OF_PTRS
@@ -465,7 +471,7 @@
             # XXX this is needed, because functions tend to live forever
             #     hence our testing is not performing that well
             del tracker.alloced[rffi.cast(lltype.Signed, array.ll_buffer)]
-        return space.wrap(array)
+        return array
 
     def call(self, space, args_w):
         from pypy.module._rawffi.array import W_ArrayInstance
@@ -516,12 +522,12 @@
                     # we get a 8 byte value in big endian
                     n = rffi.sizeof(lltype.Signed) - result.shape.size
                     result.buffer_advance(n)
-                return space.wrap(result)
+                return result
             else:
                 self.ptr.call(args_ll, lltype.nullptr(rffi.VOIDP.TO))
                 return space.w_None
         except StackCheckError as e:
-            raise OperationError(space.w_ValueError, space.wrap(e.message))
+            raise OperationError(space.w_ValueError, space.newtext(e.message))
 
 @unwrap_spec(addr=r_uint, flags=int)
 def descr_new_funcptr(space, w_tp, addr, w_args, w_res, flags=FUNCFLAG_CDECL):
@@ -537,7 +543,7 @@
                          flags)
     except LibFFIError:
         raise got_libffi_error(space)
-    return space.wrap(W_FuncPtr(space, ptr, argshapes, resshape))
+    return W_FuncPtr(space, ptr, argshapes, resshape)
 
 W_FuncPtr.typedef = TypeDef(
     'FuncPtr',
@@ -555,7 +561,7 @@
             raise oefmt(space.w_ValueError, "Expecting string of length one")
         tp_letter = tp_letter[0] # fool annotator
         try:
-            return space.wrap(intmask(getattr(TYPEMAP[tp_letter], name)))
+            return space.newint(intmask(getattr(TYPEMAP[tp_letter], name)))
         except KeyError:
             raise oefmt(space.w_ValueError, "Unknown type specification %s",
                         tp_letter)
@@ -584,7 +590,7 @@
         s = rffi.wcharp2unicode(wcharp_addr)
     else:
         s = rffi.wcharp2unicoden(wcharp_addr, maxlength)
-    return space.wrap(s)
+    return space.newunicode(s)
 
 @unwrap_spec(address=r_uint, maxlength=int)
 def charp2rawstring(space, address, maxlength=-1):
@@ -598,7 +604,7 @@
     if maxlength == -1:
         return wcharp2unicode(space, address)
     s = rffi.wcharpsize2unicode(rffi.cast(rffi.CWCHARP, address), maxlength)
-    return space.wrap(s)
+    return space.newunicode(s)
 
 @unwrap_spec(address=r_uint, newcontent='bufferstr')
 def rawstring2charp(space, address, newcontent):
@@ -615,8 +621,8 @@
     @unwrap_spec(hresult=int)
     def check_HRESULT(space, hresult):
         if rwin32.FAILED(hresult):
-            raise OperationError(space.w_WindowsError, space.wrap(hresult))
-        return space.wrap(hresult)
+            raise OperationError(space.w_WindowsError, space.newint(hresult))
+        return space.newint(hresult)
 
 def get_libc(space):
     name = get_libc_name()
@@ -624,10 +630,10 @@
         cdll = CDLL(name)
     except OSError as e:
         raise wrap_oserror(space, e)
-    return space.wrap(W_CDLL(space, name, cdll))
+    return W_CDLL(space, name, cdll)
 
 def get_errno(space):
-    return space.wrap(rposix.get_saved_alterrno())
+    return space.newint(rposix.get_saved_alterrno())
 
 def set_errno(space, w_errno):
     rposix.set_saved_alterrno(space.int_w(w_errno))
@@ -644,7 +650,7 @@
     # always have at least a dummy version of these functions
     # (https://bugs.pypy.org/issue1242)
     def get_last_error(space):
-        return space.wrap(0)
+        return space.newint(0)
     @unwrap_spec(error=int)
     def set_last_error(space, error):
         pass
diff --git a/pypy/module/_rawffi/structure.py b/pypy/module/_rawffi/structure.py
--- a/pypy/module/_rawffi/structure.py
+++ b/pypy/module/_rawffi/structure.py
@@ -192,30 +192,30 @@
 
     @unwrap_spec(autofree=bool)
     def descr_call(self, space, autofree=False):
-        return space.wrap(self.allocate(space, 1, autofree))
+        return self.allocate(space, 1, autofree)
 
     def descr_repr(self, space):
         fieldnames = ' '.join(["'%s'" % name for name, _, _ in self.fields])
-        return space.wrap("<_rawffi.Structure %s (%d, %d)>" % (fieldnames,
-                                                               self.size,
-                                                               self.alignment))
+        return space.newtext("<_rawffi.Structure %s (%d, %d)>" % (fieldnames,
+                                                                  self.size,
+                                                                  
self.alignment))
 
     @unwrap_spec(address=r_uint)
     def fromaddress(self, space, address):
-        return space.wrap(W_StructureInstance(space, self, address))
+        return W_StructureInstance(space, self, address)
 
     @unwrap_spec(attr=str)
     def descr_fieldoffset(self, space, attr):
         index = self.getindex(space, attr)
-        return space.wrap(self.ll_positions[index])
+        return space.newint(self.ll_positions[index])
 
     @unwrap_spec(attr=str)
     def descr_fieldsize(self, space, attr):
         index = self.getindex(space, attr)
         if self.ll_bitsizes and index < len(self.ll_bitsizes):
-            return space.wrap(self.ll_bitsizes[index])
+            return space.newint(self.ll_bitsizes[index])
         else:
-            return space.wrap(self.fields[index][1].size)
+            return space.newint(self.fields[index][1].size)
 
     # get the corresponding ffi_type
     ffi_struct = lltype.nullptr(clibffi.FFI_STRUCT_P.TO)
@@ -262,7 +262,7 @@
     else:
         fields = unpack_fields(space, w_shapeinfo)
         S = W_Structure(space, fields, 0, 0, union, pack)
-    return space.wrap(S)
+    return S
 
 W_Structure.typedef = TypeDef(
     'Structure',
@@ -347,7 +347,7 @@
 
     def descr_repr(self, space):
         addr = rffi.cast(lltype.Unsigned, self.ll_buffer)
-        return space.wrap("<_rawffi struct %x>" % (addr,))
+        return space.newtext("<_rawffi struct %x>" % (addr,))
 
     @unwrap_spec(attr=str)
     def getattr(self, space, attr):
@@ -369,7 +369,7 @@
     def descr_fieldaddress(self, space, attr):
         i = self.shape.getindex(space, attr)
         ptr = rffi.ptradd(self.ll_buffer, self.shape.ll_positions[i])
-        return space.wrap(rffi.cast(lltype.Unsigned, ptr))
+        return space.newint(rffi.cast(lltype.Unsigned, ptr))
 
     def getrawsize(self):
         return self.shape.size
diff --git a/pypy/module/_rawffi/tracker.py b/pypy/module/_rawffi/tracker.py
--- a/pypy/module/_rawffi/tracker.py
+++ b/pypy/module/_rawffi/tracker.py
@@ -24,7 +24,7 @@
     if not tracker.DO_TRACING:
         raise oefmt(space.w_RuntimeError,
                     "DO_TRACING not enabled in this PyPy")
-    return space.wrap(len(tracker.alloced))
+    return space.newint(len(tracker.alloced))
 
 def print_alloced_objects(space):
     xxx
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to