Author: Wim Lavrijsen <wlavrij...@lbl.gov> Branch: reflex-support Changeset: r66943:70107f8d73a6 Date: 2013-09-13 11:25 -0700 http://bitbucket.org/pypy/pypy/changeset/70107f8d73a6/
Log: test that global methods can be installed as member functions diff --git a/pypy/module/cppyy/test/example01.cxx b/pypy/module/cppyy/test/example01.cxx --- a/pypy/module/cppyy/test/example01.cxx +++ b/pypy/module/cppyy/test/example01.cxx @@ -156,6 +156,10 @@ return ::globalAddOneToInt(a); } +int installableAddOneToInt(example01& e, int a) { + return e.staticAddOneToInt(a); +} + int ns_example01::gMyGlobalInt = 99; diff --git a/pypy/module/cppyy/test/example01.h b/pypy/module/cppyy/test/example01.h --- a/pypy/module/cppyy/test/example01.h +++ b/pypy/module/cppyy/test/example01.h @@ -67,6 +67,8 @@ extern int gMyGlobalInt; } +int installableAddOneToInt(example01&, int a); + #define itypeValue(itype, tname) \ itype tname##Value(itype arg0, int argn=0, itype arg1=1, itype arg2=2) diff --git a/pypy/module/cppyy/test/example01.xml b/pypy/module/cppyy/test/example01.xml --- a/pypy/module/cppyy/test/example01.xml +++ b/pypy/module/cppyy/test/example01.xml @@ -8,6 +8,7 @@ <class name="z_" /> <function name="globalAddOneToInt" /> + <function name="installableAddOneToInt" /> <namespace name="ns_example01" /> <function name="ns_example01::globalAddOneToInt" /> diff --git a/pypy/module/cppyy/test/example01_LinkDef.h b/pypy/module/cppyy/test/example01_LinkDef.h --- a/pypy/module/cppyy/test/example01_LinkDef.h +++ b/pypy/module/cppyy/test/example01_LinkDef.h @@ -12,6 +12,7 @@ #pragma link C++ class z_; #pragma link C++ function globalAddOneToInt(int); +#pragma link C++ function installableAddOneToInt(example01&, int); #pragma link C++ namespace ns_example01; #pragma link C++ function ns_example01::globalAddOneToInt(int); diff --git a/pypy/module/cppyy/test/test_pythonify.py b/pypy/module/cppyy/test/test_pythonify.py --- a/pypy/module/cppyy/test/test_pythonify.py +++ b/pypy/module/cppyy/test/test_pythonify.py @@ -327,6 +327,17 @@ e = cppyy.gbl.example01(2) assert 5 == meth(e, 3) + def test01_installable_function(self): + """Test installing and calling global C++ function as python method""" + + import cppyy + + cppyy.gbl.example01.fresh = cppyy.gbl.installableAddOneToInt + + e = cppyy.gbl.example01(0) + assert 2 == e.fresh(1) + assert 3 == e.fresh(2) + class AppTestPYTHONIFY_UI: spaceconfig = dict(usemodules=['cppyy', '_rawffi', '_ffi', 'itertools']) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit