Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r63043:2694840763c7
Date: 2013-04-04 14:37 -0700
http://bitbucket.org/pypy/pypy/changeset/2694840763c7/
Log: third waypoint; loadable capi now works, but not yet set as default
diff --git a/pypy/module/cppyy/capi/__init__.py
b/pypy/module/cppyy/capi/__init__.py
--- a/pypy/module/cppyy/capi/__init__.py
+++ b/pypy/module/cppyy/capi/__init__.py
@@ -9,8 +9,8 @@
# the selection of the desired backend (default is Reflex).
# choose C-API access method:
-from pypy.module.cppyy.capi.loadable_capi import *
-#from pypy.module.cppyy.capi.builtin_capi import *
+#from pypy.module.cppyy.capi.loadable_capi import *
+from pypy.module.cppyy.capi.builtin_capi import *
from pypy.module.cppyy.capi.capi_types import C_OBJECT,\
C_NULL_TYPE, C_NULL_OBJECT
diff --git a/pypy/module/cppyy/capi/builtin_capi.py
b/pypy/module/cppyy/capi/builtin_capi.py
--- a/pypy/module/cppyy/capi/builtin_capi.py
+++ b/pypy/module/cppyy/capi/builtin_capi.py
@@ -358,14 +358,14 @@
[C_SCOPE, C_INDEX], rffi.INT,
threadsafe=ts_reflect,
compilation_info=backend.eci)
-def c_method_num_args(cppscope, index):
+def c_method_num_args(space, cppscope, index):
return _c_method_num_args(cppscope.handle, index)
_c_method_req_args = rffi.llexternal(
"cppyy_method_req_args",
[C_SCOPE, C_INDEX], rffi.INT,
threadsafe=ts_reflect,
compilation_info=backend.eci)
-def c_method_req_args(cppscope, index):
+def c_method_req_args(space, cppscope, index):
return _c_method_req_args(cppscope.handle, index)
_c_method_arg_type = rffi.llexternal(
"cppyy_method_arg_type",
@@ -394,7 +394,7 @@
[C_SCOPE, C_INDEX], rffi.INT,
threadsafe=ts_reflect,
compilation_info=backend.eci)
-def c_method_is_template(cppscope, index):
+def c_method_is_template(space, cppscope, index):
return _c_method_is_template(cppscope.handle, index)
_c_method_num_template_args = rffi.llexternal(
"cppyy_method_num_template_args",
@@ -418,14 +418,14 @@
[C_SCOPE, C_INDEX], C_METHOD,
threadsafe=ts_reflect,
compilation_info=backend.eci)
-def c_get_method(cppscope, index):
+def c_get_method(space, cppscope, index):
return _c_get_method(cppscope.handle, index)
_c_get_global_operator = rffi.llexternal(
"cppyy_get_global_operator",
[C_SCOPE, C_SCOPE, C_SCOPE, rffi.CCHARP], WLAVC_INDEX,
threadsafe=ts_reflect,
compilation_info=backend.eci)
-def c_get_global_operator(nss, lc, rc, op):
+def c_get_global_operator(space, nss, lc, rc, op):
if nss is not None:
return _c_get_global_operator(nss.handle, lc.handle, rc.handle, op)
return rffi.cast(WLAVC_INDEX, -1)
@@ -436,14 +436,14 @@
[C_TYPE, C_INDEX], rffi.INT,
threadsafe=ts_reflect,
compilation_info=backend.eci)
-def c_is_constructor(cppclass, index):
+def c_is_constructor(space, cppclass, index):
return _c_is_constructor(cppclass.handle, index)
_c_is_staticmethod = rffi.llexternal(
"cppyy_is_staticmethod",
[C_TYPE, C_INDEX], rffi.INT,
threadsafe=ts_reflect,
compilation_info=backend.eci)
-def c_is_staticmethod(cppclass, index):
+def c_is_staticmethod(space, cppclass, index):
return _c_is_staticmethod(cppclass.handle, index)
# data member reflection information -----------------------------------------
@@ -452,7 +452,7 @@
[C_SCOPE], rffi.INT,
threadsafe=ts_reflect,
compilation_info=backend.eci)
-def c_num_datamembers(cppscope):
+def c_num_datamembers(space, cppscope):
return _c_num_datamembers(cppscope.handle)
_c_datamember_name = rffi.llexternal(
"cppyy_datamember_name",
@@ -473,7 +473,7 @@
[C_SCOPE, rffi.INT], rffi.SIZE_T,
threadsafe=ts_reflect,
compilation_info=backend.eci)
-def c_datamember_offset(cppscope, datamember_index):
+def c_datamember_offset(space, cppscope, datamember_index):
return _c_datamember_offset(cppscope.handle, datamember_index)
_c_datamember_index = rffi.llexternal(
@@ -481,7 +481,7 @@
[C_SCOPE, rffi.CCHARP], rffi.INT,
threadsafe=ts_reflect,
compilation_info=backend.eci)
-def c_datamember_index(cppscope, name):
+def c_datamember_index(space, cppscope, name):
return _c_datamember_index(cppscope.handle, name)
# data member properties -----------------------------------------------------
@@ -490,27 +490,31 @@
[C_SCOPE, rffi.INT], rffi.INT,
threadsafe=ts_reflect,
compilation_info=backend.eci)
-def c_is_publicdata(cppscope, datamember_index):
+def c_is_publicdata(space, cppscope, datamember_index):
return _c_is_publicdata(cppscope.handle, datamember_index)
_c_is_staticdata = rffi.llexternal(
"cppyy_is_staticdata",
[C_SCOPE, rffi.INT], rffi.INT,
threadsafe=ts_reflect,
compilation_info=backend.eci)
-def c_is_staticdata(cppscope, datamember_index):
+def c_is_staticdata(space, cppscope, datamember_index):
return _c_is_staticdata(cppscope.handle, datamember_index)
# misc helpers ---------------------------------------------------------------
-c_strtoll = rffi.llexternal(
+_c_strtoll = rffi.llexternal(
"cppyy_strtoll",
[rffi.CCHARP], rffi.LONGLONG,
threadsafe=ts_helper,
compilation_info=backend.eci)
-c_strtoull = rffi.llexternal(
+def c_strtoll(space, svalue):
+ return _c_strtoll(svalue)
+_c_strtoull = rffi.llexternal(
"cppyy_strtoull",
[rffi.CCHARP], rffi.ULONGLONG,
threadsafe=ts_helper,
compilation_info=backend.eci)
+def c_strtoull(space, svalue):
+ return _c_strtoull(svalue)
c_free = rffi.llexternal(
"cppyy_free",
[rffi.VOIDP], lltype.Void,
@@ -523,23 +527,36 @@
c_free(voidp)
return string
-c_charp2stdstring = rffi.llexternal(
+_c_charp2stdstring = rffi.llexternal(
"cppyy_charp2stdstring",
[rffi.CCHARP], C_OBJECT,
threadsafe=ts_helper,
compilation_info=backend.eci)
-c_stdstring2stdstring = rffi.llexternal(
+def c_charp2stdstring(space, svalue):
+ charp = rffi.str2charp(svalue)
+ result = _c_charp2stdstring(charp)
+ rffi.free_charp(charp)
+ return result
+_c_stdstring2stdstring = rffi.llexternal(
"cppyy_stdstring2stdstring",
[C_OBJECT], C_OBJECT,
threadsafe=ts_helper,
compilation_info=backend.eci)
-c_assign2stdstring = rffi.llexternal(
+def c_stdstring2stdstring(space, cppobject):
+ return _c_stdstring2stdstring(cppobject)
+_c_assign2stdstring = rffi.llexternal(
"cppyy_assign2stdstring",
[C_OBJECT, rffi.CCHARP], lltype.Void,
threadsafe=ts_helper,
compilation_info=backend.eci)
-c_free_stdstring = rffi.llexternal(
+def c_assign2stdstring(space, cppobject, svalue):
+ charp = rffi.str2charp(svalue)
+ _c_assign2stdstring(cppobject, charp)
+ rffi.free_charp(charp)
+_c_free_stdstring = rffi.llexternal(
"cppyy_free_stdstring",
[C_OBJECT], lltype.Void,
threadsafe=ts_helper,
compilation_info=backend.eci)
+def c_free_stdstring(space, cppobject):
+ _c_free_stdstring(cppobject)
diff --git a/pypy/module/cppyy/capi/loadable_capi.py
b/pypy/module/cppyy/capi/loadable_capi.py
--- a/pypy/module/cppyy/capi/loadable_capi.py
+++ b/pypy/module/cppyy/capi/loadable_capi.py
@@ -1,5 +1,5 @@
from rpython.rtyper.lltypesystem import rffi, lltype
-from rpython.rlib import jit, jit_libffi, rdynload, objectmodel
+from rpython.rlib import jit, jit_libffi, libffi, rdynload, objectmodel
from rpython.tool import leakfinder
from pypy.interpreter.error import OperationError
@@ -9,13 +9,15 @@
from pypy.module.cppyy.capi.capi_types import C_SCOPE, C_TYPE, C_OBJECT,\
C_METHOD, C_INDEX, C_INDEX_ARRAY, WLAVC_INDEX, C_METHPTRGETTER_PTR
-import reflex_capi as backend
reflection_library = 'rflxlib.so'
def identify():
return 'loadable_capi'
+# this is not technically correct, but will do for now
+std_string_name = 'std::basic_string<char>'
+
class _Arg: # poor man's union
_immutable_ = True
def __init__(self, l = 0, s = '', vp = rffi.cast(rffi.VOIDP, 0) ):
@@ -61,10 +63,7 @@
else: # only other use is sring
n = len(obj._string)
assert raw_string == rffi.cast(rffi.CCHARP, 0)
- raw_string = lltype.malloc(rffi.CCHARP.TO, n+1,
flavor='raw')
- for j in range(n):
- raw_string[j] = obj._string[j]
- raw_string[n] = '\x00'
+ raw_string = rffi.str2charp(obj._string)
data = rffi.cast(rffi.CCHARPP, data)
data[0] = raw_string
@@ -75,19 +74,10 @@
resultdata = rffi.ptradd(buffer, cif_descr.exchange_result)
finally:
if raw_string != rffi.cast(rffi.CCHARP, 0):
- lltype.free(raw_string, flavor='raw')
+ rffi.free_charp(raw_string)
lltype.free(buffer, flavor='raw')
return rffi.cast(rffi.LONGP, resultdata)
-std_string_name = backend.std_string_name
-
-ts_reflect = backend.ts_reflect
-ts_call = backend.ts_call
-ts_memory = backend.ts_memory
-ts_helper = backend.ts_helper
-
-c_load_dictionary = backend.c_load_dictionary
-
class State(object):
def __init__(self, space):
self.library = None
@@ -112,6 +102,7 @@
c_int = nt.new_primitive_type(space, 'int')
c_long = nt.new_primitive_type(space, 'long')
c_llong = nt.new_primitive_type(space, 'long long')
+ c_ullong = nt.new_primitive_type(space, 'unsigned long long')
c_float = nt.new_primitive_type(space, 'float')
c_double = nt.new_primitive_type(space, 'double')
@@ -123,23 +114,24 @@
self.capi_call_ifaces = {
# name to opaque C++ scope representation
- 'num_scopes' : ([c_scope], c_int),
- 'scope_name' : ([c_scope, c_int],
c_ccharp),
+ 'num_scopes' : ([c_scope], c_int),
+ 'scope_name' : ([c_scope, c_int],
c_ccharp),
- 'resolve_name' : ([c_ccharp],
c_ccharp),
- 'get_scope' : ([c_ccharp], c_scope),
- 'get_template' : ([c_ccharp], c_type),
- 'actual_class' : ([c_type, c_object], c_type),
+ 'resolve_name' : ([c_ccharp],
c_ccharp),
+ 'get_scope' : ([c_ccharp], c_scope),
+ 'get_template' : ([c_ccharp], c_type),
+ 'actual_class' : ([c_type, c_object], c_type),
# memory management
- 'allocate' : ([c_type],
c_object),
- 'deallocate' : ([c_type, c_object], c_void),
- 'destruct' : ([c_type, c_object], c_void),
+ 'allocate' : ([c_type],
c_object),
+ 'deallocate' : ([c_type, c_object], c_void),
+ 'destruct' : ([c_type, c_object], c_void),
# method/function dispatching
'call_v' : ([c_method, c_object, c_int, c_voidp], c_void),
'call_b' : ([c_method, c_object, c_int, c_voidp], c_uchar),
'call_c' : ([c_method, c_object, c_int, c_voidp], c_char),
+
'call_h' : ([c_method, c_object, c_int, c_voidp], c_short),
'call_i' : ([c_method, c_object, c_int, c_voidp], c_int),
'call_l' : ([c_method, c_object, c_int, c_voidp], c_long),
@@ -153,7 +145,7 @@
'constructor' : ([c_method, c_object, c_int, c_voidp],
c_object),
'call_o' : ([c_method, c_object, c_int, c_voidp, c_type],
c_object),
- 'get_methptr_getter' : ([c_scope, c_index],
c_voidp), # TODO: verify
+ 'get_methptr_getter' : ([c_scope, c_index],
c_voidp), # TODO: verify
# handling of function argument buffer
'allocate_function_args' : ([c_size_t], c_voidp),
@@ -162,40 +154,64 @@
'function_arg_typeoffset' : ([],
c_size_t),
# scope reflection information
- 'is_namespace' : ([c_scope], c_int),
- 'is_enum' : ([c_ccharp], c_int),
+ 'is_namespace' : ([c_scope], c_int),
+ 'is_enum' : ([c_ccharp], c_int),
# type/class reflection information
- 'final_name' : ([c_type],
c_ccharp),
- 'scoped_final_name' : ([c_type],
c_ccharp),
- 'has_complex_hierarchy' : ([c_type], c_int),
- 'num_bases' : ([c_type], c_int),
- 'base_name' : ([c_type, c_int],
c_ccharp),
- 'is_subtype' : ([c_type, c_type], c_int),
+ 'final_name' : ([c_type],
c_ccharp),
+ 'scoped_final_name' : ([c_type],
c_ccharp),
+ 'has_complex_hierarchy' : ([c_type], c_int),
+ 'num_bases' : ([c_type], c_int),
+ 'base_name' : ([c_type, c_int],
c_ccharp),
+ 'is_subtype' : ([c_type, c_type], c_int),
- 'base_offset' : ([c_type, c_type, c_object, c_int],
c_long),
+ 'base_offset' : ([c_type, c_type, c_object, c_int],
c_long),
# method/function reflection information
- 'num_methods' : ([c_scope], c_int),
- 'method_index_at' : ([c_scope, c_int], c_index),
+ 'num_methods' : ([c_scope], c_int),
+ 'method_index_at' : ([c_scope, c_int], c_index),
'method_indices_from_name' : ([c_scope, c_ccharp],
c_index_array),
- 'method_name' : ([c_scope, c_index],
c_ccharp),
- 'method_result_type' : ([c_scope, c_index],
c_ccharp),
- 'method_num_args' : ([c_scope, c_index], c_int),
+ 'method_name' : ([c_scope, c_index],
c_ccharp),
+ 'method_result_type' : ([c_scope, c_index],
c_ccharp),
+ 'method_num_args' : ([c_scope, c_index], c_int),
+ 'method_req_args' : ([c_scope, c_index], c_int),
+ 'method_arg_type' : ([c_scope, c_index, c_int],
c_ccharp),
+ 'method_arg_default' : ([c_scope, c_index, c_int],
c_ccharp),
+ 'method_signature' : ([c_scope, c_index],
c_ccharp),
- 'method_arg_type' : ([c_scope, c_index, c_int],
c_ccharp),
- 'method_arg_default' : ([c_scope, c_index, c_int],
c_ccharp),
- 'method_signature' : ([c_scope, c_index],
c_ccharp),
-
+ 'method_is_template' : ([c_scope, c_index], c_int),
+ 'method_num_template_args' : ([c_scope, c_index], c_int),
'method_template_arg_name' : ([c_scope, c_index, c_index],
c_ccharp),
+ 'get_method' : ([c_scope, c_index],
c_method),
+ 'get_global_operator' : ([c_scope, c_scope, c_scope,
c_ccharp], c_index),
+
+ # method properties
+ 'is_constructor' : ([c_type, c_index], c_int),
+ 'is_staticmethod' : ([c_type, c_index], c_int),
+
# data member reflection information
- 'datamember_name' : ([c_scope, c_int],
c_ccharp),
- 'datamember_type' : ([c_scope, c_int],
c_ccharp),
+ 'num_datamembers' : ([c_scope], c_int),
+ 'datamember_name' : ([c_scope, c_int],
c_ccharp),
+ 'datamember_type' : ([c_scope, c_int],
c_ccharp),
+ 'datamember_offset' : ([c_scope, c_int],
c_size_t),
+
+ 'datamember_index' : ([c_scope, c_ccharp], c_int),
+
+ # data member properties
+ 'is_publicdata' : ([c_scope, c_int], c_int),
+ 'is_staticdata' : ([c_scope, c_int], c_int),
# misc helpers
- 'free' : ([c_voidp], c_void),
+ 'strtoll' : ([c_ccharp], c_llong),
+ 'strtoull' : ([c_ccharp],
c_ullong),
+ 'free' : ([c_voidp], c_void),
+
+ 'charp2stdstring' : ([c_ccharp],
c_object),
+ 'stdstring2stdstring' : ([c_object],
c_object),
+ 'assign2stdstring' : ([c_object, c_ccharp], c_void),
+ 'free_stdstring' : ([c_object], c_void),
}
def load_reflection_library(space):
@@ -232,7 +248,11 @@
return c_call.ctype.rcall(c_call._cdata, args)
def _longptr_to_int(longptr):
- return int(rffi.cast(rffi.INTP, longptr)[0])
+ # TODO: not understanding why this should be rffi.LONGP instead of
rffi.INTP ??
+ return int(rffi.cast(rffi.LONGP, longptr)[0])
+
+def c_load_dictionary(name):
+ return libffi.CDLL(name)
# name to opaque C++ scope representation ------------------------------------
def c_num_scopes(space, cppscope):
@@ -274,7 +294,7 @@
return rffi.cast(rffi.SHORTP, call_capi(space, 'call_h', args))[0]
def c_call_i(space, cppmethod, cppobject, nargs, cargs):
args = [_Arg(l=cppmethod), _Arg(l=cppobject), _Arg(l=nargs),
_Arg(vp=cargs)]
- return rffi.cast(rffi.INTP, call_capi(space, 'call_i', args))[0]
+ return rffi.cast(rffi.INTP, call_capi(space, 'call_i', args))[0] # TODO:
should this be LONGP, too?
def c_call_l(space, cppmethod, cppobject, nargs, cargs):
args = [_Arg(l=cppmethod), _Arg(l=cppobject), _Arg(l=nargs),
_Arg(vp=cargs)]
return rffi.cast(rffi.LONGP, call_capi(space, 'call_l', args))[0]
@@ -384,21 +404,12 @@
def c_method_result_type(space, cppscope, index):
args = [_Arg(l=cppscope.handle), _Arg(l=index)]
return charp2str_free(space, call_capi(space, 'method_result_type', args))
-_c_method_num_args = rffi.llexternal(
- "cppyy_method_num_args",
- [C_SCOPE, C_INDEX], rffi.INT,
- threadsafe=ts_reflect,
- compilation_info=backend.eci)
-def c_method_num_args(cppscope, index):
+def c_method_num_args(space, cppscope, index):
args = [_Arg(l=cppscope.handle), _Arg(l=index)]
- return _c_method_num_args(cppscope.handle, index)
-_c_method_req_args = rffi.llexternal(
- "cppyy_method_req_args",
- [C_SCOPE, C_INDEX], rffi.INT,
- threadsafe=ts_reflect,
- compilation_info=backend.eci)
-def c_method_req_args(cppscope, index):
- return _c_method_req_args(cppscope.handle, index)
+ return _longptr_to_int(call_capi(space, 'method_num_args', args))
+def c_method_req_args(space, cppscope, index):
+ args = [_Arg(l=cppscope.handle), _Arg(l=index)]
+ return _longptr_to_int(call_capi(space, 'method_req_args', args))
def c_method_arg_type(space, cppscope, index, arg_index):
args = [_Arg(l=cppscope.handle), _Arg(l=index), _Arg(l=arg_index)]
return charp2str_free(space, call_capi(space, 'method_arg_type', args))
@@ -409,20 +420,14 @@
args = [_Arg(l=cppscope.handle), _Arg(l=index)]
return charp2str_free(space, call_capi(space, 'method_signature', args))
-_c_method_is_template = rffi.llexternal(
- "cppyy_method_is_template",
- [C_SCOPE, C_INDEX], rffi.INT,
- threadsafe=ts_reflect,
- compilation_info=backend.eci)
-def c_method_is_template(cppscope, index):
- return _c_method_is_template(cppscope.handle, index)
-_c_method_num_template_args = rffi.llexternal(
- "cppyy_method_num_template_args",
- [C_SCOPE, C_INDEX], rffi.INT,
- threadsafe=ts_reflect,
- compilation_info=backend.eci)
+def c_method_is_template(space, cppscope, index):
+ args = [_Arg(l=cppscope.handle), _Arg(l=index)]
+ return _longptr_to_int(call_capi(space, 'method_is_template', args))
+def _c_method_num_template_args(space, cppscope, index):
+ args = [_Arg(l=cppscope.handle), _Arg(l=index)]
+ return _longptr_to_int(call_capi(space, 'method_num_template_args', args))
def c_template_args(space, cppscope, index):
- nargs = _c_method_num_template_args(cppscope.handle, index)
+ nargs = _c_method_num_template_args(space, cppscope, index)
arg1 = _Arg(l=cppscope.handle)
arg2 = _Arg(l=index)
args = [c_resolve_name(space, charp2str_free(space,
@@ -430,106 +435,53 @@
) for iarg in range(nargs)]
return args
-_c_get_method = rffi.llexternal(
- "cppyy_get_method",
- [C_SCOPE, C_INDEX], C_METHOD,
- threadsafe=ts_reflect,
- compilation_info=backend.eci)
-def c_get_method(cppscope, index):
- return _c_get_method(cppscope.handle, index)
-_c_get_global_operator = rffi.llexternal(
- "cppyy_get_global_operator",
- [C_SCOPE, C_SCOPE, C_SCOPE, rffi.CCHARP], WLAVC_INDEX,
- threadsafe=ts_reflect,
- compilation_info=backend.eci)
-def c_get_global_operator(nss, lc, rc, op):
+def c_get_method(space, cppscope, index):
+ args = [_Arg(l=cppscope.handle), _Arg(l=index)]
+ return rffi.cast(C_METHOD, call_capi(space, 'get_method', args)[0])
+def c_get_global_operator(space, nss, lc, rc, op):
if nss is not None:
- return _c_get_global_operator(nss.handle, lc.handle, rc.handle, op)
+ args = [_Arg(l=nss.handle), _Arg(l=lc.handle), _Arg(l=rc.handle),
_Arg(s=op)]
+ return rffi.cast(WLAVC_INDEX, call_capi(space, 'get_global_operator',
args)[0])
return rffi.cast(WLAVC_INDEX, -1)
# method properties ----------------------------------------------------------
-_c_is_constructor = rffi.llexternal(
- "cppyy_is_constructor",
- [C_TYPE, C_INDEX], rffi.INT,
- threadsafe=ts_reflect,
- compilation_info=backend.eci)
-def c_is_constructor(cppclass, index):
- return _c_is_constructor(cppclass.handle, index)
-_c_is_staticmethod = rffi.llexternal(
- "cppyy_is_staticmethod",
- [C_TYPE, C_INDEX], rffi.INT,
- threadsafe=ts_reflect,
- compilation_info=backend.eci)
-def c_is_staticmethod(cppclass, index):
- return _c_is_staticmethod(cppclass.handle, index)
+def c_is_constructor(space, cppclass, index):
+ args = [_Arg(l=cppclass.handle), _Arg(l=index)]
+ return _longptr_to_int(call_capi(space, 'is_constructor', args))
+def c_is_staticmethod(space, cppclass, index):
+ args = [_Arg(l=cppclass.handle), _Arg(l=index)]
+ return _longptr_to_int(call_capi(space, 'is_staticmethod', args))
# data member reflection information -----------------------------------------
-_c_num_datamembers = rffi.llexternal(
- "cppyy_num_datamembers",
- [C_SCOPE], rffi.INT,
- threadsafe=ts_reflect,
- compilation_info=backend.eci)
-def c_num_datamembers(cppscope):
- return _c_num_datamembers(cppscope.handle)
-_c_datamember_name = rffi.llexternal(
- "cppyy_datamember_name",
- [C_SCOPE, rffi.INT], rffi.CCHARP,
- threadsafe=ts_reflect,
- compilation_info=backend.eci)
+def c_num_datamembers(space, cppscope):
+ return _longptr_to_int(call_capi(space, 'num_datamembers',
[_Arg(l=cppscope.handle)]))
def c_datamember_name(space, cppscope, datamember_index):
args = [_Arg(l=cppscope.handle), _Arg(l=datamember_index)]
return charp2str_free(space, call_capi(space, 'datamember_name', args))
-_c_datamember_type = rffi.llexternal(
- "cppyy_datamember_type",
- [C_SCOPE, rffi.INT], rffi.CCHARP,
- threadsafe=ts_reflect,
- compilation_info=backend.eci)
def c_datamember_type(space, cppscope, datamember_index):
args = [_Arg(l=cppscope.handle), _Arg(l=datamember_index)]
return charp2str_free(space, call_capi(space, 'datamember_type', args))
-_c_datamember_offset = rffi.llexternal(
- "cppyy_datamember_offset",
- [C_SCOPE, rffi.INT], rffi.SIZE_T,
- threadsafe=ts_reflect,
- compilation_info=backend.eci)
-def c_datamember_offset(cppscope, datamember_index):
- return _c_datamember_offset(cppscope.handle, datamember_index)
+def c_datamember_offset(space, cppscope, datamember_index):
+ args = [_Arg(l=cppscope.handle), _Arg(l=datamember_index)]
+ return rffi.cast(rffi.SIZE_T, rffi.cast(rffi.ULONGP, call_capi(space,
'datamember_offset', args))[0])
-_c_datamember_index = rffi.llexternal(
- "cppyy_datamember_index",
- [C_SCOPE, rffi.CCHARP], rffi.INT,
- threadsafe=ts_reflect,
- compilation_info=backend.eci)
-def c_datamember_index(cppscope, name):
- return _c_datamember_index(cppscope.handle, name)
+def c_datamember_index(space, cppscope, name):
+ args = [_Arg(l=cppscope.handle), _Arg(s=name)]
+ return _longptr_to_int(call_capi(space, 'datamember_index', args))
# data member properties -----------------------------------------------------
-_c_is_publicdata = rffi.llexternal(
- "cppyy_is_publicdata",
- [C_SCOPE, rffi.INT], rffi.INT,
- threadsafe=ts_reflect,
- compilation_info=backend.eci)
-def c_is_publicdata(cppscope, datamember_index):
- return _c_is_publicdata(cppscope.handle, datamember_index)
-_c_is_staticdata = rffi.llexternal(
- "cppyy_is_staticdata",
- [C_SCOPE, rffi.INT], rffi.INT,
- threadsafe=ts_reflect,
- compilation_info=backend.eci)
-def c_is_staticdata(cppscope, datamember_index):
- return _c_is_staticdata(cppscope.handle, datamember_index)
+def c_is_publicdata(space, cppscope, datamember_index):
+ args = [_Arg(l=cppscope.handle), _Arg(l=datamember_index)]
+ return _longptr_to_int(call_capi(space, 'is_publicdata', args))
+def c_is_staticdata(space, cppscope, datamember_index):
+ args = [_Arg(l=cppscope.handle), _Arg(l=datamember_index)]
+ return _longptr_to_int(call_capi(space, 'is_staticdata', args))
# misc helpers ---------------------------------------------------------------
-c_strtoll = rffi.llexternal(
- "cppyy_strtoll",
- [rffi.CCHARP], rffi.LONGLONG,
- threadsafe=ts_helper,
- compilation_info=backend.eci)
-c_strtoull = rffi.llexternal(
- "cppyy_strtoull",
- [rffi.CCHARP], rffi.ULONGLONG,
- threadsafe=ts_helper,
- compilation_info=backend.eci)
+def c_strtoll(space, svalue):
+ return rffi.cast(rffi.LONGLONGP, call_capi(space, 'strtoll',
[_Arg(s=svalue)]))[0]
+def c_strtoull(space, svalue):
+ return rffi.cast(rffi.ULONGLONGP, call_capi(space, 'strtoull',
[_Arg(s=svalue)]))[0]
def c_free(space, voidp):
call_capi(space, 'free', [_Arg(vp=voidp)])
@@ -539,27 +491,15 @@
c_free(space, rffi.cast(rffi.VOIDP, charp))
return pystr
-c_charp2stdstring = rffi.llexternal(
- "cppyy_charp2stdstring",
- [rffi.CCHARP], C_OBJECT,
- threadsafe=ts_helper,
- compilation_info=backend.eci)
-c_stdstring2stdstring = rffi.llexternal(
- "cppyy_stdstring2stdstring",
- [C_OBJECT], C_OBJECT,
- threadsafe=ts_helper,
- compilation_info=backend.eci)
-c_assign2stdstring = rffi.llexternal(
- "cppyy_assign2stdstring",
- [C_OBJECT, rffi.CCHARP], lltype.Void,
- threadsafe=ts_helper,
- compilation_info=backend.eci)
-c_free_stdstring = rffi.llexternal(
- "cppyy_free_stdstring",
- [C_OBJECT], lltype.Void,
- threadsafe=ts_helper,
- compilation_info=backend.eci)
-
+def c_charp2stdstring(space, svalue):
+ return rffi.cast(C_OBJECT, call_capi(space, 'charp2stdstring',
[_Arg(s=svalue)])[0])
+def c_stdstring2stdstring(space, cppobject):
+ return rffi.cast(C_OBJECT, call_capi(space, 'stdstring2stdstring',
[_Arg(l=cppobject)])[0])
+def c_assign2stdstring(space, cppobject, svalue):
+ args = [_Arg(l=cppobject), _Arg(s=svalue)]
+ return rffi.cast(C_OBJECT, call_capi(space, 'assign2stdstring', args)[0])
+def c_free_stdstring(space, cppobject):
+ call_capi(space, 'free_stdstring', [_Arg(l=cppobject)])[0]
# loadable-capi-specific pythonizations (none, as the capi isn't known until
runtime)
def register_pythonizations(space):
diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -511,27 +511,23 @@
def _unwrap_object(self, space, w_obj):
try:
- charp = rffi.str2charp(space.str_w(w_obj))
- arg = capi.c_charp2stdstring(charp)
- rffi.free_charp(charp)
- return arg
- except OperationError:
+ return capi.c_charp2stdstring(space, space.str_w(w_obj))
+ except Exception, e:
arg = InstanceConverter._unwrap_object(self, space, w_obj)
- return capi.c_stdstring2stdstring(arg)
+ result = capi.c_stdstring2stdstring(space, arg)
+ return result
def to_memory(self, space, w_obj, w_value, offset):
try:
address = rffi.cast(capi.C_OBJECT, self._get_raw_address(space,
w_obj, offset))
- charp = rffi.str2charp(space.str_w(w_value))
- capi.c_assign2stdstring(address, charp)
- rffi.free_charp(charp)
+ capi.c_assign2stdstring(space, address, space.str_w(w_value))
return
except Exception:
pass
return InstanceConverter.to_memory(self, space, w_obj, w_value, offset)
def free_argument(self, space, arg, call_local):
- capi.c_free_stdstring(rffi.cast(capi.C_OBJECT, rffi.cast(rffi.VOIDPP,
arg)[0]))
+ capi.c_free_stdstring(space, rffi.cast(capi.C_OBJECT,
rffi.cast(rffi.VOIDPP, arg)[0]))
class StdStringRefConverter(InstancePtrConverter):
_immutable_fields_ = ['cppclass']
@@ -685,7 +681,7 @@
class BasicConverter(ffitypes.typeid(c_type), IntTypeConverterMixin,
TypeConverter):
_immutable_ = True
def __init__(self, space, default):
- self.default = rffi.cast(self.c_type, capi.c_strtoll(default))
+ self.default = rffi.cast(self.c_type, capi.c_strtoll(space,
default))
class ConstRefConverter(ConstRefNumericTypeConverterMixin,
BasicConverter):
_immutable_ = True
libffitype = jit_libffi.types.pointer
@@ -702,7 +698,7 @@
class BasicConverter(ffitypes.typeid(c_type), IntTypeConverterMixin,
TypeConverter):
_immutable_ = True
def __init__(self, space, default):
- self.default = rffi.cast(self.c_type, capi.c_strtoll(default))
+ self.default = rffi.cast(self.c_type, capi.c_strtoll(space,
default))
class ConstRefConverter(ConstRefNumericTypeConverterMixin,
BasicConverter):
_immutable_ = True
libffitype = jit_libffi.types.pointer
@@ -728,7 +724,7 @@
class BasicConverter(ffitypes.typeid(c_type), IntTypeConverterMixin,
TypeConverter):
_immutable_ = True
def __init__(self, space, default):
- self.default = rffi.cast(self.c_type, capi.c_strtoull(default))
+ self.default = rffi.cast(self.c_type, capi.c_strtoull(space,
default))
class ConstRefConverter(ConstRefNumericTypeConverterMixin,
BasicConverter):
_immutable_ = True
libffitype = jit_libffi.types.pointer
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
@@ -139,7 +139,7 @@
self.space = space
self.scope = containing_scope
self.index = method_index
- self.cppmethod = capi.c_get_method(self.scope, 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)
@@ -663,7 +663,7 @@
idx = capi.c_method_index_at(self.space, self, i)
pyname = helper.map_operator_name(self.space,
capi.c_method_name(self.space, self, idx),
- capi.c_method_num_args(self, idx),
+ capi.c_method_num_args(self.space, self, idx),
capi.c_method_result_type(self.space, self, idx))
cppmethod = self._make_cppfunction(pyname, idx)
methods_temp.setdefault(pyname, []).append(cppmethod)
@@ -744,8 +744,8 @@
kind = "namespace"
def _make_cppfunction(self, pyname, index):
- num_args = capi.c_method_num_args(self, index)
- args_required = capi.c_method_req_args(self, index)
+ num_args = capi.c_method_num_args(self.space, self, index)
+ args_required = capi.c_method_req_args(self.space, self, index)
arg_defs = []
for i in range(num_args):
arg_type = capi.c_method_arg_type(self.space, self, index, i)
@@ -755,15 +755,15 @@
def _make_datamember(self, dm_name, dm_idx):
type_name = capi.c_datamember_type(self.space, self, dm_idx)
- offset = capi.c_datamember_offset(self, dm_idx)
+ offset = capi.c_datamember_offset(self.space, self, dm_idx)
datamember = W_CPPStaticData(self.space, self, type_name, offset)
self.datamembers[dm_name] = datamember
return datamember
def _find_datamembers(self):
- num_datamembers = capi.c_num_datamembers(self)
+ num_datamembers = capi.c_num_datamembers(self.space, self)
for i in range(num_datamembers):
- if not capi.c_is_publicdata(self, i):
+ if not capi.c_is_publicdata(self.space, self, i):
continue
datamember_name = capi.c_datamember_name(self.space, self, i)
if not datamember_name in self.datamembers:
@@ -781,7 +781,7 @@
return overload
def find_datamember(self, dm_name):
- dm_idx = capi.c_datamember_index(self, dm_name)
+ dm_idx = capi.c_datamember_index(self.space, self, dm_name)
if dm_idx < 0:
raise self.missing_attribute_error(dm_name)
datamember = self._make_datamember(dm_name, dm_idx)
@@ -805,7 +805,7 @@
if mname: allmeth.setdefault(mname, 0)
for m in allmeth.keys():
alldir.append(self.space.wrap(m))
- for i in range(capi.c_num_datamembers(self)):
+ for i in range(capi.c_num_datamembers(self.space, self)):
dname = capi.c_datamember_name(self.space, self, i)
if dname: alldir.append(self.space.wrap(dname))
return self.space.newlist(alldir)
@@ -834,21 +834,21 @@
self.default_constructor = None
def _make_cppfunction(self, pyname, index):
- num_args = capi.c_method_num_args(self, index)
- args_required = capi.c_method_req_args(self, index)
+ num_args = capi.c_method_num_args(self.space, self, index)
+ args_required = capi.c_method_req_args(self.space, self, index)
arg_defs = []
for i in range(num_args):
arg_type = capi.c_method_arg_type(self.space, self, index, i)
arg_dflt = capi.c_method_arg_default(self.space, self, index, i)
arg_defs.append((arg_type, arg_dflt))
- if capi.c_is_constructor(self, index):
+ 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, index):
+ 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)
- elif capi.c_is_staticmethod(self, index):
+ elif capi.c_is_staticmethod(self.space, self, index):
cppfunction = CPPFunction(self.space, self, index, arg_defs,
args_required)
elif pyname == "__setitem__":
cppfunction = CPPSetItem(self.space, self, index, arg_defs,
args_required)
@@ -857,14 +857,14 @@
return cppfunction
def _find_datamembers(self):
- num_datamembers = capi.c_num_datamembers(self)
+ num_datamembers = capi.c_num_datamembers(self.space, self)
for i in range(num_datamembers):
- if not capi.c_is_publicdata(self, i):
+ if not capi.c_is_publicdata(self.space, self, i):
continue
datamember_name = capi.c_datamember_name(self.space, self, i)
type_name = capi.c_datamember_type(self.space, self, i)
- offset = capi.c_datamember_offset(self, i)
- is_static = bool(capi.c_is_staticdata(self, i))
+ offset = capi.c_datamember_offset(self.space, self, i)
+ is_static = bool(capi.c_is_staticdata(self.space, self, i))
if is_static:
datamember = W_CPPStaticData(self.space, self, type_name,
offset)
else:
@@ -1017,7 +1017,7 @@
other = self.space.interp_w(W_CPPInstance, w_other,
can_be_None=False)
for name in ["", "__gnu_cxx"]:
nss = scope_byname(self.space, name)
- meth_idx = capi.c_get_global_operator(nss, self.cppclass,
other.cppclass, "==")
+ meth_idx = capi.c_get_global_operator(self.space, nss,
self.cppclass, other.cppclass, "==")
if meth_idx != -1:
f = nss._make_cppfunction("operator==", meth_idx)
ol = W_CPPOverload(self.space, nss, [f])
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit