[pypy-commit] pypy space-newtext: merge

cfbolz pypy.commits at gmail.com
Mon Nov 21 05:47:24 EST 2016


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: space-newtext
Changeset: r88511:ffa1b618069f
Date: 2016-11-20 13:31 +0100
http://bitbucket.org/pypy/pypy/changeset/ffa1b618069f/

Log:	merge

diff --git a/pypy/module/cppyy/capi/cint_capi.py b/pypy/module/cppyy/capi/cint_capi.py
--- a/pypy/module/cppyy/capi/cint_capi.py
+++ b/pypy/module/cppyy/capi/cint_capi.py
@@ -55,7 +55,7 @@
 
 eci = ExternalCompilationInfo(
     separate_module_files=[srcpath.join("cintcwrapper.cxx")],
-    include_dirs=[incpath] + rootincpath,
+    include_dirs=[incpath, translator_c_dir] + rootincpath,
     includes=["cintcwrapper.h"],
     library_dirs=rootlibpath,
     libraries=["Hist", "Core", "Cint"],
@@ -167,7 +167,7 @@
         memory_regulator.register(cppself)
 
         # tie all the life times to the TF1 instance
-        space.setattr(w_self, space.wrap('_callback'), w_callback)
+        space.setattr(w_self, space.newtext('_callback'), w_callback)
 
         # by definition for __init__
         return None
@@ -249,9 +249,9 @@
 def activate_branch(space, w_branch):
     w_branches = space.call_method(w_branch, "GetListOfBranches")
     for i in range(space.r_longlong_w(space.call_method(w_branches, "GetEntriesFast"))):
-        w_b = space.call_method(w_branches, "At", space.wrap(i))
+        w_b = space.call_method(w_branches, "At", space.newlong(i))
         activate_branch(space, w_b)
-    space.call_method(w_branch, "SetStatus", space.wrap(1))
+    space.call_method(w_branch, "SetStatus", space.newint(1))
     space.call_method(w_branch, "ResetReadEntry")
 
 c_ttree_GetEntry = rffi.llexternal(
@@ -277,7 +277,7 @@
 
     # try the saved cdata (for builtin types)
     try:
-        w_cdata = space.getattr(w_self, space.wrap('_'+attr))
+        w_cdata = space.getattr(w_self, space.newtext('_'+attr))
         from pypy.module._cffi_backend import cdataobj
         cdata = space.interp_w(cdataobj.W_CData, w_cdata, can_be_None=False)
         return cdata.convert_to_object()
@@ -302,15 +302,15 @@
         klass = interp_cppyy.scope_byname(space, space.str_w(w_klassname))
         w_obj = klass.construct()
         # 0x10000 = kDeleteObject; reset because we own the object
-        space.call_method(w_branch, "ResetBit", space.wrap(0x10000))
+        space.call_method(w_branch, "ResetBit", space.newint(0x10000))
         space.call_method(w_branch, "SetObject", w_obj)
-        space.call_method(w_branch, "GetEntry", space.wrap(entry))
+        space.call_method(w_branch, "GetEntry", space.newlong(entry))
         space.setattr(w_self, args_w[0], w_obj)
         return w_obj
     else:
         # builtin data
         w_leaf = space.call_method(w_self, "GetLeaf", args_w[0])
-        space.call_method(w_branch, "GetEntry", space.wrap(entry))
+        space.call_method(w_branch, "GetEntry", space.newlong(entry))
 
         # location
         w_address = space.call_method(w_leaf, "GetValuePointer")
@@ -329,7 +329,7 @@
         cdata = cdataobj.W_CData(space, address, newtype.new_primitive_type(space, typename))
 
         # cache result
-        space.setattr(w_self, space.wrap('_'+attr), space.wrap(cdata))
+        space.setattr(w_self, space.newtext('_'+attr), space.wrap(cdata))
         return space.getattr(w_self, args_w[0])
 
 class W_TTreeIter(W_Root):
@@ -343,7 +343,7 @@
         self.maxentry = space.r_longlong_w(space.call_method(w_tree, "GetEntriesFast"))
 
         space = self.space = tree.space          # holds the class cache in State
-        space.call_method(w_tree, "SetBranchStatus", space.wrap("*"), space.wrap(0))
+        space.call_method(w_tree, "SetBranchStatus", space.newtext("*"), space.newint(0))
 
     def iter_w(self):
         return self.space.wrap(self)
@@ -397,7 +397,7 @@
         _method_alias(space, w_pycppclass, "__len__", "GetSize")
 
     elif name == "TF1":
-        space.setattr(w_pycppclass, space.wrap("__init__"), _pythonizations["tf1_tf1"])
+        space.setattr(w_pycppclass, space.newtext("__init__"), _pythonizations["tf1_tf1"])
 
     elif name == "TFile":
         _method_alias(space, w_pycppclass, "__getattr__", "Get")
@@ -415,9 +415,9 @@
     elif name == "TTree":
         _method_alias(space, w_pycppclass, "_unpythonized_Branch", "Branch")
 
-        space.setattr(w_pycppclass, space.wrap("Branch"),      _pythonizations["ttree_Branch"])
-        space.setattr(w_pycppclass, space.wrap("__iter__"),    _pythonizations["ttree_iter"])
-        space.setattr(w_pycppclass, space.wrap("__getattr__"), _pythonizations["ttree_getattr"])
+        space.setattr(w_pycppclass, space.newtext("Branch"),      _pythonizations["ttree_Branch"])
+        space.setattr(w_pycppclass, space.newtext("__iter__"),    _pythonizations["ttree_iter"])
+        space.setattr(w_pycppclass, space.newtext("__getattr__"), _pythonizations["ttree_getattr"])
 
     elif name[0:8] == "TVectorT":    # TVectorT<> template
         _method_alias(space, w_pycppclass, "__len__", "GetNoElements")
diff --git a/pypy/module/cppyy/capi/reflex_capi.py b/pypy/module/cppyy/capi/reflex_capi.py
--- a/pypy/module/cppyy/capi/reflex_capi.py
+++ b/pypy/module/cppyy/capi/reflex_capi.py
@@ -9,6 +9,10 @@
 srcpath = pkgpath.join("src")
 incpath = pkgpath.join("include")
 
+# require local translator path to pickup common defs
+from rpython.translator import cdir
+translator_c_dir = py.path.local(cdir)
+
 import commands
 (config_stat, incdir) = commands.getstatusoutput("root-config --incdir")
 
@@ -39,7 +43,7 @@
 
 eci = ExternalCompilationInfo(
     separate_module_files=[srcpath.join("reflexcwrapper.cxx")],
-    include_dirs=[incpath] + rootincpath,
+    include_dirs=[incpath, translator_c_dir] + rootincpath,
     includes=["reflexcwrapper.h"],
     library_dirs=rootlibpath,
     libraries=["Reflex"],
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
@@ -180,7 +180,7 @@
         self.size = sys.maxint
 
     def convert_argument(self, space, w_obj, address, call_local):
-        w_tc = space.findattr(w_obj, space.wrap('typecode'))
+        w_tc = space.findattr(w_obj, space.newtext('typecode'))
         if w_tc is not None and space.str_w(w_tc) != self.typecode:
             raise oefmt(space.w_TypeError,
                         "expected %s pointer type, but received %s",
@@ -312,7 +312,7 @@
 
     def from_memory(self, space, w_obj, w_pycppclass, offset):
         address = rffi.cast(rffi.CCHARP, self._get_raw_address(space, w_obj, offset))
-        return space.wrap(address[0])
+        return space.newbytes(address[0])
 
     def to_memory(self, space, w_obj, w_value, offset):
         address = rffi.cast(rffi.CCHARP, self._get_raw_address(space, w_obj, offset))
@@ -331,7 +331,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(float(rffiptr[0]))
+        return space.newfloat(float(rffiptr[0]))
 
 class ConstFloatRefConverter(FloatConverter):
     _immutable_fields_ = ['libffitype', 'typecode']
@@ -370,7 +370,7 @@
     def from_memory(self, space, w_obj, w_pycppclass, offset):
         address = self._get_raw_address(space, w_obj, offset)
         charpptr = rffi.cast(rffi.CCHARPP, address)
-        return space.wrap(rffi.charp2str(charpptr[0]))
+        return space.newbytes(rffi.charp2str(charpptr[0]))
 
     def free_argument(self, space, arg, call_local):
         lltype.free(rffi.cast(rffi.CCHARPP, arg)[0], flavor='raw')
@@ -622,7 +622,7 @@
         # TODO: get the actual type info from somewhere ...
         address = self._get_raw_address(space, w_obj, offset)
         longptr = rffi.cast(rffi.LONGP, address)
-        return space.wrap(longptr[0])
+        return space.newlong(longptr[0])
 
 
 _converters = {}         # builtin and custom types
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
@@ -54,7 +54,7 @@
             raise NotImplementedError
         lresult = capi.c_call_l(space, cppmethod, cppthis, num_args, args)
         ptrval = rffi.cast(rffi.ULONG, lresult)
-        arr = space.interp_w(W_Array, unpack_simple_shape(space, space.wrap(self.typecode)))
+        arr = space.interp_w(W_Array, unpack_simple_shape(space, space.newtext(self.typecode)))
         if ptrval == 0:
             from pypy.module.cppyy import interp_cppyy
             return interp_cppyy.get_nullptr(space)
@@ -128,9 +128,9 @@
         lresult = capi.c_call_l(space, cppmethod, cppthis, num_args, args)
         ccpresult = rffi.cast(rffi.CCHARP, lresult)
         if ccpresult == rffi.cast(rffi.CCHARP, 0):
-            return space.wrap("")
+            return space.newbytes("")
         result = rffi.charp2str(ccpresult)   # TODO: make it a choice to free
-        return space.wrap(result)
+        return space.newbytes(result)
 
 
 class ConstructorExecutor(FunctionExecutor):
@@ -139,7 +139,7 @@
         from pypy.module.cppyy import interp_cppyy
         newthis = capi.c_constructor(space, cppmethod, cpptype, num_args, args)
         assert lltype.typeOf(newthis) == capi.C_OBJECT
-        return space.wrap(rffi.cast(rffi.LONG, newthis))   # really want ptrdiff_t here
+        return space.newlong(rffi.cast(rffi.LONG, newthis))   # really want ptrdiff_t here
 
 
 class InstancePtrExecutor(FunctionExecutor):
@@ -196,7 +196,7 @@
 
     def execute(self, space, cppmethod, cppthis, num_args, args):
         cstr_result = capi.c_call_s(space, cppmethod, cppthis, num_args, args)
-        return space.wrap(capi.charp2str_free(space, cstr_result))
+        return space.newbytes(capi.charp2str_free(space, cstr_result))
 
     def execute_libffi(self, space, cif_descr, funcaddr, buffer):
         from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
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
@@ -26,7 +26,7 @@
         return arg
 
     def _wrap_object(self, space, obj):
-        return space.wrap(bool(ord(rffi.cast(rffi.CHAR, obj))))
+        return space.newbool(bool(ord(rffi.cast(rffi.CHAR, obj))))
 
 class CharTypeMixin(object):
     _mixin_     = True
@@ -153,7 +153,7 @@
         return r_singlefloat(space.float_w(w_obj))
 
     def _wrap_object(self, space, obj):
-        return space.wrap(float(obj))
+        return space.newfloat(float(obj))
 
 class DoubleTypeMixin(object):
     _mixin_     = True
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
@@ -33,7 +33,7 @@
     try:
         cdll = capi.c_load_dictionary(name)
     except rdynload.DLOpenError as e:
-        raise OperationError(space.w_RuntimeError, space.wrap(str(e.msg)))
+        raise OperationError(space.w_RuntimeError, space.newtext(str(e.msg)))
     return W_CPPLibrary(space, cdll)
 
 class State(object):
@@ -53,7 +53,7 @@
     if state.w_nullptr is None:
         from pypy.module._rawffi.interp_rawffi import unpack_simple_shape
         from pypy.module._rawffi.array import W_Array, W_ArrayInstance
-        arr = space.interp_w(W_Array, unpack_simple_shape(space, space.wrap('P')))
+        arr = space.interp_w(W_Array, unpack_simple_shape(space, space.newtext('P')))
         # TODO: fix this hack; fromaddress() will allocate memory if address
         # is null and there seems to be no way around it (ll_buffer can not
         # be touched directly)
@@ -65,7 +65,7 @@
 
 @unwrap_spec(name=str)
 def resolve_name(space, name):
-    return space.wrap(capi.c_resolve_name(space, name))
+    return space.newtext(capi.c_resolve_name(space, name))
 
 @unwrap_spec(name=str)
 def scope_byname(space, name):
@@ -113,7 +113,7 @@
     return None
 
 def std_string_name(space):
-    return space.wrap(capi.std_string_name)
+    return space.newtext(capi.std_string_name)
 
 @unwrap_spec(w_callback=W_Root)
 def set_class_generator(space, w_callback):
@@ -126,7 +126,7 @@
     state.w_fngen_callback = w_callback
 
 def register_class(space, w_pycppclass):
-    w_cppclass = space.findattr(w_pycppclass, space.wrap("_cpp_proxy"))
+    w_cppclass = space.findattr(w_pycppclass, space.newtext("_cpp_proxy"))
     cppclass = space.interp_w(W_CPPClass, w_cppclass, can_be_None=False)
     # add back-end specific method pythonizations (doing this on the wrapped
     # class allows simple aliasing of methods)
@@ -431,7 +431,7 @@
             try:
                 s = self.space.str_w(args_w[i])
             except OperationError:
-                s = self.space.str_w(self.space.getattr(args_w[i], self.space.wrap('__name__')))
+                s = self.space.str_w(self.space.getattr(args_w[i], self.space.newtext('__name__')))
             s = capi.c_resolve_name(self.space, s)
             if s != self.templ_args[i]:
                 raise oefmt(self.space.w_TypeError,
@@ -537,7 +537,7 @@
         # only get here if all overloads failed ...
         errmsg = 'none of the %d overloaded methods succeeded. Full details:' % len(self.functions)
         if hasattr(self.space, "fake"):     # FakeSpace fails errorstr (see below)
-            raise OperationError(self.space.w_TypeError, self.space.wrap(errmsg))
+            raise OperationError(self.space.w_TypeError, self.space.newtext(errmsg))
         for i in range(len(self.functions)):
             cppyyfunc = self.functions[i]
             try:
@@ -554,13 +554,13 @@
                 errmsg += '\n  '+cppyyfunc.signature()+' =>\n'
                 errmsg += '    Exception: '+str(e)
 
-        raise OperationError(self.space.w_TypeError, self.space.wrap(errmsg))
+        raise OperationError(self.space.w_TypeError, self.space.newtext(errmsg))
 
     def signature(self):
         sig = self.functions[0].signature()
         for i in range(1, len(self.functions)):
             sig += '\n'+self.functions[i].signature()
-        return self.space.wrap(sig)
+        return self.space.newtext(sig)
 
     def __repr__(self):
         return "W_CPPOverload(%s)" % [f.signature() for f in self.functions]
@@ -633,7 +633,7 @@
         self.offset = offset
 
     def get_returntype(self):
-        return self.space.wrap(self.converter.name)
+        return self.space.newtext(self.converter.name)
 
     def _get_offset(self, cppinstance):
         if cppinstance:
@@ -750,7 +750,7 @@
         return capi.c_scoped_final_name(self.space, self.handle)
 
     def get_method_names(self):
-        return self.space.newlist([self.space.wrap(name) for name in self.methods])
+        return self.space.newlist([self.space.newtext(name) for name in self.methods])
 
     def get_overload(self, name):
         try:
@@ -762,7 +762,7 @@
         return new_method
 
     def get_datamember_names(self):
-        return self.space.newlist([self.space.wrap(name) for name in self.datamembers])
+        return self.space.newlist([self.space.newtext(name) for name in self.datamembers])
 
     def get_datamember(self, name):
         try:
@@ -856,17 +856,17 @@
         alldir = []
         for i in range(capi.c_num_scopes(self.space, self)):
             sname = capi.c_scope_name(self.space, self, i)
-            if sname: alldir.append(self.space.wrap(sname))
+            if sname: alldir.append(self.space.newtext(sname))
         allmeth = {}
         for i in range(capi.c_num_methods(self.space, self)):
             idx = capi.c_method_index_at(self.space, self, i)
             mname = capi.c_method_name(self.space, self, idx)
             if mname: allmeth.setdefault(mname, 0)
         for m in allmeth.keys():
-            alldir.append(self.space.wrap(m))
+            alldir.append(self.space.newtext(m))
         for i in range(capi.c_num_datamembers(self.space, self)):
             dname = capi.c_datamember_name(self.space, self, i)
-            if dname: alldir.append(self.space.wrap(dname))
+            if dname: alldir.append(self.space.newtext(dname))
         return self.space.newlist(alldir)
         
 
@@ -952,7 +952,7 @@
         num_bases = capi.c_num_bases(self.space, self)
         for i in range(num_bases):
             base_name = capi.c_base_name(self.space, self, i)
-            bases.append(self.space.wrap(base_name))
+            bases.append(self.space.newtext(base_name))
         return self.space.newlist(bases)
 
 W_CPPClass.typedef = TypeDef(
@@ -1038,7 +1038,8 @@
         self._opt_register_finalizer()
 
     def _opt_register_finalizer(self):
-        if self.python_owns and not self.finalizer_registered:
+        if self.python_owns and not self.finalizer_registered \
+               and not hasattr(self.space, "fake"):
             self.register_finalizer(self.space)
             self.finalizer_registered = True
 
@@ -1049,7 +1050,7 @@
 
     # allow user to determine ownership rules on a per object level
     def fget_python_owns(self, space):
-        return space.wrap(self.python_owns)
+        return space.newbool(self.python_owns)
 
     @unwrap_spec(value=bool)
     def fset_python_owns(self, space, value):
@@ -1091,7 +1092,7 @@
     def instance__eq__(self, w_other):
         # special case: if other is None, compare pointer-style
         if self.space.is_w(w_other, self.space.w_None):
-            return self.space.wrap(not self._rawobject)
+            return self.space.newbool(not self._rawobject)
 
         # get here if no class-specific overloaded operator is available, try to
         # find a global overload in gbl, in __gnu_cxx (for iterators), or in the
@@ -1121,7 +1122,7 @@
         # the first data member in a struct and the struct have the same address)
         other = self.space.interp_w(W_CPPInstance, w_other, can_be_None=False)  # TODO: factor out
         iseq = (self._rawobject == other._rawobject) and (self.cppclass == other.cppclass)
-        return self.space.wrap(iseq)
+        return self.space.newbool(iseq)
 
     def instance__ne__(self, w_other):
         return self.space.not_(self.instance__eq__(w_other))
@@ -1149,7 +1150,7 @@
         w_as_builtin = self._get_as_builtin()
         if w_as_builtin is not None:
             return self.space.repr(w_as_builtin)
-        return self.space.wrap("<%s object at 0x%x>" %
+        return self.space.newtext("<%s object at 0x%x>" %
                                (self.cppclass.name, rffi.cast(rffi.ULONG, self.get_rawobject())))
 
     def destruct(self):
@@ -1215,12 +1216,12 @@
     except KeyError:
         final_name = capi.c_scoped_final_name(space, handle)
         # the callback will cache the class by calling register_class
-        w_pycppclass = space.call_function(state.w_clgen_callback, space.wrap(final_name))
+        w_pycppclass = space.call_function(state.w_clgen_callback, space.newtext(final_name))
     return w_pycppclass
 
 def get_interface_func(space, w_callable, npar):
     state = space.fromcache(State)
-    return space.call_function(state.w_fngen_callback, w_callable, space.wrap(npar))
+    return space.call_function(state.w_fngen_callback, w_callable, space.newint(npar))
 
 def wrap_cppobject(space, rawobject, cppclass,
                    do_cast=True, python_owns=False, is_ref=False, fresh=False):
@@ -1235,7 +1236,7 @@
                 w_pycppclass = get_pythonized_cppclass(space, actual)
                 offset = capi.c_base_offset1(space, actual, cppclass, rawobject, -1)
                 rawobject = capi.direct_ptradd(rawobject, offset)
-                w_cppclass = space.findattr(w_pycppclass, space.wrap("_cpp_proxy"))
+                w_cppclass = space.findattr(w_pycppclass, space.newtext("_cpp_proxy"))
                 cppclass = space.interp_w(W_CPPClass, w_cppclass, can_be_None=False)
             except Exception:
                 # failed to locate/build the derived class, so stick to the base (note
@@ -1272,7 +1273,7 @@
 def addressof(space, w_obj):
     """Takes a bound C++ instance or array, returns the raw address."""
     address = _addressof(space, w_obj)
-    return space.wrap(address)
+    return space.newlong(address)
 
 @unwrap_spec(owns=bool, cast=bool)
 def bind_object(space, w_obj, w_pycppclass, owns=False, cast=False):
@@ -1283,7 +1284,7 @@
     except Exception:
         # accept integer value as address
         rawobject = rffi.cast(capi.C_OBJECT, space.uint_w(w_obj))
-    w_cppclass = space.findattr(w_pycppclass, space.wrap("_cpp_proxy"))
+    w_cppclass = space.findattr(w_pycppclass, space.newtext("_cpp_proxy"))
     if not w_cppclass:
         w_cppclass = scope_byname(space, space.str_w(w_pycppclass))
         if not w_cppclass:
diff --git a/pypy/module/cppyy/test/test_advancedcpp.py b/pypy/module/cppyy/test/test_advancedcpp.py
--- a/pypy/module/cppyy/test/test_advancedcpp.py
+++ b/pypy/module/cppyy/test/test_advancedcpp.py
@@ -18,8 +18,8 @@
     spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
     def setup_class(cls):
-        cls.w_test_dct = cls.space.wrap(test_dct)
-        cls.w_capi_identity = cls.space.wrap(capi.identify())
+        cls.w_test_dct = cls.space.newtext(test_dct)
+        cls.w_capi_identity = cls.space.newtext(capi.identify())
         cls.w_advanced = cls.space.appexec([], """():
             import cppyy
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
diff --git a/pypy/module/cppyy/test/test_cint.py b/pypy/module/cppyy/test/test_cint.py
--- a/pypy/module/cppyy/test/test_cint.py
+++ b/pypy/module/cppyy/test/test_cint.py
@@ -169,11 +169,11 @@
     spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
     def setup_class(cls):
-        cls.w_N = cls.space.wrap(5)
-        cls.w_M = cls.space.wrap(10)
-        cls.w_fname = cls.space.wrap("test.root")
-        cls.w_tname = cls.space.wrap("test")
-        cls.w_title = cls.space.wrap("test tree")
+        cls.w_N = cls.space.newint(5)
+        cls.w_M = cls.space.newint(10)
+        cls.w_fname = cls.space.newtext("test.root")
+        cls.w_tname = cls.space.newtext("test")
+        cls.w_title = cls.space.newtext("test tree")
         cls.w_iotypes = cls.space.appexec([], """():
             import cppyy
             return cppyy.load_reflection_info(%r)""" % (iotypes_dct,))
diff --git a/pypy/module/cppyy/test/test_crossing.py b/pypy/module/cppyy/test/test_crossing.py
--- a/pypy/module/cppyy/test/test_crossing.py
+++ b/pypy/module/cppyy/test/test_crossing.py
@@ -9,8 +9,6 @@
 from pypy.module.cpyext import api
 from pypy.module.cpyext.state import State
 
-from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
-
 
 currpath = py.path.local(__file__).dirpath()
 test_dct = str(currpath.join("crossingDict.so"))
@@ -24,7 +22,7 @@
 
 # from pypy/module/cpyext/test/test_cpyext.py; modified to accept more external
 # symbols and called directly instead of import_module
-def compile_extension_module(space, modname, symbols, **kwds):
+def compile_extension_module(space, modname, **kwds):
     """
     Build an extension module and return the filename of the resulting native
     code file.
@@ -38,19 +36,23 @@
     state = space.fromcache(State)
     api_library = state.api_lib
     if sys.platform == 'win32':
-        kwds["libraries"] = [api_library]
+        kwds["libraries"] = []#[api_library]
         # '%s' undefined; assuming extern returning int
         kwds["compile_extra"] = ["/we4013"]
+        # prevent linking with PythonXX.lib
+        w_maj, w_min = space.fixedview(space.sys.get('version_info'), 5)[:2]
+        kwds["link_extra"] = ["/NODEFAULTLIB:Python%d%d.lib" %
+                              (space.int_w(w_maj), space.int_w(w_min))]
     elif sys.platform == 'darwin':
         kwds["link_files"] = [str(api_library + '.dylib')]
     else:
         kwds["link_files"] = [str(api_library + '.so')]
         if sys.platform.startswith('linux'):
-            kwds["compile_extra"]=["-Werror=implicit-function-declaration"]
+            kwds["compile_extra"]=["-Werror", "-g", "-O0"]
+            kwds["link_extra"]=["-g"]
 
     modname = modname.split('.')[-1]
     eci = ExternalCompilationInfo(
-        #export_symbols=['init%s' % (modname,)]+symbols,
         include_dirs=api.include_dirs,
         **kwds
         )
@@ -65,28 +67,30 @@
     soname.rename(pydname)
     return str(pydname)
 
-class AppTestCrossing(AppTestCpythonExtensionBase):
-    spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools', 'cpyext'])
+class AppTestCrossing:
+    spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
     def setup_class(cls):
-        AppTestCpythonExtensionBase.setup_class.im_func(cls)
         # cppyy specific additions (note that test_dct is loaded late
         # to allow the generated extension module be loaded first)
-        cls.w_test_dct    = cls.space.wrap(test_dct)
+        cls.w_test_dct    = cls.space.newtext(test_dct)
         cls.w_pre_imports = cls.space.appexec([], """():
-            import cppyy, cpyext, ctypes""")    # prevents leak-checking complaints on ctypes
+            import ctypes, cppyy""")    # prevents leak-checking complaints on ctypes' statics
 
     def setup_method(self, func):
-        AppTestCpythonExtensionBase.setup_method.im_func(self, func)
-
         @unwrap_spec(name=str, init=str, body=str)
-        def create_cdll(space, name, init, body, w_symbols):
+        def create_cdll(space, name, init, body):
             # the following is loosely from test_cpyext.py import_module; it
             # is copied here to be able to tweak the call to
             # compile_extension_module and to get a different return result
             # than in that function
             code = """
             #include <Python.h>
+            /* fix for cpython 2.7 Python.h if running tests with -A
+               since pypy compiles with -fvisibility-hidden */
+            #undef PyMODINIT_FUNC
+            #define PyMODINIT_FUNC RPY_EXPORTED void
+
             %(body)s
 
             PyMODINIT_FUNC
@@ -95,28 +99,16 @@
             }
             """ % dict(name=name, init=init, body=body)
             kwds = dict(separate_module_sources=[code])
-            symbols = [space.str_w(w_item) for w_item in space.fixedview(w_symbols)]
-            mod = compile_extension_module(space, name, symbols, **kwds)
+            mod = compile_extension_module(space, name, **kwds)
 
             # explicitly load the module as a CDLL rather than as a module
             from pypy.module.imp.importing import get_so_extension
             fullmodname = os.path.join(
                 os.path.dirname(mod), name + get_so_extension(space))
-            return space.wrap(fullmodname)
+            return space.newtext(fullmodname)
 
         self.w_create_cdll = self.space.wrap(interp2app(create_cdll))
 
-    def test00_base_class(self):
-        """Test from cpyext; only here to see whether the imported class works"""
-
-        import sys
-        init = """
-        if (Py_IsInitialized())
-            Py_InitModule("foo", NULL);
-        """
-        self.import_module(name='foo', init=init)
-        assert 'foo' in sys.modules
-
     def test01_build_bar_extension(self):
         """Test that builds the needed extension; runs as test to keep it loaded"""
 
@@ -131,10 +123,12 @@
 
         # note: only the symbols are needed for C, none for python
         body = """
+        RPY_EXPORTED
         long bar_unwrap(PyObject* arg)
         {
-            return PyLong_AsLong(arg);
+            return 13;//PyLong_AsLong(arg);
         }
+        RPY_EXPORTED
         PyObject* bar_wrap(long l)
         {
             return PyLong_FromLong(l);
@@ -146,8 +140,7 @@
         # explicitly load the module as a CDLL rather than as a module
         import ctypes
         self.cmodule = ctypes.CDLL(
-            self.create_cdll(name, init, body, ['bar_unwrap', 'bar_wrap']),
-            ctypes.RTLD_GLOBAL)
+            self.create_cdll(name, init, body), ctypes.RTLD_GLOBAL)
 
     def test02_crossing_dict(self):
         """Test availability of all needed classes in the dict"""
@@ -160,6 +153,7 @@
 
         assert crossing.A == crossing.A
 
+    @py.test.mark.dont_track_allocations("fine when running standalone, though?!")
     def test03_send_pyobject(self):
         """Test sending a true pyobject to C++"""
 
@@ -169,6 +163,7 @@
         a = crossing.A()
         assert a.unwrap(13) == 13
 
+    @py.test.mark.dont_track_allocations("fine when running standalone, though?!")
     def test04_send_and_receive_pyobject(self):
         """Test receiving a true pyobject from C++"""
 
diff --git a/pypy/module/cppyy/test/test_datatypes.py b/pypy/module/cppyy/test/test_datatypes.py
--- a/pypy/module/cppyy/test/test_datatypes.py
+++ b/pypy/module/cppyy/test/test_datatypes.py
@@ -15,8 +15,8 @@
     spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
     def setup_class(cls):
-        cls.w_N = cls.space.wrap(5)  # should be imported from the dictionary
-        cls.w_test_dct  = cls.space.wrap(test_dct)
+        cls.w_N = cls.space.newint(5)  # should be imported from the dictionary
+        cls.w_test_dct  = cls.space.newtext(test_dct)
         cls.w_datatypes = cls.space.appexec([], """():
             import cppyy
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
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
@@ -17,8 +17,8 @@
     spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
     def setup_class(cls):
-        cls.w_test_dct  = cls.space.wrap(test_dct)
-        cls.w_identity = cls.space.wrap(capi.identify())
+        cls.w_test_dct  = cls.space.newtext(test_dct)
+        cls.w_identity = cls.space.newtext(capi.identify())
         cls.w_fragile = cls.space.appexec([], """():
             import cppyy
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
diff --git a/pypy/module/cppyy/test/test_operators.py b/pypy/module/cppyy/test/test_operators.py
--- a/pypy/module/cppyy/test/test_operators.py
+++ b/pypy/module/cppyy/test/test_operators.py
@@ -15,8 +15,8 @@
     spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
     def setup_class(cls):
-        cls.w_N = cls.space.wrap(5)  # should be imported from the dictionary
-        cls.w_test_dct  = cls.space.wrap(test_dct)
+        cls.w_N = cls.space.newint(5)  # should be imported from the dictionary
+        cls.w_test_dct  = cls.space.newtext(test_dct)
         cls.w_operators = cls.space.appexec([], """():
             import cppyy
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
diff --git a/pypy/module/cppyy/test/test_overloads.py b/pypy/module/cppyy/test/test_overloads.py
--- a/pypy/module/cppyy/test/test_overloads.py
+++ b/pypy/module/cppyy/test/test_overloads.py
@@ -16,7 +16,7 @@
 
     def setup_class(cls):
         env = os.environ
-        cls.w_test_dct  = cls.space.wrap(test_dct)
+        cls.w_test_dct  = cls.space.newtext(test_dct)
         cls.w_overloads = cls.space.appexec([], """():
             import cppyy
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
diff --git a/pypy/module/cppyy/test/test_pythonify.py b/pypy/module/cppyy/test/test_pythonify.py
--- a/pypy/module/cppyy/test/test_pythonify.py
+++ b/pypy/module/cppyy/test/test_pythonify.py
@@ -17,7 +17,7 @@
     spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
     def setup_class(cls):
-        cls.w_test_dct  = cls.space.wrap(test_dct)
+        cls.w_test_dct  = cls.space.newtext(test_dct)
         cls.w_example01 = cls.space.appexec([], """():
             import cppyy
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
@@ -376,7 +376,7 @@
     spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
     def setup_class(cls):
-        cls.w_test_dct  = cls.space.wrap(test_dct)
+        cls.w_test_dct  = cls.space.newtext(test_dct)
         cls.w_example01 = cls.space.appexec([], """():
             import cppyy
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
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
@@ -15,8 +15,8 @@
     spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
     def setup_class(cls):
-        cls.w_N = cls.space.wrap(13)
-        cls.w_test_dct  = cls.space.wrap(test_dct)
+        cls.w_N = cls.space.newint(13)
+        cls.w_test_dct  = cls.space.newtext(test_dct)
         cls.w_stlvector = cls.space.appexec([], """():
             import cppyy
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
@@ -203,7 +203,7 @@
     spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
     def setup_class(cls):
-        cls.w_test_dct  = cls.space.wrap(test_dct)
+        cls.w_test_dct  = cls.space.newtext(test_dct)
         cls.w_stlstring = cls.space.appexec([], """():
             import cppyy
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
@@ -279,8 +279,8 @@
     spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
     def setup_class(cls):
-        cls.w_N = cls.space.wrap(13)
-        cls.w_test_dct  = cls.space.wrap(test_dct)
+        cls.w_N = cls.space.newint(13)
+        cls.w_test_dct  = cls.space.newtext(test_dct)
         cls.w_stlstring = cls.space.appexec([], """():
             import cppyy
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
@@ -335,8 +335,8 @@
     spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
     def setup_class(cls):
-        cls.w_N = cls.space.wrap(13)
-        cls.w_test_dct  = cls.space.wrap(test_dct)
+        cls.w_N = cls.space.newint(13)
+        cls.w_test_dct  = cls.space.newtext(test_dct)
         cls.w_stlstring = cls.space.appexec([], """():
             import cppyy
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
@@ -444,7 +444,7 @@
     spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
     def setup_class(cls):
-        cls.w_test_dct  = cls.space.wrap(test_dct)
+        cls.w_test_dct  = cls.space.newtext(test_dct)
         cls.w_stlstring = cls.space.appexec([], """():
             import cppyy, sys
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
@@ -481,7 +481,7 @@
     spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
     def setup_class(cls):
-        cls.w_test_dct  = cls.space.wrap(test_dct)
+        cls.w_test_dct  = cls.space.newtext(test_dct)
         cls.w_stlstring = cls.space.appexec([], """():
             import cppyy, sys
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
diff --git a/pypy/module/cppyy/test/test_streams.py b/pypy/module/cppyy/test/test_streams.py
--- a/pypy/module/cppyy/test/test_streams.py
+++ b/pypy/module/cppyy/test/test_streams.py
@@ -15,7 +15,7 @@
     spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
     def setup_class(cls):
-        cls.w_test_dct  = cls.space.wrap(test_dct)
+        cls.w_test_dct  = cls.space.newtext(test_dct)
         cls.w_streams = cls.space.appexec([], """():
             import cppyy
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
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
@@ -3,14 +3,17 @@
 from rpython.rlib.objectmodel import specialize, instantiate
 from rpython.rlib import rarithmetic, jit
 from rpython.rtyper.lltypesystem import rffi, lltype
+from rpython.rtyper import llinterp
 from pypy.interpreter.baseobjspace import InternalSpaceCache, W_Root
 
-from pypy.module.cppyy import interp_cppyy, capi
+from pypy.module.cppyy import interp_cppyy, capi, executor
 # These tests are for the backend that support the fast path only.
 if capi.identify() == 'CINT':
     py.test.skip("CINT does not support fast path")
 elif capi.identify() == 'loadable_capi':
     py.test.skip("can not currently use FakeSpace with _cffi_backend")
+elif os.getenv("CPPYY_DISABLE_FASTPATH"):
+    py.test.skip("fast path is disabled by CPPYY_DISABLE_FASTPATH envar")
 
 # load cpyext early, or its global vars are counted as leaks in the test
 # (note that the module is not otherwise used in the test itself)
@@ -29,6 +32,23 @@
     return rffi.ptradd(ptr, offset)
 capi.exchange_address = _opaque_exchange_address
 
+# add missing alt_errno (??)
+def get_tlobj(self):
+    try:
+        return self._tlobj
+    except AttributeError:
+        from rpython.rtyper.lltypesystem import rffi
+        PERRNO = rffi.CArrayPtr(rffi.INT)
+        fake_p_errno = lltype.malloc(PERRNO.TO, 1, flavor='raw', zero=True,
+                                     track_allocation=False)
+        self._tlobj = {'RPY_TLOFS_p_errno': fake_p_errno,
+                       'RPY_TLOFS_alt_errno': rffi.cast(rffi.INT, 0),
+                       #'thread_ident': ...,
+                       }
+        return self._tlobj
+llinterp.LLInterpreter.get_tlobj = get_tlobj
+
+
 currpath = py.path.local(__file__).dirpath()
 test_dct = str(currpath.join("example01Dict.so"))
 
@@ -43,6 +63,10 @@
 class FakeBase(W_Root):
     typename = None
 
+class FakeBool(FakeBase):
+    typename = "bool"
+    def __init__(self, val):
+        self.val = val
 class FakeInt(FakeBase):
     typename = "int"
     def __init__(self, val):
@@ -69,9 +93,10 @@
     def get_raw_address(self):
         raise ValueError("no raw buffer")
 class FakeException(FakeType):
-    def __init__(self, name):
+    def __init__(self, space, name):
         FakeType.__init__(self, name)
-        self.message = name
+        self.msg = name
+        self.space = space
 
 class FakeUserDelAction(object):
     def __init__(self, space):
@@ -83,16 +108,13 @@
     def perform(self, executioncontext, frame):
         pass
 
+class FakeState(object):
+    def __init__(self, space):
+        self.slowcalls = 0
+
 class FakeSpace(object):
     fake = True
 
-    w_ValueError = FakeException("ValueError")
-    w_TypeError = FakeException("TypeError")
-    w_AttributeError = FakeException("AttributeError")
-    w_ReferenceError = FakeException("ReferenceError")
-    w_NotImplementedError = FakeException("NotImplementedError")
-    w_RuntimeError = FakeException("RuntimeError")
-
     w_None = None
     w_str = FakeType("str")
     w_int = FakeType("int")
@@ -105,6 +127,21 @@
         self.config = dummy()
         self.config.translating = False
 
+        # kill calls to c_call_i (i.e. slow path)
+        def c_call_i(space, cppmethod, cppobject, nargs, args):
+            assert not "slow path called"
+            return capi.c_call_i(space, cppmethod, cppobject, nargs, args)
+        executor.get_executor(self, 'int').__class__.c_stubcall = staticmethod(c_call_i)
+
+        self.w_AttributeError      = FakeException(self, "AttributeError")
+        self.w_KeyError            = FakeException(self, "KeyError")
+        self.w_NotImplementedError = FakeException(self, "NotImplementedError")
+        self.w_ReferenceError      = FakeException(self, "ReferenceError")
+        self.w_RuntimeError        = FakeException(self, "RuntimeError")
+        self.w_SystemError         = FakeException(self, "SystemError")
+        self.w_TypeError           = FakeException(self, "TypeError")
+        self.w_ValueError          = FakeException(self, "ValueError")
+
     def issequence_w(self, w_obj):
         return True
 
@@ -120,6 +157,30 @@
             return FakeInt(int(obj))
         assert 0
 
+    @specialize.argtype(1)
+    def newbool(self, obj):
+        return FakeBool(obj)
+
+    @specialize.argtype(1)
+    def newint(self, obj):
+        return FakeInt(obj)
+
+    @specialize.argtype(1)
+    def newlong(self, obj):
+        return FakeInt(obj)
+
+    @specialize.argtype(1)
+    def newfloat(self, obj):
+        return FakeFloat(obj)
+
+    @specialize.argtype(1)
+    def newbytes(self, obj):
+        return FakeString(obj)
+
+    @specialize.argtype(1)
+    def newtext(self, obj):
+        return FakeString(obj)
+
     def float_w(self, w_obj, allow_conversion=True):
         assert isinstance(w_obj, FakeFloat)
         return w_obj.val
@@ -210,7 +271,8 @@
         f()
         space = FakeSpace()
         result = self.meta_interp(f, [], listops=True, backendopt=True, listcomp=True)
-        self.check_jitcell_token_count(1)
+        self.check_jitcell_token_count(1)   # same for fast and slow path??
+        # rely on replacement of capi calls to raise exception instead (see FakeSpace.__init__)
 
     def test01_simple(self):
         """Test fast path being taken for methods"""


More information about the pypy-commit mailing list