Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r55487:cf60751f1e6a
Date: 2012-06-07 11:32 -0700
http://bitbucket.org/pypy/pypy/changeset/cf60751f1e6a/
Log: add automatic class loader based on .rootmap files; and its test
diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -25,6 +25,7 @@
^pypy/module/cppyy/src/.+\.errors$
^pypy/module/cppyy/test/.+_rflx\.cpp$
^pypy/module/cppyy/test/.+\.so$
+^pypy/module/cppyy/test/.+\.rootmap$
^pypy/module/cppyy/test/.+\.exe$
^pypy/module/cppyy/test/.+_cint.h$
^pypy/doc/.+\.html$
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
@@ -10,6 +10,10 @@
#include "Reflex/PropertyList.h"
#include "Reflex/TypeTemplate.h"
+#define private public
+#include "Reflex/PluginService.h"
+#undef private
+
#include <string>
#include <sstream>
#include <utility>
@@ -61,6 +65,8 @@
cppyy_scope_t cppyy_get_scope(const char* scope_name) {
Reflex::Scope s = Reflex::Scope::ByName(scope_name);
+ if (!s) Reflex::PluginService::Instance().LoadFactoryLib(scope_name);
+ s = Reflex::Scope::ByName(scope_name);
if (s.IsEnum()) // pretend to be builtin by returning 0
return (cppyy_type_t)0;
return (cppyy_type_t)s.Id();
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
@@ -35,7 +35,7 @@
g++ -o $@ $^ -shared -lReflex $(cppflags) $(cppflags2)
%_rflx.cpp: %.h %.xml
- $(genreflex) $< $(genreflexflags) --selection=$*.xml
+ $(genreflex) $< $(genreflexflags) --selection=$*.xml
--rootmap=$*Dict.rootmap --rootmap-lib=$*Dict.so
else
%Dict.so: %_cint.cxx %.cxx
g++ -o $@ $^ -shared $(cppflags) $(cppflags2)
@@ -53,4 +53,4 @@
.PHONY: clean
clean:
- -rm -f $(dicts)
+ -rm -f $(dicts) $(subst .so,.rootmap,$(dicts))
diff --git a/pypy/module/cppyy/test/test_aclassloader.py
b/pypy/module/cppyy/test/test_aclassloader.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/cppyy/test/test_aclassloader.py
@@ -0,0 +1,26 @@
+import py, os, sys
+from pypy.conftest import gettestobjspace
+
+
+currpath = py.path.local(__file__).dirpath()
+
+def setup_module(mod):
+ if sys.platform == 'win32':
+ py.test.skip("win32 not supported so far")
+ err = os.system("cd '%s' && make example01Dict.so" % currpath)
+ if err:
+ raise OSError("'make' failed (see stderr)")
+
+
+class AppTestACLASSLOADER:
+ def setup_class(cls):
+ cls.space = gettestobjspace(usemodules=['cppyy'])
+
+ def test01_class_autoloading(self):
+ """Test whether a class can be found through .rootmap."""
+ import cppyy
+ example01_class = cppyy.gbl.example01
+ assert example01_class
+ cl2 = cppyy.gbl.example01
+ assert cl2
+ assert example01_class is cl2
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit