Author: Wim Lavrijsen <wlavrij...@lbl.gov> Branch: reflex-support Changeset: r53676:c90727271485 Date: 2012-03-15 07:14 -0700 http://bitbucket.org/pypy/pypy/changeset/c90727271485/
Log: factor out the need of passing wrapped types into function calls (note that this also means that test_cppyy.py can no longer use the generic CPPInstance as return type, but will automatically work with the actual type as appropriate; same goes for test_zjit.py) diff --git a/pypy/module/cppyy/capi/__init__.py b/pypy/module/cppyy/capi/__init__.py --- a/pypy/module/cppyy/capi/__init__.py +++ b/pypy/module/cppyy/capi/__init__.py @@ -157,6 +157,12 @@ compilation_info=backend.eci) def c_final_name(cpptype): return charp2str_free(_c_final_name(cpptype)) +_c_scoped_final_name = rffi.llexternal( + "cppyy_scoped_final_name", + [C_TYPE], rffi.CCHARP, + compilation_info=backend.eci) +def c_scoped_final_name(cpptype): + return charp2str_free(_c_scoped_final_name(cpptype)) c_has_complex_hierarchy = rffi.llexternal( "cppyy_has_complex_hierarchy", [C_TYPE], rffi.INT, 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 @@ -18,10 +18,10 @@ def __init__(self, space, name, cpptype): self.name = name - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): raise TypeError('return type not available or supported ("%s")' % self.name) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): from pypy.module.cppyy.interp_cppyy import FastCallNotPossible raise FastCallNotPossible @@ -30,7 +30,7 @@ _immutable_ = True typecode = 'P' - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): if hasattr(space, "fake"): raise NotImplementedError lresult = capi.c_call_l(cppmethod, cppthis, num_args, args) @@ -43,11 +43,11 @@ _immutable_ = True libffitype = libffi.types.void - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): capi.c_call_v(cppmethod, cppthis, num_args, args) return space.w_None - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): libffifunc.call(argchain, lltype.Void) return space.w_None @@ -56,11 +56,11 @@ _immutable_ = True libffitype = libffi.types.schar - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): result = capi.c_call_b(cppmethod, cppthis, num_args, args) return space.wrap(result) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): result = libffifunc.call(argchain, rffi.CHAR) return space.wrap(bool(ord(result))) @@ -68,11 +68,11 @@ _immutable_ = True libffitype = libffi.types.schar - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): result = capi.c_call_c(cppmethod, cppthis, num_args, args) return space.wrap(result) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): result = libffifunc.call(argchain, rffi.CHAR) return space.wrap(result) @@ -80,11 +80,11 @@ _immutable_ = True libffitype = libffi.types.sshort - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): result = capi.c_call_h(cppmethod, cppthis, num_args, args) return space.wrap(result) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): result = libffifunc.call(argchain, rffi.SHORT) return space.wrap(result) @@ -95,11 +95,11 @@ def _wrap_result(self, space, result): return space.wrap(result) - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): result = capi.c_call_i(cppmethod, cppthis, num_args, args) return self._wrap_result(space, result) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): result = libffifunc.call(argchain, rffi.INT) return space.wrap(result) @@ -110,11 +110,11 @@ def _wrap_result(self, space, result): return space.wrap(rffi.cast(rffi.UINT, result)) - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): result = capi.c_call_l(cppmethod, cppthis, num_args, args) return self._wrap_result(space, result) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): result = libffifunc.call(argchain, rffi.UINT) return space.wrap(result) @@ -125,11 +125,11 @@ def _wrap_result(self, space, result): return space.wrap(result) - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): result = capi.c_call_l(cppmethod, cppthis, num_args, args) return self._wrap_result(space, result) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): result = libffifunc.call(argchain, rffi.LONG) return space.wrap(result) @@ -140,7 +140,7 @@ def _wrap_result(self, space, result): return space.wrap(rffi.cast(rffi.ULONG, result)) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): result = libffifunc.call(argchain, rffi.ULONG) return space.wrap(result) @@ -152,11 +152,11 @@ intptr = rffi.cast(rffi.INTP, result) return space.wrap(intptr[0]) - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): result = capi.c_call_r(cppmethod, cppthis, num_args, args) return self._wrap_result(space, result) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): result = libffifunc.call(argchain, rffi.INTP) return space.wrap(result[0]) @@ -168,7 +168,7 @@ longptr = rffi.cast(rffi.LONGP, result) return space.wrap(longptr[0]) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): result = libffifunc.call(argchain, rffi.LONGP) return space.wrap(result[0]) @@ -176,11 +176,11 @@ _immutable_ = True libffitype = libffi.types.float - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): result = capi.c_call_f(cppmethod, cppthis, num_args, args) return space.wrap(float(result)) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): result = libffifunc.call(argchain, rffi.FLOAT) return space.wrap(float(result)) @@ -188,11 +188,11 @@ _immutable_ = True libffitype = libffi.types.double - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): result = capi.c_call_d(cppmethod, cppthis, num_args, args) return space.wrap(result) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): result = libffifunc.call(argchain, rffi.DOUBLE) return space.wrap(result) @@ -200,7 +200,7 @@ class CStringExecutor(FunctionExecutor): _immutable_ = True - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): lresult = capi.c_call_l(cppmethod, cppthis, num_args, args) ccpresult = rffi.cast(rffi.CCHARP, lresult) result = rffi.charp2str(ccpresult) # TODO: make it a choice to free @@ -244,41 +244,41 @@ FunctionExecutor.__init__(self, space, name, cpptype) self.cpptype = cpptype - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): from pypy.module.cppyy import interp_cppyy long_result = capi.c_call_l(cppmethod, cppthis, num_args, args) ptr_result = rffi.cast(capi.C_OBJECT, long_result) - return interp_cppyy.wrap_cppobject(space, w_returntype, self.cpptype, ptr_result, False, False) + return interp_cppyy.wrap_cppobject(space, None, self.cpptype, ptr_result, False, False) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): from pypy.module.cppyy import interp_cppyy ptr_result = rffi.cast(capi.C_OBJECT, libffifunc.call(argchain, rffi.VOIDP)) - return interp_cppyy.wrap_cppobject(space, w_returntype, self.cpptype, ptr_result, False, False) + return interp_cppyy.wrap_cppobject(space, None, self.cpptype, ptr_result, False, False) class InstancePtrPtrExecutor(InstancePtrExecutor): _immutable_ = True - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): from pypy.module.cppyy import interp_cppyy voidp_result = capi.c_call_r(cppmethod, cppthis, num_args, args) ref_address = rffi.cast(rffi.VOIDPP, voidp_result) ptr_result = rffi.cast(capi.C_OBJECT, ref_address[0]) - return interp_cppyy.wrap_cppobject(space, w_returntype, self.cpptype, ptr_result, False, False) + return interp_cppyy.wrap_cppobject(space, None, self.cpptype, ptr_result, False, False) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): from pypy.module.cppyy.interp_cppyy import FastCallNotPossible raise FastCallNotPossible class InstanceExecutor(InstancePtrExecutor): _immutable_ = True - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): from pypy.module.cppyy import interp_cppyy long_result = capi.c_call_o(cppmethod, cppthis, num_args, args, self.cpptype.handle) ptr_result = rffi.cast(capi.C_OBJECT, long_result) - return interp_cppyy.wrap_cppobject(space, w_returntype, self.cpptype, ptr_result, False, True) + return interp_cppyy.wrap_cppobject(space, None, self.cpptype, ptr_result, False, True) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): from pypy.module.cppyy.interp_cppyy import FastCallNotPossible raise FastCallNotPossible @@ -286,11 +286,11 @@ class StdStringExecutor(InstancePtrExecutor): _immutable_ = True - def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args): + def execute(self, space, cppmethod, cppthis, num_args, args): charp_result = capi.c_call_s(cppmethod, cppthis, num_args, args) return space.wrap(capi.charp2str_free(charp_result)) - def execute_libffi(self, space, w_returntype, libffifunc, argchain): + def execute_libffi(self, space, libffifunc, argchain): from pypy.module.cppyy.interp_cppyy import FastCallNotPossible raise FastCallNotPossible diff --git a/pypy/module/cppyy/include/capi.h b/pypy/module/cppyy/include/capi.h --- a/pypy/module/cppyy/include/capi.h +++ b/pypy/module/cppyy/include/capi.h @@ -53,6 +53,7 @@ /* class reflection information ------------------------------------------- */ char* cppyy_final_name(cppyy_type_t type); + char* cppyy_scoped_final_name(cppyy_type_t type); int cppyy_has_complex_hierarchy(cppyy_type_t type); int cppyy_num_bases(cppyy_type_t type); char* cppyy_base_name(cppyy_type_t type, int base_index); 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 @@ -127,9 +127,8 @@ self._libffifunc = None @jit.unroll_safe - def call(self, cppthis, w_type, args_w): + def call(self, cppthis, args_w): jit.promote(self) - jit.promote(w_type) assert lltype.typeOf(cppthis) == capi.C_OBJECT args_expected = len(self.arg_defs) args_given = len(args_w) @@ -141,18 +140,18 @@ if self._libffifunc: try: - return self.do_fast_call(cppthis, w_type, args_w) + return self.do_fast_call(cppthis, args_w) except FastCallNotPossible: pass # can happen if converters or executor does not implement ffi args = self.prepare_arguments(args_w) try: - return self.executor.execute(self.space, w_type, self.cppmethod, cppthis, len(args_w), args) + return self.executor.execute(self.space, self.cppmethod, cppthis, len(args_w), args) finally: self.free_arguments(args, len(args_w)) @jit.unroll_safe - def do_fast_call(self, cppthis, w_type, args_w): + def do_fast_call(self, cppthis, args_w): jit.promote(self) argchain = libffi.ArgChain() argchain.arg(cppthis) @@ -164,7 +163,7 @@ for j in range(i+1, len(self.arg_defs)): conv = self.arg_converters[j] conv.default_argument_libffi(self.space, argchain) - return self.executor.execute_libffi(self.space, w_type, self._libffifunc, argchain) + return self.executor.execute_libffi(self.space, self._libffifunc, argchain) def _setup(self, cppthis): self.arg_converters = [converter.get_converter(self.space, arg_type, arg_dflt) @@ -231,15 +230,15 @@ class CPPConstructor(CPPMethod): _immutable_ = True - def call(self, cppthis, w_type, args_w): + def call(self, cppthis, args_w): newthis = capi.c_allocate(self.cpptype.handle) assert lltype.typeOf(newthis) == capi.C_OBJECT try: - CPPMethod.call(self, newthis, None, args_w) + CPPMethod.call(self, newthis, args_w) except Exception: capi.c_deallocate(self.cpptype.handle, newthis) raise - return wrap_new_cppobject_nocast(self.space, w_type, self.cpptype, newthis, False, True) + return wrap_new_cppobject_nocast(self.space, None, self.cpptype, newthis, False, True) class W_CPPOverload(Wrappable): @@ -259,7 +258,7 @@ return self.space.wrap(self.functions[0].executor.name) @jit.unroll_safe - def call(self, w_cppinstance, w_type, args_w): + def call(self, w_cppinstance, args_w): cppinstance = self.space.interp_w(W_CPPInstance, w_cppinstance, can_be_None=True) if cppinstance is not None: cppinstance._nullcheck() @@ -275,7 +274,7 @@ for i in range(len(self.functions)): cppyyfunc = self.functions[i] try: - return cppyyfunc.call(cppthis, w_type, args_w) + return cppyyfunc.call(cppthis, args_w) except Exception, e: errmsg += '\n\t'+str(e) @@ -288,7 +287,7 @@ 'CPPOverload', is_static = interp2app(W_CPPOverload.is_static, unwrap_spec=['self']), get_returntype = interp2app(W_CPPOverload.get_returntype, unwrap_spec=['self']), - call = interp2app(W_CPPOverload.call, unwrap_spec=['self', W_Root, W_Root, 'args_w']), + call = interp2app(W_CPPOverload.call, unwrap_spec=['self', W_Root, 'args_w']), ) @@ -412,7 +411,6 @@ self.space.wrap("%s '%s' has no attribute %s" % (self.kind, self.name, name))) - # For now, keep namespaces and classes separate as namespaces are extensible # with info from multiple dictionaries and do not need to bother with meta # classes for inheritance. Both are python classes, though, and refactoring @@ -657,7 +655,18 @@ memory_regulator = MemoryRegulator() +def get_wrapped_type(space, handle): + state = space.fromcache(State) + try: + w_type = state.type_registry[handle] + except KeyError: + final_name = capi.c_scoped_final_name(handle) + w_type = space.call_function(state.w_clgen_callback, space.wrap(final_name)) + return w_type + def wrap_new_cppobject_nocast(space, w_type, cpptype, rawobject, isref, python_owns): + if w_type is None: + w_type = get_wrapped_type(space, cpptype.handle) w_cppinstance = space.allocate_instance(W_CPPInstance, w_type) cppinstance = space.interp_w(W_CPPInstance, w_cppinstance, can_be_None=False) W_CPPInstance.__init__(cppinstance, space, cpptype, rawobject, isref, python_owns) @@ -676,12 +685,7 @@ if actual != cpptype.handle: offset = capi.c_base_offset(actual, cpptype.handle, rawobject) rawobject = capi.direct_ptradd(rawobject, offset) - state = space.fromcache(State) - try: - w_type = state.type_registry[actual] - except KeyError: - final_name = capi.c_final_name(actual) - w_type = space.call_function(state.w_clgen_callback, space.wrap(final_name)) + w_type = get_wrapped_type(space, actual) w_cpptype = space.findattr(w_type, space.wrap("_cpp_proxy")) cpptype = space.interp_w(W_CPPType, w_cpptype, can_be_None=False) return wrap_cppobject_nocast(space, w_type, cpptype, rawobject, isref, python_owns) diff --git a/pypy/module/cppyy/pythonify.py b/pypy/module/cppyy/pythonify.py --- a/pypy/module/cppyy/pythonify.py +++ b/pypy/module/cppyy/pythonify.py @@ -48,24 +48,14 @@ cppyy._set_class_generator(clgen_callback) def make_static_function(cpptype, func_name, cppol): - rettype = cppol.get_returntype() - if not rettype: # return builtin type - def function(*args): - return cppol.call(None, None, *args) - else: # return instance - def function(*args): - return cppol.call(None, get_cppclass(rettype), *args) + def function(*args): + return cppol.call(None, *args) function.__name__ = func_name return staticmethod(function) def make_method(meth_name, cppol): - rettype = cppol.get_returntype() - if not rettype: # return builtin type - def method(self, *args): - return cppol.call(self, None, *args) - else: # return instance - def method(self, *args): - return cppol.call(self, get_cppclass(rettype), *args) + def method(self, *args): + return cppol.call(self, *args) method.__name__ = meth_name return method @@ -151,7 +141,7 @@ raise TypeError(msg) else: def __new__(cls, *args): - return constructor_overload.call(None, cls, *args) + return constructor_overload.call(None, *args) return __new__ def make_cppclass(scope, class_name, final_class_name, cpptype): diff --git a/pypy/module/cppyy/src/cintcwrapper.cxx b/pypy/module/cppyy/src/cintcwrapper.cxx --- a/pypy/module/cppyy/src/cintcwrapper.cxx +++ b/pypy/module/cppyy/src/cintcwrapper.cxx @@ -378,6 +378,15 @@ return cppstring_to_cstring(cr.GetClassName()); } +char* cppyy_scoped_final_name(cppyy_type_t handle) { + TClassRef cr = type_from_handle(handle); + if (cr.GetClass() && cr->GetClassInfo()) { + std::string true_name = G__TypeInfo(cr->GetName()).TrueName(); + return cppstring_to_cstring(true_name); + } + return cppstring_to_cstring(cr.GetClassName()); +} + int cppyy_has_complex_hierarchy(cppyy_type_t handle) { // as long as no fast path is supported for CINT, calculating offsets (which // are cached by the JIT) is not going to hurt diff --git a/pypy/module/cppyy/src/reflexcwrapper.cxx b/pypy/module/cppyy/src/reflexcwrapper.cxx --- a/pypy/module/cppyy/src/reflexcwrapper.cxx +++ b/pypy/module/cppyy/src/reflexcwrapper.cxx @@ -222,6 +222,14 @@ return cppstring_to_cstring(name); } +char* cppyy_scoped_final_name(cppyy_type_t handle) { + Reflex::Scope s = scope_from_handle(handle); + if (s.IsEnum()) + return cppstring_to_cstring("unsigned int"); + std::string name = s.Name(Reflex::SCOPED | Reflex::FINAL); + return cppstring_to_cstring(name); +} + static int cppyy_has_complex_hierarchy(const Reflex::Type& t) { int is_complex = 1; diff --git a/pypy/module/cppyy/test/test_cppyy.py b/pypy/module/cppyy/test/test_cppyy.py --- a/pypy/module/cppyy/test/test_cppyy.py +++ b/pypy/module/cppyy/test/test_cppyy.py @@ -43,30 +43,30 @@ import sys, math t = self.example01 - res = t.get_overload("staticAddOneToInt").call(None, None, 1) + res = t.get_overload("staticAddOneToInt").call(None, 1) assert res == 2 - res = t.get_overload("staticAddOneToInt").call(None, None, 1L) + res = t.get_overload("staticAddOneToInt").call(None, 1L) assert res == 2 - res = t.get_overload("staticAddOneToInt").call(None, None, 1, 2) + res = t.get_overload("staticAddOneToInt").call(None, 1, 2) assert res == 4 - res = t.get_overload("staticAddOneToInt").call(None, None, -1) + res = t.get_overload("staticAddOneToInt").call(None, -1) assert res == 0 maxint32 = int(2 ** 31 - 1) - res = t.get_overload("staticAddOneToInt").call(None, None, maxint32-1) + res = t.get_overload("staticAddOneToInt").call(None, maxint32-1) assert res == maxint32 - res = t.get_overload("staticAddOneToInt").call(None, None, maxint32) + res = t.get_overload("staticAddOneToInt").call(None, maxint32) assert res == -maxint32-1 - raises(TypeError, 't.get_overload("staticAddOneToInt").call(None, None, 1, [])') - raises(TypeError, 't.get_overload("staticAddOneToInt").call(None, None, 1.)') - raises(TypeError, 't.get_overload("staticAddOneToInt").call(None, None, maxint32+1)') + raises(TypeError, 't.get_overload("staticAddOneToInt").call(None, 1, [])') + raises(TypeError, 't.get_overload("staticAddOneToInt").call(None, 1.)') + raises(TypeError, 't.get_overload("staticAddOneToInt").call(None, maxint32+1)') def test02_static_double(self): """Test passing of a double and returning of a double on a static function.""" t = self.example01 - res = t.get_overload("staticAddToDouble").call(None, None, 0.09) + res = t.get_overload("staticAddToDouble").call(None, 0.09) assert res == 0.09 + 0.01 def test03_static_constcharp(self): @@ -75,14 +75,14 @@ t = self.example01 - res = t.get_overload("staticAtoi").call(None, None, "1") + res = t.get_overload("staticAtoi").call(None, "1") assert res == 1 - res = t.get_overload("staticStrcpy").call(None, None, "aap") # TODO: this leaks + res = t.get_overload("staticStrcpy").call(None, "aap") # TODO: this leaks assert res == "aap" - res = t.get_overload("staticStrcpy").call(None, None, u"aap") # TODO: this leaks + res = t.get_overload("staticStrcpy").call(None, u"aap") # TODO: this leaks assert res == "aap" - raises(TypeError, 't.get_overload("staticStrcpy").call(None, None, 1.)') # TODO: this leaks + raises(TypeError, 't.get_overload("staticStrcpy").call(None, 1.)') # TODO: this leaks def test04_method_int(self): """Test passing of a int, returning of a int, and memory cleanup, on @@ -91,30 +91,30 @@ t = self.example01 - assert t.get_overload("getCount").call(None, None) == 0 + assert t.get_overload("getCount").call(None) == 0 - e1 = t.get_overload(t.type_name).call(None, cppyy.CPPInstance, 7) - assert t.get_overload("getCount").call(None, None) == 1 - res = t.get_overload("addDataToInt").call(e1, None, 4) + e1 = t.get_overload(t.type_name).call(None, 7) + assert t.get_overload("getCount").call(None) == 1 + res = t.get_overload("addDataToInt").call(e1, 4) assert res == 11 - res = t.get_overload("addDataToInt").call(e1, None, -4) + res = t.get_overload("addDataToInt").call(e1, -4) assert res == 3 e1.destruct() - assert t.get_overload("getCount").call(None, None) == 0 - raises(ReferenceError, 't.get_overload("addDataToInt").call(e1, None, 4)') + assert t.get_overload("getCount").call(None) == 0 + raises(ReferenceError, 't.get_overload("addDataToInt").call(e1, 4)') - e1 = t.get_overload(t.type_name).call(None, cppyy.CPPInstance, 7) - e2 = t.get_overload(t.type_name).call(None, cppyy.CPPInstance, 8) - assert t.get_overload("getCount").call(None, None) == 2 + e1 = t.get_overload(t.type_name).call(None, 7) + e2 = t.get_overload(t.type_name).call(None, 8) + assert t.get_overload("getCount").call(None) == 2 e1.destruct() - assert t.get_overload("getCount").call(None, None) == 1 + assert t.get_overload("getCount").call(None) == 1 e2.destruct() - assert t.get_overload("getCount").call(None, None) == 0 + assert t.get_overload("getCount").call(None) == 0 e2.destruct() - assert t.get_overload("getCount").call(None, None) == 0 + assert t.get_overload("getCount").call(None) == 0 - raises(TypeError, t.get_overload("addDataToInt").call, 41, None, 4) + raises(TypeError, t.get_overload("addDataToInt").call, 41, 4) def test05_memory(self): """Test memory destruction and integrity.""" @@ -124,29 +124,29 @@ t = self.example01 - assert t.get_overload("getCount").call(None, None) == 0 + assert t.get_overload("getCount").call(None) == 0 - e1 = t.get_overload(t.type_name).call(None, cppyy.CPPInstance, 7) - assert t.get_overload("getCount").call(None, None) == 1 - res = t.get_overload("addDataToInt").call(e1, None, 4) + e1 = t.get_overload(t.type_name).call(None, 7) + assert t.get_overload("getCount").call(None) == 1 + res = t.get_overload("addDataToInt").call(e1, 4) assert res == 11 - res = t.get_overload("addDataToInt").call(e1, None, -4) + res = t.get_overload("addDataToInt").call(e1, -4) assert res == 3 e1 = None gc.collect() - assert t.get_overload("getCount").call(None, None) == 0 + assert t.get_overload("getCount").call(None) == 0 - e1 = t.get_overload(t.type_name).call(None, cppyy.CPPInstance, 7) - e2 = t.get_overload(t.type_name).call(None, cppyy.CPPInstance, 8) - assert t.get_overload("getCount").call(None, None) == 2 + e1 = t.get_overload(t.type_name).call(None, 7) + e2 = t.get_overload(t.type_name).call(None, 8) + assert t.get_overload("getCount").call(None) == 2 e1 = None gc.collect() - assert t.get_overload("getCount").call(None, None) == 1 + assert t.get_overload("getCount").call(None) == 1 e2.destruct() - assert t.get_overload("getCount").call(None, None) == 0 + assert t.get_overload("getCount").call(None) == 0 e2 = None gc.collect() - assert t.get_overload("getCount").call(None, None) == 0 + assert t.get_overload("getCount").call(None) == 0 def test06_method_double(self): """Test passing of a double and returning of double on a method""" @@ -154,16 +154,16 @@ t = self.example01 - e = t.get_overload(t.type_name).call(None, cppyy.CPPInstance, 13) - res = t.get_overload("addDataToDouble").call(e, None, 16) + e = t.get_overload(t.type_name).call(None, 13) + res = t.get_overload("addDataToDouble").call(e, 16) assert round(res-29, 8) == 0. e.destruct() - e = t.get_overload(t.type_name).call(None, cppyy.CPPInstance, -13) - res = t.get_overload("addDataToDouble").call(e, None, 16) + e = t.get_overload(t.type_name).call(None, -13) + res = t.get_overload("addDataToDouble").call(e, 16) assert round(res-3, 8) == 0. e.destruct() - assert t.get_overload("getCount").call(None, None) == 0 + assert t.get_overload("getCount").call(None) == 0 def test07_method_constcharp(self): """Test passing of a C string and returning of a C string on a @@ -172,15 +172,15 @@ t = self.example01 - e = t.get_overload(t.type_name).call(None, cppyy.CPPInstance, 42) - res = t.get_overload("addDataToAtoi").call(e, None, "13") + e = t.get_overload(t.type_name).call(None, 42) + res = t.get_overload("addDataToAtoi").call(e, "13") assert res == 55 - res = t.get_overload("addToStringValue").call(e, None, "12") # TODO: this leaks + res = t.get_overload("addToStringValue").call(e, "12") # TODO: this leaks assert res == "54" - res = t.get_overload("addToStringValue").call(e, None, "-12") # TODO: this leaks + res = t.get_overload("addToStringValue").call(e, "-12") # TODO: this leaks assert res == "30" e.destruct() - assert t.get_overload("getCount").call(None, None) == 0 + assert t.get_overload("getCount").call(None) == 0 def test08_pass_object_by_pointer(self): """Test passing of an instance as an argument.""" @@ -189,18 +189,18 @@ t1 = self.example01 t2 = self.payload - pl = t2.get_overload(t2.type_name).call(None, cppyy.CPPInstance, 3.14) - assert round(t2.get_overload("getData").call(pl, None)-3.14, 8) == 0 - t1.get_overload("staticSetPayload").call(None, None, pl, 41.) # now pl is a CPPInstance - assert t2.get_overload("getData").call(pl, None) == 41. + pl = t2.get_overload(t2.type_name).call(None, 3.14) + assert round(t2.get_overload("getData").call(pl)-3.14, 8) == 0 + t1.get_overload("staticSetPayload").call(None, pl, 41.) # now pl is a CPPInstance + assert t2.get_overload("getData").call(pl) == 41. - e = t1.get_overload(t1.type_name).call(None, cppyy.CPPInstance, 50) - t1.get_overload("setPayload").call(e, None, pl); - assert round(t2.get_overload("getData").call(pl, None)-50., 8) == 0 + e = t1.get_overload(t1.type_name).call(None, 50) + t1.get_overload("setPayload").call(e, pl); + assert round(t2.get_overload("getData").call(pl)-50., 8) == 0 e.destruct() pl.destruct() - assert t1.get_overload("getCount").call(None, None) == 0 + assert t1.get_overload("getCount").call(None) == 0 def test09_return_object_by_pointer(self): """Test returning of an instance as an argument.""" @@ -209,15 +209,15 @@ t1 = self.example01 t2 = self.payload - pl1 = t2.get_overload(t2.type_name).call(None, cppyy.CPPInstance, 3.14) - assert round(t2.get_overload("getData").call(pl1, None)-3.14, 8) == 0 - pl2 = t1.get_overload("staticCyclePayload").call(None, cppyy.CPPInstance, pl1, 38.) - assert t2.get_overload("getData").call(pl2, None) == 38. + pl1 = t2.get_overload(t2.type_name).call(None, 3.14) + assert round(t2.get_overload("getData").call(pl1)-3.14, 8) == 0 + pl2 = t1.get_overload("staticCyclePayload").call(None, pl1, 38.) + assert t2.get_overload("getData").call(pl2) == 38. - e = t1.get_overload(t1.type_name).call(None, cppyy.CPPInstance, 50) - pl2 = t1.get_overload("cyclePayload").call(e, cppyy.CPPInstance, pl1); - assert round(t2.get_overload("getData").call(pl2, None)-50., 8) == 0 + e = t1.get_overload(t1.type_name).call(None, 50) + pl2 = t1.get_overload("cyclePayload").call(e, pl1); + assert round(t2.get_overload("getData").call(pl2)-50., 8) == 0 e.destruct() pl1.destruct() - assert t1.get_overload("getCount").call(None, None) == 0 + assert t1.get_overload("getCount").call(None) == 0 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 @@ -44,9 +44,6 @@ def perform(self, executioncontext, frame): pass -class FakeReturnType(object): - pass - class FakeSpace(object): fake = True @@ -128,7 +125,6 @@ return None def allocate_instance(self, cls, w_type): - assert isinstance(w_type, FakeReturnType) return instantiate(cls) def call_function(self, w_func, *args_w): @@ -149,13 +145,13 @@ def f(): lib = interp_cppyy.load_dictionary(space, "./example01Dict.so") cls = interp_cppyy.type_byname(space, "example01") - inst = cls.get_overload("example01").call(None, FakeReturnType(), [FakeInt(0)]) + inst = cls.get_overload("example01").call(None, [FakeInt(0)]) addDataToInt = cls.get_overload("addDataToInt") assert isinstance(inst, interp_cppyy.W_CPPInstance) i = 10 while i > 0: drv.jit_merge_point(inst=inst, addDataToInt=addDataToInt, i=i) - addDataToInt.call(inst, None, [FakeInt(i)]) + addDataToInt.call(inst, [FakeInt(i)]) i -= 1 return 7 f() @@ -174,13 +170,13 @@ def f(): lib = interp_cppyy.load_dictionary(space, "./example01Dict.so") cls = interp_cppyy.type_byname(space, "example01") - inst = cls.get_overload("example01").call(None, FakeReturnType(), [FakeInt(0)]) + inst = cls.get_overload("example01").call(None, [FakeInt(0)]) addDataToInt = cls.get_overload("overloadedAddDataToInt") assert isinstance(inst, interp_cppyy.W_CPPInstance) i = 10 while i > 0: drv.jit_merge_point(inst=inst, addDataToInt=addDataToInt, i=i) - addDataToInt.call(inst, None, [FakeInt(i)]) + addDataToInt.call(inst, [FakeInt(i)]) i -= 1 return 7 f() _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit