[pypy-commit] pypy release-2.3.x: merge default into release
mattip
noreply at buildbot.pypy.org
Fri May 2 08:29:17 CEST 2014
Author: mattip <matti.picus at gmail.com>
Branch: release-2.3.x
Changeset: r71189:6a851784bf2f
Date: 2014-05-02 09:28 +0300
http://bitbucket.org/pypy/pypy/changeset/6a851784bf2f/
Log: merge default into release
diff too long, truncating to 2000 out of 3386 lines
diff --git a/lib-python/2.7/cProfile.py b/lib-python/2.7/cProfile.py
--- a/lib-python/2.7/cProfile.py
+++ b/lib-python/2.7/cProfile.py
@@ -161,7 +161,7 @@
# ____________________________________________________________
def main():
- import os, sys
+ import os, sys, types
from optparse import OptionParser
usage = "cProfile.py [-o output_file_path] [-s sort] scriptfile [arg] ..."
parser = OptionParser(usage=usage)
@@ -184,12 +184,10 @@
sys.path.insert(0, os.path.dirname(progname))
with open(progname, 'rb') as fp:
code = compile(fp.read(), progname, 'exec')
- globs = {
- '__file__': progname,
- '__name__': '__main__',
- '__package__': None,
- }
- runctx(code, globs, None, options.outfile, options.sort)
+ mainmod = types.ModuleType('__main__')
+ mainmod.__file__ = progname
+ mainmod.__package__ = None
+ runctx(code, mainmod.__dict__, None, options.outfile, options.sort)
else:
parser.print_usage()
return parser
diff --git a/pypy/doc/whatsnew-2.3.0.rst b/pypy/doc/whatsnew-2.3.0.rst
--- a/pypy/doc/whatsnew-2.3.0.rst
+++ b/pypy/doc/whatsnew-2.3.0.rst
@@ -161,3 +161,7 @@
.. branch: refactor-buffer-api
Properly implement old/new buffer API for objects and start work on replacing bufferstr usage
+
+.. branch: issue1430
+Add a lock for unsafe calls to gethostbyname and gethostbyaddr
+
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -3,6 +3,5 @@
=======================
.. this is a revision shortly after release-2.3.x
-.. startrev: 0524dae88c75
+.. startrev: 0f75ad4d14ce
-
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -692,23 +692,17 @@
def allocate_lock(self):
"""Return an interp-level Lock object if threads are enabled,
and a dummy object if they are not."""
- if self.config.objspace.usemodules.thread:
- # we use a sub-function to avoid putting the 'import' statement
- # here, where the flow space would see it even if thread=False
- return self.__allocate_lock()
- else:
- return dummy_lock
-
- def __allocate_lock(self):
- from rpython.rlib.rthread import allocate_lock, error
+ from rpython.rlib import rthread
+ if not self.config.objspace.usemodules.thread:
+ return rthread.dummy_lock
# hack: we can't have prebuilt locks if we're translating.
# In this special situation we should just not lock at all
# (translation is not multithreaded anyway).
if not we_are_translated() and self.config.translating:
raise CannotHaveLock()
try:
- return allocate_lock()
- except error:
+ return rthread.allocate_lock()
+ except rthread.error:
raise OperationError(self.w_RuntimeError,
self.wrap("out of resources"))
@@ -1415,10 +1409,10 @@
def _getarg_error(self, expected, w_obj):
if self.is_none(w_obj):
- name = "None"
+ e = oefmt(self.w_TypeError, "must be %s, not None", expected)
else:
- name = self.type(w_obj).get_module_type_name()
- raise oefmt(self.w_TypeError, "must be %s, not %s", expected, name)
+ e = oefmt(self.w_TypeError, "must be %s, not %T", expected, w_obj)
+ raise e
@specialize.arg(1)
def getarg_w(self, code, w_obj):
@@ -1722,24 +1716,6 @@
return space.getitem(w_glob, space.wrap('anonymous'))
-class DummyLock(object):
- def acquire(self, flag):
- return True
-
- def release(self):
- pass
-
- def _freeze_(self):
- return True
-
- def __enter__(self):
- pass
-
- def __exit__(self, *args):
- pass
-
-dummy_lock = DummyLock()
-
# Table describing the regular part of the interface of object spaces,
# namely all methods which only take w_ arguments and return a w_ result
# (if any).
diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -362,9 +362,9 @@
value = getattr(self, attr)
if fmt == 'R':
result = space.str_w(space.repr(value))
- elif fmt in 'NT':
- if fmt == 'T':
- value = space.type(value)
+ elif fmt == 'T':
+ result = space.type(value).get_module_type_name()
+ elif fmt == 'N':
result = value.getname(space)
else:
result = str(value)
@@ -404,7 +404,7 @@
%N - The result of w_arg.getname(space)
%R - The result of space.str_w(space.repr(w_arg))
- %T - The result of space.type(w_arg).getname(space)
+ %T - The result of space.type(w_arg).get_module_type_name()
"""
if not len(args):
diff --git a/pypy/module/__builtin__/compiling.py b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -27,6 +27,7 @@
consts.PyCF_DONT_IMPLY_DEDENT | consts.PyCF_SOURCE_IS_UTF8):
raise OperationError(space.w_ValueError,
space.wrap("compile() unrecognized flags"))
+
if not dont_inherit:
caller = ec.gettopframe_nohidden()
if caller:
@@ -37,8 +38,7 @@
space.wrap("compile() arg 3 must be 'exec' "
"or 'eval' or 'single'"))
- w_ast_type = space.gettypeobject(ast.AST.typedef)
- if space.isinstance_w(w_source, w_ast_type):
+ if space.isinstance_w(w_source, space.gettypeobject(ast.AST.typedef)):
ast_node = space.interp_w(ast.mod, w_source)
ast_node.sync_app_attrs(space)
code = ec.compiler.compile_ast(ast_node, filename, mode, flags)
@@ -47,20 +47,20 @@
if space.isinstance_w(w_source, space.w_unicode):
w_utf_8_source = space.call_method(w_source, "encode",
space.wrap("utf-8"))
- str_ = space.str_w(w_utf_8_source)
+ source = space.str_w(w_utf_8_source)
# This flag tells the parser to reject any coding cookies it sees.
flags |= consts.PyCF_SOURCE_IS_UTF8
else:
- str_ = space.readbuf_w(w_source).as_str()
+ source = space.readbuf_w(w_source).as_str()
- if '\x00' in str_:
+ if '\x00' in source:
raise OperationError(space.w_TypeError, space.wrap(
"compile() expected string without null bytes"))
if flags & consts.PyCF_ONLY_AST:
- code = ec.compiler.compile_to_ast(str_, filename, mode, flags)
+ code = ec.compiler.compile_to_ast(source, filename, mode, flags)
else:
- code = ec.compiler.compile(str_, filename, mode, flags)
+ code = ec.compiler.compile(source, filename, mode, flags)
return space.wrap(code)
diff --git a/pypy/module/_ast/test/test_ast.py b/pypy/module/_ast/test/test_ast.py
--- a/pypy/module/_ast/test/test_ast.py
+++ b/pypy/module/_ast/test/test_ast.py
@@ -19,6 +19,11 @@
ast = self.ast
assert isinstance(ast.__version__, str)
+ def test_flags(self):
+ skip("broken")
+ from copy_reg import _HEAPTYPE
+ assert self.ast.Module.__flags__ & _HEAPTYPE
+
def test_build_ast(self):
ast = self.ast
mod = self.get_ast("x = 4")
@@ -218,19 +223,19 @@
x = ast.Num()
assert x._fields == ('n',)
exc = raises(AttributeError, getattr, x, 'n')
- assert exc.value.args[0] == "'Num' object has no attribute 'n'"
+ assert "Num' object has no attribute 'n'" in exc.value.args[0]
x = ast.Num(42)
assert x.n == 42
exc = raises(AttributeError, getattr, x, 'lineno')
- assert exc.value.args[0] == "'Num' object has no attribute 'lineno'"
+ assert "Num' object has no attribute 'lineno'" in exc.value.args[0]
y = ast.Num()
x.lineno = y
assert x.lineno == y
exc = raises(AttributeError, getattr, x, 'foobar')
- assert exc.value.args[0] == "'Num' object has no attribute 'foobar'"
+ assert "Num' object has no attribute 'foobar'" in exc.value.args[0]
x = ast.Num(lineno=2)
assert x.lineno == 2
@@ -244,9 +249,8 @@
raises(TypeError, ast.Num, 1, 2, lineno=0)
def test_issue1680_nonseq(self):
+ # Test deleting an attribute manually
- # Test deleting an attribute manually
-
_ast = self.ast
mod = self.get_ast("self.attr")
assert isinstance(mod, _ast.Module)
@@ -287,9 +291,8 @@
assert not hasattr(mod.body[0], 'name')
def test_issue1680_seq(self):
+ # Test deleting an attribute manually
- # Test deleting an attribute manually
-
_ast = self.ast
mod = self.get_ast("self.attr")
assert isinstance(mod, _ast.Module)
@@ -392,9 +395,8 @@
import ast
num_node = ast.Num(n=2, lineno=2, col_offset=3)
dict_res = num_node.__dict__
-
assert dict_res == {'n':2, 'lineno':2, 'col_offset':3}
-
+
def test_issue1673_Num_notfullinit(self):
import ast
import copy
@@ -402,7 +404,7 @@
assert num_node.n == 2
assert num_node.lineno == 2
num_node2 = copy.deepcopy(num_node)
-
+
def test_issue1673_Num_fullinit(self):
import ast
import copy
@@ -413,7 +415,7 @@
assert num_node.col_offset == num_node2.col_offset
dict_res = num_node2.__dict__
assert dict_res == {'n':2, 'lineno':2, 'col_offset':3}
-
+
def test_issue1673_Str(self):
import ast
import copy
@@ -423,4 +425,3 @@
str_node2 = copy.deepcopy(str_node)
dict_res = str_node2.__dict__
assert dict_res == {'n':2, 'lineno':2}
-
\ No newline at end of file
diff --git a/pypy/module/_lsprof/interp_lsprof.py b/pypy/module/_lsprof/interp_lsprof.py
--- a/pypy/module/_lsprof/interp_lsprof.py
+++ b/pypy/module/_lsprof/interp_lsprof.py
@@ -59,7 +59,7 @@
self.tt, self.it, calls_repr))
def get_code(self, space):
- return self.frame
+ return returns_code(space, self.frame)
W_StatsEntry.typedef = TypeDef(
'StatsEntry',
@@ -86,7 +86,7 @@
frame_repr, self.callcount, self.reccallcount, self.tt, self.it))
def get_code(self, space):
- return self.frame
+ return returns_code(space, self.frame)
W_StatsSubEntry.typedef = TypeDef(
'SubStatsEntry',
@@ -189,50 +189,82 @@
subentry._stop(tt, it)
- at jit.elidable_promote()
def create_spec_for_method(space, w_function, w_type):
- w_function = w_function
+ class_name = None
if isinstance(w_function, Function):
name = w_function.name
+ # try to get the real class that defines the method,
+ # which is a superclass of the class of the instance
+ from pypy.objspace.std.typeobject import W_TypeObject # xxx
+ if isinstance(w_type, W_TypeObject):
+ w_realclass, _ = space.lookup_in_type_where(w_type, name)
+ if isinstance(w_realclass, W_TypeObject):
+ class_name = w_realclass.get_module_type_name()
else:
name = '?'
- # try to get the real class that defines the method,
- # which is a superclass of the class of the instance
- from pypy.objspace.std.typeobject import W_TypeObject # xxx
- class_name = w_type.getname(space) # if the rest doesn't work
- if isinstance(w_type, W_TypeObject) and name != '?':
- w_realclass, _ = space.lookup_in_type_where(w_type, name)
- if isinstance(w_realclass, W_TypeObject):
- class_name = w_realclass.get_module_type_name()
- return "{method '%s' of '%s' objects}" % (name, class_name)
+ if class_name is None:
+ class_name = w_type.getname(space) # if the rest doesn't work
+ return "<method '%s' of '%s' objects>" % (name, class_name)
- at jit.elidable_promote()
def create_spec_for_function(space, w_func):
- if w_func.w_module is None:
- module = ''
+ assert isinstance(w_func, Function)
+ if w_func.w_module is not None:
+ module = space.str_w(w_func.w_module)
+ if module != '__builtin__':
+ return '<%s.%s>' % (module, w_func.name)
+ return '<%s>' % w_func.name
+
+
+def create_spec_for_object(space, w_type):
+ class_name = w_type.getname(space)
+ return "<'%s' object>" % (class_name,)
+
+
+class W_DelayedBuiltinStr(W_Root):
+ # This class should not be seen at app-level, but is useful to
+ # contain a (w_func, w_type) pair returned by prepare_spec().
+ # Turning this pair into a string cannot be done eagerly in
+ # an @elidable function because of space.str_w(), but it can
+ # be done lazily when we really want it.
+
+ _immutable_fields_ = ['w_func', 'w_type']
+
+ def __init__(self, w_func, w_type):
+ self.w_func = w_func
+ self.w_type = w_type
+ self.w_string = None
+
+ def wrap_string(self, space):
+ if self.w_string is None:
+ if self.w_type is None:
+ s = create_spec_for_function(space, self.w_func)
+ elif self.w_func is None:
+ s = create_spec_for_object(space, self.w_type)
+ else:
+ s = create_spec_for_method(space, self.w_func, self.w_type)
+ self.w_string = space.wrap(s)
+ return self.w_string
+
+W_DelayedBuiltinStr.typedef = TypeDef(
+ 'DelayedBuiltinStr',
+ __str__ = interp2app(W_DelayedBuiltinStr.wrap_string),
+)
+
+def returns_code(space, w_frame):
+ if isinstance(w_frame, W_DelayedBuiltinStr):
+ return w_frame.wrap_string(space)
+ return w_frame # actually a PyCode object
+
+
+def prepare_spec(space, w_arg):
+ if isinstance(w_arg, Method):
+ return (w_arg.w_function, w_arg.w_class)
+ elif isinstance(w_arg, Function):
+ return (w_arg, None)
else:
- module = space.str_w(w_func.w_module)
- if module == '__builtin__':
- module = ''
- else:
- module += '.'
- return '{%s%s}' % (module, w_func.name)
-
-
- at jit.elidable_promote()
-def create_spec_for_object(space, w_obj):
- class_name = space.type(w_obj).getname(space)
- return "{'%s' object}" % (class_name,)
-
-
-def create_spec(space, w_arg):
- if isinstance(w_arg, Method):
- return create_spec_for_method(space, w_arg.w_function, w_arg.w_class)
- elif isinstance(w_arg, Function):
- return create_spec_for_function(space, w_arg)
- else:
- return create_spec_for_object(space, w_arg)
+ return (None, space.type(w_arg))
+prepare_spec._always_inline_ = True
def lsprof_call(space, w_self, frame, event, w_arg):
@@ -245,12 +277,10 @@
w_self._enter_return(code)
elif event == 'c_call':
if w_self.builtins:
- key = create_spec(space, w_arg)
- w_self._enter_builtin_call(key)
+ w_self._enter_builtin_call(w_arg)
elif event == 'c_return' or event == 'c_exception':
if w_self.builtins:
- key = create_spec(space, w_arg)
- w_self._enter_builtin_return(key)
+ w_self._enter_builtin_return(w_arg)
else:
# ignore or raise an exception???
pass
@@ -313,13 +343,14 @@
return entry
raise
- @jit.elidable
- def _get_or_make_builtin_entry(self, key, make=True):
+ @jit.elidable_promote()
+ def _get_or_make_builtin_entry(self, w_func, w_type, make):
+ key = (w_func, w_type)
try:
return self.builtin_data[key]
except KeyError:
if make:
- entry = ProfilerEntry(self.space.wrap(key))
+ entry = ProfilerEntry(W_DelayedBuiltinStr(w_func, w_type))
self.builtin_data[key] = entry
return entry
raise
@@ -343,18 +374,18 @@
context._stop(self, entry)
self.current_context = context.previous
- def _enter_builtin_call(self, key):
- self = jit.promote(self)
- entry = self._get_or_make_builtin_entry(key)
+ def _enter_builtin_call(self, w_arg):
+ w_func, w_type = prepare_spec(self.space, w_arg)
+ entry = self._get_or_make_builtin_entry(w_func, w_type, True)
self.current_context = ProfilerContext(self, entry)
- def _enter_builtin_return(self, key):
+ def _enter_builtin_return(self, w_arg):
context = self.current_context
if context is None:
return
- self = jit.promote(self)
+ w_func, w_type = prepare_spec(self.space, w_arg)
try:
- entry = self._get_or_make_builtin_entry(key, False)
+ entry = self._get_or_make_builtin_entry(w_func, w_type, False)
except KeyError:
pass
else:
diff --git a/pypy/module/_lsprof/test/test_cprofile.py b/pypy/module/_lsprof/test/test_cprofile.py
--- a/pypy/module/_lsprof/test/test_cprofile.py
+++ b/pypy/module/_lsprof/test/test_cprofile.py
@@ -11,6 +11,48 @@
import _lsprof
assert repr(_lsprof.Profiler) == "<type '_lsprof.Profiler'>"
+ def test_builtins(self):
+ import _lsprof
+ prof = _lsprof.Profiler()
+ lst = []
+ prof.enable()
+ lst.append(len(lst))
+ prof.disable()
+ stats = prof.getstats()
+ expected = (
+ "<len>",
+ "<method 'append' of 'list' objects>",
+ "<method 'disable' of '_lsprof.Profiler' objects>",
+ )
+ for entry in stats:
+ assert entry.code in expected
+
+ def test_builtins_callers(self):
+ import _lsprof
+ prof = _lsprof.Profiler(subcalls=True)
+ lst = []
+ def f1():
+ lst.append(len(lst))
+ prof.enable(subcalls=True)
+ f1()
+ prof.disable()
+ stats = prof.getstats()
+ expected = (
+ "<len>",
+ "<method 'append' of 'list' objects>",
+ )
+ by_id = set()
+ for entry in stats:
+ if entry.code == f1.__code__:
+ assert len(entry.calls) == 2
+ for subentry in entry.calls:
+ assert subentry.code in expected
+ by_id.add(id(subentry.code))
+ elif entry.code in expected:
+ by_id.add(id(entry.code))
+ # :-( cProfile.py relies on the id() of the strings...
+ assert len(by_id) == len(expected)
+
def test_direct(self):
import _lsprof
def getticks():
@@ -37,10 +79,8 @@
stats = prof.getstats()
entries = {}
for entry in stats:
- if not hasattr(entry.code, 'co_name'):
- print entry.code
- else:
- entries[entry.code.co_name] = entry
+ assert hasattr(entry.code, 'co_name')
+ entries[entry.code.co_name] = entry
efoo = entries['foo']
assert efoo.callcount == 2
assert efoo.reccallcount == 1
@@ -104,8 +144,8 @@
entries = {}
for entry in stats:
entries[entry.code] = entry
- efoo = entries[foo.func_code]
- ebar = entries[bar.func_code]
+ efoo = entries[foo.__code__]
+ ebar = entries[bar.__code__]
assert 0.9 < efoo.totaltime < 2.9
# --- cannot test .inlinetime, because it does not include
# --- the time spent doing the call to time.time()
@@ -179,12 +219,12 @@
lines.remove(line)
break
else:
- print 'NOT FOUND:', pattern.rstrip('\n')
- print '--- GOT ---'
- print got
- print
- print '--- EXPECTED ---'
- print expected
+ print('NOT FOUND: %s' % pattern.rstrip('\n'))
+ print('--- GOT ---')
+ print(got)
+ print()
+ print('--- EXPECTED ---')
+ print(expected)
assert False
assert not lines
finally:
diff --git a/pypy/module/_rawffi/test/test__rawffi.py b/pypy/module/_rawffi/test/test__rawffi.py
--- a/pypy/module/_rawffi/test/test__rawffi.py
+++ b/pypy/module/_rawffi/test/test__rawffi.py
@@ -1084,27 +1084,27 @@
s = S(autofree=True)
b = buffer(s)
assert len(b) == 40
- b[4] = 'X'
- b[:3] = 'ABC'
- assert b[:6] == 'ABC\x00X\x00'
+ b[4] = b'X'
+ b[:3] = b'ABC'
+ assert b[:6] == b'ABC\x00X\x00'
A = _rawffi.Array('c')
a = A(10, autofree=True)
- a[3] = 'x'
+ a[3] = b'x'
b = buffer(a)
assert len(b) == 10
- assert b[3] == 'x'
- b[6] = 'y'
- assert a[6] == 'y'
- b[3:5] = 'zt'
- assert a[3] == 'z'
- assert a[4] == 't'
+ assert b[3] == b'x'
+ b[6] = b'y'
+ assert a[6] == b'y'
+ b[3:5] = b'zt'
+ assert a[3] == b'z'
+ assert a[4] == b't'
b = memoryview(a)
assert len(b) == 10
- assert b[3] == 'z'
- b[3] = 'x'
- assert b[3] == 'x'
+ assert b[3] == b'z'
+ b[3] = b'x'
+ assert b[3] == b'x'
def test_union(self):
import _rawffi
diff --git a/pypy/module/_socket/__init__.py b/pypy/module/_socket/__init__.py
--- a/pypy/module/_socket/__init__.py
+++ b/pypy/module/_socket/__init__.py
@@ -17,6 +17,8 @@
def startup(self, space):
from rpython.rlib.rsocket import rsocket_startup
rsocket_startup()
+ from pypy.module._socket.interp_func import State
+ space.fromcache(State).startup(space)
def buildloaders(cls):
from rpython.rlib import rsocket
diff --git a/pypy/module/_socket/interp_func.py b/pypy/module/_socket/interp_func.py
--- a/pypy/module/_socket/interp_func.py
+++ b/pypy/module/_socket/interp_func.py
@@ -42,8 +42,9 @@
Return the true host name, a list of aliases, and a list of IP addresses,
for a host. The host argument is a string giving a host name or IP number.
"""
+ lock = space.fromcache(State).netdb_lock
try:
- res = rsocket.gethostbyname_ex(host)
+ res = rsocket.gethostbyname_ex(host, lock)
except SocketError, e:
raise converted_error(space, e)
return common_wrapgethost(space, res)
@@ -55,8 +56,9 @@
Return the true host name, a list of aliases, and a list of IP addresses,
for a host. The host argument is a string giving a host name or IP number.
"""
+ lock = space.fromcache(State).netdb_lock
try:
- res = rsocket.gethostbyaddr(host)
+ res = rsocket.gethostbyaddr(host, lock)
except SocketError, e:
raise converted_error(space, e)
return common_wrapgethost(space, res)
@@ -310,3 +312,10 @@
raise OperationError(space.w_ValueError,
space.wrap('Timeout value out of range'))
rsocket.setdefaulttimeout(timeout)
+
+class State(object):
+ def __init__(self, space):
+ self.netdb_lock = None
+
+ def startup(self, space):
+ self.netdb_lock = space.allocate_lock()
diff --git a/pypy/module/_socket/interp_socket.py b/pypy/module/_socket/interp_socket.py
--- a/pypy/module/_socket/interp_socket.py
+++ b/pypy/module/_socket/interp_socket.py
@@ -600,7 +600,8 @@
method = getattr(W_RSocket, methodname + '_w')
socketmethods[methodname] = interp2app(method)
-W_RSocket.typedef = TypeDef("_socket.socket",
+W_RSocket.typedef = TypeDef("socket",
+ __module__ = "_socket",
__doc__ = """\
socket([family[, type[, proto]]]) -> socket object
diff --git a/pypy/module/_socket/test/test_sock_app.py b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -313,6 +313,11 @@
cls.space = space
cls.w_udir = space.wrap(str(udir))
+ def test_module(self):
+ import _socket
+ assert _socket.socket.__name__ == 'socket'
+ assert _socket.socket.__module__ == '_socket'
+
def test_ntoa_exception(self):
import _socket
raises(_socket.error, _socket.inet_ntoa, "ab")
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
@@ -1,30 +1,31 @@
# NOT_RPYTHON
# do not load cppyy here, see _init_pythonify()
-import types, sys
+import types
+import sys
# 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
# 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
- except Exception, e:
+ except Exception as e:
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 +92,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 +138,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 +153,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 +164,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 +172,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 +208,7 @@
return pycppclass
def make_cpptemplatetype(scope, template_name):
- return CppyyTemplateType(template_name, scope)
+ return CPPTemplate(template_name, scope)
def get_pycppitem(scope, name):
@@ -309,7 +303,7 @@
return self._getitem__unchecked(idx)
def python_style_sliceable_getitem(self, slice_or_idx):
- if type(slice_or_idx) == types.SliceType:
+ if type(slice_or_idx) == slice:
nseq = self.__class__()
nseq += [python_style_getitem(self, i) \
for i in range(*slice_or_idx.indices(len(self)))]
@@ -426,15 +420,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);
More information about the pypy-commit
mailing list