Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r45606:78c5c11329a0
Date: 2011-07-14 15:08 -0700
http://bitbucket.org/pypy/pypy/changeset/78c5c11329a0/
Log: further progress on CINT backend and some Reflex backend sync
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
@@ -89,39 +89,39 @@
c_call_v = rffi.llexternal(
"cppyy_call_v",
- [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], lltype.Void,
+ [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDP], lltype.Void,
compilation_info=eci)
c_call_o = rffi.llexternal(
"cppyy_call_o",
- [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP, C_TYPEHANDLE],
rffi.LONG,
+ [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDP, C_TYPEHANDLE],
rffi.LONG,
compilation_info=eci)
c_call_b = rffi.llexternal(
"cppyy_call_b",
- [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.INT,
+ [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.INT,
compilation_info=eci)
c_call_c = rffi.llexternal(
"cppyy_call_c",
- [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.CHAR,
+ [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.CHAR,
compilation_info=eci)
c_call_h = rffi.llexternal(
"cppyy_call_h",
- [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.SHORT,
+ [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.SHORT,
compilation_info=eci)
c_call_i = rffi.llexternal(
"cppyy_call_i",
- [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.INT,
+ [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.INT,
compilation_info=eci)
c_call_l = rffi.llexternal(
"cppyy_call_l",
- [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.LONG,
+ [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.LONG,
compilation_info=eci)
c_call_f = rffi.llexternal(
"cppyy_call_f",
- [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.DOUBLE,
+ [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.DOUBLE,
compilation_info=eci)
c_call_d = rffi.llexternal(
"cppyy_call_d",
- [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDPP], rffi.DOUBLE,
+ [C_TYPEHANDLE, rffi.INT, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.DOUBLE,
compilation_info=eci)
@@ -131,6 +131,29 @@
compilation_info=eci)
+c_allocate_function_args = rffi.llexternal(
+ "cppyy_allocate_function_args",
+ [rffi.SIZE_T], rffi.VOIDP,
+ compilation_info=eci)
+
+c_deallocate_function_args = rffi.llexternal(
+ "cppyy_deallocate_function_args",
+ [rffi.VOIDP], lltype.Void,
+ compilation_info=eci)
+
+c_function_arg_sizeof = rffi.llexternal(
+ "cppyy_function_arg_sizeof",
+ [], rffi.SIZE_T,
+ compilation_info=eci,
+ elidable_function=True)
+
+c_function_arg_typeoffset = rffi.llexternal(
+ "cppyy_function_arg_typeoffset",
+ [], rffi.SIZE_T,
+ compilation_info=eci,
+ elidable_function=True)
+
+
c_num_methods = rffi.llexternal(
"cppyy_num_methods",
[C_TYPEHANDLE], rffi.INT,
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
@@ -369,6 +369,8 @@
def convert_argument(self, space, w_obj, address):
x = rffi.cast(rffi.DOUBLEP, address)
x[0] = self._unwrap_object(space, w_obj)
+ typecode = _direct_ptradd(address, capi.c_function_arg_typeoffset())
+ typecode[0] = 'd'
def convert_argument_libffi(self, space, w_obj, argchain):
argchain.arg(self._unwrap_object(space, w_obj))
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
@@ -231,6 +231,8 @@
newthis = capi.c_allocate(self.cpptype.handle)
assert lltype.typeOf(newthis) == rffi.VOIDP
try:
+ # TODO: this does not work for CINT, as it calls a temp object
+ # by value returning method, not placement on newthis ...
CPPMethod.call(self, newthis, None, args_w)
except Exception, e:
capi.c_deallocate(self.cpptype.handle, newthis)
diff --git a/pypy/module/cppyy/src/cintcwrapper.cxx
b/pypy/module/cppyy/src/cintcwrapper.cxx
--- a/pypy/module/cppyy/src/cintcwrapper.cxx
+++ b/pypy/module/cppyy/src/cintcwrapper.cxx
@@ -13,6 +13,7 @@
#include "TMethod.h"
#include "TMethodArg.h"
+#include <assert.h>
#include <string.h>
#include <iostream>
#include <map>
@@ -81,73 +82,85 @@
/* method/function dispatching -------------------------------------------- */
long cppyy_call_o(cppyy_typehandle_t handle, int method_index,
- cppyy_object_t self, int numargs, void* args[],
+ cppyy_object_t self, int numargs, void* args,
cppyy_typehandle_t rettype) {
- void* result = cppyy_allocate(rettype);
- /* TODO: perform call ... */
- return (long)result;
-}
-
-static inline G__value cppyy_call_T(cppyy_typehandle_t handle,
- int method_index, cppyy_object_t self, int numargs, void* args[]) {
TClassRef cr = type_from_handle(handle);
TMethod* m = (TMethod*)cr->GetListOfMethods()->At(method_index);
G__InterfaceMethod meth = (G__InterfaceMethod)m->InterfaceMethod();
- G__param libp;
- for (int i = 0; i < numargs; ++i ) {
- G__letint(&libp.para[i], 'u', *(long*)args[i]); // TODO: use actual
type code
- }
+ G__param* libp = (G__param*)((char*)args - offsetof(G__param, para));
+ assert(libp->paran == numargs);
+
+ long obj = (long)cppyy_allocate(rettype);
+ G__setgvp(obj);
G__value result;
- meth(&result, 0, &libp, 0);
+ G__setnull(&result);
+ meth(&result, 0, libp, 0);
+
+ // G__pop_tempobject_nodel(); # TODO: not sure ...
+ return obj;
+}
+
+static inline G__value cppyy_call_T(cppyy_typehandle_t handle,
+ int method_index, cppyy_object_t self, int numargs, void* args) {
+ TClassRef cr = type_from_handle(handle);
+ TMethod* m = (TMethod*)cr->GetListOfMethods()->At(method_index);
+
+ G__InterfaceMethod meth = (G__InterfaceMethod)m->InterfaceMethod();
+ G__param* libp = (G__param*)((char*)args - offsetof(G__param, para));
+ assert(libp->paran == numargs);
+
+ G__value result;
+ G__setnull(&result);
+ meth(&result, 0, libp, 0);
return result;
}
void cppyy_call_v(cppyy_typehandle_t handle, int method_index,
- cppyy_object_t self, int numargs, void* args[]) {
+ cppyy_object_t self, int numargs, void* args) {
cppyy_call_T(handle, method_index, self, numargs, args);
}
int cppyy_call_b(cppyy_typehandle_t handle, int method_index,
- cppyy_object_t self, int numargs, void* args[]) {
+ cppyy_object_t self, int numargs, void* args) {
G__value result = cppyy_call_T(handle, method_index, self, numargs, args);
return (bool)G__int(result);
}
char cppyy_call_c(cppyy_typehandle_t handle, int method_index,
- cppyy_object_t self, int numargs, void* args[]) {
+ cppyy_object_t self, int numargs, void* args) {
G__value result = cppyy_call_T(handle, method_index, self, numargs, args);
return (char)G__int(result);
}
short cppyy_call_h(cppyy_typehandle_t handle, int method_index,
- cppyy_object_t self, int numargs, void* args[]) {
+ cppyy_object_t self, int numargs, void* args) {
G__value result = cppyy_call_T(handle, method_index, self, numargs, args);
return (short)G__int(result);
}
int cppyy_call_i(cppyy_typehandle_t handle, int method_index,
- cppyy_object_t self, int numargs, void* args[]) {
+ cppyy_object_t self, int numargs, void* args) {
G__value result = cppyy_call_T(handle, method_index, self, numargs, args);
return (int)G__int(result);
}
long cppyy_call_l(cppyy_typehandle_t handle, int method_index,
- cppyy_object_t self, int numargs, void* args[]) {
+ cppyy_object_t self, int numargs, void* args) {
G__value result = cppyy_call_T(handle, method_index, self, numargs, args);
return G__int(result);
}
double cppyy_call_f(cppyy_typehandle_t handle, int method_index,
- cppyy_object_t self, int numargs, void* args[]) {
+ cppyy_object_t self, int numargs, void* args) {
G__value result = cppyy_call_T(handle, method_index, self, numargs, args);
return G__double(result);
}
double cppyy_call_d(cppyy_typehandle_t handle, int method_index,
- cppyy_object_t self, int numargs, void* args[]) {
+ cppyy_object_t self, int numargs, void* args) {
G__value result = cppyy_call_T(handle, method_index, self, numargs, args);
return G__double(result);
}
@@ -158,6 +171,30 @@
}
+/* handling of function argument buffer ----------------------------------- */
+void* cppyy_allocate_function_args(size_t nargs) {
+ assert(sizeof(CPPYY_G__value) == sizeof(G__value));
+ G__param* libp = (G__param*)malloc(
+ offsetof(G__param, para) + nargs*sizeof(CPPYY_G__value));
+ libp->paran = (int)nargs;
+ for (int i = 0; i < nargs; ++i)
+ libp->para[i].type = 'l';
+ return (void*)libp->para;
+}
+
+void cppyy_deallocate_function_args(void* args) {
+ free((char*)args - offsetof(G__param, para));
+}
+
+size_t cppyy_function_arg_sizeof() {
+ return sizeof(CPPYY_G__value);
+}
+
+size_t cppyy_function_arg_typeoffset() {
+ return offsetof(CPPYY_G__value, type);
+}
+
+
/* scope reflection information ------------------------------------------- */
int cppyy_is_namespace(cppyy_typehandle_t handle) {
TClassRef cr = type_from_handle(handle);
@@ -195,7 +232,7 @@
return 1;
TClassRef crd = type_from_handle(dh);
TClassRef crb = type_from_handle(bh);
- return (int)crd->GetBaseClass(crb);
+ return crd->GetBaseClass(crb) != 0;
}
size_t cppyy_base_offset(cppyy_typehandle_t dh, cppyy_typehandle_t bh) {
diff --git a/pypy/module/cppyy/src/reflexcwrapper.cxx
b/pypy/module/cppyy/src/reflexcwrapper.cxx
--- a/pypy/module/cppyy/src/reflexcwrapper.cxx
+++ b/pypy/module/cppyy/src/reflexcwrapper.cxx
@@ -34,7 +34,7 @@
std::vector<void*> arguments;
arguments.reserve(numargs);
for (int i=0; i < numargs; ++i) {
- if (((CPPYY_G__value*)args)[i].type == 'l')
+ if (((CPPYY_G__value*)args)[i].type != 'a')
arguments.push_back(&((CPPYY_G__value*)args)[i]);
else
arguments.push_back((void*)(*(long*)&((CPPYY_G__value*)args)[i]));
@@ -200,7 +200,7 @@
}
-/* handling of function argument buffer */
+/* handling of function argument buffer ----------------------------------- */
void* cppyy_allocate_function_args(size_t nargs) {
CPPYY_G__param* libp = (CPPYY_G__param*)malloc(
sizeof(int/*CPPYY_G__param.paran*/) + nargs*sizeof(CPPYY_G__value));
diff --git a/pypy/module/cppyy/test/Makefile b/pypy/module/cppyy/test/Makefile
--- a/pypy/module/cppyy/test/Makefile
+++ b/pypy/module/cppyy/test/Makefile
@@ -28,7 +28,7 @@
$(genreflex) example01.h $(genreflexflags) --selection=example01.xml
g++ -o $@ example01_rflx.cpp example01.cxx -shared -lReflex $(cppflags)
$(cppflags2)
-# rootcint -f example01_cint.cxx -c example01.h
+# rootcint -f example01_cint.cxx -c example01.h example01_LinkDef.h
# g++ -I$ROOTSYS/include example01_cint.cxx example01.cxx -shared -o
example01Dict.so -L$ROOTSYS/lib -lCore -lCint
datatypesDict.so: datatypes.cxx datatypes.h
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit