Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r70884:6400eef5ba99
Date: 2014-04-22 23:30 -0700
http://bitbucket.org/pypy/pypy/changeset/6400eef5ba99/
Log: open up a few more 'dummy' tests
diff --git a/pypy/module/cppyy/capi/capi_types.py
b/pypy/module/cppyy/capi/capi_types.py
--- a/pypy/module/cppyy/capi/capi_types.py
+++ b/pypy/module/cppyy/capi/capi_types.py
@@ -1,7 +1,7 @@
from rpython.rtyper.lltypesystem import rffi, lltype
# shared ll definitions
-_C_OPAQUE_PTR = rffi.VOIDP
+_C_OPAQUE_PTR = rffi.LONG
_C_OPAQUE_NULL = lltype.nullptr(rffi.LONGP.TO)# ALT: _C_OPAQUE_PTR.TO
C_SCOPE = _C_OPAQUE_PTR
diff --git a/pypy/module/cppyy/include/capi.h b/pypy/module/cppyy/include/capi.h
--- a/pypy/module/cppyy/include/capi.h
+++ b/pypy/module/cppyy/include/capi.h
@@ -7,11 +7,11 @@
extern "C" {
#endif // ifdef __cplusplus
- typedef void* cppyy_scope_t;
+ typedef long cppyy_scope_t;
typedef cppyy_scope_t cppyy_type_t;
- typedef void* cppyy_object_t;
- typedef void* cppyy_method_t;
- typedef long cppyy_index_t;
+ typedef long cppyy_object_t;
+ typedef long cppyy_method_t;
+ typedef long cppyy_index_t;
typedef void* (*cppyy_methptrgetter_t)(cppyy_object_t);
/* name to opaque C++ scope representation
-------------------------------- */
diff --git a/pypy/module/cppyy/include/cppyy.h
b/pypy/module/cppyy/include/cppyy.h
--- a/pypy/module/cppyy/include/cppyy.h
+++ b/pypy/module/cppyy/include/cppyy.h
@@ -17,7 +17,7 @@
#ifdef __cplusplus
struct CPPYY_G__p2p {
#else
-#typedef struct
+typedef struct {
#endif
long i;
int reftype;
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
@@ -718,7 +718,6 @@
def get_method_names(self):
return self.space.newlist([self.space.wrap(name) for name in
self.methods])
- @jit.elidable_promote('0')
def get_overload(self, name):
try:
return self.methods[name]
@@ -731,7 +730,6 @@
def get_datamember_names(self):
return self.space.newlist([self.space.wrap(name) for name in
self.datamembers])
- @jit.elidable_promote('0')
def get_datamember(self, name):
try:
return self.datamembers[name]
@@ -741,7 +739,7 @@
self.datamembers[name] = new_dm
return new_dm
- @jit.elidable_promote('0')
+ @jit.elidable_promote()
def dispatch(self, name, signature):
overload = self.get_overload(name)
sig = '(%s)' % signature
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
@@ -5,6 +5,7 @@
#include <string>
#include <vector>
+#include <assert.h>
#include <stdlib.h>
#include <string.h>
@@ -15,22 +16,26 @@
typedef std::map<std::string, cppyy_scope_t> Handles_t;
static Handles_t s_handles;
-class Cppyy_PseudoInfo {
-public:
- Cppyy_PseudoInfo(int num_methods=0, const char* methods[]=0) :
- m_num_methods(num_methods) {
- m_methods.reserve(num_methods);
- for (int i=0; i < num_methods; ++i) {
- m_methods.push_back(methods[i]);
- }
- }
+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) {}
-public:
- int m_num_methods;
- std::vector<std::string> m_methods;
+ std::string m_name;
+ std::vector<std::string> m_argtypes;
+ std::string m_returntype;
};
-typedef std::map<cppyy_scope_t, Cppyy_PseudoInfo> Scopes_t;
+struct Cppyy_PseudoClassInfo {
+ Cppyy_PseudoClassInfo() {}
+ Cppyy_PseudoClassInfo(const std::vector<Cppyy_PseudoMethodInfo>& methods) :
+ m_methods(methods ) {}
+
+ std::vector<Cppyy_PseudoMethodInfo> m_methods;
+};
+
+typedef std::map<cppyy_scope_t, Cppyy_PseudoClassInfo> Scopes_t;
static Scopes_t s_scopes;
struct Cppyy_InitPseudoReflectionInfo {
@@ -38,8 +43,31 @@
// class example01 --
static long s_scope_id = 0;
s_handles["example01"] = (cppyy_scope_t)++s_scope_id;
- const char* methods[] = {"staticAddToDouble"};
- Cppyy_PseudoInfo info(1, methods);
+
+ std::vector<Cppyy_PseudoMethodInfo> methods;
+
+ // static double staticAddToDouble(double a);
+ std::vector<std::string> argtypes;
+ argtypes.push_back("double");
+ methods.push_back(Cppyy_PseudoMethodInfo("staticAddToDouble",
argtypes, "double"));
+
+ // 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"));
+ argtypes.push_back("int");
+ methods.push_back(Cppyy_PseudoMethodInfo("staticAddOneToInt",
argtypes, "int"));
+
+ // static int staticAtoi(const char* str);
+ argtypes.clear();
+ argtypes.push_back("const char*");
+ methods.push_back(Cppyy_PseudoMethodInfo("staticAtoi", argtypes,
"int"));
+
+ // static char* staticStrcpy(const char* strin);
+ methods.push_back(Cppyy_PseudoMethodInfo("staticStrcpy", argtypes,
"char*"));
+
+ Cppyy_PseudoClassInfo info(methods);
s_scopes[(cppyy_scope_t)s_scope_id] = info;
// -- class example01
}
@@ -71,10 +99,82 @@
/* method/function dispatching -------------------------------------------- */
+template<typename T>
+static inline T cppyy_call_T(cppyy_method_t method, cppyy_object_t self, int
nargs, void* args) {
+ T result = T();
+ switch ((long)method) {
+ case 0: // double staticAddToDouble(double)
+ assert(!self && nargs == 1);
+ result = ((CPPYY_G__value*)args)[0].obj.d + 0.01;
+ break;
+ case 1: // int staticAddOneToInt(int)
+ assert(!self && nargs == 1);
+ result = ((CPPYY_G__value*)args)[0].obj.in + 1;
+ break;
+ case 2: // int staticAddOneToInt(int, int)
+ assert(!self && nargs == 2);
+ result = ((CPPYY_G__value*)args)[0].obj.in +
((CPPYY_G__value*)args)[1].obj.in + 1;
+ break;
+ case 3: // int staticAtoi(const char* str)
+ assert(!self && nargs == 1);
+ result = ::atoi((const char*)(*(long*)&((CPPYY_G__value*)args)[0]));
+ break;
+ default:
+ break;
+ }
+ return result;
+}
+
+int cppyy_call_i(cppyy_method_t method, cppyy_object_t self, int nargs, void*
args) {
+ return cppyy_call_T<int>(method, self, nargs, args);
+}
+
+long cppyy_call_l(cppyy_method_t method, cppyy_object_t self, int nargs, void*
args) {
+ // char* staticStrcpy(const char* strin)
+ const char* strin = (const char*)(*(long*)&((CPPYY_G__value*)args)[0]);
+ char* strout = (char*)malloc(::strlen(strin)+1);
+ ::strcpy(strout, strin);
+ return (long)strout;
+}
+
+double cppyy_call_d(cppyy_method_t method, cppyy_object_t self, int nargs,
void* args) {
+ return cppyy_call_T<double>(method, self, nargs, args);
+}
+
+char* cppyy_call_s(cppyy_method_t method, cppyy_object_t self, int nargs,
void* args) {
+ // char* staticStrcpy(const char* strin)
+ const char* strin = (const char*)(*(long*)&((CPPYY_G__value*)args)[0]);
+ char* strout = (char*)malloc(::strlen(strin)+1);
+ ::strcpy(strout, strin);
+ return strout;
+}
+
cppyy_methptrgetter_t cppyy_get_methptr_getter(cppyy_type_t /* handle */,
cppyy_index_t /* method_index */) {
return (cppyy_methptrgetter_t)0;
}
+/* handling of function argument buffer ----------------------------------- */
+void* cppyy_allocate_function_args(size_t nargs) {
+ CPPYY_G__value* args =
(CPPYY_G__value*)malloc(nargs*sizeof(CPPYY_G__value));
+ for (size_t i = 0; i < nargs; ++i)
+ args[i].type = 'l';
+ return (void*)args;
+}
+
+
+/* handling of function argument buffer ----------------------------------- */
+void cppyy_deallocate_function_args(void* args) {
+ free(args);
+}
+
+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_scope_t /* handle */) {
@@ -106,7 +206,7 @@
/* method/function reflection information --------------------------------- */
int cppyy_num_methods(cppyy_scope_t handle) {
- return s_scopes[handle].m_num_methods;
+ return s_scopes[handle].m_methods.size();
}
cppyy_index_t cppyy_method_index_at(cppyy_scope_t /* scope */, int imeth) {
@@ -114,31 +214,32 @@
}
char* cppyy_method_name(cppyy_scope_t handle, cppyy_index_t method_index) {
- return cppstring_to_cstring(s_scopes[handle].m_methods[(int)method_index]);
+ return
cppstring_to_cstring(s_scopes[handle].m_methods[(int)method_index].m_name);
}
-char* cppyy_method_result_type(cppyy_scope_t /* handle */, cppyy_index_t /*
method_index */) {
- return cppstring_to_cstring("double");
+char* cppyy_method_result_type(cppyy_scope_t handle, cppyy_index_t
method_index) {
+ return
cppstring_to_cstring(s_scopes[handle].m_methods[method_index].m_returntype);
}
-int cppyy_method_num_args(cppyy_scope_t /* handle */, cppyy_index_t /*
method_index */) {
- return 1;
+int cppyy_method_num_args(cppyy_scope_t handle, cppyy_index_t method_index) {
+ return s_scopes[handle].m_methods[method_index].m_argtypes.size();
}
int cppyy_method_req_args(cppyy_scope_t handle, cppyy_index_t method_index) {
return cppyy_method_num_args(handle, method_index);
}
-char* cppyy_method_arg_type(cppyy_scope_t /* handle */, cppyy_index_t /*
method_index */, int /* arg_index */) {
- return cppstring_to_cstring("double");
+char* cppyy_method_arg_type(cppyy_scope_t handle, cppyy_index_t method_index,
int arg_index) {
+ return
cppstring_to_cstring(s_scopes[handle].m_methods[method_index].m_argtypes[arg_index]);
}
-char* cppyy_method_arg_default(cppyy_scope_t handle, cppyy_index_t
method_index, int arg_index) {
+char* cppyy_method_arg_default(
+ cppyy_scope_t /* handle */, cppyy_index_t /* method_index */, int /*
arg_index */) {
return cppstring_to_cstring("");
}
char* cppyy_method_signature(cppyy_scope_t /* handle */, cppyy_index_t /*
method_index */) {
- return cppstring_to_cstring("double");
+ return cppstring_to_cstring("");
}
int cppyy_method_is_template(cppyy_scope_t /* handle */, cppyy_index_t /*
method_index */) {
@@ -167,6 +268,26 @@
/* misc helpers ----------------------------------------------------------- */
+long long cppyy_strtoll(const char* str) {
+ return strtoll(str, NULL, 0);
+}
+
+extern "C" unsigned long long cppyy_strtoull(const char* str) {
+ return strtoull(str, NULL, 0);
+}
+
void cppyy_free(void* ptr) {
free(ptr);
}
+
+cppyy_object_t cppyy_charp2stdstring(const char* str) {
+ void* arena = new char[sizeof(std::string)];
+ new (arena) std::string(str);
+ return (cppyy_object_t)arena;
+}
+
+cppyy_object_t cppyy_stdstring2stdstring(cppyy_object_t ptr) {
+ void* arena = new char[sizeof(std::string)];
+ new (arena) std::string(*(std::string*)ptr);
+ return (cppyy_object_t)arena;
+}
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
@@ -163,7 +163,7 @@
double cppyy_call_d(cppyy_method_t method, cppyy_object_t self, int nargs,
void* args) {
return cppyy_call_T<double>(method, self, nargs, args);
-}
+}
void* cppyy_call_r(cppyy_method_t method, cppyy_object_t self, int nargs,
void* args) {
return (void*)cppyy_call_T<long>(method, self, nargs, args);
diff --git a/pypy/module/cppyy/test/conftest.py
b/pypy/module/cppyy/test/conftest.py
--- a/pypy/module/cppyy/test/conftest.py
+++ b/pypy/module/cppyy/test/conftest.py
@@ -7,8 +7,11 @@
if 'dummy' in lcapi.reflection_library:
# run only tests that are covered by the dummy backend and tests
# that do not rely on reflex
- if not item.location[0] in ['test_helper.py', 'test_cppyy.py'] or \
- (item.location[0] == 'test_cppyy.py' and not
'TestCPPYYImplementation' in item.location[2]):
+ if not item.location[0] in ['test_helper.py', 'test_cppyy.py']:
+ py.test.skip("genreflex is not installed")
+ import re
+ if item.location[0] == 'test_cppyy.py' and \
+ not re.search("test0[1-3]", item.location[2]):
py.test.skip("genreflex is not installed")
def pytest_configure(config):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit