[pypy-commit] pypy reflex-support: likewise, lazy lookups for CINT back-end

wlav noreply at buildbot.pypy.org
Tue Apr 3 01:43:38 CEST 2012


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r54161:8277dedafc32
Date: 2012-03-30 14:57 -0700
http://bitbucket.org/pypy/pypy/changeset/8277dedafc32/

Log:	likewise, lazy lookups for CINT back-end

diff --git a/pypy/module/cppyy/src/cintcwrapper.cxx b/pypy/module/cppyy/src/cintcwrapper.cxx
--- a/pypy/module/cppyy/src/cintcwrapper.cxx
+++ b/pypy/module/cppyy/src/cintcwrapper.cxx
@@ -36,6 +36,23 @@
 extern "C" void G__LockCriticalSection();
 extern "C" void G__UnlockCriticalSection();
 
+/* ROOT meta internals ---------------------------------------------------- */
+namespace {
+
+class Cppyy_OpenedTClass : public TDictionary {
+public:
+   mutable TObjArray *fStreamerInfo;    //Array of TVirtualStreamerInfo
+   mutable std::map<std::string, TObjArray*> *fConversionStreamerInfo; //Array of the streamer infos derived from another class.
+   TList             *fRealData;        //linked list for persistent members including base classes
+   TList             *fBase;            //linked list for base classes
+   TList             *fData;            //linked list for data members
+   TList             *fMethod;          //linked list for methods
+   TList             *fAllPubData;      //all public data members (including from base classes)
+   TList             *fAllPubMethod;    //all public methods (including from base classes)
+};
+
+} // unnamed namespace
+
 
 /* data for life time management ------------------------------------------ */
 #define GLOBAL_HANDLE 1l
@@ -540,6 +557,30 @@
     return cppstring_to_cstring(sig.str());
 }
 
+int cppyy_method_index(cppyy_scope_t handle, const char* name) {
+    TClassRef cr = type_from_handle(handle);
+    if (cr.GetClass()) {
+        gInterpreter->UpdateListOfMethods(cr.GetClass());
+        int imeth = 0;
+        TFunction* func;
+        TIter next(cr->GetListOfMethods());
+        while ((func = (TFunction*)next())) {
+            if (strcmp(name, func->GetName()) == 0) {
+                if (func->Property() & G__BIT_ISPUBLIC)
+                    return imeth;
+                return -1;
+            }
+            ++imeth;
+        }
+    }
+    TFunction* func = gROOT->GetGlobalFunction(name, NULL, kTRUE);
+    if (!func)
+        return -1;
+    int idx = g_globalfuncs.size();
+    g_globalfuncs.push_back(*func);
+    return idx;
+}
+
 cppyy_method_t cppyy_get_method(cppyy_scope_t handle, int method_index) {
     TFunction* f = type_get_method(handle, method_index);
     return (cppyy_method_t)f->InterfaceMethod();
@@ -621,6 +662,39 @@
     return (size_t)gbl.GetAddress();
 }
 
+int cppyy_data_member_index(cppyy_scope_t handle, const char* name) {
+    TClassRef cr = type_from_handle(handle);
+    if (cr.GetClass()) {
+        // called from updates; add a hard reset as the code itself caches in
+        // Class (TODO: by-pass ROOT/meta)
+        Cppyy_OpenedTClass* c = (Cppyy_OpenedTClass*)cr.GetClass();
+        if (c->fData) {
+            c->fData->Delete();
+            delete c->fData; c->fData = 0;
+            delete c->fAllPubData; c->fAllPubData = 0;
+        }
+        // the following appears dumb, but TClass::GetDataMember() does a linear
+        // search itself, so there is no gain
+        int idm = 0;
+        TDataMember* dm;
+        TIter next(cr->GetListOfDataMembers());
+        while ((dm = (TDataMember*)next())) {
+            if (strcmp(name, dm->GetName()) == 0) {
+                if (dm->Property() & G__BIT_ISPUBLIC)
+                    return idm;
+                return -1;
+            }
+            ++idm;
+        }
+    }
+    TGlobal* gbl = (TGlobal*)gROOT->GetListOfGlobals(kTRUE)->FindObject(name);
+    if (!gbl)
+        return -1;
+    int idx = g_globalvars.size();
+    g_globalvars.push_back(*gbl);
+    return idx;
+}
+
 
 /* data member properties ------------------------------------------------  */
 int cppyy_is_publicdata(cppyy_scope_t handle, int data_member_index) {
diff --git a/pypy/module/cppyy/test/advancedcpp_LinkDef.h b/pypy/module/cppyy/test/advancedcpp_LinkDef.h
--- a/pypy/module/cppyy/test/advancedcpp_LinkDef.h
+++ b/pypy/module/cppyy/test/advancedcpp_LinkDef.h
@@ -36,7 +36,9 @@
 #pragma link C++ struct a_ns::d_ns::e_class;
 #pragma link C++ struct a_ns::d_ns::e_class::f_class;
 #pragma link C++ variable a_ns::g_a;
+#pragma link C++ function a_ns::get_g_a;
 #pragma link C++ variable a_ns::d_ns::g_d;
+#pragma link C++ function a_ns::d_ns::get_g_d;
 
 #pragma link C++ class some_abstract_class;
 #pragma link C++ class some_concrete_class;


More information about the pypy-commit mailing list