[pypy-commit] pypy space-newtext: remove the simple wraps from cpyext (left more complex cases for now)

cfbolz pypy.commits at gmail.com
Thu Nov 3 05:51:10 EDT 2016


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: space-newtext
Changeset: r88109:fdd451dbedab
Date: 2016-11-03 10:31 +0100
http://bitbucket.org/pypy/pypy/changeset/fdd451dbedab/

Log:	remove the simple wraps from cpyext (left more complex cases for
	now)

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -911,7 +911,7 @@
                 else:
                     message = str(e)
                 state.set_exception(OperationError(space.w_SystemError,
-                                                   space.wrap(message)))
+                                                   space.newtext(message)))
             else:
                 failed = False
 
diff --git a/pypy/module/cpyext/bytesobject.py b/pypy/module/cpyext/bytesobject.py
--- a/pypy/module/cpyext/bytesobject.py
+++ b/pypy/module/cpyext/bytesobject.py
@@ -305,9 +305,9 @@
 
     w_encoding = w_errors = None
     if encoding:
-        w_encoding = space.wrap(rffi.charp2str(encoding))
+        w_encoding = space.newtext(rffi.charp2str(encoding))
     if errors:
-        w_errors = space.wrap(rffi.charp2str(errors))
+        w_errors = space.newtext(rffi.charp2str(errors))
     return space.call_method(w_str, 'encode', w_encoding, w_errors)
 
 @cpython_api([PyObject, CONST_STRING, CONST_STRING], PyObject)
@@ -325,9 +325,9 @@
 
     w_encoding = w_errors = None
     if encoding:
-        w_encoding = space.wrap(rffi.charp2str(encoding))
+        w_encoding = space.newtext(rffi.charp2str(encoding))
     if errors:
-        w_errors = space.wrap(rffi.charp2str(errors))
+        w_errors = space.newtext(rffi.charp2str(errors))
     return space.call_method(w_str, "decode", w_encoding, w_errors)
 
 @cpython_api([PyObject, PyObject], PyObject)
diff --git a/pypy/module/cpyext/cdatetime.py b/pypy/module/cpyext/cdatetime.py
--- a/pypy/module/cpyext/cdatetime.py
+++ b/pypy/module/cpyext/cdatetime.py
@@ -41,25 +41,25 @@
     datetimeAPI = lltype.malloc(PyDateTime_CAPI, flavor='raw',
                                 track_allocation=False)
 
-    w_datetime = PyImport_Import(space, space.wrap("datetime"))
+    w_datetime = PyImport_Import(space, space.newtext("datetime"))
 
-    w_type = space.getattr(w_datetime, space.wrap("date"))
+    w_type = space.getattr(w_datetime, space.newtext("date"))
     datetimeAPI.c_DateType = rffi.cast(
         PyTypeObjectPtr, make_ref(space, w_type))
 
-    w_type = space.getattr(w_datetime, space.wrap("datetime"))
+    w_type = space.getattr(w_datetime, space.newtext("datetime"))
     datetimeAPI.c_DateTimeType = rffi.cast(
         PyTypeObjectPtr, make_ref(space, w_type))
 
-    w_type = space.getattr(w_datetime, space.wrap("time"))
+    w_type = space.getattr(w_datetime, space.newtext("time"))
     datetimeAPI.c_TimeType = rffi.cast(
         PyTypeObjectPtr, make_ref(space, w_type))
 
-    w_type = space.getattr(w_datetime, space.wrap("timedelta"))
+    w_type = space.getattr(w_datetime, space.newtext("timedelta"))
     datetimeAPI.c_DeltaType = rffi.cast(
         PyTypeObjectPtr, make_ref(space, w_type))
 
-    w_type = space.getattr(w_datetime, space.wrap("tzinfo"))
+    w_type = space.getattr(w_datetime, space.newtext("tzinfo"))
     datetimeAPI.c_TZInfoType = rffi.cast(
         PyTypeObjectPtr, make_ref(space, w_type))
 
@@ -137,7 +137,7 @@
     day = rffi.cast(lltype.Signed, day)
     return space.call_function(
         w_type,
-        space.wrap(year), space.wrap(month), space.wrap(day))
+        space.newint(year), space.newint(month), space.newint(day))
 
 @cpython_api([rffi.INT_real, rffi.INT_real, rffi.INT_real, rffi.INT_real,
               PyObject, PyTypeObjectPtr], PyObject)
@@ -150,8 +150,8 @@
     usecond = rffi.cast(lltype.Signed, usecond)
     return space.call_function(
         w_type,
-        space.wrap(hour), space.wrap(minute), space.wrap(second),
-        space.wrap(usecond), w_tzinfo)
+        space.newint(hour), space.newint(minute), space.newint(second),
+        space.newint(usecond), w_tzinfo)
 
 @cpython_api([rffi.INT_real, rffi.INT_real, rffi.INT_real,
               rffi.INT_real, rffi.INT_real, rffi.INT_real, rffi.INT_real,
@@ -171,18 +171,18 @@
     usecond = rffi.cast(lltype.Signed, usecond)
     return space.call_function(
         w_type,
-        space.wrap(year), space.wrap(month), space.wrap(day),
-        space.wrap(hour), space.wrap(minute), space.wrap(second),
-        space.wrap(usecond), w_tzinfo)
+        space.newint(year), space.newint(month), space.newint(day),
+        space.newint(hour), space.newint(minute), space.newint(second),
+        space.newint(usecond), w_tzinfo)
 
 @cpython_api([PyObject], PyObject)
 def PyDateTime_FromTimestamp(space, w_args):
     """Create and return a new datetime.datetime object given an argument tuple
     suitable for passing to datetime.datetime.fromtimestamp().
     """
-    w_datetime = PyImport_Import(space, space.wrap("datetime"))
-    w_type = space.getattr(w_datetime, space.wrap("datetime"))
-    w_method = space.getattr(w_type, space.wrap("fromtimestamp"))
+    w_datetime = PyImport_Import(space, space.newtext("datetime"))
+    w_type = space.getattr(w_datetime, space.newtext("datetime"))
+    w_method = space.getattr(w_type, space.newtext("fromtimestamp"))
     return space.call(w_method, w_args)
 
 @cpython_api([PyObject], PyObject)
@@ -190,9 +190,9 @@
     """Create and return a new datetime.date object given an argument tuple
     suitable for passing to datetime.date.fromtimestamp().
     """
-    w_datetime = PyImport_Import(space, space.wrap("datetime"))
-    w_type = space.getattr(w_datetime, space.wrap("date"))
-    w_method = space.getattr(w_type, space.wrap("fromtimestamp"))
+    w_datetime = PyImport_Import(space, space.newtext("datetime"))
+    w_type = space.getattr(w_datetime, space.newtext("date"))
+    w_method = space.getattr(w_type, space.newtext("fromtimestamp"))
     return space.call(w_method, w_args)
 
 @cpython_api([rffi.INT_real, rffi.INT_real, rffi.INT_real, rffi.INT_real,
@@ -209,7 +209,7 @@
     useconds = rffi.cast(lltype.Signed, useconds)
     return space.call_function(
         w_type,
-        space.wrap(days), space.wrap(seconds), space.wrap(useconds))
+        space.newint(days), space.newint(seconds), space.newint(useconds))
 
 # Accessors
 
@@ -217,67 +217,67 @@
 def PyDateTime_GET_YEAR(space, w_obj):
     """Return the year, as a positive int.
     """
-    return space.int_w(space.getattr(w_obj, space.wrap("year")))
+    return space.int_w(space.getattr(w_obj, space.newtext("year")))
 
 @cpython_api([rffi.VOIDP], rffi.INT_real, error=CANNOT_FAIL)
 def PyDateTime_GET_MONTH(space, w_obj):
     """Return the month, as an int from 1 through 12.
     """
-    return space.int_w(space.getattr(w_obj, space.wrap("month")))
+    return space.int_w(space.getattr(w_obj, space.newtext("month")))
 
 @cpython_api([rffi.VOIDP], rffi.INT_real, error=CANNOT_FAIL)
 def PyDateTime_GET_DAY(space, w_obj):
     """Return the day, as an int from 1 through 31.
     """
-    return space.int_w(space.getattr(w_obj, space.wrap("day")))
+    return space.int_w(space.getattr(w_obj, space.newtext("day")))
 
 @cpython_api([rffi.VOIDP], rffi.INT_real, error=CANNOT_FAIL)
 def PyDateTime_DATE_GET_HOUR(space, w_obj):
     """Return the hour, as an int from 0 through 23.
     """
-    return space.int_w(space.getattr(w_obj, space.wrap("hour")))
+    return space.int_w(space.getattr(w_obj, space.newtext("hour")))
 
 @cpython_api([rffi.VOIDP], rffi.INT_real, error=CANNOT_FAIL)
 def PyDateTime_DATE_GET_MINUTE(space, w_obj):
     """Return the minute, as an int from 0 through 59.
     """
-    return space.int_w(space.getattr(w_obj, space.wrap("minute")))
+    return space.int_w(space.getattr(w_obj, space.newtext("minute")))
 
 @cpython_api([rffi.VOIDP], rffi.INT_real, error=CANNOT_FAIL)
 def PyDateTime_DATE_GET_SECOND(space, w_obj):
     """Return the second, as an int from 0 through 59.
     """
-    return space.int_w(space.getattr(w_obj, space.wrap("second")))
+    return space.int_w(space.getattr(w_obj, space.newtext("second")))
 
 @cpython_api([rffi.VOIDP], rffi.INT_real, error=CANNOT_FAIL)
 def PyDateTime_DATE_GET_MICROSECOND(space, w_obj):
     """Return the microsecond, as an int from 0 through 999999.
     """
-    return space.int_w(space.getattr(w_obj, space.wrap("microsecond")))
+    return space.int_w(space.getattr(w_obj, space.newtext("microsecond")))
 
 @cpython_api([rffi.VOIDP], rffi.INT_real, error=CANNOT_FAIL)
 def PyDateTime_TIME_GET_HOUR(space, w_obj):
     """Return the hour, as an int from 0 through 23.
     """
-    return space.int_w(space.getattr(w_obj, space.wrap("hour")))
+    return space.int_w(space.getattr(w_obj, space.newtext("hour")))
 
 @cpython_api([rffi.VOIDP], rffi.INT_real, error=CANNOT_FAIL)
 def PyDateTime_TIME_GET_MINUTE(space, w_obj):
     """Return the minute, as an int from 0 through 59.
     """
-    return space.int_w(space.getattr(w_obj, space.wrap("minute")))
+    return space.int_w(space.getattr(w_obj, space.newtext("minute")))
 
 @cpython_api([rffi.VOIDP], rffi.INT_real, error=CANNOT_FAIL)
 def PyDateTime_TIME_GET_SECOND(space, w_obj):
     """Return the second, as an int from 0 through 59.
     """
-    return space.int_w(space.getattr(w_obj, space.wrap("second")))
+    return space.int_w(space.getattr(w_obj, space.newtext("second")))
 
 @cpython_api([rffi.VOIDP], rffi.INT_real, error=CANNOT_FAIL)
 def PyDateTime_TIME_GET_MICROSECOND(space, w_obj):
     """Return the microsecond, as an int from 0 through 999999.
     """
-    return space.int_w(space.getattr(w_obj, space.wrap("microsecond")))
+    return space.int_w(space.getattr(w_obj, space.newtext("microsecond")))
 
 # XXX these functions are not present in the Python API
 # But it does not seem possible to expose a different structure
@@ -285,12 +285,12 @@
 
 @cpython_api([rffi.VOIDP], rffi.INT_real, error=CANNOT_FAIL)
 def PyDateTime_DELTA_GET_DAYS(space, w_obj):
-    return space.int_w(space.getattr(w_obj, space.wrap("days")))
+    return space.int_w(space.getattr(w_obj, space.newtext("days")))
 
 @cpython_api([rffi.VOIDP], rffi.INT_real, error=CANNOT_FAIL)
 def PyDateTime_DELTA_GET_SECONDS(space, w_obj):
-    return space.int_w(space.getattr(w_obj, space.wrap("seconds")))
+    return space.int_w(space.getattr(w_obj, space.newtext("seconds")))
 
 @cpython_api([rffi.VOIDP], rffi.INT_real, error=CANNOT_FAIL)
 def PyDateTime_DELTA_GET_MICROSECONDS(space, w_obj):
-    return space.int_w(space.getattr(w_obj, space.wrap("microseconds")))
+    return space.int_w(space.getattr(w_obj, space.newtext("microseconds")))
diff --git a/pypy/module/cpyext/codecs.py b/pypy/module/cpyext/codecs.py
--- a/pypy/module/cpyext/codecs.py
+++ b/pypy/module/cpyext/codecs.py
@@ -6,7 +6,7 @@
 def PyCodec_IncrementalEncoder(space, encoding, errors):
     w_codec = interp_codecs.lookup_codec(space, rffi.charp2str(encoding))
     if errors:
-        w_errors = space.wrap(rffi.charp2str(errors))
+        w_errors = space.newtext(rffi.charp2str(errors))
         return space.call_method(w_codec, "incrementalencoder", w_errors)
     else:
         return space.call_method(w_codec, "incrementalencoder")
@@ -15,7 +15,7 @@
 def PyCodec_IncrementalDecoder(space, encoding, errors):
     w_codec = interp_codecs.lookup_codec(space, rffi.charp2str(encoding))
     if errors:
-        w_errors = space.wrap(rffi.charp2str(errors))
+        w_errors = space.newtext(rffi.charp2str(errors))
         return space.call_method(w_codec, "incrementaldecoder", w_errors)
     else:
         return space.call_method(w_codec, "incrementaldecoder")
diff --git a/pypy/module/cpyext/dictobject.py b/pypy/module/cpyext/dictobject.py
--- a/pypy/module/cpyext/dictobject.py
+++ b/pypy/module/cpyext/dictobject.py
@@ -74,7 +74,7 @@
         key = rffi.charp2str(key_ptr)
         # our dicts dont have a standardized interface, so we need
         # to go through the space
-        space.delitem(w_dict, space.wrap(key))
+        space.delitem(w_dict, space.newtext(key))
         return 0
     else:
         PyErr_BadInternalCall(space)
diff --git a/pypy/module/cpyext/eval.py b/pypy/module/cpyext/eval.py
--- a/pypy/module/cpyext/eval.py
+++ b/pypy/module/cpyext/eval.py
@@ -31,7 +31,7 @@
     caller = space.getexecutioncontext().gettopframe_nohidden()
     if caller is not None:
         w_globals = caller.get_w_globals()
-        w_builtins = space.getitem(w_globals, space.wrap('__builtins__'))
+        w_builtins = space.getitem(w_globals, space.newtext('__builtins__'))
         if not space.isinstance_w(w_builtins, space.w_dict):
             w_builtins = w_builtins.getdict(space)
     else:
diff --git a/pypy/module/cpyext/floatobject.py b/pypy/module/cpyext/floatobject.py
--- a/pypy/module/cpyext/floatobject.py
+++ b/pypy/module/cpyext/floatobject.py
@@ -42,7 +42,7 @@
 
 @cpython_api([lltype.Float], PyObject)
 def PyFloat_FromDouble(space, value):
-    return space.wrap(value)
+    return space.newfloat(value)
 
 @cpython_api([PyObject], lltype.Float, error=-1)
 def PyFloat_AsDouble(space, w_obj):
diff --git a/pypy/module/cpyext/frameobject.py b/pypy/module/cpyext/frameobject.py
--- a/pypy/module/cpyext/frameobject.py
+++ b/pypy/module/cpyext/frameobject.py
@@ -63,9 +63,8 @@
     frame = space.FrameClass(space, code, w_globals, outer_func=None)
     d = frame.getorcreatedebug()
     d.f_lineno = rffi.getintfield(py_frame, 'c_f_lineno')
-    w_obj = space.wrap(frame)
-    track_reference(space, py_obj, w_obj)
-    return w_obj
+    track_reference(space, py_obj, frame)
+    return frame
 
 @cpython_api([PyThreadState, PyCodeObject, PyObject, PyObject], PyFrameObject,
              result_is_ll=True)
diff --git a/pypy/module/cpyext/funcobject.py b/pypy/module/cpyext/funcobject.py
--- a/pypy/module/cpyext/funcobject.py
+++ b/pypy/module/cpyext/funcobject.py
@@ -54,7 +54,7 @@
 def function_attach(space, py_obj, w_obj):
     py_func = rffi.cast(PyFunctionObject, py_obj)
     assert isinstance(w_obj, Function)
-    py_func.c_func_name = make_ref(space, space.wrap(w_obj.name))
+    py_func.c_func_name = make_ref(space, space.newtext(w_obj.name))
 
 @cpython_api([PyObject], lltype.Void, header=None)
 def function_dealloc(space, py_obj):
@@ -66,8 +66,8 @@
 def code_attach(space, py_obj, w_obj):
     py_code = rffi.cast(PyCodeObject, py_obj)
     assert isinstance(w_obj, PyCode)
-    py_code.c_co_name = make_ref(space, space.wrap(w_obj.co_name))
-    py_code.c_co_filename = make_ref(space, space.wrap(w_obj.co_filename))
+    py_code.c_co_name = make_ref(space, space.newtext(w_obj.co_name))
+    py_code.c_co_filename = make_ref(space, space.newtext(w_obj.co_filename))
     co_flags = 0
     for name, value in ALL_CODE_FLAGS:
         if w_obj.co_flags & getattr(pycode, name):
@@ -87,8 +87,7 @@
 def PyFunction_GetCode(space, w_func):
     """Return the code object associated with the function object op."""
     func = space.interp_w(Function, w_func)
-    w_code = space.wrap(func.code)
-    return w_code      # borrowed ref
+    return func.code      # borrowed ref
 
 @cpython_api([PyObject, PyObject, PyObject], PyObject)
 def PyMethod_New(space, w_func, w_self, w_cls):
@@ -132,40 +131,40 @@
     create a frame, use PyCode_NewEmpty() instead.  Calling
     PyCode_New() directly can bind you to a precise Python
     version since the definition of the bytecode changes often."""
-    return space.wrap(PyCode(space,
-                             argcount=rffi.cast(lltype.Signed, argcount),
-                             nlocals=rffi.cast(lltype.Signed, nlocals),
-                             stacksize=rffi.cast(lltype.Signed, stacksize),
-                             flags=rffi.cast(lltype.Signed, flags),
-                             code=space.str_w(w_code),
-                             consts=space.fixedview(w_consts),
-                             names=unwrap_list_of_strings(space, w_names),
-                             varnames=unwrap_list_of_strings(space, w_varnames),
-                             filename=space.str_w(w_filename),
-                             name=space.str_w(w_funcname),
-                             firstlineno=rffi.cast(lltype.Signed, firstlineno),
-                             lnotab=space.str_w(w_lnotab),
-                             freevars=unwrap_list_of_strings(space, w_freevars),
-                             cellvars=unwrap_list_of_strings(space, w_cellvars)))
+    return PyCode(space,
+                  argcount=rffi.cast(lltype.Signed, argcount),
+                  nlocals=rffi.cast(lltype.Signed, nlocals),
+                  stacksize=rffi.cast(lltype.Signed, stacksize),
+                  flags=rffi.cast(lltype.Signed, flags),
+                  code=space.str_w(w_code),
+                  consts=space.fixedview(w_consts),
+                  names=unwrap_list_of_strings(space, w_names),
+                  varnames=unwrap_list_of_strings(space, w_varnames),
+                  filename=space.str_w(w_filename),
+                  name=space.str_w(w_funcname),
+                  firstlineno=rffi.cast(lltype.Signed, firstlineno),
+                  lnotab=space.str_w(w_lnotab),
+                  freevars=unwrap_list_of_strings(space, w_freevars),
+                  cellvars=unwrap_list_of_strings(space, w_cellvars))
 
 @cpython_api([CONST_STRING, CONST_STRING, rffi.INT_real], PyCodeObject)
 def PyCode_NewEmpty(space, filename, funcname, firstlineno):
     """Creates a new empty code object with the specified source location."""
-    return space.wrap(PyCode(space,
-                             argcount=0,
-                             nlocals=0,
-                             stacksize=0,
-                             flags=0,
-                             code="",
-                             consts=[],
-                             names=[],
-                             varnames=[],
-                             filename=rffi.charp2str(filename),
-                             name=rffi.charp2str(funcname),
-                             firstlineno=rffi.cast(lltype.Signed, firstlineno),
-                             lnotab="",
-                             freevars=[],
-                             cellvars=[]))
+    return PyCode(space,
+                  argcount=0,
+                  nlocals=0,
+                  stacksize=0,
+                  flags=0,
+                  code="",
+                  consts=[],
+                  names=[],
+                  varnames=[],
+                  filename=rffi.charp2str(filename),
+                  name=rffi.charp2str(funcname),
+                  firstlineno=rffi.cast(lltype.Signed, firstlineno),
+                  lnotab="",
+                  freevars=[],
+                  cellvars=[])
 
 @cpython_api([PyCodeObject], Py_ssize_t, error=CANNOT_FAIL)
 def PyCode_GetNumFree(space, w_co):
diff --git a/pypy/module/cpyext/import_.py b/pypy/module/cpyext/import_.py
--- a/pypy/module/cpyext/import_.py
+++ b/pypy/module/cpyext/import_.py
@@ -20,35 +20,35 @@
     # Get the builtins from current globals
     if caller is not None:
         w_globals = caller.get_w_globals()
-        w_builtin = space.getitem(w_globals, space.wrap('__builtins__'))
+        w_builtin = space.getitem(w_globals, space.newtext('__builtins__'))
     else:
         # No globals -- use standard builtins, and fake globals
         w_builtin = space.getbuiltinmodule('__builtin__')
         w_globals = space.newdict()
-        space.setitem(w_globals, space.wrap("__builtins__"), w_builtin)
+        space.setitem(w_globals, space.newtext("__builtins__"), w_builtin)
 
     # Get the __import__ function from the builtins
     if space.isinstance_w(w_builtin, space.w_dict):
-        w_import = space.getitem(w_builtin, space.wrap("__import__"))
+        w_import = space.getitem(w_builtin, space.newtext("__import__"))
     else:
-        w_import = space.getattr(w_builtin, space.wrap("__import__"))
+        w_import = space.getattr(w_builtin, space.newtext("__import__"))
 
     # Call the __import__ function with the proper argument list
     # Always use absolute import here.
     return space.call_function(w_import,
                                w_name, w_globals, w_globals,
-                               space.newlist([space.wrap("__doc__")]))
+                               space.newlist([space.newtext("__doc__")]))
 
 @cpython_api([CONST_STRING], PyObject)
 def PyImport_ImportModule(space, name):
-    return PyImport_Import(space, space.wrap(rffi.charp2str(name)))
+    return PyImport_Import(space, space.newtext(rffi.charp2str(name)))
 
 @cpython_api([CONST_STRING], PyObject)
 def PyImport_ImportModuleNoBlock(space, name):
     space.warn(
-        space.wrap('PyImport_ImportModuleNoBlock() is not non-blocking'),
+        space.newtext('PyImport_ImportModuleNoBlock() is not non-blocking'),
         space.w_RuntimeWarning)
-    return PyImport_Import(space, space.wrap(rffi.charp2str(name)))
+    return PyImport_Import(space, space.newtext(rffi.charp2str(name)))
 
 @cpython_api([PyObject], PyObject)
 def PyImport_ReloadModule(space, w_mod):
@@ -72,8 +72,8 @@
     modulename = rffi.charp2str(name)
     w_mod = check_sys_modules_w(space, modulename)
     if not w_mod or space.is_w(w_mod, space.w_None):
-        w_mod = Module(space, space.wrap(modulename))
-        space.setitem(space.sys.get('modules'), space.wrap(modulename), w_mod)
+        w_mod = Module(space, space.newtext(modulename))
+        space.setitem(space.sys.get('modules'), space.newtext(modulename), w_mod)
     # return a borrowed ref --- assumes one copy in sys.modules
     return w_mod
 
@@ -116,11 +116,11 @@
     """Like PyImport_ExecCodeModule(), but the __file__ attribute of
     the module object is set to pathname if it is non-NULL."""
     code = space.interp_w(PyCode, w_code)
-    w_name = space.wrap(rffi.charp2str(name))
+    w_name = space.newtext(rffi.charp2str(name))
     if pathname:
         pathname = rffi.charp2str(pathname)
     else:
         pathname = code.co_filename
     w_mod = importing.add_module(space, w_name)
-    space.setattr(w_mod, space.wrap('__file__'), space.wrap(pathname))
+    space.setattr(w_mod, space.newtext('__file__'), space.newtext(pathname))
     return importing.exec_code_module(space, w_mod, code, w_name)
diff --git a/pypy/module/cpyext/intobject.py b/pypy/module/cpyext/intobject.py
--- a/pypy/module/cpyext/intobject.py
+++ b/pypy/module/cpyext/intobject.py
@@ -53,7 +53,7 @@
     """Create a new integer object with a value of ival.
 
     """
-    return space.wrap(ival)
+    return space.newint(ival)
 
 @cpython_api([PyObject], lltype.Signed, error=-1)
 def PyInt_AsLong(space, w_obj):
@@ -127,8 +127,8 @@
     LONG_MAX, a long integer object is returned.
     """
     if ival <= LONG_MAX:
-        return space.wrap(intmask(ival))
-    return space.wrap(ival)
+        return space.newint(intmask(ival))
+    return space.newint(ival)
 
 @cpython_api([Py_ssize_t], PyObject)
 def PyInt_FromSsize_t(space, ival):
@@ -136,7 +136,7 @@
     than LONG_MAX or smaller than LONG_MIN, a long integer object is
     returned.
     """
-    return space.wrap(ival)
+    return space.newint(ival)
 
 @cpython_api([CONST_STRING, rffi.CCHARPP, rffi.INT_real], PyObject)
 def PyInt_FromString(space, str, pend, base):
@@ -154,8 +154,8 @@
     returned.  If overflow warnings are not being suppressed, NULL will be
     returned in this case."""
     s = rffi.charp2str(str)
-    w_str = space.wrap(s)
-    w_base = space.wrap(rffi.cast(lltype.Signed, base))
+    w_str = space.newtext(s)
+    w_base = space.newint(rffi.cast(lltype.Signed, base))
     if pend:
         pend[0] = rffi.ptradd(str, len(s))
     return space.call_function(space.w_int, w_str, w_base)
diff --git a/pypy/module/cpyext/iterator.py b/pypy/module/cpyext/iterator.py
--- a/pypy/module/cpyext/iterator.py
+++ b/pypy/module/cpyext/iterator.py
@@ -40,7 +40,7 @@
 def PyIter_Check(space, w_obj):
     """Return true if the object o supports the iterator protocol."""
     try:
-        w_attr = space.getattr(space.type(w_obj), space.wrap("next"))
+        w_attr = space.getattr(space.type(w_obj), space.newtext("next"))
     except:
         return False
     else:
diff --git a/pypy/module/cpyext/listobject.py b/pypy/module/cpyext/listobject.py
--- a/pypy/module/cpyext/listobject.py
+++ b/pypy/module/cpyext/listobject.py
@@ -84,7 +84,7 @@
     """Insert the item item into list list in front of index index.  Return
     0 if successful; return -1 and set an exception if unsuccessful.
     Analogous to list.insert(index, item)."""
-    space.call_method(space.w_list, "insert", w_list, space.wrap(index), w_item)
+    space.call_method(space.w_list, "insert", w_list, space.newint(index), w_item)
     return 0
 
 @cpython_api([rffi.VOIDP], Py_ssize_t, error=CANNOT_FAIL)
@@ -134,8 +134,8 @@
     and high.  Return NULL and set an exception if unsuccessful.  Analogous
     to list[low:high].  Negative indices, as when slicing from Python, are not
     supported."""
-    w_start = space.wrap(low)
-    w_stop = space.wrap(high)
+    w_start = space.newint(low)
+    w_stop = space.newint(high)
     return space.getslice(w_list, w_start, w_stop)
 
 @cpython_api([PyObject, Py_ssize_t, Py_ssize_t, PyObject], rffi.INT_real, error=-1)
@@ -145,8 +145,8 @@
     be NULL, indicating the assignment of an empty list (slice deletion).
     Return 0 on success, -1 on failure.  Negative indices, as when
     slicing from Python, are not supported."""
-    w_start = space.wrap(low)
-    w_stop = space.wrap(high)
+    w_start = space.newint(low)
+    w_stop = space.newint(high)
     if w_sequence:
         space.setslice(w_list, w_start, w_stop, w_sequence)
     else:
diff --git a/pypy/module/cpyext/longobject.py b/pypy/module/cpyext/longobject.py
--- a/pypy/module/cpyext/longobject.py
+++ b/pypy/module/cpyext/longobject.py
@@ -128,7 +128,7 @@
     except OperationError as e:
         if not e.match(space, space.w_OverflowError):
             raise
-    if space.is_true(space.gt(w_long, space.wrap(0))):
+    if space.is_true(space.gt(w_long, space.newint(0))):
         overflow_ptr[0] = rffi.cast(rffi.INT_real, 1)
     else:
         overflow_ptr[0] = rffi.cast(rffi.INT_real, -1)
@@ -149,7 +149,7 @@
     except OperationError as e:
         if not e.match(space, space.w_OverflowError):
             raise
-    if space.is_true(space.gt(w_long, space.wrap(0))):
+    if space.is_true(space.gt(w_long, space.newint(0))):
         overflow_ptr[0] = rffi.cast(rffi.INT_real, 1)
     else:
         overflow_ptr[0] = rffi.cast(rffi.INT_real, -1)
@@ -158,7 +158,7 @@
 @cpython_api([lltype.Float], PyObject)
 def PyLong_FromDouble(space, val):
     """Return a new PyLongObject object from v, or NULL on failure."""
-    return space.long(space.wrap(val))
+    return space.long(space.newfloat(val))
 
 @cpython_api([PyObject], lltype.Float, error=-1.0)
 def PyLong_AsDouble(space, w_long):
@@ -179,8 +179,8 @@
     between 2 and 36, inclusive.  Leading spaces are ignored.  If there are
     no digits, ValueError will be raised."""
     s = rffi.charp2str(str)
-    w_str = space.wrap(s)
-    w_base = space.wrap(rffi.cast(lltype.Signed, base))
+    w_str = space.newtext(s)
+    w_base = space.newint(rffi.cast(lltype.Signed, base))
     if pend:
         pend[0] = rffi.ptradd(str, len(s))
     return space.call_function(space.w_long, w_str, w_base)
@@ -192,8 +192,8 @@
     string, length gives the number of characters, and base is the radix
     for the conversion.  The radix must be in the range [2, 36]; if it is
     out of range, ValueError will be raised."""
-    w_value = space.wrap(rffi.wcharpsize2unicode(u, length))
-    w_base = space.wrap(rffi.cast(lltype.Signed, base))
+    w_value = space.newunicode(rffi.wcharpsize2unicode(u, length))
+    w_base = space.newint(rffi.cast(lltype.Signed, base))
     return space.call_function(space.w_long, w_value, w_base)
 
 @cpython_api([rffi.VOIDP], PyObject)
@@ -205,7 +205,7 @@
     value = rffi.cast(ADDR, p)    # signed integer
     if value < 0:
         return space.newlong_from_rarith_int(rffi.cast(lltype.Unsigned, p))
-    return space.wrap(value)
+    return space.newint(value)
 
 @cpython_api([PyObject], rffi.VOIDP, error=lltype.nullptr(rffi.VOIDP.TO))
 def PyLong_AsVoidPtr(space, w_long):
diff --git a/pypy/module/cpyext/methodobject.py b/pypy/module/cpyext/methodobject.py
--- a/pypy/module/cpyext/methodobject.py
+++ b/pypy/module/cpyext/methodobject.py
@@ -92,14 +92,14 @@
                 raise oefmt(space.w_TypeError,
                             "%s() takes exactly one argument (%d given)",
                             self.name, length)
-            w_arg = space.getitem(w_args, space.wrap(0))
+            w_arg = space.getitem(w_args, space.newint(0))
             return generic_cpy_call(space, func, w_self, w_arg)
         elif flags & METH_VARARGS:
             return generic_cpy_call(space, func, w_self, w_args)
         else: # METH_OLDARGS, the really old style
             size = length
             if size == 1:
-                w_arg = space.getitem(w_args, space.wrap(0))
+                w_arg = space.getitem(w_args, space.newint(0))
             elif size == 0:
                 w_arg = None
             else:
@@ -109,7 +109,7 @@
     def get_doc(self, space):
         doc = self.ml.c_ml_doc
         if doc:
-            return space.wrap(rffi.charp2str(rffi.cast(rffi.CCHARP,doc)))
+            return space.newtext(rffi.charp2str(rffi.cast(rffi.CCHARP,doc)))
         else:
             return space.w_None
 
@@ -193,9 +193,9 @@
         return self.wrapper_func(space, w_self, w_args, func_to_call)
 
     def descr_method_repr(self):
-        return self.space.wrap("<slot wrapper '%s' of '%s' objects>" %
-                               (self.method_name,
-                                self.w_objclass.name))
+        return self.space.newtext("<slot wrapper '%s' of '%s' objects>" %
+                                  (self.method_name,
+                                   self.w_objclass.name))
 
 def cwrapper_descr_call(space, w_self, __args__):
     self = space.interp_w(W_PyCWrapperObject, w_self)
@@ -204,7 +204,7 @@
     w_self = args_w[0]
     w_kw = space.newdict()
     for key, w_obj in kw_w.items():
-        space.setitem(w_kw, space.wrap(key), w_obj)
+        space.setitem(w_kw, space.newtext(key), w_obj)
     return self.call(space, w_self, w_args, w_kw)
 
 
@@ -214,7 +214,7 @@
     w_args = space.newtuple(args_w)
     w_kw = space.newdict()
     for key, w_obj in kw_w.items():
-        space.setitem(w_kw, space.wrap(key), w_obj)
+        space.setitem(w_kw, space.newtext(key), w_obj)
     ret = self.call(space, None, w_args, w_kw)
     return ret
 
@@ -225,7 +225,7 @@
     w_args = space.newtuple(args_w[1:])
     w_kw = space.newdict()
     for key, w_obj in kw_w.items():
-        space.setitem(w_kw, space.wrap(key), w_obj)
+        space.setitem(w_kw, space.newtext(key), w_obj)
     ret = self.call(space, w_instance, w_args, w_kw)
     return ret
 
@@ -234,14 +234,14 @@
                         not space.is_w(w_obj, space.w_None) or
                         space.is_w(w_cls, space.type(space.w_None)))
     if asking_for_bound:
-        return space.wrap(Method(space, w_function, w_obj, w_cls))
+        return Method(space, w_function, w_obj, w_cls)
     else:
         return w_function
 
 def cclassmethod_descr_get(space, w_function, w_obj, w_cls=None):
     if not w_cls:
         w_cls = space.type(w_obj)
-    return space.wrap(Method(space, w_function, w_cls, space.w_None))
+    return Method(space, w_function, w_cls, space.w_None)
 
 
 W_PyCFunctionObject.typedef = TypeDef(
@@ -290,7 +290,7 @@
 
 @cpython_api([lltype.Ptr(PyMethodDef), PyObject, PyObject], PyObject)
 def PyCFunction_NewEx(space, ml, w_self, w_name):
-    return space.wrap(W_PyCFunctionObject(space, ml, w_self, w_name))
+    return W_PyCFunctionObject(space, ml, w_self, w_name)
 
 @cpython_api([PyObject], PyCFunction_typedef)
 def PyCFunction_GetFunction(space, w_obj):
@@ -305,19 +305,19 @@
 
 @cpython_api([PyObject], PyObject)
 def PyStaticMethod_New(space, w_func):
-    return space.wrap(StaticMethod(w_func))
+    return StaticMethod(w_func)
 
 @cpython_api([PyObject], PyObject)
 def PyClassMethod_New(space, w_func):
-    return space.wrap(ClassMethod(w_func))
+    return ClassMethod(w_func)
 
 @cpython_api([PyTypeObjectPtr, lltype.Ptr(PyMethodDef)], PyObject)
 def PyDescr_NewMethod(space, w_type, method):
-    return space.wrap(W_PyCMethodObject(space, method, w_type))
+    return W_PyCMethodObject(space, method, w_type)
 
 @cpython_api([PyObject, lltype.Ptr(PyMethodDef)], PyObject)
 def PyDescr_NewClassMethod(space, w_type, method):
-    return space.wrap(W_PyCClassMethodObject(space, method, w_type))
+    return W_PyCClassMethodObject(space, method, w_type)
 
 @cpython_api([lltype.Ptr(PyMethodDef), PyObject, CONST_STRING], PyObject)
 def Py_FindMethod(space, table, w_obj, name_ptr):
@@ -341,10 +341,10 @@
                 break
             if name == "__methods__":
                 method_list_w.append(
-                    space.wrap(rffi.charp2str(rffi.cast(rffi.CCHARP, method.c_ml_name))))
+                    space.newtext(rffi.charp2str(rffi.cast(rffi.CCHARP, method.c_ml_name))))
             elif rffi.charp2str(rffi.cast(rffi.CCHARP, method.c_ml_name)) == name: # XXX expensive copy
-                return space.wrap(W_PyCFunctionObject(space, method, w_obj))
+                return W_PyCFunctionObject(space, method, w_obj)
     if name == "__methods__":
         return space.newlist(method_list_w)
-    raise OperationError(space.w_AttributeError, space.wrap(name))
+    raise OperationError(space.w_AttributeError, space.newtext(name))
 
diff --git a/pypy/module/cpyext/modsupport.py b/pypy/module/cpyext/modsupport.py
--- a/pypy/module/cpyext/modsupport.py
+++ b/pypy/module/cpyext/modsupport.py
@@ -21,12 +21,12 @@
     loaded, you will get an empty module object. Use PyImport_ImportModule()
     or one of its variants to import a module.  Package structures implied by a
     dotted name for name are not created if not already present."""
-    w_name = space.wrap(name)
+    w_name = space.newtext(name)
     w_modules = space.sys.get('modules')
 
     w_mod = space.finditem_str(w_modules, name)
     if w_mod is None:
-        w_mod = space.wrap(Module(space, w_name))
+        w_mod = Module(space, w_name)
         space.setitem(w_modules, w_name, w_mod)
 
     return w_mod
@@ -65,15 +65,15 @@
         dict_w = {}
     convert_method_defs(space, dict_w, methods, None, w_self, modname)
     for key, w_value in dict_w.items():
-        space.setattr(w_mod, space.wrap(key), w_value)
+        space.setattr(w_mod, space.newtext(key), w_value)
     if doc:
-        space.setattr(w_mod, space.wrap("__doc__"),
-                      space.wrap(rffi.charp2str(doc)))
+        space.setattr(w_mod, space.newtext("__doc__"),
+                      space.newtext(rffi.charp2str(doc)))
     return w_mod   # borrowed result kept alive in PyImport_AddModule()
 
 
 def convert_method_defs(space, dict_w, methods, w_type, w_self=None, name=None):
-    w_name = space.wrap(name)
+    w_name = space.newtext_or_none(name)
     methods = rffi.cast(rffi.CArrayPtr(PyMethodDef), methods)
     if methods:
         i = -1
@@ -90,7 +90,7 @@
                     raise oefmt(space.w_ValueError,
                             "module functions cannot set METH_CLASS or "
                             "METH_STATIC")
-                w_obj = space.wrap(W_PyCFunctionObject(space, method, w_self, w_name))
+                w_obj = W_PyCFunctionObject(space, method, w_self, w_name)
             else:
                 if methodname in dict_w and not (flags & METH_COEXIST):
                     continue
diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -119,7 +119,7 @@
     value on success, or NULL on failure. This is the equivalent of the Python
     expression o.attr_name."""
     name = rffi.charp2str(name_ptr)
-    return space.getattr(w_obj, space.wrap(name))
+    return space.getattr(w_obj, space.newtext(name))
 
 @cpython_api([PyObject, PyObject], rffi.INT_real, error=CANNOT_FAIL)
 def PyObject_HasAttr(space, w_obj, w_name):
@@ -133,7 +133,7 @@
 def PyObject_HasAttrString(space, w_obj, name_ptr):
     try:
         name = rffi.charp2str(name_ptr)
-        w_res = operation.hasattr(space, w_obj, space.wrap(name))
+        w_res = operation.hasattr(space, w_obj, space.newtext(name))
         return space.is_true(w_res)
     except OperationError:
         return 0
@@ -145,7 +145,7 @@
 
 @cpython_api([PyObject, CONST_STRING, PyObject], rffi.INT_real, error=-1)
 def PyObject_SetAttrString(space, w_obj, name_ptr, w_value):
-    w_name = space.wrap(rffi.charp2str(name_ptr))
+    w_name = space.newtext(rffi.charp2str(name_ptr))
     operation.setattr(space, w_obj, w_name, w_value)
     return 0
 
@@ -160,7 +160,7 @@
 def PyObject_DelAttrString(space, w_obj, name_ptr):
     """Delete attribute named attr_name, for object o. Returns -1 on failure.
     This is the equivalent of the Python statement del o.attr_name."""
-    w_name = space.wrap(rffi.charp2str(name_ptr))
+    w_name = space.newtext(rffi.charp2str(name_ptr))
     space.delattr(w_obj, w_name)
     return 0
 
@@ -235,7 +235,7 @@
 @cpython_api([PyObject], PyObject)
 def PyObject_Str(space, w_obj):
     if w_obj is None:
-        return space.wrap("<NULL>")
+        return space.newtext("<NULL>")
     return space.str(w_obj)
 
 @cpython_api([PyObject], PyObject)
@@ -245,13 +245,13 @@
     Python expression repr(o).  Called by the repr() built-in function and
     by reverse quotes."""
     if w_obj is None:
-        return space.wrap("<NULL>")
+        return space.newtext("<NULL>")
     return space.repr(w_obj)
 
 @cpython_api([PyObject, PyObject], PyObject)
 def PyObject_Format(space, w_obj, w_format_spec):
     if w_format_spec is None:
-        w_format_spec = space.wrap('')
+        w_format_spec = space.newtext('')
     return space.call_method(w_obj, '__format__', w_format_spec)
 
 @cpython_api([PyObject], PyObject)
@@ -261,7 +261,7 @@
     the Python expression unicode(o).  Called by the unicode() built-in
     function."""
     if w_obj is None:
-        return space.wrap(u"<NULL>")
+        return space.newunicode(u"<NULL>")
     return space.call_function(space.w_unicode, w_obj)
 
 @cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
@@ -385,7 +385,7 @@
         fd = space.int_w(w_obj)
     except OperationError:
         try:
-            w_meth = space.getattr(w_obj, space.wrap('fileno'))
+            w_meth = space.getattr(w_obj, space.newtext('fileno'))
         except OperationError:
             raise oefmt(space.w_TypeError,
                         "argument must be an int, or have a fileno() method.")
@@ -409,7 +409,7 @@
 
 @cpython_api([rffi.DOUBLE], rffi.LONG, error=-1)
 def _Py_HashDouble(space, v):
-    return space.int_w(space.hash(space.wrap(v)))
+    return space.int_w(space.hash(space.newfloat(v)))
 
 @cpython_api([PyObject], lltype.Signed, error=-1)
 def PyObject_HashNotImplemented(space, o):
diff --git a/pypy/module/cpyext/pyerrors.py b/pypy/module/cpyext/pyerrors.py
--- a/pypy/module/cpyext/pyerrors.py
+++ b/pypy/module/cpyext/pyerrors.py
@@ -21,7 +21,7 @@
 @cpython_api([PyObject, CONST_STRING], lltype.Void)
 def PyErr_SetString(space, w_type, message_ptr):
     message = rffi.charp2str(message_ptr)
-    PyErr_SetObject(space, w_type, space.wrap(message))
+    PyErr_SetObject(space, w_type, space.newtext(message))
 
 @cpython_api([PyObject], lltype.Void, error=CANNOT_FAIL)
 def PyErr_SetNone(space, w_type):
@@ -58,7 +58,7 @@
     if operror:
         ptype[0] = make_ref(space, operror.w_type)
         pvalue[0] = make_ref(space, operror.get_w_value(space))
-        ptraceback[0] = make_ref(space, space.wrap(operror.get_traceback()))
+        ptraceback[0] = make_ref(space, operror.get_traceback())
     else:
         ptype[0] = lltype.nullptr(PyObject.TO)
         pvalue[0] = lltype.nullptr(PyObject.TO)
@@ -170,13 +170,13 @@
     msg = os.strerror(errno)
     if w_value:
         w_error = space.call_function(w_type,
-                                      space.wrap(errno),
-                                      space.wrap(msg),
+                                      space.newint(errno),
+                                      space.newtext(msg),
                                       w_value)
     else:
         w_error = space.call_function(w_type,
-                                      space.wrap(errno),
-                                      space.wrap(msg))
+                                      space.newint(errno),
+                                      space.newtext(msg))
     raise OperationError(w_type, w_error)
 
 @cpython_api([], rffi.INT_real, error=-1)
@@ -252,11 +252,11 @@
     documentation.  There is no C API for warning control."""
     if w_category is None:
         w_category = space.w_None
-    w_message = space.wrap(rffi.charp2str(message_ptr))
-    w_stacklevel = space.wrap(rffi.cast(lltype.Signed, stacklevel))
+    w_message = space.newtext(rffi.charp2str(message_ptr))
+    w_stacklevel = space.newint(rffi.cast(lltype.Signed, stacklevel))
 
-    w_module = PyImport_Import(space, space.wrap("warnings"))
-    w_warn = space.getattr(w_module, space.wrap("warn"))
+    w_module = PyImport_Import(space, space.newtext("warnings"))
+    w_warn = space.getattr(w_module, space.newtext("warn"))
     space.call_function(w_warn, w_message, w_category, w_stacklevel)
     return 0
 
@@ -286,7 +286,7 @@
 
     w_type = operror.w_type
     w_value = operror.get_w_value(space)
-    w_tb = space.wrap(operror.get_traceback())
+    w_tb = operror.get_traceback()
 
     if rffi.cast(lltype.Signed, set_sys_last_vars):
         space.sys.setdictvalue(space, "last_type", w_type)
@@ -317,10 +317,10 @@
 
 @cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
 def PyTraceBack_Print(space, w_tb, w_file):
-    space.call_method(w_file, "write", space.wrap(
+    space.call_method(w_file, "write", space.newtext(
         'Traceback (most recent call last):\n'))
     w_traceback = space.call_method(space.builtin, '__import__',
-                                    space.wrap("traceback"))
+                                    space.newtext("traceback"))
     space.call_method(w_traceback, "print_tb", w_tb, space.w_None, w_file)
     return 0
 
@@ -373,7 +373,7 @@
     if operror:
         ptype[0] = make_ref(space, operror.w_type)
         pvalue[0] = make_ref(space, operror.get_w_value(space))
-        ptraceback[0] = make_ref(space, space.wrap(operror.get_traceback()))
+        ptraceback[0] = make_ref(space, operror.get_traceback())
     else:
         ptype[0] = lltype.nullptr(PyObject.TO)
         pvalue[0] = lltype.nullptr(PyObject.TO)
diff --git a/pypy/module/cpyext/pyfile.py b/pypy/module/cpyext/pyfile.py
--- a/pypy/module/cpyext/pyfile.py
+++ b/pypy/module/cpyext/pyfile.py
@@ -22,15 +22,15 @@
     0, however, one line is read regardless of length, but EOFError is
     raised if the end of the file is reached immediately."""
     try:
-        w_readline = space.getattr(w_obj, space.wrap('readline'))
+        w_readline = space.getattr(w_obj, space.newtext('readline'))
     except OperationError:
         raise oefmt(space.w_TypeError,
             "argument must be a file, or have a readline() method.")
 
     n = rffi.cast(lltype.Signed, n)
-    if space.is_true(space.gt(space.wrap(n), space.wrap(0))):
-        return space.call_function(w_readline, space.wrap(n))
-    elif space.is_true(space.lt(space.wrap(n), space.wrap(0))):
+    if space.is_true(space.gt(space.newint(n), space.newint(0))):
+        return space.call_function(w_readline, space.newint(n))
+    elif space.is_true(space.lt(space.newint(n), space.newint(0))):
         return space.call_function(w_readline)
     else:
         # XXX Raise EOFError as specified
@@ -117,7 +117,7 @@
 @cpython_api([PyObject], PyObject)
 def PyFile_Name(space, w_p):
     """Return the name of the file specified by p as a string object."""
-    w_name = space.getattr(w_p, space.wrap("name"))
+    w_name = space.getattr(w_p, space.newtext("name"))
     return w_name     # borrowed ref, should be a W_StringObject from the file
 
 @cpython_api([PyObject, rffi.INT_real], rffi.INT_real, error=CANNOT_FAIL)
@@ -137,8 +137,8 @@
             w_newflag = space.w_True
         else:
             w_newflag = space.w_False
-        oldflag = space.int_w(space.getattr(w_p, space.wrap("softspace")))
-        space.setattr(w_p, space.wrap("softspace"), w_newflag)
+        oldflag = space.int_w(space.getattr(w_p, space.newtext("softspace")))
+        space.setattr(w_p, space.newtext("softspace"), w_newflag)
         return oldflag
     except OperationError as e:
         return 0
diff --git a/pypy/module/cpyext/sequence.py b/pypy/module/cpyext/sequence.py
--- a/pypy/module/cpyext/sequence.py
+++ b/pypy/module/cpyext/sequence.py
@@ -19,7 +19,7 @@
     """Return the result of repeating sequence object o count times, or NULL on
     failure.  This is the equivalent of the Python expression o * count.
     """
-    return space.mul(w_obj, space.wrap(count))
+    return space.mul(w_obj, space.newint(count))
 
 @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
 def PySequence_Check(space, w_obj):
@@ -55,7 +55,7 @@
         return W_ListObject.newlist_cpyext(space, space.listview(w_obj))
     except OperationError as e:
         if e.match(space, space.w_TypeError):
-            raise OperationError(space.w_TypeError, space.wrap(rffi.charp2str(m)))
+            raise OperationError(space.w_TypeError, space.newtext(rffi.charp2str(m)))
         raise e
 
 @cpython_api([rffi.VOIDP, Py_ssize_t], PyObject, result_borrowed=True)
@@ -107,20 +107,20 @@
 def PySequence_GetSlice(space, w_obj, start, end):
     """Return the slice of sequence object o between i1 and i2, or NULL on
     failure. This is the equivalent of the Python expression o[i1:i2]."""
-    return space.getslice(w_obj, space.wrap(start), space.wrap(end))
+    return space.getslice(w_obj, space.newint(start), space.newint(end))
 
 @cpython_api([PyObject, Py_ssize_t, Py_ssize_t, PyObject], rffi.INT_real, error=-1)
 def PySequence_SetSlice(space, w_obj, start, end, w_value):
     """Assign the sequence object v to the slice in sequence object o from i1 to
     i2.  This is the equivalent of the Python statement o[i1:i2] = v."""
-    space.setslice(w_obj, space.wrap(start), space.wrap(end), w_value)
+    space.setslice(w_obj, space.newint(start), space.newint(end), w_value)
     return 0
 
 @cpython_api([PyObject, Py_ssize_t, Py_ssize_t], rffi.INT_real, error=-1)
 def PySequence_DelSlice(space, w_obj, start, end):
     """Delete the slice in sequence object o from i1 to i2.  Returns -1 on
     failure.  This is the equivalent of the Python statement del o[i1:i2]."""
-    space.delslice(w_obj, space.wrap(start), space.wrap(end))
+    space.delslice(w_obj, space.newint(start), space.newint(end))
     return 0
 
 @cpython_api([rffi.VOIDP, Py_ssize_t], PyObject)
@@ -132,7 +132,7 @@
 
     This function used an int type for i. This might require
     changes in your code for properly supporting 64-bit systems."""
-    return space.getitem(w_obj, space.wrap(i))
+    return space.getitem(w_obj, space.newint(i))
 
 @cpython_api([PyObject, Py_ssize_t], PyObject)
 def PySequence_GetItem(space, w_obj, i):
@@ -175,7 +175,7 @@
 
     This function used an int type for count. This might require
     changes in your code for properly supporting 64-bit systems."""
-    return space.inplace_mul(w_o, space.wrap(count))
+    return space.inplace_mul(w_o, space.newint(count))
 
 
 @cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
@@ -203,14 +203,14 @@
     if PyDict_Check(space, w_o) or not PySequence_Check(space, w_o):
         raise oefmt(space.w_TypeError,
                     "'%T' object does not support item assignment", w_o)
-    space.setitem(w_o, space.wrap(i), w_v)
+    space.setitem(w_o, space.newint(i), w_v)
     return 0
 
 @cpython_api([PyObject, Py_ssize_t], rffi.INT_real, error=-1)
 def PySequence_DelItem(space, w_o, i):
     """Delete the ith element of object o.  Returns -1 on failure.  This is the
     equivalent of the Python statement del o[i]."""
-    space.delitem(w_o, space.wrap(i))
+    space.delitem(w_o, space.newint(i))
     return 0
 
 @cpython_api([PyObject, PyObject], Py_ssize_t, error=-1)
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -133,7 +133,7 @@
     res = rffi.cast(lltype.Signed, res)
     if res == -1:
         space.fromcache(State).check_and_raise_exception(always=True)
-    return space.wrap(bool(res))
+    return space.newbool(bool(res))
 
 def wrap_getattr(space, w_self, w_args, func):
     func_target = rffi.cast(getattrfunc, func)
@@ -222,7 +222,7 @@
 def wrap_lenfunc(space, w_self, w_args, func):
     func_len = rffi.cast(lenfunc, func)
     check_num_args(space, w_args, 0)
-    return space.wrap(generic_cpy_call(space, func_len, w_self))
+    return space.newint(generic_cpy_call(space, func_len, w_self))
 
 def wrap_sq_item(space, w_self, w_args, func):
     func_target = rffi.cast(ssizeargfunc, func)
@@ -259,7 +259,7 @@
     res = rffi.cast(lltype.Signed, res)
     if res == -1:
         space.fromcache(State).check_and_raise_exception(always=True)
-    return space.wrap(bool(res))
+    return space.newbool(bool(res))
 
 def wrap_objobjargproc(space, w_self, w_args, func):
     func_target = rffi.cast(objobjargproc, func)
@@ -302,7 +302,7 @@
     res = generic_cpy_call(space, func_target, w_self)
     if res == -1:
         space.fromcache(State).check_and_raise_exception(always=True)
-    return space.wrap(res)
+    return space.newint(res)
 
 class CPyBuffer(Buffer):
     # Similar to Py_buffer
@@ -422,7 +422,7 @@
                     "%T.__cmp__(x,y) requires y to be a '%T', not a '%T'",
                     w_self, w_self, w_other)
 
-    return space.wrap(generic_cpy_call(space, func_target, w_self, w_other))
+    return space.newint(generic_cpy_call(space, func_target, w_self, w_other))
 
 from rpython.rlib.nonconst import NonConstant
 
@@ -513,7 +513,7 @@
             @cpython_api([PyObject, Py_ssize_t], PyObject, header=header)
             @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), typedef.name))
             def slot_func(space, w_self, arg):
-                return space.call_function(slot_fn, w_self, space.wrap(arg))
+                return space.call_function(slot_fn, w_self, space.newint(arg))
             api_func = slot_func.api_func
             handled = True
 
diff --git a/pypy/module/cpyext/state.py b/pypy/module/cpyext/state.py
--- a/pypy/module/cpyext/state.py
+++ b/pypy/module/cpyext/state.py
@@ -99,7 +99,7 @@
             space = self.space
             argv = space.sys.get('argv')
             if space.len_w(argv):
-                argv0 = space.getitem(argv, space.wrap(0))
+                argv0 = space.getitem(argv, space.newint(0))
                 progname = space.str_w(argv0)
             else:
                 progname = "pypy"
@@ -137,7 +137,7 @@
         if not isinstance(w_mod, Module):
             msg = "fixup_extension: module '%s' not loaded" % name
             raise OperationError(space.w_SystemError,
-                                 space.wrap(msg))
+                                 space.newtext(msg))
         w_dict = w_mod.getdict(space)
         w_copy = space.call_method(w_dict, 'copy')
         self.extensions[path] = w_copy
diff --git a/pypy/module/cpyext/structmember.py b/pypy/module/cpyext/structmember.py
--- a/pypy/module/cpyext/structmember.py
+++ b/pypy/module/cpyext/structmember.py
@@ -45,13 +45,15 @@
         if typ == member_type:
             result = rffi.cast(rffi.CArrayPtr(lltyp), addr)
             if lltyp is rffi.FLOAT:
-                w_result = space.wrap(lltype.cast_primitive(lltype.Float,
+                w_result = space.newfloat(lltype.cast_primitive(lltype.Float,
                                                             result[0]))
             elif typ == T_BOOL:
                 x = rffi.cast(lltype.Signed, result[0])
-                w_result = space.wrap(x != 0)
+                w_result = space.newbool(x != 0)
+            elif typ == T_DOUBLE:
+                w_result = space.newfloat(result[0])
             else:
-                w_result = space.wrap(result[0])
+                w_result = space.newint(result[0])
             return w_result
 
     if member_type == T_STRING:
@@ -77,7 +79,7 @@
         if obj_ptr[0]:
             w_result = from_ref(space, obj_ptr[0])
         else:
-            w_name = space.wrap(rffi.charp2str(w_member.c_name))
+            w_name = space.newtext(rffi.charp2str(w_member.c_name))
             raise OperationError(space.w_AttributeError, w_name)
     else:
         raise oefmt(space.w_SystemError, "bad memberdescr type")
@@ -98,7 +100,7 @@
     elif w_value is None:
         if member_type == T_OBJECT_EX:
             if not rffi.cast(PyObjectP, addr)[0]:
-                w_name = space.wrap(rffi.charp2str(w_member.c_name))
+                w_name = space.newtext(rffi.charp2str(w_member.c_name))
                 raise OperationError(space.w_AttributeError, w_name)
         elif member_type != T_OBJECT:
             raise oefmt(space.w_TypeError,
diff --git a/pypy/module/cpyext/tupleobject.py b/pypy/module/cpyext/tupleobject.py
--- a/pypy/module/cpyext/tupleobject.py
+++ b/pypy/module/cpyext/tupleobject.py
@@ -210,4 +210,4 @@
     """Take a slice of the tuple pointed to by p from low to high and return it
     as a new tuple.
     """
-    return space.getslice(w_obj, space.wrap(low), space.wrap(high))
+    return space.getslice(w_obj, space.newint(low), space.newint(high))
diff --git a/pypy/module/cpyext/unicodeobject.py b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -403,9 +403,9 @@
     set."""
     if not encoding:
         raise oefmt(space.w_TypeError, "decoding Unicode is not supported")
-    w_encoding = space.wrap(rffi.charp2str(encoding))
+    w_encoding = space.newtext(rffi.charp2str(encoding))
     if errors:
-        w_errors = space.wrap(rffi.charp2str(errors))
+        w_errors = space.newtext(rffi.charp2str(errors))
     else:
         w_errors = None
 
@@ -415,7 +415,7 @@
         w_meth = None
     else:
         try:
-            w_meth = space.getattr(w_obj, space.wrap('decode'))
+            w_meth = space.getattr(w_obj, space.newtext('decode'))
         except OperationError as e:
             if not e.match(space, space.w_AttributeError):
                 raise
@@ -428,7 +428,7 @@
 def PyUnicode_FromString(space, s):
     """Create a Unicode object from an UTF-8 encoded null-terminated char buffer"""
     w_str = space.newbytes(rffi.charp2str(s))
-    return space.call_method(w_str, 'decode', space.wrap("utf-8"))
+    return space.call_method(w_str, 'decode', space.newtext("utf-8"))
 
 @cpython_api([CONST_STRING, Py_ssize_t], PyObject, result_is_ll=True)
 def PyUnicode_FromStringAndSize(space, s, size):
@@ -451,7 +451,7 @@
     The ordinal must be in range(0x10000) on narrow Python builds
     (UCS2), and range(0x110000) on wide builds (UCS4). A ValueError is
     raised in case it is not."""
-    w_ordinal = space.wrap(rffi.cast(lltype.Signed, ordinal))
+    w_ordinal = space.newint(rffi.cast(lltype.Signed, ordinal))
     return space.call_function(space.builtin.get('unichr'), w_ordinal)
 
 @cpython_api([PyObjectP, Py_ssize_t], rffi.INT_real, error=-1)
@@ -497,10 +497,10 @@
         """
         w_s = space.newbytes(rffi.charpsize2str(s, size))
         if errors:
-            w_errors = space.wrap(rffi.charp2str(errors))
+            w_errors = space.newtext(rffi.charp2str(errors))
         else:
             w_errors = None
-        return space.call_method(w_s, 'decode', space.wrap(encoding), w_errors)
+        return space.call_method(w_s, 'decode', space.newtext(encoding), w_errors)
     globals()['PyUnicode_Decode%s' % suffix] = PyUnicode_DecodeXXX
 
     @cpython_api([CONST_WSTRING, Py_ssize_t, CONST_STRING], PyObject)
@@ -509,12 +509,12 @@
         """Encode the Py_UNICODE buffer of the given size and return a
         Python string object.  Return NULL if an exception was raised
         by the codec."""
-        w_u = space.wrap(rffi.wcharpsize2unicode(s, size))
+        w_u = space.newunicode(rffi.wcharpsize2unicode(s, size))
         if errors:
-            w_errors = space.wrap(rffi.charp2str(errors))
+            w_errors = space.newtext(rffi.charp2str(errors))
         else:
             w_errors = None
-        return space.call_method(w_u, 'encode', space.wrap(encoding), w_errors)
+        return space.call_method(w_u, 'encode', space.newtext(encoding), w_errors)
     globals()['PyUnicode_Encode%s' % suffix] = PyUnicode_EncodeXXX
 
 make_conversion_functions('UTF8', 'utf-8')
@@ -575,7 +575,7 @@
     if pbyteorder is not None:
         pbyteorder[0] = rffi.cast(rffi.INT, byteorder)
 
-    return space.wrap(result)
+    return space.newunicode(result)
 
 @cpython_api([rffi.CCHARP, Py_ssize_t, rffi.CCHARP, rffi.INTP], PyObject)
 def PyUnicode_DecodeUTF32(space, s, size, llerrors, pbyteorder):
@@ -631,7 +631,7 @@
     if pbyteorder is not None:
         pbyteorder[0] = rffi.cast(rffi.INT, byteorder)
 
-    return space.wrap(result)
+    return space.newunicode(result)
 
 @cpython_api([rffi.CWCHARP, Py_ssize_t, rffi.CCHARP, rffi.CCHARP],
              rffi.INT_real, error=-1)
@@ -701,7 +701,7 @@
     return the resulting Unicode object. maxcount == -1 means replace all
     occurrences."""
     return space.call_method(w_str, "replace", w_substr, w_replstr,
-                             space.wrap(maxcount))
+                             space.newint(maxcount))
 
 @cpython_api([PyObject, PyObject, Py_ssize_t, Py_ssize_t, rffi.INT_real],
              rffi.INT_real, error=-1)
@@ -721,7 +721,7 @@
     """Return the number of non-overlapping occurrences of substr in
     str[start:end].  Return -1 if an error occurred."""
     w_count = space.call_method(w_str, "count", w_substr,
-                                space.wrap(start), space.wrap(end))
+                                space.newint(start), space.newint(end))
     return space.int_w(w_count)
 
 @cpython_api([PyObject, PyObject, Py_ssize_t, Py_ssize_t, rffi.INT_real],
@@ -735,10 +735,10 @@
     has been set."""
     if rffi.cast(lltype.Signed, direction) > 0:
         w_pos = space.call_method(w_str, "find", w_substr,
-                                  space.wrap(start), space.wrap(end))
+                                  space.newint(start), space.newint(end))
     else:
         w_pos = space.call_method(w_str, "rfind", w_substr,
-                                  space.wrap(start), space.wrap(end))
+                                  space.newint(start), space.newint(end))
     return space.int_w(w_pos)
 
 @cpython_api([PyObject, PyObject, Py_ssize_t], PyObject)
@@ -750,7 +750,7 @@
     are not included in the resulting list."""
     if w_sep is None:
         w_sep = space.w_None
-    return space.call_method(w_str, "split", w_sep, space.wrap(maxsplit))
+    return space.call_method(w_str, "split", w_sep, space.newint(maxsplit))
 
 @cpython_api([PyObject, rffi.INT_real], PyObject)
 def PyUnicode_Splitlines(space, w_str, keepend):
@@ -758,4 +758,4 @@
     Unicode strings.  CRLF is considered to be one line break.  If
     keepend is 0, the Line break characters are not included in the
     resulting strings."""
-    return space.call_method(w_str, "splitlines", space.wrap(keepend))
+    return space.call_method(w_str, "splitlines", space.newbool(bool(keepend)))


More information about the pypy-commit mailing list