[pypy-commit] pypy default: merge reflex-support into default: this opens several more tests based on the dummy backend
wlav
noreply at buildbot.pypy.org
Thu May 1 09:26:22 CEST 2014
Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch:
Changeset: r71126:d6759a0aff01
Date: 2014-05-01 00:25 -0700
http://bitbucket.org/pypy/pypy/changeset/d6759a0aff01/
Log: merge reflex-support into default: this opens several more tests
based on the dummy backend
diff --git a/pypy/module/cppyy/__init__.py b/pypy/module/cppyy/__init__.py
--- a/pypy/module/cppyy/__init__.py
+++ b/pypy/module/cppyy/__init__.py
@@ -16,7 +16,7 @@
'_register_class' : 'interp_cppyy.register_class',
'_is_static' : 'interp_cppyy.is_static',
'_get_nullptr' : 'interp_cppyy.get_nullptr',
- 'CPPInstance' : 'interp_cppyy.W_CPPInstance',
+ 'CPPInstanceBase' : 'interp_cppyy.W_CPPInstance',
'addressof' : 'interp_cppyy.addressof',
'bind_object' : 'interp_cppyy.bind_object',
}
@@ -25,7 +25,7 @@
'_init_pythonify' : 'pythonify._init_pythonify',
'load_reflection_info' : 'pythonify.load_reflection_info',
'add_pythonization' : 'pythonify.add_pythonization',
- 'Template' : 'pythonify.CppyyTemplateType',
+ 'Template' : 'pythonify.CPPTemplate',
}
def __init__(self, space, *args):
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
@@ -127,19 +127,18 @@
argc = len(args_w)
try:
- # Note: argcount is +1 for the class (== w_self)
- if argc < 5 or 6 < argc:
+ if argc < 4 or 5 < argc:
raise TypeError("wrong number of arguments")
- # second argument must be a name
- funcname = space.str_w(args_w[1])
+ # first argument must be a name
+ funcname = space.str_w(args_w[0])
# last (optional) argument is number of parameters
npar = 0
- if argc == 6: npar = space.int_w(args_w[5])
+ if argc == 5: npar = space.int_w(args_w[4])
- # third argument must be a callable python object
- w_callable = args_w[2]
+ # second argument must be a callable python object
+ w_callable = args_w[1]
if not space.is_true(space.callable(w_callable)):
raise TypeError("2nd argument is not a valid python callable")
@@ -159,17 +158,21 @@
# so far, so good; leaves on issue: CINT is expecting a wrapper, but
# we need the overload that takes a function pointer, which is not in
# the dictionary, hence this helper:
- newinst = _create_tf1(space.str_w(args_w[1]), funcaddr,
- space.float_w(args_w[3]), space.float_w(args_w[4]), npar)
-
- from pypy.module.cppyy import interp_cppyy
- w_instance = interp_cppyy.wrap_cppobject(space, newinst, tf1_class,
- do_cast=False, python_owns=True, fresh=True)
+ newinst = _create_tf1(space.str_w(args_w[0]), funcaddr,
+ space.float_w(args_w[2]), space.float_w(args_w[3]), npar)
+
+ # w_self is a null-ptr bound as TF1
+ from pypy.module.cppyy.interp_cppyy import W_CPPInstance, memory_regulator
+ cppself = space.interp_w(W_CPPInstance, w_self, can_be_None=False)
+ cppself._rawobject = newinst
+ memory_regulator.register(cppself)
# tie all the life times to the TF1 instance
- space.setattr(w_instance, space.wrap('_callback'), w_callback)
+ space.setattr(w_self, space.wrap('_callback'), w_callback)
- return w_instance
+ # by definition for __init__
+ return None
+
except (OperationError, TypeError, IndexError), e:
newargs_w = args_w[1:] # drop class
@@ -312,7 +315,7 @@
# location
w_address = space.call_method(w_leaf, "GetValuePointer")
- buf = space.buffer_w(w_address)
+ buf = space.getarg_w('s*', w_address)
from pypy.module._rawffi import buffer
assert isinstance(buf, buffer.RawFFIBuffer)
address = rffi.cast(rffi.CCHARP, buf.datainstance.ll_buffer)
@@ -395,7 +398,7 @@
_method_alias(space, w_pycppclass, "__len__", "GetSize")
elif name == "TF1":
- space.setattr(w_pycppclass, space.wrap("__new__"), _pythonizations["tf1_tf1"])
+ space.setattr(w_pycppclass, space.wrap("__init__"), _pythonizations["tf1_tf1"])
elif name == "TFile":
_method_alias(space, w_pycppclass, "__getattr__", "Get")
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
@@ -155,18 +155,16 @@
the memory_regulator."""
_attrs_ = ['space', 'scope', 'index', 'cppmethod', 'arg_defs', 'args_required',
- 'args_expected', 'converters', 'executor', '_funcaddr', 'cif_descr',
- 'uses_local']
+ 'converters', 'executor', '_funcaddr', 'cif_descr', 'uses_local']
_immutable_ = True
- def __init__(self, space, containing_scope, method_index, arg_defs, args_required):
+ def __init__(self, space, declaring_scope, method_index, arg_defs, args_required):
self.space = space
- self.scope = containing_scope
+ self.scope = declaring_scope
self.index = method_index
self.cppmethod = capi.c_get_method(self.space, self.scope, method_index)
self.arg_defs = arg_defs
self.args_required = args_required
- self.args_expected = len(arg_defs)
# Setup of the method dispatch's innards is done lazily, i.e. only when
# the method is actually used.
@@ -176,6 +174,12 @@
self._funcaddr = lltype.nullptr(rffi.VOIDP.TO)
self.uses_local = False
+ @staticmethod
+ def unpack_cppthis(space, w_cppinstance, declaring_scope):
+ cppinstance = space.interp_w(W_CPPInstance, w_cppinstance, can_be_None=False)
+ cppinstance._nullcheck()
+ return cppinstance.get_cppthis(declaring_scope)
+
def _address_from_local_buffer(self, call_local, idx):
if not call_local:
return call_local
@@ -277,7 +281,7 @@
funcaddr = methgetter(rffi.cast(capi.C_OBJECT, cppthis))
self._funcaddr = rffi.cast(rffi.VOIDP, funcaddr)
- nargs = self.args_expected + 1 # +1: cppthis
+ nargs = len(self.arg_defs) + 1 # +1: cppthis
# memory block for CIF description (note: not tracked as the life
# time of methods is normally the duration of the application)
@@ -335,7 +339,7 @@
# extra
cif_descr.abi = clibffi.FFI_DEFAULT_ABI
- cif_descr.nargs = self.args_expected + 1 # +1: cppthis
+ cif_descr.nargs = len(self.arg_defs) + 1 # +1: cppthis
res = jit_libffi.jit_ffi_prep_cif(cif_descr)
if res != clibffi.FFI_OK:
@@ -405,28 +409,29 @@
class CPPFunction(CPPMethod):
- """Global (namespaced) function dispatcher. For now, the base class has
- all the needed functionality, by allowing the C++ this pointer to be null
- in the call. An optimization is expected there, however."""
+ """Global (namespaced) function dispatcher."""
_immutable_ = True
+ @staticmethod
+ def unpack_cppthis(space, w_cppinstance, declaring_scope):
+ return capi.C_NULL_OBJECT
+
def __repr__(self):
return "CPPFunction: %s" % self.signature()
class CPPTemplatedCall(CPPMethod):
- """Method dispatcher that first needs to resolve the template instance.
- Note that the derivation is from object: the CPPMethod is a data member."""
+ """Method dispatcher that first resolves the template instance."""
- _attrs_ = ['space', 'templ_args', 'method']
+ _attrs_ = ['space', 'templ_args']
_immutable_ = True
- def __init__(self, space, templ_args, containing_scope, method_index, arg_defs, args_required):
+ def __init__(self, space, templ_args, declaring_scope, method_index, arg_defs, args_required):
self.space = space
self.templ_args = templ_args
# TODO: might have to specialize for CPPTemplatedCall on CPPMethod/CPPFunction here
- CPPMethod.__init__(self, space, containing_scope, method_index, arg_defs, args_required)
+ CPPMethod.__init__(self, space, declaring_scope, method_index, arg_defs, args_required)
def call(self, cppthis, args_w):
assert lltype.typeOf(cppthis) == capi.C_OBJECT
@@ -456,24 +461,15 @@
_immutable_ = True
+ @staticmethod
+ def unpack_cppthis(space, w_cppinstance, declaring_scope):
+ return rffi.cast(capi.C_OBJECT, declaring_scope.handle)
+
def call(self, cppthis, args_w):
- # TODO: these casts are very, very un-pretty; need to find a way of
- # re-using CPPMethod's features w/o these roundabouts
- vscope = rffi.cast(capi.C_OBJECT, self.scope.handle)
- cppinstance = None
- try:
- cppinstance = self.space.interp_w(W_CPPInstance, args_w[0], can_be_None=False)
- use_args_w = args_w[1:]
- except (OperationError, TypeError), e:
- use_args_w = args_w
- w_result = CPPMethod.call(self, vscope, use_args_w)
- newthis = rffi.cast(capi.C_OBJECT, self.space.int_w(w_result))
- if cppinstance:
- cppinstance._rawobject = newthis
- memory_regulator.register(cppinstance)
- return args_w[0]
- return wrap_cppobject(self.space, newthis, self.scope,
- do_cast=False, python_owns=True, fresh=True)
+ # Note: this does not return a wrapped instance, just a pointer to the
+ # new instance; the overload must still wrap it before returning. Also,
+ # cppthis is declaring_scope.handle (as per unpack_cppthis(), above).
+ return CPPMethod.call(self, cppthis, args_w)
def __repr__(self):
return "CPPConstructor: %s" % self.signature()
@@ -505,9 +501,10 @@
_attrs_ = ['space', 'scope', 'functions']
_immutable_fields_ = ['scope', 'functions[*]']
- def __init__(self, space, containing_scope, functions):
+ def __init__(self, space, declaring_scope, functions):
self.space = space
- self.scope = containing_scope
+ self.scope = declaring_scope
+ assert len(functions)
from rpython.rlib import debug
self.functions = debug.make_sure_not_resized(functions)
@@ -520,12 +517,10 @@
@jit.unroll_safe
@unwrap_spec(args_w='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()
- cppthis = cppinstance.get_cppthis(self.scope)
- else:
- cppthis = capi.C_NULL_OBJECT
+ # instance handling is specific to the function type only, so take it out
+ # of the loop over function overloads
+ cppthis = self.functions[0].unpack_cppthis(
+ self.space, w_cppinstance, self.functions[0].scope)
assert lltype.typeOf(cppthis) == capi.C_OBJECT
# The following code tries out each of the functions in order. If
@@ -585,6 +580,39 @@
)
+class W_CPPConstructorOverload(W_CPPOverload):
+ @jit.elidable_promote()
+ def is_static(self):
+ return self.space.w_False
+
+ @jit.elidable_promote()
+ def unpack_cppthis(self, w_cppinstance):
+ return rffi.cast(capi.C_OBJECT, self.scope.handle)
+
+ @jit.unroll_safe
+ @unwrap_spec(args_w='args_w')
+ def call(self, w_cppinstance, args_w):
+ w_result = W_CPPOverload.call(self, w_cppinstance, args_w)
+ newthis = rffi.cast(capi.C_OBJECT, self.space.int_w(w_result))
+ cppinstance = self.space.interp_w(W_CPPInstance, w_cppinstance, can_be_None=True)
+ if cppinstance is not None:
+ cppinstance._rawobject = newthis
+ memory_regulator.register(cppinstance)
+ return w_cppinstance
+ return wrap_cppobject(self.space, newthis, self.functions[0].scope,
+ do_cast=False, python_owns=True, fresh=True)
+
+ def __repr__(self):
+ return "W_CPPConstructorOverload(%s)" % [f.signature() for f in self.functions]
+
+W_CPPConstructorOverload.typedef = TypeDef(
+ 'CPPConstructorOverload',
+ is_static = interp2app(W_CPPConstructorOverload.is_static),
+ call = interp2app(W_CPPConstructorOverload.call),
+ signature = interp2app(W_CPPOverload.signature),
+)
+
+
class W_CPPBoundMethod(W_Root):
_attrs_ = ['cppthis', 'method']
@@ -605,9 +633,9 @@
_attrs_ = ['space', 'scope', 'converter', 'offset']
_immutable_fields = ['scope', 'converter', 'offset']
- def __init__(self, space, containing_scope, type_name, offset):
+ def __init__(self, space, declaring_scope, type_name, offset):
self.space = space
- self.scope = containing_scope
+ self.scope = declaring_scope
self.converter = converter.get_converter(self.space, type_name, '')
self.offset = offset
@@ -717,7 +745,10 @@
# create the overload methods from the method sets
for pyname, methods in methods_temp.iteritems():
CPPMethodSort(methods).sort()
- overload = W_CPPOverload(self.space, self, methods[:])
+ if pyname == self.name:
+ overload = W_CPPConstructorOverload(self.space, self, methods[:])
+ else:
+ overload = W_CPPOverload(self.space, self, methods[:])
self.methods[pyname] = overload
def full_name(self):
@@ -857,14 +888,13 @@
class W_CPPClass(W_CPPScope):
- _attrs_ = ['space', 'default_constructor', 'name', 'handle', 'methods', 'datamembers']
- _immutable_fields_ = ['kind', 'default_constructor', 'methods[*]', 'datamembers[*]']
+ _attrs_ = ['space', 'name', 'handle', 'methods', 'datamembers']
+ _immutable_fields_ = ['kind', 'constructor', 'methods[*]', 'datamembers[*]']
kind = "class"
def __init__(self, space, name, opaque_handle):
W_CPPScope.__init__(self, space, name, opaque_handle)
- self.default_constructor = None
def _make_cppfunction(self, pyname, index):
num_args = capi.c_method_num_args(self.space, self, index)
@@ -876,8 +906,6 @@
arg_defs.append((arg_type, arg_dflt))
if capi.c_is_constructor(self.space, self, index):
cppfunction = CPPConstructor(self.space, self, index, arg_defs, args_required)
- if args_required == 0:
- self.default_constructor = cppfunction
elif capi.c_method_is_template(self.space, self, index):
templ_args = capi.c_template_args(self.space, self, index)
cppfunction = CPPTemplatedCall(self.space, templ_args, self, index, arg_defs, args_required)
@@ -905,9 +933,7 @@
self.datamembers[datamember_name] = datamember
def construct(self):
- if self.default_constructor is not None:
- return self.default_constructor.call(capi.C_NULL_OBJECT, [])
- raise self.missing_attribute_error("default_constructor")
+ return self.get_overload(self.name).call(None, [])
def find_overload(self, name):
raise self.missing_attribute_error(name)
@@ -1046,6 +1072,16 @@
raise
return None
+ def instance__init__(self, args_w):
+ try:
+ constructor_overload = self.cppclass.get_overload(self.cppclass.name)
+ constructor_overload.call(self, args_w)
+ except OperationError, e:
+ if not e.match(self.space, self.space.w_AttributeError):
+ raise
+ raise OperationError(self.space.w_TypeError,
+ self.space.wrap("cannot instantiate abstract class '%s'" % self.cppclass.name))
+
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):
@@ -1128,6 +1164,7 @@
'CPPInstance',
cppclass = interp_attrproperty('cppclass', cls=W_CPPInstance),
_python_owns = GetSetProperty(W_CPPInstance.fget_python_owns, W_CPPInstance.fset_python_owns),
+ __init__ = interp2app(W_CPPInstance.instance__init__),
__eq__ = interp2app(W_CPPInstance.instance__eq__),
__ne__ = interp2app(W_CPPInstance.instance__ne__),
__nonzero__ = interp2app(W_CPPInstance.instance__nonzero__),
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
@@ -7,7 +7,7 @@
# with info from multiple dictionaries and do not need to bother with meta
# classes for inheritance. Both are python classes, though, and refactoring
# may be in order at some point.
-class CppyyScopeMeta(type):
+class CPPScope(type):
def __getattr__(self, name):
try:
return get_pycppitem(self, name) # will cache on self
@@ -15,16 +15,16 @@
raise AttributeError("%s object has no attribute '%s' (details: %s)" %
(self, name, str(e)))
-class CppyyNamespaceMeta(CppyyScopeMeta):
+class CPPNamespace(CPPScope):
def __dir__(cls):
return cls._cpp_proxy.__dir__()
-class CppyyClassMeta(CppyyScopeMeta):
+class CPPClass(CPPScope):
pass
-# class CppyyClass defined in _init_pythonify()
+# class CPPInstance defined in _init_pythonify()
-class CppyyTemplateType(object):
+class CPPTemplate(object):
def __init__(self, name, scope=None):
self._name = name
if scope is None:
@@ -91,7 +91,7 @@
# build up a representation of a C++ namespace (namespaces are classes)
# create a meta class to allow properties (for static data write access)
- metans = type(CppyyNamespaceMeta)(namespace_name+'_meta', (CppyyNamespaceMeta,), {})
+ metans = type(CPPNamespace)(namespace_name+'_meta', (CPPNamespace,), {})
if cppns:
d = {"_cpp_proxy" : cppns}
@@ -137,21 +137,14 @@
break
return tuple(bases)
-def make_new(class_name, cppclass):
- try:
- constructor_overload = cppclass.get_overload(cppclass.type_name)
- except AttributeError:
- msg = "cannot instantiate abstract class '%s'" % class_name
- def __new__(cls, *args):
- raise TypeError(msg)
- else:
- def __new__(cls, *args):
- # create a place-holder only as there may be a derived class defined
- import cppyy
- instance = cppyy.bind_object(0, class_name, True)
- if not instance.__class__ is cls:
- instance.__class__ = cls # happens for derived class
- return instance
+def make_new(class_name):
+ def __new__(cls, *args):
+ # create a place-holder only as there may be a derived class defined
+ import cppyy
+ instance = cppyy.bind_object(0, class_name, True)
+ if not instance.__class__ is cls:
+ instance.__class__ = cls # happens for derived class
+ return instance
return __new__
def make_pycppclass(scope, class_name, final_class_name, cppclass):
@@ -159,7 +152,7 @@
# get a list of base classes for class creation
bases = [get_pycppclass(base) for base in cppclass.get_base_names()]
if not bases:
- bases = [CppyyClass,]
+ bases = [CPPInstance,]
else:
# it's technically possible that the required class now has been built
# if one of the base classes uses it in e.g. a function interface
@@ -170,7 +163,7 @@
# create a meta class to allow properties (for static data write access)
metabases = [type(base) for base in bases]
- metacpp = type(CppyyClassMeta)(class_name+'_meta', _drop_cycles(metabases), {})
+ metacpp = type(CPPClass)(class_name+'_meta', _drop_cycles(metabases), {})
# create the python-side C++ class representation
def dispatch(self, name, signature):
@@ -178,7 +171,7 @@
return types.MethodType(make_method(name, cppol), self, type(self))
d = {"_cpp_proxy" : cppclass,
"__dispatch__" : dispatch,
- "__new__" : make_new(class_name, cppclass),
+ "__new__" : make_new(class_name),
}
pycppclass = metacpp(class_name, _drop_cycles(bases), d)
@@ -214,7 +207,7 @@
return pycppclass
def make_cpptemplatetype(scope, template_name):
- return CppyyTemplateType(template_name, scope)
+ return CPPTemplate(template_name, scope)
def get_pycppitem(scope, name):
@@ -426,15 +419,12 @@
# at pypy-c startup, rather than on the "import cppyy" statement
import cppyy
- # top-level classes
- global CppyyClass
- class CppyyClass(cppyy.CPPInstance):
- __metaclass__ = CppyyClassMeta
-
- def __init__(self, *args, **kwds):
- # self is only a placeholder; now create the actual C++ object
- args = (self,) + args
- self._cpp_proxy.get_overload(self._cpp_proxy.type_name).call(None, *args)
+ # root of all proxy classes: CPPInstance in pythonify exists to combine the
+ # CPPClass meta class with the interp-level CPPInstanceBase
+ global CPPInstance
+ class CPPInstance(cppyy.CPPInstanceBase):
+ __metaclass__ = CPPClass
+ pass
# class generator callback
cppyy._set_class_generator(clgen_callback)
diff --git a/pypy/module/cppyy/src/dummy_backend.cxx b/pypy/module/cppyy/src/dummy_backend.cxx
--- a/pypy/module/cppyy/src/dummy_backend.cxx
+++ b/pypy/module/cppyy/src/dummy_backend.cxx
@@ -4,17 +4,22 @@
#include <map>
#include <string>
#include <sstream>
+#include <utility>
#include <vector>
#include <assert.h>
+#include <stddef.h>
#include <stdlib.h>
#include <string.h>
+#pragma GCC diagnostic ignored "-Winvalid-offsetof"
+
// add example01.cxx code
int globalAddOneToInt(int a);
namespace dummy {
#include "example01.cxx"
+#include "datatypes.cxx"
}
int globalAddOneToInt(int a) {
@@ -27,168 +32,307 @@
typedef std::map<std::string, cppyy_scope_t> Handles_t;
static Handles_t s_handles;
+enum EMethodType { kNormal=0, kConstructor=1, kStatic=2 };
+
struct Cppyy_PseudoMethodInfo {
Cppyy_PseudoMethodInfo(const std::string& name,
const std::vector<std::string>& argtypes,
- const std::string& returntype) :
- m_name(name), m_argtypes(argtypes), m_returntype(returntype) {}
+ const std::string& returntype,
+ EMethodType mtype = kNormal) :
+ m_name(name), m_argtypes(argtypes), m_returntype(returntype), m_type(mtype) {}
std::string m_name;
std::vector<std::string> m_argtypes;
std::string m_returntype;
+ EMethodType m_type;
+};
+
+struct Cppyy_PseudoDatambrInfo {
+ Cppyy_PseudoDatambrInfo(const std::string& name,
+ const std::string& type,
+ size_t offset, bool isstatic) :
+ m_name(name), m_type(type), m_offset(offset), m_isstatic(isstatic) {}
+
+ std::string m_name;
+ std::string m_type;
+ size_t m_offset;
+ bool m_isstatic;
};
struct Cppyy_PseudoClassInfo {
Cppyy_PseudoClassInfo() {}
- Cppyy_PseudoClassInfo(const std::vector<Cppyy_PseudoMethodInfo>& methods) :
- m_methods(methods ) {}
+ Cppyy_PseudoClassInfo(const std::vector<Cppyy_PseudoMethodInfo>& methods,
+ long method_offset,
+ const std::vector<Cppyy_PseudoDatambrInfo>& data) :
+ m_methods(methods), m_method_offset(method_offset), m_datambrs(data) {}
std::vector<Cppyy_PseudoMethodInfo> m_methods;
+ long m_method_offset;
+ std::vector<Cppyy_PseudoDatambrInfo> m_datambrs;
};
typedef std::map<cppyy_scope_t, Cppyy_PseudoClassInfo> Scopes_t;
static Scopes_t s_scopes;
-static int example01_last_static_method = 0;
-static int example01_last_constructor = 0;
-static int payload_methods_offset = 0;
+static std::map<std::string, long> s_methods;
+
+#define PUBLIC_CPPYY_DATA(dmname, dmtype) \
+ data.push_back(Cppyy_PseudoDatambrInfo("m_"#dmname, #dmtype, \
+ offsetof(dummy::cppyy_test_data, m_##dmname), false)); \
+ argtypes.clear(); \
+ methods.push_back(Cppyy_PseudoMethodInfo( \
+ "get_"#dmname, argtypes, #dmtype)); \
+ s_methods["cppyy_test_data::get_"#dmname] = s_method_id++; \
+ argtypes.push_back(#dmtype); \
+ methods.push_back(Cppyy_PseudoMethodInfo( \
+ "set_"#dmname, argtypes, "void")); \
+ s_methods["cppyy_test_data::set_"#dmname] = s_method_id++; \
+ argtypes.clear(); \
+ argtypes.push_back("const "#dmtype"&"); \
+ methods.push_back(Cppyy_PseudoMethodInfo( \
+ "set_"#dmname"_c", argtypes, "void")); \
+ s_methods["cppyy_test_data::set_"#dmname"_c"] = s_method_id++
+
+#define PUBLIC_CPPYY_DATA2(dmname, dmtype) \
+ PUBLIC_CPPYY_DATA(dmname, dmtype); \
+ data.push_back(Cppyy_PseudoDatambrInfo("m_"#dmname"_array", #dmtype"[5]", \
+ offsetof(dummy::cppyy_test_data, m_##dmname##_array), false)); \
+ data.push_back(Cppyy_PseudoDatambrInfo("m_"#dmname"_array2", #dmtype"*", \
+ offsetof(dummy::cppyy_test_data, m_##dmname##_array2), false)); \
+ argtypes.clear(); \
+ methods.push_back(Cppyy_PseudoMethodInfo( \
+ "get_"#dmname"_array", argtypes, #dmtype"*")); \
+ s_methods["cppyy_test_data::get_"#dmname"_array"] = s_method_id++; \
+ methods.push_back(Cppyy_PseudoMethodInfo( \
+ "get_"#dmname"_array2", argtypes, #dmtype"*")); \
+ s_methods["cppyy_test_data::get_"#dmname"_array2"] = s_method_id++
+
+#define PUBLIC_CPPYY_DATA3(dmname, dmtype, key) \
+ PUBLIC_CPPYY_DATA2(dmname, dmtype); \
+ argtypes.push_back(#dmtype"*"); \
+ methods.push_back(Cppyy_PseudoMethodInfo( \
+ "pass_array", argtypes, #dmtype"*")); \
+ s_methods["cppyy_test_data::pass_array_"#dmname] = s_method_id++; \
+ argtypes.clear(); argtypes.push_back("void*"); \
+ methods.push_back(Cppyy_PseudoMethodInfo( \
+ "pass_void_array_"#key, argtypes, #dmtype"*")); \
+ s_methods["cppyy_test_data::pass_void_array_"#key] = s_method_id++
+
+#define PUBLIC_CPPYY_STATIC_DATA(dmname, dmtype) \
+ data.push_back(Cppyy_PseudoDatambrInfo("s_"#dmname, #dmtype, \
+ (size_t)&dummy::cppyy_test_data::s_##dmname, true))
+
struct Cppyy_InitPseudoReflectionInfo {
Cppyy_InitPseudoReflectionInfo() {
// class example01 --
- static long s_scope_id = 0;
+ static long s_scope_id = 0;
+ static long s_method_id = 0;
{ // class example01 --
s_handles["example01"] = (cppyy_scope_t)++s_scope_id;
std::vector<Cppyy_PseudoMethodInfo> methods;
- // ( 0) static double staticAddToDouble(double a)
+ // static double staticAddToDouble(double a)
std::vector<std::string> argtypes;
argtypes.push_back("double");
- methods.push_back(Cppyy_PseudoMethodInfo("staticAddToDouble", argtypes, "double"));
+ methods.push_back(Cppyy_PseudoMethodInfo("staticAddToDouble", argtypes, "double", kStatic));
+ s_methods["static_example01::staticAddToDouble_double"] = s_method_id++;
- // ( 1) static int staticAddOneToInt(int a)
- // ( 2) static int staticAddOneToInt(int a, int b)
+ // static int staticAddOneToInt(int a)
+ // static int staticAddOneToInt(int a, int b)
argtypes.clear();
argtypes.push_back("int");
- methods.push_back(Cppyy_PseudoMethodInfo("staticAddOneToInt", argtypes, "int"));
+ methods.push_back(Cppyy_PseudoMethodInfo("staticAddOneToInt", argtypes, "int", kStatic));
+ s_methods["static_example01::staticAddOneToInt_int"] = s_method_id++;
argtypes.push_back("int");
- methods.push_back(Cppyy_PseudoMethodInfo("staticAddOneToInt", argtypes, "int"));
+ methods.push_back(Cppyy_PseudoMethodInfo("staticAddOneToInt", argtypes, "int", kStatic));
+ s_methods["static_example01::staticAddOneToInt_int_int"] = s_method_id++;
- // ( 3) static int staticAtoi(const char* str)
+ // static int staticAtoi(const char* str)
argtypes.clear();
argtypes.push_back("const char*");
- methods.push_back(Cppyy_PseudoMethodInfo("staticAtoi", argtypes, "int"));
+ methods.push_back(Cppyy_PseudoMethodInfo("staticAtoi", argtypes, "int", kStatic));
+ s_methods["static_example01::staticAtoi_cchar*"] = s_method_id++;
- // ( 4) static char* staticStrcpy(const char* strin)
- methods.push_back(Cppyy_PseudoMethodInfo("staticStrcpy", argtypes, "char*"));
+ // static char* staticStrcpy(const char* strin)
+ methods.push_back(Cppyy_PseudoMethodInfo("staticStrcpy", argtypes, "char*", kStatic));
+ s_methods["static_example01::staticStrcpy_cchar*"] = s_method_id++;
- // ( 5) static void staticSetPayload(payload* p, double d)
- // ( 6) static payload* staticCyclePayload(payload* p, double d)
- // ( 7) static payload staticCopyCyclePayload(payload* p, double d)
+ // static void staticSetPayload(payload* p, double d)
+ // static payload* staticCyclePayload(payload* p, double d)
+ // static payload staticCopyCyclePayload(payload* p, double d)
argtypes.clear();
argtypes.push_back("payload*");
argtypes.push_back("double");
- methods.push_back(Cppyy_PseudoMethodInfo("staticSetPayload", argtypes, "void"));
- methods.push_back(Cppyy_PseudoMethodInfo("staticCyclePayload", argtypes, "payload*"));
- methods.push_back(Cppyy_PseudoMethodInfo("staticCopyCyclePayload", argtypes, "payload"));
+ methods.push_back(Cppyy_PseudoMethodInfo("staticSetPayload", argtypes, "void", kStatic));
+ s_methods["static_example01::staticSetPayload_payload*_double"] = s_method_id++;
+ methods.push_back(Cppyy_PseudoMethodInfo("staticCyclePayload", argtypes, "payload*", kStatic));
+ s_methods["static_example01::staticCyclePayload_payload*_double"] = s_method_id++;
+ methods.push_back(Cppyy_PseudoMethodInfo("staticCopyCyclePayload", argtypes, "payload", kStatic));
+ s_methods["static_example01::staticCopyCyclePayload_payload*_double"] = s_method_id++;
- // ( 8) static int getCount()
- // ( 9) static void setCount(int)
+ // static int getCount()
+ // static void setCount(int)
argtypes.clear();
- methods.push_back(Cppyy_PseudoMethodInfo("getCount", argtypes, "int"));
+ methods.push_back(Cppyy_PseudoMethodInfo("getCount", argtypes, "int", kStatic));
+ s_methods["static_example01::getCount"] = s_method_id++;
argtypes.push_back("int");
- methods.push_back(Cppyy_PseudoMethodInfo("setCount", argtypes, "void"));
+ methods.push_back(Cppyy_PseudoMethodInfo("setCount", argtypes, "void", kStatic));
+ s_methods["static_example01::setCount_int"] = s_method_id++;
- // cut-off is used in cppyy_is_static
- example01_last_static_method = methods.size();
+ // example01()
+ // example01(int a)
+ argtypes.clear();
+ methods.push_back(Cppyy_PseudoMethodInfo("example01", argtypes, "constructor", kConstructor));
+ s_methods["example01::example01"] = s_method_id++;
+ argtypes.push_back("int");
+ methods.push_back(Cppyy_PseudoMethodInfo("example01", argtypes, "constructor", kConstructor));
+ s_methods["example01::example01_int"] = s_method_id++;
- // (10) example01()
- // (11) example01(int a)
- argtypes.clear();
- methods.push_back(Cppyy_PseudoMethodInfo("example01", argtypes, "constructor"));
- argtypes.push_back("int");
- methods.push_back(Cppyy_PseudoMethodInfo("example01", argtypes, "constructor"));
-
- // cut-off is used in cppyy_is_constructor
- example01_last_constructor = methods.size();
-
- // (12) int addDataToInt(int a)
+ // int addDataToInt(int a)
argtypes.clear();
argtypes.push_back("int");
methods.push_back(Cppyy_PseudoMethodInfo("addDataToInt", argtypes, "int"));
+ s_methods["example01::addDataToInt_int"] = s_method_id++;
- // (13) int addDataToIntConstRef(const int& a)
+ // int addDataToIntConstRef(const int& a)
argtypes.clear();
argtypes.push_back("const int&");
methods.push_back(Cppyy_PseudoMethodInfo("addDataToIntConstRef", argtypes, "int"));
+ s_methods["example01::addDataToIntConstRef_cint&"] = s_method_id++;
- // (14) int overloadedAddDataToInt(int a, int b)
+ // int overloadedAddDataToInt(int a, int b)
argtypes.clear();
argtypes.push_back("int");
argtypes.push_back("int");
methods.push_back(Cppyy_PseudoMethodInfo("overloadedAddDataToInt", argtypes, "int"));
+ s_methods["example01::overloadedAddDataToInt_int_int"] = s_method_id++;
- // (15) int overloadedAddDataToInt(int a)
- // (16) int overloadedAddDataToInt(int a, int b, int c)
+ // int overloadedAddDataToInt(int a)
+ // int overloadedAddDataToInt(int a, int b, int c)
argtypes.clear();
argtypes.push_back("int");
methods.push_back(Cppyy_PseudoMethodInfo("overloadedAddDataToInt", argtypes, "int"));
-
+ s_methods["example01::overloadedAddDataToInt_int"] = s_method_id++;
argtypes.push_back("int");
argtypes.push_back("int");
methods.push_back(Cppyy_PseudoMethodInfo("overloadedAddDataToInt", argtypes, "int"));
+ s_methods["example01::overloadedAddDataToInt_int_int_int"] = s_method_id++;
- // (17) double addDataToDouble(double a)
+ // double addDataToDouble(double a)
argtypes.clear();
argtypes.push_back("double");
methods.push_back(Cppyy_PseudoMethodInfo("addDataToDouble", argtypes, "double"));
+ s_methods["example01::addDataToDouble_double"] = s_method_id++;
- // (18) int addDataToAtoi(const char* str)
- // (19) char* addToStringValue(const char* str)
+ // int addDataToAtoi(const char* str)
+ // char* addToStringValue(const char* str)
argtypes.clear();
argtypes.push_back("const char*");
methods.push_back(Cppyy_PseudoMethodInfo("addDataToAtoi", argtypes, "int"));
+ s_methods["example01::addDataToAtoi_cchar*"] = s_method_id++;
methods.push_back(Cppyy_PseudoMethodInfo("addToStringValue", argtypes, "char*"));
+ s_methods["example01::addToStringValue_cchar*"] = s_method_id++;
- // (20) void setPayload(payload* p)
- // (21) payload* cyclePayload(payload* p)
- // (22) payload copyCyclePayload(payload* p)
+ // void setPayload(payload* p)
+ // payload* cyclePayload(payload* p)
+ // payload copyCyclePayload(payload* p)
argtypes.clear();
argtypes.push_back("payload*");
methods.push_back(Cppyy_PseudoMethodInfo("setPayload", argtypes, "void"));
+ s_methods["example01::setPayload_payload*"] = s_method_id++;
methods.push_back(Cppyy_PseudoMethodInfo("cyclePayload", argtypes, "payload*"));
+ s_methods["example01::cyclePayload_payload*"] = s_method_id++;
methods.push_back(Cppyy_PseudoMethodInfo("copyCyclePayload", argtypes, "payload"));
+ s_methods["example01::copyCyclePayload_payload*"] = s_method_id++;
- payload_methods_offset = methods.size();
-
- Cppyy_PseudoClassInfo info(methods);
+ Cppyy_PseudoClassInfo info(
+ methods, s_method_id - methods.size(), std::vector<Cppyy_PseudoDatambrInfo>());
s_scopes[(cppyy_scope_t)s_scope_id] = info;
} // -- class example01
+ //====================================================================
+
{ // class payload --
s_handles["payload"] = (cppyy_scope_t)++s_scope_id;
std::vector<Cppyy_PseudoMethodInfo> methods;
- // (23) payload(double d = 0.)
+ // payload(double d = 0.)
std::vector<std::string> argtypes;
argtypes.push_back("double");
- methods.push_back(Cppyy_PseudoMethodInfo("payload", argtypes, "constructor"));
+ methods.push_back(Cppyy_PseudoMethodInfo("payload", argtypes, "constructor", kConstructor));
+ s_methods["payload::payload_double"] = s_method_id++;
- // (24) double getData()
+ // double getData()
argtypes.clear();
methods.push_back(Cppyy_PseudoMethodInfo("getData", argtypes, "double"));
+ s_methods["payload::getData"] = s_method_id++;
- // (25) void setData(double d)
+ // void setData(double d)
argtypes.clear();
argtypes.push_back("double");
methods.push_back(Cppyy_PseudoMethodInfo("setData", argtypes, "void"));
+ s_methods["payload::setData_double"] = s_method_id++;
- Cppyy_PseudoClassInfo info(methods);
+ Cppyy_PseudoClassInfo info(
+ methods, s_method_id - methods.size(), std::vector<Cppyy_PseudoDatambrInfo>());
s_scopes[(cppyy_scope_t)s_scope_id] = info;
} // -- class payload
+
+ //====================================================================
+
+ { // class cppyy_test_data --
+ s_handles["cppyy_test_data"] = (cppyy_scope_t)++s_scope_id;
+
+ std::vector<Cppyy_PseudoMethodInfo> methods;
+
+ // cppyy_test_data()
+ std::vector<std::string> argtypes;
+ methods.push_back(Cppyy_PseudoMethodInfo("cppyy_test_data", argtypes, "constructor", kConstructor));
+ s_methods["cppyy_test_data::cppyy_test_data"] = s_method_id++;
+
+ methods.push_back(Cppyy_PseudoMethodInfo("destroy_arrays", argtypes, "void"));
+ s_methods["cppyy_test_data::destroy_arrays"] = s_method_id++;
+
+ std::vector<Cppyy_PseudoDatambrInfo> data;
+ PUBLIC_CPPYY_DATA2(bool, bool);
+ PUBLIC_CPPYY_DATA (char, char);
+ PUBLIC_CPPYY_DATA (uchar, unsigned char);
+ PUBLIC_CPPYY_DATA3(short, short, h);
+ PUBLIC_CPPYY_DATA3(ushort, unsigned short, H);
+ PUBLIC_CPPYY_DATA3(int, int, i);
+ PUBLIC_CPPYY_DATA3(uint, unsigned int, I);
+ PUBLIC_CPPYY_DATA3(long, long, l);
+ PUBLIC_CPPYY_DATA3(ulong, unsigned long, L);
+ PUBLIC_CPPYY_DATA (llong, long long);
+ PUBLIC_CPPYY_DATA (ullong, unsigned long long);
+ PUBLIC_CPPYY_DATA3(float, float, f);
+ PUBLIC_CPPYY_DATA3(double, double, d);
+ PUBLIC_CPPYY_DATA (enum, cppyy_test_data::what);
+ PUBLIC_CPPYY_DATA (voidp, void*);
+
+ PUBLIC_CPPYY_STATIC_DATA(char, char);
+ PUBLIC_CPPYY_STATIC_DATA(uchar, unsigned char);
+ PUBLIC_CPPYY_STATIC_DATA(short, short);
+ PUBLIC_CPPYY_STATIC_DATA(ushort, unsigned short);
+ PUBLIC_CPPYY_STATIC_DATA(int, int);
+ PUBLIC_CPPYY_STATIC_DATA(uint, unsigned int);
+ PUBLIC_CPPYY_STATIC_DATA(long, long);
+ PUBLIC_CPPYY_STATIC_DATA(ulong, unsigned long);
+ PUBLIC_CPPYY_STATIC_DATA(llong, long long);
+ PUBLIC_CPPYY_STATIC_DATA(ullong, unsigned long long);
+ PUBLIC_CPPYY_STATIC_DATA(float, float);
+ PUBLIC_CPPYY_STATIC_DATA(double, double);
+ PUBLIC_CPPYY_STATIC_DATA(enum, cppyy_test_data::what);
+ PUBLIC_CPPYY_STATIC_DATA(voidp, void*);
+
+ Cppyy_PseudoClassInfo info(methods, s_method_id - methods.size(), data);
+ s_scopes[(cppyy_scope_t)s_scope_id] = info;
+ } // -- class cppyy_test_data
+
}
} _init;
@@ -230,155 +374,387 @@
/* method/function dispatching -------------------------------------------- */
void cppyy_call_v(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
- switch ((long)method) {
- case 5: // static void example01:;staticSetPayload(payload* p, double d)
+ long idx = (long)method;
+ if (idx == s_methods["static_example01::staticSetPayload_payload*_double"]) {
assert(!self && nargs == 2);
dummy::example01::staticSetPayload((dummy::payload*)(*(long*)&((CPPYY_G__value*)args)[0]),
((CPPYY_G__value*)args)[1].obj.d);
- break;
- case 9: // static void example01::setCount(int)
+ } else if (idx == s_methods["static_example01::setCount_int"]) {
assert(!self && nargs == 1);
dummy::example01::setCount(((CPPYY_G__value*)args)[0].obj.in);
- break;
- case 20: // void example01::setPayload(payload* p);
+ } else if (idx == s_methods["example01::setPayload_payload*"]) {
assert(self && nargs == 1);
((dummy::example01*)self)->setPayload((dummy::payload*)(*(long*)&((CPPYY_G__value*)args)[0]));
- break;
- default:
+ } else if (idx == s_methods["cppyy_test_data::destroy_arrays"]) {
+ assert(self && nargs == 0);
+ ((dummy::cppyy_test_data*)self)->destroy_arrays();
+ } else if (idx == s_methods["cppyy_test_data::set_bool"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_bool((bool)((CPPYY_G__value*)args)[0].obj.in);
+ } else if (idx == s_methods["cppyy_test_data::set_char"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_char(((CPPYY_G__value*)args)[0].obj.ch);
+ } else if (idx == s_methods["cppyy_test_data::set_uchar"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_uchar(((CPPYY_G__value*)args)[0].obj.uch);
+ } else if (idx == s_methods["cppyy_test_data::set_short"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_short(((CPPYY_G__value*)args)[0].obj.sh);
+ } else if (idx == s_methods["cppyy_test_data::set_short_c"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_short_c(*(short*)&((CPPYY_G__value*)args)[0]);
+ } else if (idx == s_methods["cppyy_test_data::set_ushort"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_ushort(((CPPYY_G__value*)args)[0].obj.ush);
+ } else if (idx == s_methods["cppyy_test_data::set_ushort_c"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_ushort_c(*(unsigned short*)&((CPPYY_G__value*)args)[0]);
+ } else if (idx == s_methods["cppyy_test_data::set_int"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_int(((CPPYY_G__value*)args)[0].obj.in);
+ } else if (idx == s_methods["cppyy_test_data::set_int_c"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_int_c(*(int*)&((CPPYY_G__value*)args)[0]);
+ } else if (idx == s_methods["cppyy_test_data::set_uint"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_uint(((CPPYY_G__value*)args)[0].obj.uin);
+ } else if (idx == s_methods["cppyy_test_data::set_uint_c"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_uint_c(*(unsigned int*)&((CPPYY_G__value*)args)[0]);
+ } else if (idx == s_methods["cppyy_test_data::set_long"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_long(((CPPYY_G__value*)args)[0].obj.i);
+ } else if (idx == s_methods["cppyy_test_data::set_long_c"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_long_c(*(long*)&((CPPYY_G__value*)args)[0]);
+ } else if (idx == s_methods["cppyy_test_data::set_ulong"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_ulong(((CPPYY_G__value*)args)[0].obj.ulo);
+ } else if (idx == s_methods["cppyy_test_data::set_ulong_c"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_ulong_c(*(unsigned long*)&((CPPYY_G__value*)args)[0]);
+ } else if (idx == s_methods["cppyy_test_data::set_llong"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_llong(((CPPYY_G__value*)args)[0].obj.ll);
+ } else if (idx == s_methods["cppyy_test_data::set_llong_c"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_llong_c(*(long long*)&((CPPYY_G__value*)args)[0]);
+ } else if (idx == s_methods["cppyy_test_data::set_ullong"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_ullong(((CPPYY_G__value*)args)[0].obj.ull);
+ } else if (idx == s_methods["cppyy_test_data::set_ullong_c"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_ullong_c(*(unsigned long*)&((CPPYY_G__value*)args)[0]);
+ } else if (idx == s_methods["cppyy_test_data::set_float"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_float(((CPPYY_G__value*)args)[0].obj.fl);
+ } else if (idx == s_methods["cppyy_test_data::set_float_c"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_float_c(*(float*)&((CPPYY_G__value*)args)[0]);
+ } else if (idx == s_methods["cppyy_test_data::set_double"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_double(((CPPYY_G__value*)args)[0].obj.d);
+ } else if (idx == s_methods["cppyy_test_data::set_double_c"]) {
+ assert(self && nargs == 1);
+ ((dummy::cppyy_test_data*)self)->set_double_c(*(double*)&((CPPYY_G__value*)args)[0]);
+ } else {
assert(!"method unknown in cppyy_call_v");
- break;
}
}
+unsigned char cppyy_call_b(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
+ unsigned char result = 0;
+ const long idx = (long)method;
+ if (idx == s_methods["cppyy_test_data::get_bool"]) {
+ assert(self && nargs == 0);
+ result = (unsigned char)((dummy::cppyy_test_data*)self)->get_bool();
+ } else {
+ assert(!"method unknown in cppyy_call_b");
+ }
+ return result;
+}
+
+char cppyy_call_c(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
+ char result = 0;
+ const long idx = (long)method;
+ if (idx == s_methods["cppyy_test_data::get_char"]) {
+ assert(self && nargs == 0);
+ result = ((dummy::cppyy_test_data*)self)->get_char();
+ } else if (idx == s_methods["cppyy_test_data::get_uchar"]) {
+ assert(self && nargs == 0);
+ result = (char)((dummy::cppyy_test_data*)self)->get_uchar();
+ } else {
+ assert(!"method unknown in cppyy_call_c");
+ }
+ return result;
+}
+
+short cppyy_call_h(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
+ short result = 0;
+ const long idx = (long)method;
+ if (idx == s_methods["cppyy_test_data::get_short"]) {
+ assert(self && nargs == 0);
+ result = ((dummy::cppyy_test_data*)self)->get_short();
+ } else if (idx == s_methods["cppyy_test_data::get_ushort"]) {
+ assert(self && nargs == 0);
+ result = (short)((dummy::cppyy_test_data*)self)->get_ushort();
+ } else {
+ assert(!"method unknown in cppyy_call_h");
+ }
+ return result;
+}
+
int cppyy_call_i(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
int result = 0;
- switch ((long)method) {
- case 1: // static int example01::staticAddOneToInt(int)
+ const long idx = (long)method;
+ if (idx == s_methods["static_example01::staticAddOneToInt_int"]) {
assert(!self && nargs == 1);
result = dummy::example01::staticAddOneToInt(((CPPYY_G__value*)args)[0].obj.in);
- break;
- case 2: // static int example01::staticAddOneToInt(int, int)
+ } else if (idx == s_methods["static_example01::staticAddOneToInt_int_int"]) {
assert(!self && nargs == 2);
result = dummy::example01::staticAddOneToInt(
((CPPYY_G__value*)args)[0].obj.in, ((CPPYY_G__value*)args)[1].obj.in);
- break;
- case 3: // static int example01::staticAtoi(const char* str)
+ } else if (idx == s_methods["static_example01::staticAtoi_cchar*"]) {
assert(!self && nargs == 1);
result = dummy::example01::staticAtoi((const char*)(*(long*)&((CPPYY_G__value*)args)[0]));
- break;
- case 8: // static int example01::getCount()
+ } else if (idx == s_methods["static_example01::getCount"]) {
assert(!self && nargs == 0);
result = dummy::example01::getCount();
- break;
- case 12: // int example01::addDataToInt(int a)
+ } else if (idx == s_methods["example01::addDataToInt_int"]) {
assert(self && nargs == 1);
result = ((dummy::example01*)self)->addDataToInt(((CPPYY_G__value*)args)[0].obj.in);
- break;
- case 18: // int example01::addDataToAtoi(const char* str)
+ } else if (idx == s_methods["example01::addDataToAtoi_cchar*"]) {
assert(self && nargs == 1);
result = ((dummy::example01*)self)->addDataToAtoi(
(const char*)(*(long*)&((CPPYY_G__value*)args)[0]));
- break;
- default:
+ } else if (idx == s_methods["cppyy_test_data::get_int"]) {
+ assert(self && nargs == 0);
+ result = ((dummy::cppyy_test_data*)self)->get_int();
+ } else {
assert(!"method unknown in cppyy_call_i");
- break;
}
return result;
}
long cppyy_call_l(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
long result = 0;
- switch ((long)method) {
- case 4: // static char* example01::staticStrcpy(const char* strin)
+ const long idx = (long)method;
+ if (idx == s_methods["static_example01::staticStrcpy_cchar*"]) {
assert(!self && nargs == 1);
result = (long)dummy::example01::staticStrcpy(
(const char*)(*(long*)&((CPPYY_G__value*)args)[0]));
- break;
- case 6: // static payload* example01::staticCyclePayload(payload* p, double d)
+ } else if (idx == s_methods["static_example01::staticCyclePayload_payload*_double"]) {
assert(!self && nargs == 2);
result = (long)dummy::example01::staticCyclePayload(
(dummy::payload*)(*(long*)&((CPPYY_G__value*)args)[0]),
((CPPYY_G__value*)args)[1].obj.d);
- break;
- case 19: // char* example01::addToStringValue(const char* str)
+ } else if (idx == s_methods["example01::addToStringValue_cchar*"]) {
assert(self && nargs == 1);
result = (long)((dummy::example01*)self)->addToStringValue(
(const char*)(*(long*)&((CPPYY_G__value*)args)[0]));
- break;
- case 21: // payload* example01::cyclePayload(payload* p)
+ } else if (idx == s_methods["example01::cyclePayload_payload*"]) {
assert(self && nargs == 1);
result = (long)((dummy::example01*)self)->cyclePayload(
(dummy::payload*)(*(long*)&((CPPYY_G__value*)args)[0]));
- break;
- default:
+ } else if (idx == s_methods["cppyy_test_data::get_uint"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_uint();
+ } else if (idx == s_methods["cppyy_test_data::get_long"]) {
+ assert(self && nargs == 0);
+ result = ((dummy::cppyy_test_data*)self)->get_long();
+ } else if (idx == s_methods["cppyy_test_data::get_ulong"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_ulong();
+ } else if (idx == s_methods["cppyy_test_data::get_bool_array"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_bool_array();
+ } else if (idx == s_methods["cppyy_test_data::get_bool_array2"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_bool_array2();
+ } else if (idx == s_methods["cppyy_test_data::get_short_array"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_short_array();
+ } else if (idx == s_methods["cppyy_test_data::get_short_array2"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_short_array2();
+ } else if (idx == s_methods["cppyy_test_data::get_ushort_array"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_ushort_array();
+ } else if (idx == s_methods["cppyy_test_data::get_ushort_array2"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_ushort_array2();
+ } else if (idx == s_methods["cppyy_test_data::get_int_array"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_int_array();
+ } else if (idx == s_methods["cppyy_test_data::get_int_array2"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_int_array2();
+ } else if (idx == s_methods["cppyy_test_data::get_uint_array"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_uint_array();
+ } else if (idx == s_methods["cppyy_test_data::get_uint_array2"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_uint_array2();
+ } else if (idx == s_methods["cppyy_test_data::get_long_array"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_long_array();
+ } else if (idx == s_methods["cppyy_test_data::get_long_array2"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_long_array2();
+ } else if (idx == s_methods["cppyy_test_data::get_ulong_array"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_ulong_array();
+ } else if (idx == s_methods["cppyy_test_data::get_ulong_array2"]) {
+ assert(self && nargs == 0);
+ result = (long)((dummy::cppyy_test_data*)self)->get_ulong_array2();
+ } else if (idx == s_methods["cppyy_test_data::pass_array_short"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_array(
+ (*(short**)&((CPPYY_G__value*)args)[0]));
+ } else if (idx == s_methods["cppyy_test_data::pass_void_array_h"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_void_array_h(
+ (*(short**)&((CPPYY_G__value*)args)[0]));
+ } else if (idx == s_methods["cppyy_test_data::pass_array_ushort"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_array(
+ (*(unsigned short**)&((CPPYY_G__value*)args)[0]));
+ } else if (idx == s_methods["cppyy_test_data::pass_void_array_H"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_void_array_H(
+ (*(unsigned short**)&((CPPYY_G__value*)args)[0]));
+ } else if (idx == s_methods["cppyy_test_data::pass_array_int"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_array(
+ (*(int**)&((CPPYY_G__value*)args)[0]));
+ } else if (idx == s_methods["cppyy_test_data::pass_void_array_i"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_void_array_i(
+ (*(int**)&((CPPYY_G__value*)args)[0]));
+ } else if (idx == s_methods["cppyy_test_data::pass_array_uint"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_array(
+ (*(unsigned int**)&((CPPYY_G__value*)args)[0]));
+ } else if (idx == s_methods["cppyy_test_data::pass_void_array_I"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_void_array_I(
+ (*(unsigned int**)&((CPPYY_G__value*)args)[0]));
+ } else if (idx == s_methods["cppyy_test_data::pass_array_long"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_array(
+ (*(long**)&((CPPYY_G__value*)args)[0]));
+ } else if (idx == s_methods["cppyy_test_data::pass_void_array_l"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_void_array_l(
+ (*(long**)&((CPPYY_G__value*)args)[0]));
+ } else if (idx == s_methods["cppyy_test_data::pass_array_ulong"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_array(
+ (*(unsigned long**)&((CPPYY_G__value*)args)[0]));
+ } else if (idx == s_methods["cppyy_test_data::pass_void_array_L"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_void_array_L(
+ (*(unsigned long**)&((CPPYY_G__value*)args)[0]));
+ } else if (idx == s_methods["cppyy_test_data::pass_array_float"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_array(
+ (*(float**)&((CPPYY_G__value*)args)[0]));
+ } else if (idx == s_methods["cppyy_test_data::pass_void_array_f"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_void_array_f(
+ (*(float**)&((CPPYY_G__value*)args)[0]));
+ } else if (idx == s_methods["cppyy_test_data::pass_array_double"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_array(
+ (*(double**)&((CPPYY_G__value*)args)[0]));
+ } else if (idx == s_methods["cppyy_test_data::pass_void_array_d"]) {
+ assert(self && nargs == 1);
+ result = (long)((dummy::cppyy_test_data*)self)->pass_void_array_d(
+ (*(double**)&((CPPYY_G__value*)args)[0]));
+ } else {
assert(!"method unknown in cppyy_call_l");
- break;
}
return result;
}
+long long cppyy_call_ll(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
+ long long result = 0;
+ const long idx = (long)method;
+ if (idx == s_methods["cppyy_test_data::get_llong"]) {
+ assert(self && nargs == 0);
+ result = ((dummy::cppyy_test_data*)self)->get_llong();
+ } else if (idx == s_methods["cppyy_test_data::get_ullong"]) {
+ assert(self && nargs == 0);
+ result = (long long)((dummy::cppyy_test_data*)self)->get_ullong();
+ } else {
+ assert(!"method unknown in cppyy_call_ll");
+ }
+ return result;
+}
+
+float cppyy_call_f(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
+ float result = 0;
+ const long idx = (long)method;
+ if (idx == s_methods["cppyy_test_data::get_float"]) {
+ assert(self && nargs == 0);
+ result = ((dummy::cppyy_test_data*)self)->get_float();
+ } else {
+ assert(!"method unknown in cppyy_call_f");
+ }
+ return result;
+}
+
double cppyy_call_d(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
double result = 0.;
- switch ((long)method) {
- case 0: // static double example01::staticAddToDouble(double)
+ const long idx = (long)method;
+ if (idx == s_methods["static_example01::staticAddToDouble_double"]) {
assert(!self && nargs == 1);
result = dummy::example01::staticAddToDouble(((CPPYY_G__value*)args)[0].obj.d);
- break;
- case 17: // double example01::addDataToDouble(double a)
+ } else if (idx == s_methods["example01::addDataToDouble_double"]) {
assert(self && nargs == 1);
result = ((dummy::example01*)self)->addDataToDouble(((CPPYY_G__value*)args)[0].obj.d);
- break;
- case 24: // double payload::getData()
+ } else if (idx == s_methods["payload::getData"]) {
assert(self && nargs == 0);
result = ((dummy::payload*)self)->getData();
- break;
- default:
+ } else if (idx == s_methods["cppyy_test_data::get_double"]) {
+ assert(self && nargs == 0);
+ result = ((dummy::cppyy_test_data*)self)->get_double();
+ } else {
assert(!"method unknown in cppyy_call_d");
- break;
}
return result;
}
char* cppyy_call_s(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
char* result = 0;
- switch ((long)method) {
- case 4: // static char* example01::staticStrcpy(const char* strin)
+ const long idx = (long)method;
+ if (idx == s_methods["static_example01::staticStrcpy_cchar*"]) {
assert(!self && nargs == 1);
result = dummy::example01::staticStrcpy((const char*)(*(long*)&((CPPYY_G__value*)args)[0]));
- break;
- default:
+ } else {
assert(!"method unknown in cppyy_call_s");
- break;
}
return result;
}
cppyy_object_t cppyy_constructor(cppyy_method_t method, cppyy_type_t handle, int nargs, void* args) {
void* result = 0;
- if (handle == s_handles["example01"]) {
- switch ((long)method) {
- case 10:
- assert(nargs == 0);
- result = new dummy::example01;
- break;
- case 11:
- assert(nargs == 1);
- result = new dummy::example01(((CPPYY_G__value*)args)[0].obj.in);
- break;
- default:
- assert(!"method of example01 unknown in cppyy_constructor");
- break;
- }
- } else if (handle == s_handles["payload"]) {
- switch ((long)method) {
- case 23:
- if (nargs == 0) result = new dummy::payload;
- else if (nargs == 1) result = new dummy::payload(((CPPYY_G__value*)args)[0].obj.d);
- break;
- default:
- assert(!"method payload unknown in cppyy_constructor");
- break;
- }
+ const long idx = (long)method;
+ if (idx == s_methods["example01::example01"]) {
+ assert(nargs == 0);
+ result = new dummy::example01;
+ } else if (idx == s_methods["example01::example01_int"]) {
+ assert(nargs == 1);
+ result = new dummy::example01(((CPPYY_G__value*)args)[0].obj.in);
+ } else if (idx == s_methods["payload::payload_double"]) {
+ assert(nargs == 0 || nargs == 1);
+ if (nargs == 0) result = new dummy::payload;
+ else if (nargs == 1) result = new dummy::payload(((CPPYY_G__value*)args)[0].obj.d);
+ } else if (idx == s_methods["cppyy_test_data::cppyy_test_data"]) {
+ assert(nargs == 0);
+ result = new dummy::cppyy_test_data;
+ } else {
+ assert(!"method unknown in cppyy_constructor");
}
return (cppyy_object_t)result;
}
@@ -486,10 +862,10 @@
}
cppyy_method_t cppyy_get_method(cppyy_scope_t handle, cppyy_index_t method_index) {
- if (handle == s_handles["example01"])
- return (cppyy_method_t)method_index;
- else if (handle == s_handles["payload"])
- return (cppyy_method_t)((long)method_index + payload_methods_offset);
+ if (s_scopes.find(handle) != s_scopes.end()) {
+ long id = s_scopes[handle].m_method_offset + (long)method_index;
+ return (cppyy_method_t)id;
+ }
assert(!"unknown class in cppyy_get_method");
return (cppyy_method_t)0;
}
@@ -497,26 +873,45 @@
/* method properties ----------------------------------------------------- */
int cppyy_is_constructor(cppyy_type_t handle, cppyy_index_t method_index) {
- if (handle == s_handles["example01"])
- return example01_last_static_method <= method_index
- && method_index < example01_last_constructor;
- else if (handle == s_handles["payload"])
- return (long)method_index == 0;
+ if (s_scopes.find(handle) != s_scopes.end())
+ return s_scopes[handle].m_methods[method_index].m_type == kConstructor;
+ assert(!"unknown class in cppyy_is_constructor");
return 0;
}
int cppyy_is_staticmethod(cppyy_type_t handle, cppyy_index_t method_index) {
- if (handle == s_handles["example01"])
- return method_index < example01_last_static_method ? 1 : 0;
- if (handle == s_handles["payload"])
- return 0;
+ if (s_scopes.find(handle) != s_scopes.end())
+ return s_scopes[handle].m_methods[method_index].m_type == kStatic;
+ assert(!"unknown class in cppyy_is_staticmethod");
+ return 0;
+}
+
+
+/* data member reflection information ------------------------------------- */
+int cppyy_num_datamembers(cppyy_scope_t handle) {
+ return s_scopes[handle].m_datambrs.size();
+}
+
+char* cppyy_datamember_name(cppyy_scope_t handle, int idatambr) {
+ return cppstring_to_cstring(s_scopes[handle].m_datambrs[idatambr].m_name);
+}
+
+char* cppyy_datamember_type(cppyy_scope_t handle, int idatambr) {
+ return cppstring_to_cstring(s_scopes[handle].m_datambrs[idatambr].m_type);
+}
+
+size_t cppyy_datamember_offset(cppyy_scope_t handle, int idatambr) {
+ return s_scopes[handle].m_datambrs[idatambr].m_offset;
+}
+
+
+/* data member properties ------------------------------------------------ */
+int cppyy_is_publicdata(cppyy_scope_t handle, int idatambr) {
return 1;
}
-
-/* data member reflection information ------------------------------------- */
-int cppyy_num_datamembers(cppyy_scope_t /* handle */) {
- return 0;
+int cppyy_is_staticdata(cppyy_scope_t handle, int idatambr) {
+ return s_scopes[handle].m_datambrs[idatambr].m_isstatic;
}
diff --git a/pypy/module/cppyy/test/conftest.py b/pypy/module/cppyy/test/conftest.py
--- a/pypy/module/cppyy/test/conftest.py
+++ b/pypy/module/cppyy/test/conftest.py
@@ -7,14 +7,18 @@
if 'dummy' in lcapi.reflection_library:
# run only tests that are covered by the dummy backend and tests
# that do not rely on reflex
- if not ('test_helper.py' in item.location[0] or \
- 'test_cppyy.py' in item.location[0] or \
- 'test_pythonify.py' in item.location[0]):
+ import os
+ tst = os.path.basename(item.location[0])
+ if not tst in ('test_helper.py', 'test_cppyy.py', 'test_pythonify.py',
+ 'test_datatypes.py'):
py.test.skip("genreflex is not installed")
import re
- if 'test_pythonify.py' in item.location[0] and \
+ if tst == 'test_pythonify.py' and \
not re.search("AppTestPYTHONIFY.test0[1-6]", item.location[2]):
py.test.skip("genreflex is not installed")
+ elif tst == 'test_datatypes.py' and \
+ not re.search("AppTestDATATYPES.test0[1-8]", item.location[2]):
+ py.test.skip("genreflex is not installed")
def pytest_ignore_collect(path, config):
if py.path.local.sysfind('genreflex') is None and config.option.runappdirect:
diff --git a/pypy/module/cppyy/test/datatypes.h b/pypy/module/cppyy/test/datatypes.h
--- a/pypy/module/cppyy/test/datatypes.h
+++ b/pypy/module/cppyy/test/datatypes.h
@@ -16,9 +16,9 @@
class four_vector {
public:
four_vector(double x, double y, double z, double t) :
- m_x(x), m_y(y), m_z(z), m_t(t), m_cc_called(false) {}
+ m_cc_called(false), m_x(x), m_y(y), m_z(z), m_t(t) {}
four_vector(const four_vector& s) :
- m_x(s.m_x), m_y(s.m_y), m_z(s.m_z), m_t(s.m_t), m_cc_called(true) {}
+ m_cc_called(true), m_x(s.m_x), m_y(s.m_y), m_z(s.m_z), m_t(s.m_t) {}
double operator[](int i) {
if (i == 0) return m_x;
diff --git a/pypy/module/cppyy/test/fragile.h b/pypy/module/cppyy/test/fragile.h
--- a/pypy/module/cppyy/test/fragile.h
+++ b/pypy/module/cppyy/test/fragile.h
@@ -112,4 +112,9 @@
enum E2 { kTwice=12 };
};
+class O {
+public:
+ virtual int abstract() = 0;
+};
+
} // namespace fragile
diff --git a/pypy/module/cppyy/test/fragile_LinkDef.h b/pypy/module/cppyy/test/fragile_LinkDef.h
--- a/pypy/module/cppyy/test/fragile_LinkDef.h
+++ b/pypy/module/cppyy/test/fragile_LinkDef.h
@@ -23,6 +23,7 @@
#pragma link C++ class fragile::L;
#pragma link C++ class fragile::M;
#pragma link C++ class fragile::N;
+#pragma link C++ class fragile::O;
#pragma link C++ class fragile::nested1::A;
#pragma link C++ class fragile::nested1::nested2::A;
#pragma link C++ class fragile::nested1::nested2::nested3::A;
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
@@ -435,14 +435,16 @@
class AppTestCINTFUNCTION:
spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
+ _pypytest_leaks = None # TODO: figure out the false positives
# test the function callbacks; this does not work with Reflex, as it can
# not generate functions on the fly (it might with cffi?)
+ @py.test.mark.dont_track_allocations("TODO: understand; initialization left-over?")
def test01_global_function_callback(self):
"""Test callback of a python global function"""
- import cppyy
+ import cppyy, gc
TF1 = cppyy.gbl.TF1
def identity(x):
@@ -460,11 +462,12 @@
assert f.Eval(0.5) == 0.5
del f # force here, to prevent leak-check complaints
+ gc.collect()
def test02_callable_object_callback(self):
"""Test callback of a python callable object"""
- import cppyy
+ import cppyy, gc
TF1 = cppyy.gbl.TF1
class Linear:
@@ -478,13 +481,14 @@
assert f.Eval(1.3) == 7.6
del f # force here, to prevent leak-check complaints
+ gc.collect()
def test03_fit_with_python_gaussian(self):
"""Test fitting with a python global function"""
# note: this function is dread-fully slow when running testing un-translated
- import cppyy, math
+ import cppyy, gc, math
TF1, TH1F = cppyy.gbl.TF1, cppyy.gbl.TH1F
def pygaus(x, par):
@@ -515,6 +519,7 @@
assert round(result[2] - 1., 1) == 0 # s.d.
del f # force here, to prevent leak-check complaints
+ gc.collect()
class AppTestSURPLUS:
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
@@ -202,6 +202,12 @@
f = fragile.fglobal
assert f.__doc__ == "void fragile::fglobal(int, double, char)"
+ try:
+ o = fragile.O() # raises TypeError
+ assert 0
+ except TypeError, e:
+ assert "cannot instantiate abstract class 'O'" in str(e)
+
def test11_dir(self):
"""Test __dir__ method"""
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
@@ -338,8 +338,13 @@
import cppyy
example01 = cppyy.gbl.example01
+ assert example01.getCount() == 0
+
o = example01()
assert type(o) == example01
+ assert example01.getCount() == 1
+ o.destruct()
+ assert example01.getCount() == 0
class MyClass1(example01):
def myfunc(self):
@@ -348,7 +353,10 @@
o = MyClass1()
assert type(o) == MyClass1
assert isinstance(o, example01)
+ assert example01.getCount() == 1
assert o.myfunc() == 1
+ o.destruct()
+ assert example01.getCount() == 0
class MyClass2(example01):
def __init__(self, what):
@@ -357,7 +365,11 @@
o = MyClass2('hi')
assert type(o) == MyClass2
+ assert example01.getCount() == 1
assert o.what == 'hi'
+ o.destruct()
+
+ assert example01.getCount() == 0
class AppTestPYTHONIFY_UI:
More information about the pypy-commit
mailing list