1. marienz
  2. pypy

Commits

wlav  committed 6dce3c5

support for dir() on CINT namespaces (can't be complete, but is good enough for now)

  • Participants
  • Parent commits 3c27923
  • Branches reflex-support

Comments (0)

Files changed (4)

File pypy/module/cppyy/interp_cppyy.py

View file
         return self.space.w_True
 
     def ns__dir__(self):
+        # Collect a list of everything (currently) available in the namespace.
+        # The backend can filter by returning empty strings. Special care is
+        # taken for functions, which need not be unique (overloading).
         alldir = []
         for i in range(capi.c_num_scopes(self)):
-            alldir.append(capi.c_scope_name(self, i))
+            sname = capi.c_scope_name(self, i)
+            if sname: alldir.append(sname)
+        allmeth = []
         for i in range(capi.c_num_methods(self)):
             idx = capi.c_method_index_at(self, i)
-            alldir.append(capi.c_method_name(self, idx))
+            mname = capi.c_method_name(self, idx)
+            if mname: allmeth.append(mname)
+        alldir += set(allmeth)
         for i in range(capi.c_num_datamembers(self)):
-            alldir.append(capi.c_datamember_name(self, i))
+            dname = capi.c_datamember_name(self, i)
+            if dname: alldir.append(dname)
         return self.space.wrap(alldir)
         
 

File pypy/module/cppyy/src/cintcwrapper.cxx

View file
 #include "TClass.h"
 #include "TClassEdit.h"
 #include "TClassRef.h"
+#include "TClassTable.h"
 #include "TDataMember.h"
 #include "TFunction.h"
 #include "TGlobal.h"
 
 
 /* name to opaque C++ scope representation -------------------------------- */
+int cppyy_num_scopes(cppyy_scope_t handle) {
+    TClassRef cr = type_from_handle(handle);
+    if (cr.GetClass()) {
+        /* not supported as CINT does not store classes hierarchically */
+        return 0;
+    }
+    return gClassTable->Classes();
+}
+
+char* cppyy_scope_name(cppyy_scope_t handle, int iscope) {
+    TClassRef cr = type_from_handle(handle);
+    if (cr.GetClass()) {
+        /* not supported as CINT does not store classes hierarchically */
+        assert(!"scope name lookup not supported on inner scopes");
+        return 0;
+    }
+    std::string name = gClassTable->At(iscope);
+    if (name.find("::") == std::string::npos)
+        return cppstring_to_cstring(name);
+    return cppstring_to_cstring("");
+}
+
 char* cppyy_resolve_name(const char* cppitem_name) {
     std::string tname = cppitem_name;
 

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

View file
 #pragma link off all functions;
 
 #pragma link C++ namespace fragile;
+#pragma link C++ namespace fragile::nested1;
+#pragma link C++ namespace fragile::nested1::nested2;
+#pragma link C++ namespace fragile::nested1::nested2::nested3;
 
 #pragma link C++ class fragile::A;
 #pragma link C++ class fragile::B;
 #pragma link C++ class fragile::H;
 #pragma link C++ class fragile::I;
 #pragma link C++ class fragile::J;
+#pragma link C++ class fragile::nested1::A;
+#pragma link C++ class fragile::nested1::nested2::A;
+#pragma link C++ class fragile::nested1::nested2::nested3::A;
 
 #pragma link C++ variable fragile::gI;
 

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

View file
 import py, os, sys
 from pypy.conftest import gettestobjspace
 
+from pypy.module.cppyy import capi
 
 currpath = py.path.local(__file__).dirpath()
 test_dct = str(currpath.join("fragileDict.so"))
         cls.space = space
         env = os.environ
         cls.w_test_dct  = space.wrap(test_dct)
+        cls.w_capi = space.wrap(capi)
         cls.w_fragile = cls.space.appexec([], """():
             import cppyy
             return cppyy.load_reflection_info(%r)""" % (test_dct, ))
 
         import cppyy
 
-        members = dir(cppyy.gbl.fragile)
-        assert 'A' in members
-        assert 'B' in members
-        assert 'C' in members
-        assert 'D' in members                # classes
+        if self.capi.identify() == 'CINT':   # CINT only support classes on global space
+            members = dir(cppyy.gbl)
+            assert 'TROOT' in members
+            assert 'TSystem' in members
+            assert 'TClass' in members
+            members = dir(cppyy.gbl.fragile)
+        else:
+            members = dir(cppyy.gbl.fragile)
+            assert 'A' in members
+            assert 'B' in members
+            assert 'C' in members
+            assert 'D' in members            # classes
+
+            assert 'nested1' in members          # namespace
 
         assert 'fglobal' in members          # function
-        assert 'nested1' in members          # namespace
         assert 'gI'in members                # variable
 
     def test12_imports(self):