[pypy-svn] r76011 - in pypy/branch/reflex-support/pypy/module/cppyy: . test
wlav at codespeak.net
wlav at codespeak.net
Thu Jul 8 11:00:44 CEST 2010
Author: wlav
Date: Thu Jul 8 11:00:42 2010
New Revision: 76011
Added:
pypy/branch/reflex-support/pypy/module/cppyy/pythonify.py (contents, props changed)
pypy/branch/reflex-support/pypy/module/cppyy/test/test_pythonify.py (contents, props changed)
Modified:
pypy/branch/reflex-support/pypy/module/cppyy/__init__.py
Log:
(cfbolz,wlav) New module pythonify for user interface, and its test. Make load_lib cache resulting libraries.
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 Thu Jul 8 11:00:42 2010
@@ -4,8 +4,10 @@
""" """
interpleveldefs = {
- 'load_lib': 'interp_cppyy.load_lib',
+ '_load_lib': 'interp_cppyy.load_lib',
}
appleveldefs = {
+ 'gbl' : 'pythonify.gbl',
+ 'load_lib' : 'pythonify.load_lib',
}
Added: pypy/branch/reflex-support/pypy/module/cppyy/pythonify.py
==============================================================================
--- (empty file)
+++ pypy/branch/reflex-support/pypy/module/cppyy/pythonify.py Thu Jul 8 11:00:42 2010
@@ -0,0 +1,36 @@
+# NOT_RPYTHON
+import cppyy
+
+class _gbl(object):
+ """Global C++ namespace, i.e. ::."""
+
+ def __getattr__(self, attr):
+ raise AttributeError
+
+class CppyyClass(object):
+ def __init__(self, cppclass):
+ # fill dictionary
+ pass
+
+
+def get_cppclass(name):
+ # lookup class
+
+ # if failed, create
+
+ # create base classes
+ pass
+
+
+_loaded_shared_libs = {}
+def load_lib(name):
+ try:
+ return _loaded_shared_libs[name]
+ except KeyError:
+ lib = cppyy._load_lib(name)
+ _loaded_shared_libs[name] = lib
+ return lib
+
+
+# user interface objects
+gbl = _gbl()
Added: pypy/branch/reflex-support/pypy/module/cppyy/test/test_pythonify.py
==============================================================================
--- (empty file)
+++ pypy/branch/reflex-support/pypy/module/cppyy/test/test_pythonify.py Thu Jul 8 11:00:42 2010
@@ -0,0 +1,27 @@
+import py, os
+from pypy.conftest import gettestobjspace
+from pypy.module.cppyy import interp_cppyy, executor
+
+
+currpath = py.path.local(__file__).dirpath()
+shared_lib = str(currpath.join("example01Dict.so"))
+
+space = gettestobjspace(usemodules=['cppyy'])
+
+def setup_module(mod):
+ os.system("make")
+
+class AppTestPYTHONIFY:
+ def setup_class(cls):
+ cls.space = space
+ env = os.environ
+ cls.w_shared_lib = space.wrap(shared_lib)
+ cls.w_example01 = cls.space.appexec([], """():
+ import cppyy
+ return cppyy.load_lib(%r)""" % (shared_lib, ))
+
+ def testLoadLibCache(self):
+ """Test whether loading a library twice results in the same object."""
+ import cppyy
+ lib2 = cppyy.load_lib(self.shared_lib)
+ assert self.example01 is lib2
More information about the Pypy-commit
mailing list