[pypy-commit] pypy reflex-support: valgrind-directed cleanup

wlav noreply at buildbot.pypy.org
Tue Apr 22 19:27:02 CEST 2014


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r70856:a0a53cefce3b
Date: 2014-04-22 10:25 -0700
http://bitbucket.org/pypy/pypy/changeset/a0a53cefce3b/

Log:	valgrind-directed cleanup

diff --git a/pypy/module/cppyy/capi/capi_types.py b/pypy/module/cppyy/capi/capi_types.py
--- a/pypy/module/cppyy/capi/capi_types.py
+++ b/pypy/module/cppyy/capi/capi_types.py
@@ -1,7 +1,7 @@
 from rpython.rtyper.lltypesystem import rffi, lltype
 
 # shared ll definitions
-_C_OPAQUE_PTR = rffi.LONG
+_C_OPAQUE_PTR = rffi.VOIDP
 _C_OPAQUE_NULL = lltype.nullptr(rffi.LONGP.TO)# ALT: _C_OPAQUE_PTR.TO
 
 C_SCOPE = _C_OPAQUE_PTR
diff --git a/pypy/module/cppyy/capi/cint_capi.py b/pypy/module/cppyy/capi/cint_capi.py
--- a/pypy/module/cppyy/capi/cint_capi.py
+++ b/pypy/module/cppyy/capi/cint_capi.py
@@ -180,7 +180,7 @@
 ### TTree --------------------------------------------------------------------
 _ttree_Branch = rffi.llexternal(
     "cppyy_ttree_Branch",
-    [rffi.VOIDP, rffi.CCHARP, rffi.CCHARP, rffi.VOIDP, rffi.INT, rffi.INT], rffi.LONG,
+    [rffi.VOIDP, rffi.CCHARP, rffi.CCHARP, rffi.VOIDP, rffi.INT, rffi.INT], C_OBJECT,
     releasegil=False,
     compilation_info=eci)
 
@@ -299,6 +299,8 @@
         # some instance
         klass = interp_cppyy.scope_byname(space, space.str_w(w_klassname))
         w_obj = klass.construct()
+        # 0x10000 = kDeleteObject; reset because we own the object
+        space.call_method(w_branch, "ResetBit", space.wrap(0x10000))
         space.call_method(w_branch, "SetObject", w_obj)
         space.call_method(w_branch, "GetEntry", space.wrap(entry))
         space.setattr(w_self, args_w[0], w_obj)
diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py
--- a/pypy/module/cppyy/executor.py
+++ b/pypy/module/cppyy/executor.py
@@ -139,7 +139,7 @@
         from pypy.module.cppyy import interp_cppyy
         newthis = capi.c_constructor(space, cppmethod, cpptype, num_args, args)
         assert lltype.typeOf(newthis) == capi.C_OBJECT
-        return space.wrap(newthis)
+        return space.wrap(rffi.cast(rffi.LONG, newthis))   # really want ptrdiff_t here
 
 
 class InstancePtrExecutor(FunctionExecutor):
diff --git a/pypy/module/cppyy/include/capi.h b/pypy/module/cppyy/include/capi.h
--- a/pypy/module/cppyy/include/capi.h
+++ b/pypy/module/cppyy/include/capi.h
@@ -7,11 +7,11 @@
 extern "C" {
 #endif // ifdef __cplusplus
 
-    typedef long cppyy_scope_t;
+    typedef void* cppyy_scope_t;
     typedef cppyy_scope_t cppyy_type_t;
-    typedef long cppyy_object_t;
-    typedef long cppyy_method_t;
-    typedef long cppyy_index_t;
+    typedef void* cppyy_object_t;
+    typedef void* cppyy_method_t;
+    typedef long  cppyy_index_t;
     typedef void* (*cppyy_methptrgetter_t)(cppyy_object_t);
 
     /* name to opaque C++ scope representation -------------------------------- */
diff --git a/pypy/module/cppyy/interp_cppyy.py b/pypy/module/cppyy/interp_cppyy.py
--- a/pypy/module/cppyy/interp_cppyy.py
+++ b/pypy/module/cppyy/interp_cppyy.py
@@ -132,7 +132,7 @@
     # class allows simple aliasing of methods)
     capi.pythonize(space, cppclass.name, w_pycppclass)
     state = space.fromcache(State)
-    state.cppclass_registry[cppclass.handle] = w_pycppclass
+    state.cppclass_registry[rffi.cast(rffi.LONG, cppclass.handle)] = w_pycppclass
 
 
 class W_CPPLibrary(W_Root):
@@ -1154,7 +1154,7 @@
 def get_pythonized_cppclass(space, handle):
     state = space.fromcache(State)
     try:
-        w_pycppclass = state.cppclass_registry[handle]
+        w_pycppclass = state.cppclass_registry[rffi.cast(rffi.LONG, handle)]
     except KeyError:
         final_name = capi.c_scoped_final_name(space, handle)
         # the callback will cache the class by calling register_class
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
@@ -46,9 +46,6 @@
 extern "C" void G__LockCriticalSection();
 extern "C" void G__UnlockCriticalSection();
 
-#define G__SETMEMFUNCENV      (long)0x7fff0035
-#define G__NOP                (long)0x7fff00ff
-
 namespace {
 
 class Cppyy_OpenedTClass : public TDictionary {
@@ -147,11 +144,10 @@
         assert(g_classrefs.size() == (ClassRefs_t::size_type)GLOBAL_HANDLE);
         g_classref_indices[""] = (ClassRefs_t::size_type)GLOBAL_HANDLE;
         g_classrefs.push_back(TClassRef(""));
-        g_classref_indices["std"] = g_classrefs.size();
-        g_classrefs.push_back(TClassRef(""));    // CINT ignores std
-        g_classref_indices["::std"] = g_classrefs.size();
-        g_classrefs.push_back(TClassRef(""));    // id.
- 
+        // CINT ignores std/::std, so point them to the global namespace
+        g_classref_indices["std"]   = (ClassRefs_t::size_type)GLOBAL_HANDLE;
+        g_classref_indices["::std"] = (ClassRefs_t::size_type)GLOBAL_HANDLE;
+
         // an offset for the interpreted methods
         g_interpreted.push_back(G__MethodInfo());
 
@@ -203,6 +199,7 @@
     TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass())
         return (TFunction*)cr->GetListOfMethods()->At(idx);
+    assert(handle == (cppyy_type_t)GLOBAL_HANDLE);
     return (TFunction*)idx;
 }
 
@@ -247,6 +244,7 @@
         /* not supported as CINT does not store classes hierarchically */
         return 0;
     }
+    assert(handle == (cppyy_type_t)GLOBAL_HANDLE);
     return gClassTable->Classes();
 }
 
@@ -258,6 +256,7 @@
         assert(!"scope name lookup not supported on inner scopes");
         return 0;
     }
+    assert(handle == (cppyy_type_t)GLOBAL_HANDLE);
     std::string name = gClassTable->At(iscope);
     if (name.find("::") == std::string::npos)
         return cppstring_to_cstring(name);
@@ -411,7 +410,6 @@
     G__settemplevel(1);
 
     long index = (long)&method;
-    G__CurrentCall(G__SETMEMFUNCENV, 0, &index);
 
     // TODO: access to store_struct_offset won't work on Windows
     long store_struct_offset = G__store_struct_offset;
@@ -425,7 +423,6 @@
     if (G__get_return(0) > G__RETURN_NORMAL)
         G__security_recover(0);    // 0 ensures silence
 
-    G__CurrentCall(G__NOP, 0, 0);
     G__settemplevel(-1);
     G__UnlockCriticalSection();
 
@@ -514,7 +511,7 @@
     R__LOCKGUARD2(gCINTMutex);
     G__value result = cppyy_call_T(method, self, nargs, args);
     G__pop_tempobject_nodel();
-    return G__int(result);
+    return (cppyy_object_t)G__int(result);
 }
 
 cppyy_methptrgetter_t cppyy_get_methptr_getter(cppyy_type_t /*handle*/, cppyy_index_t /*idx*/) {
@@ -552,7 +549,7 @@
     TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass() && cr->GetClassInfo())
         return cr->Property() & G__BIT_ISNAMESPACE;
-    if (strcmp(cr.GetClassName(), "") == 0)
+    if (handle == (cppyy_scope_t)GLOBAL_HANDLE)
         return true;
     return false;
 }
@@ -655,7 +652,7 @@
     TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass() && cr->GetListOfMethods())
         return cr->GetListOfMethods()->GetSize();
-    else if (strcmp(cr.GetClassName(), "") == 0) {
+    else if (handle == (cppyy_scope_t)GLOBAL_HANDLE) {
         if (g_globalfuncs.empty()) {
             TCollection* funcs = gROOT->GetListOfGlobalFunctions(kTRUE);
 	    g_globalfuncs.reserve(funcs->GetSize());
@@ -678,6 +675,7 @@
     TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass())
         return (cppyy_index_t)imeth;
+    assert(handle == (cppyy_type_t)GLOBAL_HANDLE);
     return (cppyy_index_t)&g_globalfuncs[imeth];
 }
 
@@ -698,14 +696,12 @@
             }
             ++imeth;
         }
-    }
-
-    if (result.empty()) {
+    } else if (handle == (cppyy_scope_t)GLOBAL_HANDLE) {
         TCollection* funcs = gROOT->GetListOfGlobalFunctions(kTRUE);
         TFunction* func = 0;
         TIter ifunc(funcs);
         while ((func = (TFunction*)ifunc.Next())) {
-            if (strcmp(func->GetName(), name) == 0) {
+            if (strcmp(name, func->GetName()) == 0) {
                 g_globalfuncs.push_back(*func);
                 result.push_back((cppyy_index_t)func); 
             }
@@ -715,7 +711,7 @@
     if (result.empty())
         return (cppyy_index_t*)0;
 
-    cppyy_index_t* llresult = (cppyy_index_t*)malloc(sizeof(cppyy_index_t)*result.size()+1);
+    cppyy_index_t* llresult = (cppyy_index_t*)malloc(sizeof(cppyy_index_t)*(result.size()+1));
     for (int i = 0; i < (int)result.size(); ++i) llresult[i] = result[i];
     llresult[result.size()] = -1;
     return llresult;
@@ -844,7 +840,7 @@
     TClassRef& lccr = type_from_handle(lc);
     TClassRef& rccr = type_from_handle(rc);
 
-    if (!lccr.GetClass() || !rccr.GetClass() || scope != GLOBAL_HANDLE)
+    if (!lccr.GetClass() || !rccr.GetClass() || scope != (cppyy_scope_t)GLOBAL_HANDLE)
         return (cppyy_index_t)-1;  // (void*)-1 is in kernel space, so invalid as a method handle
 
     std::string lcname = lccr->GetName();
@@ -893,7 +889,7 @@
     TClassRef& cr = type_from_handle(handle);
     if (cr.GetClass() && cr->GetListOfDataMembers())
         return cr->GetListOfDataMembers()->GetSize();
-    else if (strcmp(cr.GetClassName(), "") == 0) {
+    else if (handle == (cppyy_scope_t)GLOBAL_HANDLE) {
         TCollection* vars = gROOT->GetListOfGlobals(kTRUE);
        	if (g_globalvars.size() != (GlobalVars_t::size_type)vars->GetSize()) {
             g_globalvars.clear();
@@ -919,6 +915,7 @@
         TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At(datamember_index);
         return cppstring_to_cstring(m->GetName());
     }
+    assert(handle == (cppyy_type_t)GLOBAL_HANDLE);
     TGlobal& gbl = g_globalvars[datamember_index];
     return cppstring_to_cstring(gbl.GetName());
 }
@@ -939,6 +936,7 @@
         }
         return cppstring_to_cstring(fullType);
     }
+    assert(handle == (cppyy_type_t)GLOBAL_HANDLE);
     TGlobal& gbl = g_globalvars[datamember_index];
     return cppstring_to_cstring(gbl.GetFullTypeName());
 }
@@ -950,6 +948,7 @@
         TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At(datamember_index);
         return (size_t)m->GetOffsetCint();
     }
+    assert(handle == (cppyy_type_t)GLOBAL_HANDLE);
     TGlobal& gbl = g_globalvars[datamember_index];
     return (size_t)gbl.GetAddress();
 }
@@ -980,13 +979,15 @@
             }
             ++idm;
         }
+    } else if (handle == (cppyy_type_t)GLOBAL_HANDLE) {
+        TGlobal* gbl = (TGlobal*)gROOT->GetListOfGlobals(kTRUE)->FindObject(name);
+        if (!gbl)
+            return -1;
+        int idx = g_globalvars.size();
+        g_globalvars.push_back(*gbl);
+        return idx;
     }
-    TGlobal* gbl = (TGlobal*)gROOT->GetListOfGlobals(kTRUE)->FindObject(name);
-    if (!gbl)
-        return -1;
-    int idx = g_globalvars.size();
-    g_globalvars.push_back(*gbl);
-    return idx;
+    return -1;
 }
 
 
@@ -998,6 +999,7 @@
         TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At(datamember_index);
         return m->Property() & G__BIT_ISPUBLIC;
     }
+    assert(handle == (cppyy_type_t)GLOBAL_HANDLE);
     return 1;  // global data is always public
 }
 
@@ -1008,6 +1010,7 @@
         TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At(datamember_index);
         return m->Property() & G__BIT_ISSTATIC;
     }
+    assert(handle == (cppyy_type_t)GLOBAL_HANDLE);
     return 1;  // global data is always static
 }
 
diff --git a/pypy/module/cppyy/src/dummy_backend.cxx b/pypy/module/cppyy/src/dummy_backend.cxx
--- a/pypy/module/cppyy/src/dummy_backend.cxx
+++ b/pypy/module/cppyy/src/dummy_backend.cxx
@@ -36,11 +36,11 @@
 struct Cppyy_InitPseudoReflectionInfo {
     Cppyy_InitPseudoReflectionInfo() {
         // class example01 --
-        static int s_scope_id = 0;
-        s_handles["example01"] = ++s_scope_id;
+        static long s_scope_id = 0;
+        s_handles["example01"] = (cppyy_scope_t)++s_scope_id;
         const char* methods[] = {"staticAddToDouble"};
         Cppyy_PseudoInfo info(1, methods);
-        s_scopes[s_scope_id] = info;
+        s_scopes[(cppyy_scope_t)s_scope_id] = info;
         // -- class example01
     }
 } _init;
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
@@ -375,7 +375,7 @@
     }
     if (result.empty())
         return (cppyy_index_t*)0;
-    cppyy_index_t* llresult = (cppyy_index_t*)malloc(sizeof(cppyy_index_t)*result.size()+1);
+    cppyy_index_t* llresult = (cppyy_index_t*)malloc(sizeof(cppyy_index_t)*(result.size()+1));
     for (int i = 0; i < (int)result.size(); ++i) llresult[i] = result[i];
     llresult[result.size()] = -1;
     return llresult;
@@ -481,7 +481,7 @@
     return (cppyy_method_t)m.Stubfunction();
 }
 
-cppyy_method_t cppyy_get_global_operator(cppyy_scope_t scope, cppyy_scope_t lc, cppyy_scope_t rc, const char* op) {
+cppyy_index_t cppyy_get_global_operator(cppyy_scope_t scope, cppyy_scope_t lc, cppyy_scope_t rc, const char* op) {
     Reflex::Type lct = type_from_handle(lc);
     Reflex::Type rct = type_from_handle(rc);
     Reflex::Scope nss = scope_from_handle(scope);


More information about the pypy-commit mailing list