[pypy-svn] r75834 - in pypy/branch/reflex-support/pypy/module/cppyy: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Jul 5 15:25:55 CEST 2010


Author: cfbolz
Date: Mon Jul  5 15:25:54 2010
New Revision: 75834

Added:
   pypy/branch/reflex-support/pypy/module/cppyy/interp_cppyy.py   (contents, props changed)
   pypy/branch/reflex-support/pypy/module/cppyy/test/Makefile
   pypy/branch/reflex-support/pypy/module/cppyy/test/example01.cxx   (contents, props changed)
   pypy/branch/reflex-support/pypy/module/cppyy/test/test_cppyy.py   (contents, props changed)
Modified:
   pypy/branch/reflex-support/pypy/module/cppyy/__init__.py
   pypy/branch/reflex-support/pypy/module/cppyy/test/   (props changed)
Log:
(arigo, antocuni, cfbolz, wlav): a tiny C++ class and a test of how we want the
interface to look for now. Now the real fun starts.


Modified: pypy/branch/reflex-support/pypy/module/cppyy/__init__.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/__init__.py	(original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/__init__.py	Mon Jul  5 15:25:54 2010
@@ -4,6 +4,7 @@
     """    """
 
     interpleveldefs = {
+        'load_lib': 'interp_cppyy.load_lib',
     }
 
     appleveldefs = {

Added: pypy/branch/reflex-support/pypy/module/cppyy/interp_cppyy.py
==============================================================================
--- (empty file)
+++ pypy/branch/reflex-support/pypy/module/cppyy/interp_cppyy.py	Mon Jul  5 15:25:54 2010
@@ -0,0 +1,43 @@
+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.rlib.libffi import CDLL
+
+def load_lib(space, name):
+    cdll = CDLL(name)
+    return W_CPPLibrary(space, cdll)
+load_lib.unwrap_spec = [ObjSpace, str]
+
+class W_CPPLibrary(Wrappable):
+    def __init__(self, space, cdll):
+        self.cdll = cdll
+        self.space = space
+
+    def type_byname(self, name):
+        return W_CPPType(self, name)
+
+W_CPPLibrary.typedef = TypeDef(
+    'CPPLibrary',
+    type_byname = interp2app(W_CPPLibrary.type_byname, unwrap_spec=['self', str]),
+)
+
+
+class W_CPPType(Wrappable):
+    def __init__(self, cpplib, name):
+        self.space = cpplib.space
+        self.cpplib = cpplib
+        self.name = name
+
+    def invoke(self, name, args_w):
+        xxx
+
+    def construct(self, args_w):
+        xxx
+
+W_CPPType.typedef = TypeDef(
+    'CPPType',
+    invoke = interp2app(W_CPPType.invoke, unwrap_spec=['self', str, 'args_w']),
+    construct = interp2app(W_CPPType.construct, unwrap_spec=['self', 'args_w']),
+)

Added: pypy/branch/reflex-support/pypy/module/cppyy/test/Makefile
==============================================================================
--- (empty file)
+++ pypy/branch/reflex-support/pypy/module/cppyy/test/Makefile	Mon Jul  5 15:25:54 2010
@@ -0,0 +1,8 @@
+LD_LIBRARY_PATH := ${LD_LIBRARY_PATH}:${ROOTSYS}/lib
+ROOTSYS := ${ROOTSYS}
+
+example01Dict.so: example01.cxx
+	echo $(ROOTSYS)
+	$(ROOTSYS)/bin/genreflex example01.cxx
+	g++ -o $@ example01_rflx.cpp -shared -I$(ROOTSYS)/include -L$(ROOTSYS)/lib -lReflex
+

Added: pypy/branch/reflex-support/pypy/module/cppyy/test/example01.cxx
==============================================================================
--- (empty file)
+++ pypy/branch/reflex-support/pypy/module/cppyy/test/example01.cxx	Mon Jul  5 15:25:54 2010
@@ -0,0 +1,16 @@
+#include <iostream>
+
+class example01 {
+public:
+    int somedata;
+    example01(int a) : somedata(a) {
+        std::cout << "constructor called" << std::endl;
+    }
+
+    static int add1(int a) {
+        return a + 1;
+    }
+    int add(int a) {
+        return somedata + a;
+    }
+};

Added: pypy/branch/reflex-support/pypy/module/cppyy/test/test_cppyy.py
==============================================================================
--- (empty file)
+++ pypy/branch/reflex-support/pypy/module/cppyy/test/test_cppyy.py	Mon Jul  5 15:25:54 2010
@@ -0,0 +1,24 @@
+import py
+import os
+from pypy.conftest import gettestobjspace
+
+currpath = py.path.local(__file__).dirpath()
+
+class AppTestCPPYY:
+    def setup_class(cls):
+        cls.space = gettestobjspace(usemodules=['cppyy'])
+        env = os.environ
+        cls.w_example01 = cls.space.appexec([], """():
+            import cppyy
+            return cppyy.load_lib(%r)""" % (str(currpath.join("example01Dict.so")), ))
+
+    def test_example01static(self):
+        t = self.example01.type_byname("example01")
+        res = t.invoke("add1", 1)
+        assert res == 2
+
+    def test_example01method(self):
+        t = self.example01.type_byname("example01")
+        instance = t.construct(7)
+        res = instance.invoke("add2", 4)
+        assert res == 11



More information about the Pypy-commit mailing list