[pypy-svn] r75835 - in pypy/branch/reflex-support/pypy/module/cppyy: . include src

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Jul 5 17:19:57 CEST 2010


Author: cfbolz
Date: Mon Jul  5 17:19:56 2010
New Revision: 75835

Added:
   pypy/branch/reflex-support/pypy/module/cppyy/include/
   pypy/branch/reflex-support/pypy/module/cppyy/include/cppyy.h
   pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h
   pypy/branch/reflex-support/pypy/module/cppyy/src/
   pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx
Modified:
   pypy/branch/reflex-support/pypy/module/cppyy/interp_cppyy.py
Log:
(cfbolz, wlav, antocuni, arigo): write just enough code to be able to call a
static method


Added: pypy/branch/reflex-support/pypy/module/cppyy/include/cppyy.h
==============================================================================
--- (empty file)
+++ pypy/branch/reflex-support/pypy/module/cppyy/include/cppyy.h	Mon Jul  5 17:19:56 2010
@@ -0,0 +1,7 @@
+#ifndef CPPYY_CPPYY
+#define CPPYY_CPPYY
+
+#include "Reflex/Type.h"
+#include "Reflex/Member.h"
+
+#endif // CPPYY_CPPYY

Added: pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h
==============================================================================
--- (empty file)
+++ pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h	Mon Jul  5 17:19:56 2010
@@ -0,0 +1,9 @@
+
+#ifndef CPPYY_REFLEXCWRAPPER
+#define CPPYY_REFLEXCWRAPPER
+
+extern "C" {
+    long callstatic_l(const char* class_name, const char* method_name, int numargs, void* args[]);
+}
+
+#endif // ifndef CPPYY_REFLEXCWRAPPER

Modified: pypy/branch/reflex-support/pypy/module/cppyy/interp_cppyy.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/interp_cppyy.py	(original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/interp_cppyy.py	Mon Jul  5 17:19:56 2010
@@ -1,10 +1,35 @@
+import py, os
+
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.gateway import ObjSpace, interp2app
 from pypy.interpreter.typedef import TypeDef
 from pypy.interpreter.baseobjspace import Wrappable
 
+from pypy.translator.tool.cbuild import ExternalCompilationInfo
+from pypy.rpython.lltypesystem import rffi, lltype
+
 from pypy.rlib.libffi import CDLL
 
+
+srcpath = py.path.local(__file__).dirpath().join("src")
+incpath = py.path.local(__file__).dirpath().join("include")
+rootincpath = os.path.join(os.environ["ROOTSYS"], "include")
+rootlibpath = os.path.join(os.environ["ROOTSYS"], "lib")
+
+eci = ExternalCompilationInfo(
+    separate_module_files=[srcpath.join("reflexcwrapper.cxx")],
+    include_dirs=[incpath, rootincpath],
+    library_dirs=[rootlibpath],
+    libraries=["Reflex"],
+    use_cpp_linker=True,
+)
+
+callstatic_l = rffi.llexternal(
+    "callstatic_l",
+    [rffi.CCHARP, rffi.CCHARP, rffi.INT, rffi.VOIDPP], rffi.LONG,
+    compilation_info=eci)
+
+
 def load_lib(space, name):
     cdll = CDLL(name)
     return W_CPPLibrary(space, cdll)
@@ -31,7 +56,17 @@
         self.name = name
 
     def invoke(self, name, args_w):
-        xxx
+        args = lltype.malloc(rffi.CArray(rffi.VOIDP), len(args_w), flavor='raw')
+        for i in range(len(args_w)):
+            arg = self.space.int_w(args_w[i])
+            x = lltype.malloc(rffi.LONGP.TO, 1, flavor='raw')
+            x[0] = arg
+            args[i] = rffi.cast(rffi.VOIDP, x)
+        result = callstatic_l(self.name, name, len(args_w), args)
+        for i in range(len(args_w)):
+            lltype.free(args[i], flavor='raw')
+        lltype.free(args, flavor='raw')
+        return self.space.wrap(result)
 
     def construct(self, args_w):
         xxx

Added: pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx
==============================================================================
--- (empty file)
+++ pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx	Mon Jul  5 17:19:56 2010
@@ -0,0 +1,12 @@
+#include "cppyy.h"
+#include "reflexcwrapper.h"
+#include <vector>
+
+long callstatic_l(const char* classname, const char* methodname, int numargs, void* args[]) {
+    long result;
+    std::vector<void*> arguments(args, args+numargs);
+    Reflex::Type t = Reflex::Type::ByName(classname);
+    Reflex::Member m = t.FunctionMemberByName(methodname);
+    m.Invoke(result, arguments);
+    return result;
+}



More information about the Pypy-commit mailing list