Commits

wlav  committed 70107f8

test that global methods can be installed as member functions

  • Participants
  • Parent commits 7551188
  • Branches reflex-support

Comments (0)

Files changed (5)

File pypy/module/cppyy/test/example01.cxx

    return ::globalAddOneToInt(a);
 }
 
+int installableAddOneToInt(example01& e, int a) {
+   return e.staticAddOneToInt(a);
+}
+
 int ns_example01::gMyGlobalInt = 99;
 
 

File pypy/module/cppyy/test/example01.h

     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)
 

File pypy/module/cppyy/test/example01.xml

   <class name="z_" />
 
   <function name="globalAddOneToInt" />
+  <function name="installableAddOneToInt" />
 
   <namespace name="ns_example01" />
   <function name="ns_example01::globalAddOneToInt" />

File pypy/module/cppyy/test/example01_LinkDef.h

 #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);

File pypy/module/cppyy/test/test_pythonify.py

         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'])