[pypy-commit] pypy cling-support: remove reflex/cint C++ codes

wlav pypy.commits at gmail.com
Tue Nov 22 20:01:03 EST 2016


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: cling-support
Changeset: r88560:e814e2578cfa
Date: 2016-11-22 16:30 -0800
http://bitbucket.org/pypy/pypy/changeset/e814e2578cfa/

Log:	remove reflex/cint C++ codes

diff --git a/pypy/module/cppyy/capi/__init__.py b/pypy/module/cppyy/capi/__init__.py
--- a/pypy/module/cppyy/capi/__init__.py
+++ b/pypy/module/cppyy/capi/__init__.py
@@ -9,8 +9,8 @@
 # the selection of the desired backend (default is Reflex).
 
 # choose C-API access method:
-from pypy.module.cppyy.capi.loadable_capi import *
-#from pypy.module.cppyy.capi.builtin_capi import *
+#from pypy.module.cppyy.capi.loadable_capi import *
+from pypy.module.cppyy.capi.builtin_capi import *
 
 from pypy.module.cppyy.capi.capi_types import C_OBJECT,\
     C_NULL_TYPE, C_NULL_OBJECT
diff --git a/pypy/module/cppyy/include/cintcwrapper.h b/pypy/module/cppyy/include/cintcwrapper.h
deleted file mode 100644
--- a/pypy/module/cppyy/include/cintcwrapper.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef CPPYY_CINTCWRAPPER
-#define CPPYY_CINTCWRAPPER
-
-#include "capi.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif // ifdef __cplusplus
-
-    /* misc helpers */
-    void* cppyy_load_dictionary(const char* lib_name);
-
-    /* pythonization helpers */
-    cppyy_object_t cppyy_create_tf1(const char* funcname, unsigned long address,
-        double xmin, double xmax, int npar);
-
-    cppyy_object_t cppyy_ttree_Branch(
-        void* vtree, const char* branchname, const char* classname,
-        void* addobj, int bufsize, int splitlevel);
-
-    long long cppyy_ttree_GetEntry(void* vtree, long long entry);
-
-    cppyy_object_t cppyy_charp2TString(const char* str);
-    cppyy_object_t cppyy_TString2TString(cppyy_object_t ptr);
-
-#ifdef __cplusplus
-}
-#endif // ifdef __cplusplus
-
-#endif // ifndef CPPYY_CINTCWRAPPER
diff --git a/pypy/module/cppyy/include/reflexcwrapper.h b/pypy/module/cppyy/include/reflexcwrapper.h
deleted file mode 100644
--- a/pypy/module/cppyy/include/reflexcwrapper.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef CPPYY_REFLEXCWRAPPER
-#define CPPYY_REFLEXCWRAPPER
-
-#include "capi.h"
-
-#endif // ifndef CPPYY_REFLEXCWRAPPER
diff --git a/pypy/module/cppyy/src/cintcwrapper.cxx b/pypy/module/cppyy/src/cintcwrapper.cxx
deleted file mode 100644
--- a/pypy/module/cppyy/src/cintcwrapper.cxx
+++ /dev/null
@@ -1,1074 +0,0 @@
-#include "cppyy.h"
-#include "cintcwrapper.h"
-
-#include "TROOT.h"
-#include "TError.h"
-#include "TList.h"
-#include "TSystem.h"
-
-#include "TApplication.h"
-#include "TInterpreter.h"
-#include "TVirtualMutex.h"
-#include "Getline.h"
-
-#include "TBaseClass.h"
-#include "TClass.h"
-#include "TClassEdit.h"
-#include "TClassRef.h"
-#include "TClassTable.h"
-#include "TDataMember.h"
-#include "TFunction.h"
-#include "TGlobal.h"
-#include "TMethod.h"
-#include "TMethodArg.h"
-
-// for pythonization
-#include "TTree.h"
-#include "TBranch.h"
-#include "TF1.h"
-#include "TString.h"
-
-#include "Api.h"
-
-#include <assert.h>
-#include <string.h>
-#include <map>
-#include <sstream>
-#include <string>
-#include <utility>
-
-// for recursive_remove callback
-#include "pypy_macros.h"
-
-
-/* ROOT/CINT internals --------------------------------------------------- */
-extern long G__store_struct_offset;
-extern "C" void G__LockCriticalSection();
-extern "C" void G__UnlockCriticalSection();
-
-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)
-};
-
-// memory regulation (cppyy_recursive_remove is generated as a cpyext capi call)
-extern "C" void _Py_cppyy_recursive_remove(void*);
-
-class Cppyy_MemoryRegulator : public TObject {
-public:
-    virtual void RecursiveRemove(TObject* object) {
-        _Py_cppyy_recursive_remove((void*)object);
-    }
-};
-
-} // unnamed namespace
-
-
-/* data for life time management ------------------------------------------ */
-#define GLOBAL_HANDLE 1l
-
-typedef std::vector<TClassRef> ClassRefs_t;
-static ClassRefs_t g_classrefs(1);
-
-typedef std::map<std::string, ClassRefs_t::size_type> ClassRefIndices_t;
-static ClassRefIndices_t g_classref_indices;
-
-typedef std::vector<TFunction> GlobalFuncs_t;
-static GlobalFuncs_t g_globalfuncs;
-
-typedef std::vector<TGlobal> GlobalVars_t;
-static GlobalVars_t g_globalvars;
-
-typedef std::vector<G__MethodInfo> InterpretedFuncs_t;
-static InterpretedFuncs_t g_interpreted;
-
-
-/* initialization of the ROOT system (debatable ... ) --------------------- */
-namespace {
-
-static Cppyy_MemoryRegulator s_memreg;
-
-class TCppyyApplication : public TApplication {
-public:
-    TCppyyApplication(const char* acn, Int_t* argc, char** argv, Bool_t do_load = kTRUE)
-           : TApplication(acn, argc, argv) {
-
-        // Explicitly load libMathCore as CINT will not auto load it when using
-        // one of its globals. Once moved to Cling, which should work correctly,
-        // we can remove this statement.
-        gSystem->Load("libMathCore");
-
-        if (do_load) {
-            // follow TRint to minimize differences with CINT
-            ProcessLine("#include <iostream>", kTRUE);
-            ProcessLine("#include <_string>",  kTRUE); // for std::string iostream.
-            ProcessLine("#include <DllImport.h>", kTRUE);// Defined R__EXTERN
-            ProcessLine("#include <vector>",   kTRUE); // needed because they're used within the
-            ProcessLine("#include <pair>",     kTRUE); //  core ROOT dicts and CINT won't be able
-                                                       //  to properly unload these files
-        }
-
-        // save current interpreter context
-        gInterpreter->SaveContext();
-        gInterpreter->SaveGlobalsContext();
-
-        // prevent crashes on accessing history
-        Gl_histinit((char*)"-");
-
-        // prevent ROOT from exiting python
-        SetReturnFromRun(kTRUE);
-
-        // enable auto-loader
-        gInterpreter->EnableAutoLoading();
-
-        // enable memory regulation
-        gROOT->GetListOfCleanups()->Add(&s_memreg);
-    }
-};
-
-static const char* appname = "PyPyROOT";
-
-class ApplicationStarter {
-public:
-    ApplicationStarter() {
-        // setup dummy holders for global and std namespaces
-        assert(g_classrefs.size() == (ClassRefs_t::size_type)GLOBAL_HANDLE);
-        g_classref_indices[""] = (ClassRefs_t::size_type)GLOBAL_HANDLE;
-        g_classrefs.push_back(TClassRef(""));
-        // 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());
-
-        // actual application init, if necessary
-        if (!gApplication) {
-            int argc = 1;
-            char* argv[1]; argv[0] = (char*)appname;
-            gApplication = new TCppyyApplication(appname, &argc, argv, kTRUE);
-            if (!gProgName)                  // should have been set by TApplication
-                gSystem->SetProgname(appname);
-        }
-
-        // program name should've been set by TApplication; just in case ...
-        if (!gProgName) {
-            gSystem->SetProgname(appname);
-        }
-    }
-} _applicationStarter;
-
-} // unnamed namespace
-
-
-/* local helpers ---------------------------------------------------------- */
-static inline const std::string resolve_typedef(const std::string& tname) {
-    G__TypeInfo ti(tname.c_str());
-    if (!ti.IsValid())
-        return tname;
-    return TClassEdit::ShortType(TClassEdit::CleanType(ti.TrueName(), 1).c_str(), 3);
-}
-
-static inline char* cppstring_to_cstring(const std::string& name) {
-    char* name_char = (char*)malloc(name.size() + 1);
-    strcpy(name_char, name.c_str());
-    return name_char;
-}
-
-static inline char* type_cppstring_to_cstring(const std::string& tname) {
-    G__TypeInfo ti(tname.c_str());
-    std::string true_name = ti.IsValid() ? ti.TrueName() : tname;
-    return cppstring_to_cstring(true_name);
-}
-
-static inline TClassRef& type_from_handle(cppyy_type_t handle) {
-    assert((ClassRefs_t::size_type)handle < g_classrefs.size());
-    return g_classrefs[(ClassRefs_t::size_type)handle];
-}
-
-static inline TFunction* type_get_method(cppyy_type_t handle, cppyy_index_t idx) {
-    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;
-}
-
-static inline void fixup_args(G__param* libp) {
-    for (int i = 0; i < libp->paran; ++i) {
-        libp->para[i].ref = libp->para[i].obj.i;
-        const char partype = libp->para[i].type;
-        switch (partype) {
-        case 'p': {
-            libp->para[i].obj.i = (long)&libp->para[i].ref;
-            break;
-        }
-        case 'r': {
-            libp->para[i].ref = (long)&libp->para[i].obj.i;
-            break;
-        }
-        case 'f': {
-            float val = libp->para[i].obj.fl;
-            libp->para[i].obj.d = val;
-            break;
-        }
-        case 'F': {
-            libp->para[i].ref = (long)&libp->para[i].obj.i;
-            libp->para[i].type = 'f';
-            break;
-        }
-        case 'D': {
-            libp->para[i].ref = (long)&libp->para[i].obj.i;
-            libp->para[i].type = 'd';
-            break;
-        }
-        }
-    }
-}
-
-
-/* name to opaque C++ scope representation -------------------------------- */
-int cppyy_num_scopes(cppyy_scope_t handle) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    if (cr.GetClass()) {
-        /* not supported as CINT does not store classes hierarchically */
-        return 0;
-    }
-    assert(handle == (cppyy_type_t)GLOBAL_HANDLE);
-    return gClassTable->Classes();
-}
-
-char* cppyy_scope_name(cppyy_scope_t handle, int iscope) {
-    R__LOCKGUARD2(gCINTMutex);
-    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;
-    }
-    assert(handle == (cppyy_type_t)GLOBAL_HANDLE);
-    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) {
-    R__LOCKGUARD2(gCINTMutex);
-    std::string tname = cppitem_name;
-
-    // global namespace?
-    if (tname.empty())
-        return cppstring_to_cstring(cppitem_name);
-
-    // special care needed for builtin arrays
-    std::string::size_type pos = tname.rfind("[");
-    G__TypeInfo ti(tname.substr(0, pos).c_str());
-
-    // if invalid (most likely unknown), simply return old name
-    if (!ti.IsValid())
-        return cppstring_to_cstring(cppitem_name);
-
-    // special case treatment of enum types as unsigned int (CINTism)
-    if (ti.Property() & G__BIT_ISENUM)
-        return cppstring_to_cstring("unsigned int");
-
-    // actual typedef resolution; add back array declaration portion, if needed
-    std::string rt = ti.TrueName();
-
-    // builtin STL types have fake typedefs :/
-    G__TypeInfo ti_test(rt.c_str());
-    if (!ti_test.IsValid())
-        return cppstring_to_cstring(cppitem_name);
-
-    if (pos != std::string::npos)
-        rt += tname.substr(pos, std::string::npos);
-    return cppstring_to_cstring(rt);
-}
-
-cppyy_scope_t cppyy_get_scope(const char* scope_name) {
-    R__LOCKGUARD2(gCINTMutex);
-
-    // CINT still has trouble with std:: sometimes ... 
-    if (strncmp(scope_name, "std::", 5) == 0)
-        scope_name = &scope_name[5];
-
-    ClassRefIndices_t::iterator icr = g_classref_indices.find(scope_name);
-    if (icr != g_classref_indices.end())
-        return (cppyy_type_t)icr->second;
-
-    if (strcmp(scope_name, "#define") == 0)
-        return (cppyy_type_t)NULL;
-
-    // use TClass directly, to enable auto-loading
-    TClassRef cr(TClass::GetClass(scope_name, kTRUE, kTRUE));
-    if (!cr.GetClass())
-        return (cppyy_type_t)NULL;
-
-    if (!cr->GetClassInfo())
-        return (cppyy_type_t)NULL;
-
-    if (!G__TypeInfo(scope_name).IsValid())
-        return (cppyy_type_t)NULL;
-
-    ClassRefs_t::size_type sz = g_classrefs.size();
-    g_classref_indices[scope_name] = sz;
-    g_classrefs.push_back(TClassRef(scope_name));
-    return (cppyy_scope_t)sz;
-}
-
-cppyy_type_t cppyy_get_template(const char* template_name) {
-    R__LOCKGUARD2(gCINTMutex);
-
-    ClassRefIndices_t::iterator icr = g_classref_indices.find(template_name);
-    if (icr != g_classref_indices.end())
-        return (cppyy_type_t)icr->second;
-
-    if (!G__defined_templateclass((char*)template_name))
-        return (cppyy_type_t)NULL;
-
-    // #include for specific, pre-compiled STL classes
-    if (strcmp(template_name, "std::map") == 0)
-        gROOT->ProcessLine("#include <map>");
-
-    // the following yields a dummy TClassRef, but its name can be queried
-    ClassRefs_t::size_type sz = g_classrefs.size();
-    g_classref_indices[template_name] = sz;
-    g_classrefs.push_back(TClassRef(template_name));
-    return (cppyy_type_t)sz;
-}
-
-cppyy_type_t cppyy_actual_class(cppyy_type_t klass, cppyy_object_t obj) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(klass);
-    TClass* clActual = cr->GetActualClass( (void*)obj );
-    if (clActual && clActual != cr.GetClass()) {
-        // TODO: lookup through name should not be needed
-        return (cppyy_type_t)cppyy_get_scope(clActual->GetName());
-    }
-    return klass;
-}
-
-
-/* memory management ------------------------------------------------------ */
-cppyy_object_t cppyy_allocate(cppyy_type_t handle) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    return (cppyy_object_t)malloc(cr->Size());
-}
-
-void cppyy_deallocate(cppyy_type_t /*handle*/, cppyy_object_t instance) {
-    free((void*)instance);
-}
-
-void cppyy_destruct(cppyy_type_t handle, cppyy_object_t self) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    cr->Destructor((void*)self, true);
-}
-
-
-/* method/function dispatching -------------------------------------------- */
-static inline G__value cppyy_call_T(cppyy_method_t method,
-        cppyy_object_t self, int nargs, void* args) {
-
-    R__LOCKGUARD2(gCINTMutex);
-
-    G__param* libp = (G__param*)((char*)args - offsetof(G__param, para));
-    assert(libp->paran == nargs);
-    fixup_args(libp);
-
-    if ((InterpretedFuncs_t::size_type)method < g_interpreted.size()) {
-    // the idea here is that all these low values are invalid memory addresses,
-    // allowing the reuse of method to index the stored bytecodes
-        G__CallFunc callf;
-        callf.SetFunc(g_interpreted[(size_t)method]);
-        G__param p;      // G__param has fixed size; libp is sized to nargs
-        for (int i =0; i<nargs; ++i)
-            p.para[i] = libp->para[i];
-        p.paran = nargs;
-        callf.SetArgs(p);     // will copy p yet again
-        return callf.Execute((void*)self);
-    }
-
-    G__InterfaceMethod meth = (G__InterfaceMethod)method;
-
-    G__value result;
-    G__setnull(&result);
-
-    G__LockCriticalSection();      // CINT-level lock, is recursive
-    G__settemplevel(1);
-
-    long index = (long)&method;
-
-    // TODO: access to store_struct_offset won't work on Windows
-    long store_struct_offset = G__store_struct_offset;
-    if (self)
-        G__store_struct_offset = (long)self;
-
-    meth(&result, (char*)0, libp, 0);
-    if (self)
-        G__store_struct_offset = store_struct_offset;
-
-    if (G__get_return(0) > G__RETURN_NORMAL)
-        G__security_recover(0);    // 0 ensures silence
-
-    G__settemplevel(-1);
-    G__UnlockCriticalSection();
-
-    return result;
-}
-
-void cppyy_call_v(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    cppyy_call_T(method, self, nargs, args);
-}
-
-unsigned char cppyy_call_b(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    G__value result = cppyy_call_T(method, self, nargs, args);
-    return (unsigned char)(bool)G__int(result);
-}
-
-char cppyy_call_c(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    G__value result = cppyy_call_T(method, self, nargs, args);
-    return (char)G__int(result);
-}
-
-short cppyy_call_h(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    G__value result = cppyy_call_T(method, self, nargs, args);
-    return (short)G__int(result);
-}
-
-int cppyy_call_i(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    G__value result = cppyy_call_T(method, self, nargs, args);
-    return (int)G__int(result);
-}
-
-long cppyy_call_l(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    G__value result = cppyy_call_T(method, self, nargs, args);
-    return G__int(result);
-}
-
-long long cppyy_call_ll(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    G__value result = cppyy_call_T(method, self, nargs, args);
-    return G__Longlong(result);
-}
-
-float cppyy_call_f(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    G__value result = cppyy_call_T(method, self, nargs, args);
-    return (float)G__double(result);
-}
-
-double cppyy_call_d(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    G__value result = cppyy_call_T(method, self, nargs, args);
-    return G__double(result);
-}
-
-void* cppyy_call_r(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    G__value result = cppyy_call_T(method, self, nargs, args);
-    return (void*)result.ref;
-}
-
-char* cppyy_call_s(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    R__LOCKGUARD2(gCINTMutex);
-    G__value result = cppyy_call_T(method, self, nargs, args);
-    G__pop_tempobject_nodel();
-    if (result.ref && *(long*)result.ref) {
-        char* charp = cppstring_to_cstring(*(std::string*)result.ref);
-        delete (std::string*)result.ref;
-        return charp;
-    }
-    return cppstring_to_cstring("");
-}
-
-cppyy_object_t cppyy_constructor(cppyy_method_t method, cppyy_type_t handle, int nargs, void* args) {
-    R__LOCKGUARD2(gCINTMutex);
-    cppyy_object_t self = (cppyy_object_t)NULL;
-    if ((InterpretedFuncs_t::size_type)method >= g_interpreted.size()) {
-        G__setgvp((long)G__PVOID);
-        self = (cppyy_object_t)cppyy_call_l(method, (cppyy_object_t)NULL, nargs, args);
-    } else {
-    // for macro's/interpreted classes
-        self = cppyy_allocate(handle);
-        G__setgvp((long)self);
-        cppyy_call_T(method, self, nargs, args);
-    }
-    G__setgvp((long)G__PVOID);
-    return self;
-}
-
-cppyy_object_t cppyy_call_o(cppyy_type_t method, cppyy_object_t self, int nargs, void* args,
-                  cppyy_type_t /*result_type*/ ) {
-    R__LOCKGUARD2(gCINTMutex);
-    G__value result = cppyy_call_T(method, self, nargs, args);
-    G__pop_tempobject_nodel();
-    return (cppyy_object_t)G__int(result);
-}
-
-cppyy_methptrgetter_t cppyy_get_methptr_getter(cppyy_type_t /*handle*/, cppyy_index_t /*idx*/) {
-    return (cppyy_methptrgetter_t)NULL;
-}
-
-
-/* handling of function argument buffer ----------------------------------- */
-void* cppyy_allocate_function_args(int nargs) {
-    assert(sizeof(CPPYY_G__value) == sizeof(G__value));
-    G__param* libp = (G__param*)malloc(
-        offsetof(G__param, para) + nargs*sizeof(CPPYY_G__value));
-    libp->paran = (int)nargs;
-    for (int i = 0; i < nargs; ++i)
-        libp->para[i].type = 'l';
-    return (void*)libp->para;
-}
-
-void cppyy_deallocate_function_args(void* args) {
-    free((char*)args - offsetof(G__param, para));
-}
-
-size_t cppyy_function_arg_sizeof() {
-    return sizeof(CPPYY_G__value);
-}
-
-size_t cppyy_function_arg_typeoffset() {
-    return offsetof(CPPYY_G__value, type);
-}
-
-
-/* scope reflection information ------------------------------------------- */
-int cppyy_is_namespace(cppyy_scope_t handle) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    if (cr.GetClass() && cr->GetClassInfo())
-        return cr->Property() & G__BIT_ISNAMESPACE;
-    if (handle == (cppyy_scope_t)GLOBAL_HANDLE)
-        return true;
-    return false;
-}
-
-int cppyy_is_enum(const char* type_name) {
-    R__LOCKGUARD2(gCINTMutex);
-    G__TypeInfo ti(type_name);
-    return (ti.Property() & G__BIT_ISENUM);
-}
-
-
-/* type/class reflection information -------------------------------------- */
-char* cppyy_final_name(cppyy_type_t handle) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    if (cr.GetClass() && cr->GetClassInfo()) {
-        std::string true_name = G__TypeInfo(cr->GetName()).TrueName();
-        std::string::size_type pos = true_name.rfind("::");
-        if (pos != std::string::npos)
-            return cppstring_to_cstring(true_name.substr(pos+2, std::string::npos));
-        return cppstring_to_cstring(true_name);
-    }
-    return cppstring_to_cstring(cr.GetClassName());
-}
-
-char* cppyy_scoped_final_name(cppyy_type_t handle) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    if (cr.GetClass() && cr->GetClassInfo()) {
-        std::string true_name = G__TypeInfo(cr->GetName()).TrueName();
-        return cppstring_to_cstring(true_name);
-    }
-    return cppstring_to_cstring(cr.GetClassName());
-}
-
-int cppyy_has_complex_hierarchy(cppyy_type_t handle) {
-// as long as no fast path is supported for CINT, calculating offsets (which
-// are cached by the JIT) is not going to hurt 
-    return 1;
-}
-
-int cppyy_num_bases(cppyy_type_t handle) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    if (cr.GetClass() && cr->GetListOfBases() != 0)
-        return cr->GetListOfBases()->GetSize();
-    return 0;
-}
-
-char* cppyy_base_name(cppyy_type_t handle, int base_index) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    TBaseClass* b = (TBaseClass*)cr->GetListOfBases()->At(base_index);
-    return type_cppstring_to_cstring(b->GetName());
-}
-
-int cppyy_is_subtype(cppyy_type_t derived_handle, cppyy_type_t base_handle) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& derived_type = type_from_handle(derived_handle);
-    TClassRef& base_type = type_from_handle(base_handle);
-    return derived_type->GetBaseClass(base_type) != 0;
-}
-
-ptrdiff_t cppyy_base_offset(cppyy_type_t derived_handle, cppyy_type_t base_handle,
-                       cppyy_object_t address, int /* direction */) {
-    R__LOCKGUARD2(gCINTMutex);
-
-    // WARNING: CINT can not handle actual dynamic casts!
-    TClassRef& derived_type = type_from_handle(derived_handle);
-    TClassRef& base_type = type_from_handle(base_handle);
-
-    long offset = 0;
-
-    if (derived_type && base_type) {
-        G__ClassInfo* base_ci    = (G__ClassInfo*)base_type->GetClassInfo();
-        G__ClassInfo* derived_ci = (G__ClassInfo*)derived_type->GetClassInfo();
-
-        if (base_ci && derived_ci) {
-#ifdef WIN32
-            // Windows cannot cast-to-derived for virtual inheritance
-            // with CINT's (or Reflex's) interfaces.
-            long baseprop = derived_ci->IsBase(*base_ci);
-            if (!baseprop || (baseprop & G__BIT_ISVIRTUALBASE))
-                offset = derived_type->GetBaseClassOffset(base_type);
-            else
-#endif
-                offset = G__isanybase(base_ci->Tagnum(), derived_ci->Tagnum(), (long)address);
-         } else {
-             offset = derived_type->GetBaseClassOffset(base_type);
-         }
-    }
-
-    return (ptrdiff_t) offset;   // may be negative (will roll over)
-}
-
-
-/* method/function reflection information --------------------------------- */
-int cppyy_num_methods(cppyy_scope_t handle) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    if (cr.GetClass() && cr->GetListOfMethods())
-        return cr->GetListOfMethods()->GetSize();
-    else if (handle == (cppyy_scope_t)GLOBAL_HANDLE) {
-        if (g_globalfuncs.empty()) {
-            TCollection* funcs = gROOT->GetListOfGlobalFunctions(kTRUE);
-	    g_globalfuncs.reserve(funcs->GetSize());
-
-            TIter ifunc(funcs);
-
-            TFunction* func = 0;
-            while ((func = (TFunction*)ifunc.Next())) {
-                if (strcmp(func->GetName(), "G__ateval") != 0)
-                    g_globalfuncs.push_back(*func);
-            }
-        }
-	return (int)g_globalfuncs.size();
-    }
-    return 0;
-}
-
-cppyy_index_t cppyy_method_index_at(cppyy_scope_t handle, int imeth) {
-    R__LOCKGUARD2(gCINTMutex);
-    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];
-}
-
-cppyy_index_t* cppyy_method_indices_from_name(cppyy_scope_t handle, const char* name) {
-    R__LOCKGUARD2(gCINTMutex);
-
-    std::vector<cppyy_index_t> result;
-    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)
-                    result.push_back((cppyy_index_t)imeth);
-            }
-            ++imeth;
-        }
-    } 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(name, func->GetName()) == 0) {
-                g_globalfuncs.push_back(*func);
-                result.push_back((cppyy_index_t)func); 
-            }
-        }
-    }
-
-    if (result.empty())
-        return (cppyy_index_t*)0;
-
-    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;
-}
-
-
-char* cppyy_method_name(cppyy_scope_t handle, cppyy_index_t idx) {
-    R__LOCKGUARD2(gCINTMutex);
-    TFunction* f = type_get_method(handle, idx);
-    std::string name = f->GetName();
-    TClassRef& cr = type_from_handle(handle);
-    if (cr.GetClass() && cppyy_is_constructor(handle, idx))
-        return cppstring_to_cstring(name);
-    if (cppyy_method_is_template(handle, idx))
-       return cppstring_to_cstring(name.substr(0, name.find('<')));
-    return cppstring_to_cstring(name);
-}
-
-char* cppyy_method_result_type(cppyy_scope_t handle, cppyy_index_t idx) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    if (cr.GetClass() && cppyy_is_constructor(handle, idx))
-        return cppstring_to_cstring("constructor");
-    TFunction* f = type_get_method(handle, idx);
-    return type_cppstring_to_cstring(f->GetReturnTypeName());
-}
-
-int cppyy_method_num_args(cppyy_scope_t handle, cppyy_index_t idx) {
-    R__LOCKGUARD2(gCINTMutex);
-    TFunction* f = type_get_method(handle, idx);
-    return f->GetNargs();
-}
-
-int cppyy_method_req_args(cppyy_scope_t handle, cppyy_index_t idx) {
-    R__LOCKGUARD2(gCINTMutex);
-    TFunction* f = type_get_method(handle, idx);
-    return f->GetNargs() - f->GetNargsOpt();
-}
-
-char* cppyy_method_arg_type(cppyy_scope_t handle, cppyy_index_t idx, int arg_index) {
-    R__LOCKGUARD2(gCINTMutex);
-    TFunction* f = type_get_method(handle, idx);
-    TMethodArg* arg = (TMethodArg*)f->GetListOfMethodArgs()->At(arg_index);
-    return type_cppstring_to_cstring(arg->GetFullTypeName());
-}
-
-char* cppyy_method_arg_default(cppyy_scope_t /*handle*/, cppyy_index_t /*idx*/, int /*arg_index*/) {
-    /* unused: libffi does not work with CINT back-end */
-    return cppstring_to_cstring("");
-}
-
-char* cppyy_method_signature(cppyy_scope_t handle, cppyy_index_t idx) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    TFunction* f = type_get_method(handle, idx);
-    std::ostringstream sig;
-    if (cr.GetClass() && cr->GetClassInfo()
-        && strcmp(f->GetName(), ((G__ClassInfo*)cr->GetClassInfo())->Name()) != 0)
-        sig << f->GetReturnTypeName() << " ";
-    sig << cr.GetClassName() << "::" << f->GetName() << "(";
-    int nArgs = f->GetNargs();
-    for (int iarg = 0; iarg < nArgs; ++iarg) {
-        sig << ((TMethodArg*)f->GetListOfMethodArgs()->At(iarg))->GetFullTypeName();
-        if (iarg != nArgs-1)
-            sig << ", ";
-    }
-    sig << ")" << std::ends;
-    return cppstring_to_cstring(sig.str());
-}
-
-
-int cppyy_method_is_template(cppyy_scope_t handle, cppyy_index_t idx) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    TFunction* f = type_get_method(handle, idx);
-    std::string name = f->GetName();
-    return (name[name.size()-1] == '>') && (name.find('<') != std::string::npos);
-}
-
-int cppyy_method_num_template_args(cppyy_scope_t /*handle*/, cppyy_index_t /*idx*/) {
-// TODO: somehow count from the actual arguments
-    return 1;
-}
-
-char* cppyy_method_template_arg_name(
-        cppyy_scope_t handle, cppyy_index_t idx, cppyy_index_t /*iarg*/) {
-    R__LOCKGUARD2(gCINTMutex);
-// TODO: return only the name for the requested arg
-    TClassRef& cr = type_from_handle(handle);
-    TFunction* f = type_get_method(handle, idx);
-    std::string name = f->GetName();
-    std::string::size_type pos = name.find('<');
-    return cppstring_to_cstring(resolve_typedef(name.substr(pos+1, name.size()-pos-2)));
-}
-
-
-cppyy_method_t cppyy_get_method(cppyy_scope_t handle, cppyy_index_t idx) {
-    R__LOCKGUARD2(gCINTMutex);
-
-    TClassRef& cr = type_from_handle(handle);
-    TFunction* f = type_get_method(handle, idx);
-    if (cr && cr.GetClass() && !cr->IsLoaded()) {
-        G__ClassInfo* gcl = (G__ClassInfo*)cr->GetClassInfo();
-        if (gcl) {
-            long offset;
-            std::ostringstream sig;
-            int nArgs = f->GetNargs();
-            for (int iarg = 0; iarg < nArgs; ++iarg) {
-                sig << ((TMethodArg*)f->GetListOfMethodArgs()->At(iarg))->GetFullTypeName();
-                if (iarg != nArgs-1) sig << ", ";
-            }
-            G__MethodInfo gmi = gcl->GetMethod(
-                f->GetName(), sig.str().c_str(), &offset, G__ClassInfo::ExactMatch);
-            cppyy_method_t method = (cppyy_method_t)g_interpreted.size();
-            g_interpreted.push_back(gmi);
-            return method;
-        }
-    }
-    cppyy_method_t method = (cppyy_method_t)f->InterfaceMethod();
-    return method;
-}
-
-cppyy_index_t cppyy_get_global_operator(cppyy_scope_t scope, cppyy_scope_t lc, cppyy_scope_t rc, const char* op) {
-    R__LOCKGUARD2(gCINTMutex);
-
-    TClassRef& lccr = type_from_handle(lc);
-    TClassRef& rccr = type_from_handle(rc);
-
-    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();
-    std::string rcname = rccr->GetName();
-
-    std::string opname = "operator";
-    opname += op;
-
-    for (int idx = 0; idx < (int)g_globalfuncs.size(); ++idx) {
-        TFunction* func = &g_globalfuncs[idx];
-        if (func->GetListOfMethodArgs()->GetSize() != 2)
-            continue;
-
-        if (func->GetName() == opname) {
-            if (lcname == resolve_typedef(((TMethodArg*)func->GetListOfMethodArgs()->At(0))->GetTypeName()) &&
-                rcname == resolve_typedef(((TMethodArg*)func->GetListOfMethodArgs()->At(1))->GetTypeName())) {
-                return (cppyy_index_t)func;
-            }
-        }
-    }
-
-    return (cppyy_index_t)-1;
-}
-
-
-/* method properties -----------------------------------------------------  */
-int cppyy_is_constructor(cppyy_type_t handle, cppyy_index_t idx) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    TMethod* m = (TMethod*)cr->GetListOfMethods()->At(idx);
-    return strcmp(m->GetName(), ((G__ClassInfo*)cr->GetClassInfo())->Name()) == 0;
-}
-
-int cppyy_is_staticmethod(cppyy_type_t handle, cppyy_index_t idx) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    TMethod* m = (TMethod*)cr->GetListOfMethods()->At(idx);
-    return m->Property() & G__BIT_ISSTATIC;
-}
-
-
-/* data member reflection information ------------------------------------- */
-int cppyy_num_datamembers(cppyy_scope_t handle) {
-    R__LOCKGUARD2(gCINTMutex);
-
-    TClassRef& cr = type_from_handle(handle);
-    if (cr.GetClass() && cr->GetListOfDataMembers())
-        return cr->GetListOfDataMembers()->GetSize();
-    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();
-	    g_globalvars.reserve(vars->GetSize());
-
-            TIter ivar(vars);
-
-            TGlobal* var = 0;
-            while ((var = (TGlobal*)ivar.Next()))
-                g_globalvars.push_back(*var);
-
-        }
-	return (int)g_globalvars.size();
-    }
-    return 0;
-}
-
-char* cppyy_datamember_name(cppyy_scope_t handle, int datamember_index) {
-    R__LOCKGUARD2(gCINTMutex);
-
-    TClassRef& cr = type_from_handle(handle);
-    if (cr.GetClass()) {
-        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());
-}
-
-char* cppyy_datamember_type(cppyy_scope_t handle, int datamember_index) {
-    R__LOCKGUARD2(gCINTMutex);
-
-    TClassRef& cr = type_from_handle(handle);
-    if (cr.GetClass())  {
-        TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At(datamember_index);
-        std::string fullType = m->GetFullTypeName();
-        if ((int)m->GetArrayDim() > 1 || (!m->IsBasic() && m->IsaPointer()))
-            fullType.append("*");
-        else if ((int)m->GetArrayDim() == 1) {
-            std::ostringstream s;
-            s << '[' << m->GetMaxIndex(0) << ']' << std::ends;
-            fullType.append(s.str());
-        }
-        return cppstring_to_cstring(fullType);
-    }
-    assert(handle == (cppyy_type_t)GLOBAL_HANDLE);
-    TGlobal& gbl = g_globalvars[datamember_index];
-    return cppstring_to_cstring(gbl.GetFullTypeName());
-}
-
-ptrdiff_t cppyy_datamember_offset(cppyy_scope_t handle, int datamember_index) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    if (cr.GetClass()) {
-        TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At(datamember_index);
-        return (ptrdiff_t)m->GetOffsetCint();
-    }
-    assert(handle == (cppyy_type_t)GLOBAL_HANDLE);
-    TGlobal& gbl = g_globalvars[datamember_index];
-    return (ptrdiff_t)gbl.GetAddress();
-}
-
-int cppyy_datamember_index(cppyy_scope_t handle, const char* name) {
-    R__LOCKGUARD2(gCINTMutex);
-
-    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;
-        }
-    } 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;
-    }
-    return -1;
-}
-
-
-/* data member properties ------------------------------------------------  */
-int cppyy_is_publicdata(cppyy_scope_t handle, int datamember_index) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    if (cr.GetClass()) {
-        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
-}
-
-int cppyy_is_staticdata(cppyy_scope_t handle, int datamember_index) {
-    R__LOCKGUARD2(gCINTMutex);
-    TClassRef& cr = type_from_handle(handle);
-    if (cr.GetClass()) {
-        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
-}
-
-
-/* misc helpers ----------------------------------------------------------- */
-long long cppyy_strtoll(const char* str) {
-    return strtoll(str, NULL, 0);
-}
-
-extern "C" unsigned long long cppyy_strtoull(const char* str) {
-    return strtoull(str, NULL, 0);
-}
-
-void cppyy_free(void* ptr) {
-    free(ptr);
-}
-
-cppyy_object_t cppyy_charp2stdstring(const char* str) {
-    return (cppyy_object_t)new std::string(str);
-}
-
-cppyy_object_t cppyy_stdstring2stdstring(cppyy_object_t ptr) {
-    return (cppyy_object_t)new std::string(*(std::string*)ptr);
-}
-
-
-void* cppyy_load_dictionary(const char* lib_name) {
-    R__LOCKGUARD2(gCINTMutex);
-    if (0 <= gSystem->Load(lib_name))
-        return (void*)1;
-    return (void*)0;
-}
-
-
-/* pythonization helpers -------------------------------------------------- */
-typedef double (*tfn_callback)(double*, double*);
-
-cppyy_object_t cppyy_create_tf1(const char* funcname, unsigned long address,
-        double xmin, double xmax, int npar) {
-    return (cppyy_object_t)new TF1(funcname, (tfn_callback)address, xmin, xmax, npar);
-}
-
-cppyy_object_t cppyy_ttree_Branch(void* vtree, const char* branchname, const char* classname,
-        void* addobj, int bufsize, int splitlevel) {
-    // this little song-and-dance is to by-pass the handwritten Branch methods
-    TBranch* b = ((TTree*)vtree)->Bronch(branchname, classname, (void*)&addobj, bufsize, splitlevel);
-    if (b) b->SetObject(addobj);
-    return (cppyy_object_t)b;
-}
-
-long long cppyy_ttree_GetEntry(void* vtree, long long entry) {
-    return (long long)((TTree*)vtree)->GetEntry((Long64_t)entry);
-}
-
-cppyy_object_t cppyy_charp2TString(const char* str) {
-    return (cppyy_object_t)new TString(str);
-}
-
-cppyy_object_t cppyy_TString2TString(cppyy_object_t ptr) {
-    return (cppyy_object_t)new TString(*(TString*)ptr);
-}
diff --git a/pypy/module/cppyy/src/reflexcwrapper.cxx b/pypy/module/cppyy/src/reflexcwrapper.cxx
deleted file mode 100644
--- a/pypy/module/cppyy/src/reflexcwrapper.cxx
+++ /dev/null
@@ -1,627 +0,0 @@
-#include "cppyy.h"
-#include "reflexcwrapper.h"
-
-#include "Reflex/Kernel.h"
-#include "Reflex/Type.h"
-#include "Reflex/Base.h"
-#include "Reflex/Member.h"
-#include "Reflex/Object.h"
-#include "Reflex/Builder/TypeBuilder.h"
-#include "Reflex/PropertyList.h"
-#include "Reflex/TypeTemplate.h"
-
-#define private public
-#include "Reflex/PluginService.h"
-#undef private
-
-#include <string>
-#include <sstream>
-#include <utility>
-#include <vector>
-
-#include <assert.h>
-#include <stdlib.h>
-
-
-/* local helpers ---------------------------------------------------------- */
-static inline char* cppstring_to_cstring(const std::string& name) {
-    char* name_char = (char*)malloc(name.size() + 1);
-    strcpy(name_char, name.c_str());
-    return name_char;
-}
-
-static inline Reflex::Scope scope_from_handle(cppyy_type_t handle) {
-    return Reflex::Scope((Reflex::ScopeName*)handle);
-}
-
-static inline Reflex::Type type_from_handle(cppyy_type_t handle) {
-    return Reflex::Scope((Reflex::ScopeName*)handle);
-}
-
-static inline std::vector<void*> build_args(int nargs, void* args) {
-    std::vector<void*> arguments;
-    arguments.reserve(nargs);
-    for (int i = 0; i < nargs; ++i) {
-	char tc = ((CPPYY_G__value*)args)[i].type;
-        if (tc != 'a' && tc != 'o')
-            arguments.push_back(&((CPPYY_G__value*)args)[i]);
-        else
-            arguments.push_back((void*)(*(long*)&((CPPYY_G__value*)args)[i]));
-    }
-    return arguments;
-}
-
-
-/* name to opaque C++ scope representation -------------------------------- */
-int cppyy_num_scopes(cppyy_scope_t handle) {
-    Reflex::Scope s = scope_from_handle(handle);
-    return s.SubScopeSize();
-}
-
-char* cppyy_scope_name(cppyy_scope_t handle, int iscope) {
-    Reflex::Scope s = scope_from_handle(handle);
-    std::string name = s.SubScopeAt(iscope).Name(Reflex::F);
-    return cppstring_to_cstring(name);
-}
-
-char* cppyy_resolve_name(const char* cppitem_name) {
-    Reflex::Scope s = Reflex::Scope::ByName(cppitem_name);
-    if (s.IsEnum())
-        return cppstring_to_cstring("unsigned int");
-    const std::string& name = s.Name(Reflex::SCOPED|Reflex::QUALIFIED|Reflex::FINAL);
-    if (name.empty())
-        return cppstring_to_cstring(cppitem_name);
-    return cppstring_to_cstring(name);
-}
-
-cppyy_scope_t cppyy_get_scope(const char* scope_name) {
-    Reflex::Scope s = Reflex::Scope::ByName(scope_name);
-    if (!s) Reflex::PluginService::Instance().LoadFactoryLib(scope_name);
-    s = Reflex::Scope::ByName(scope_name);
-    if (s.IsEnum())     // pretend to be builtin by returning 0
-        return (cppyy_type_t)0;
-    return (cppyy_type_t)s.Id();
-}
-
-cppyy_type_t cppyy_get_template(const char* template_name) {
-   Reflex::TypeTemplate tt = Reflex::TypeTemplate::ByName(template_name);
-   return (cppyy_type_t)tt.Id();
-}
-
-cppyy_type_t cppyy_actual_class(cppyy_type_t klass, cppyy_object_t obj) {
-    Reflex::Type t = type_from_handle(klass);
-    Reflex::Type tActual = t.DynamicType(Reflex::Object(t, (void*)obj));
-    if (tActual && tActual != t) {
-        // TODO: lookup through name should not be needed (but tActual.Id()
-        // does not return a singular Id for the system :( )
-        return (cppyy_type_t)cppyy_get_scope(tActual.Name().c_str());
-    }
-    return klass;
-}
-
-
-/* memory management ------------------------------------------------------ */
-cppyy_object_t cppyy_allocate(cppyy_type_t handle) {
-    Reflex::Type t = type_from_handle(handle);
-    return (cppyy_object_t)t.Allocate();
-}
-
-void cppyy_deallocate(cppyy_type_t handle, cppyy_object_t instance) {
-    Reflex::Type t = type_from_handle(handle);
-    t.Deallocate((void*)instance);
-}
-
-void cppyy_destruct(cppyy_type_t handle, cppyy_object_t self) {
-    Reflex::Type t = type_from_handle(handle);
-    t.Destruct((void*)self, true);
-}
-
-
-/* method/function dispatching -------------------------------------------- */
-void cppyy_call_v(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    std::vector<void*> arguments = build_args(nargs, args);
-    Reflex::StubFunction stub = (Reflex::StubFunction)method;
-    stub(NULL /* return address */, (void*)self, arguments, NULL /* stub context */);
-}
-
-template<typename T>
-static inline T cppyy_call_T(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    T result;
-    std::vector<void*> arguments = build_args(nargs, args);
-    Reflex::StubFunction stub = (Reflex::StubFunction)method;
-    stub(&result, (void*)self, arguments, NULL /* stub context */);
-    return result;
-}
-
-unsigned char cppyy_call_b(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    return (unsigned char)cppyy_call_T<bool>(method, self, nargs, args);
-}
-
-char cppyy_call_c(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    return cppyy_call_T<char>(method, self, nargs, args);
-}
-
-short cppyy_call_h(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    return cppyy_call_T<short>(method, self, nargs, args);
-}
-
-int cppyy_call_i(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    return cppyy_call_T<int>(method, self, nargs, args);
-}
-
-long cppyy_call_l(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    return cppyy_call_T<long>(method, self, nargs, args);
-}
-
-long long cppyy_call_ll(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    return cppyy_call_T<long long>(method, self, nargs, args);
-}
-
-float cppyy_call_f(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    return cppyy_call_T<float>(method, self, nargs, args);
-}
-
-double cppyy_call_d(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    return cppyy_call_T<double>(method, self, nargs, args);
-}
-
-void* cppyy_call_r(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    return (void*)cppyy_call_T<long>(method, self, nargs, args);
-}
-
-char* cppyy_call_s(cppyy_method_t method, cppyy_object_t self, int nargs, void* args) {
-    std::string* cppresult = (std::string*)malloc(sizeof(std::string));
-    std::vector<void*> arguments = build_args(nargs, args);
-    Reflex::StubFunction stub = (Reflex::StubFunction)method;
-    stub(cppresult, (void*)self, arguments, NULL /* stub context */);
-    char* cstr = cppstring_to_cstring(*cppresult);
-    cppresult->std::string::~string();
-    free((void*)cppresult);        // the stub will have performed a placement-new
-    return cstr;
-}
-
-cppyy_object_t cppyy_constructor(cppyy_method_t method, cppyy_type_t handle, int nargs, void* args) {
-    cppyy_object_t self = cppyy_allocate(handle);
-    cppyy_call_v(method, self, nargs, args);
-    return self;
-}
-
-cppyy_object_t cppyy_call_o(cppyy_method_t method, cppyy_object_t self, int nargs, void* args,
-                  cppyy_type_t result_type) {
-    void* result = (void*)cppyy_allocate(result_type);
-    std::vector<void*> arguments = build_args(nargs, args);
-    Reflex::StubFunction stub = (Reflex::StubFunction)method;
-    stub(result, (void*)self, arguments, NULL /* stub context */);
-    return (cppyy_object_t)result;
-}
-
-static cppyy_methptrgetter_t get_methptr_getter(Reflex::Member m) {
-    Reflex::PropertyList plist = m.Properties();
-    if (plist.HasProperty("MethPtrGetter")) {
-        Reflex::Any& value = plist.PropertyValue("MethPtrGetter");
-        return (cppyy_methptrgetter_t)Reflex::any_cast<void*>(value);
-    }
-    return 0;
-}
-
-cppyy_methptrgetter_t cppyy_get_methptr_getter(cppyy_type_t handle, cppyy_index_t method_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.FunctionMemberAt(method_index);
-    return get_methptr_getter(m);
-}
-
-
-/* handling of function argument buffer ----------------------------------- */
-void* cppyy_allocate_function_args(int nargs) {
-    CPPYY_G__value* args = (CPPYY_G__value*)malloc(nargs*sizeof(CPPYY_G__value));
-    for (int i = 0; i < nargs; ++i)
-        args[i].type = 'l';
-    return (void*)args;
-}
-
-void cppyy_deallocate_function_args(void* args) {
-    free(args);
-}
-
-size_t cppyy_function_arg_sizeof() {
-    return sizeof(CPPYY_G__value);
-}
-
-size_t cppyy_function_arg_typeoffset() {
-    return offsetof(CPPYY_G__value, type);
-}
-
-
-/* scope reflection information ------------------------------------------- */
-int cppyy_is_namespace(cppyy_scope_t handle) {
-    Reflex::Scope s = scope_from_handle(handle);
-    return s.IsNamespace();
-}
-
-int cppyy_is_enum(const char* type_name) {
-    Reflex::Type t = Reflex::Type::ByName(type_name);
-    return t.IsEnum();
-}
-
-
-/* class reflection information ------------------------------------------- */
-char* cppyy_final_name(cppyy_type_t handle) {
-    Reflex::Scope s = scope_from_handle(handle);
-    if (s.IsEnum())
-        return cppstring_to_cstring("unsigned int");
-    std::string name = s.Name(Reflex::FINAL);
-    return cppstring_to_cstring(name);
-}
-
-char* cppyy_scoped_final_name(cppyy_type_t handle) {
-    Reflex::Scope s = scope_from_handle(handle);
-    if (s.IsEnum())
-        return cppstring_to_cstring("unsigned int");
-    std::string name = s.Name(Reflex::SCOPED | Reflex::FINAL);
-    return cppstring_to_cstring(name);
-}   
-
-static int cppyy_has_complex_hierarchy(const Reflex::Type& t) {
-    int is_complex = 1;
-    
-    size_t nbases = t.BaseSize();
-    if (1 < nbases)
-        is_complex = 1;
-    else if (nbases == 0)
-        is_complex = 0;
-    else {         // one base class only
-        Reflex::Base b = t.BaseAt(0);
-        if (b.IsVirtual())
-            is_complex = 1;       // TODO: verify; can be complex, need not be.
-        else
-            is_complex = cppyy_has_complex_hierarchy(t.BaseAt(0).ToType());
-    }
-
-    return is_complex;
-}   
-
-int cppyy_has_complex_hierarchy(cppyy_type_t handle) {
-    Reflex::Type t = type_from_handle(handle);
-    return cppyy_has_complex_hierarchy(t);
-}
-
-int cppyy_num_bases(cppyy_type_t handle) {
-    Reflex::Type t = type_from_handle(handle);
-    std::string name = t.Name(Reflex::FINAL|Reflex::SCOPED);
-    if (5 < name.size() && name.substr(0, 5) == "std::") {
-        // special case: STL base classes are usually unnecessary,
-        // so either build all (i.e. if available) or none
-        for (int i=0; i < (int)t.BaseSize(); ++i)
-            if (!t.BaseAt(i)) return 0;
-    }
-    return t.BaseSize();
-}
-
-char* cppyy_base_name(cppyy_type_t handle, int base_index) {
-    Reflex::Type t = type_from_handle(handle);
-    Reflex::Base b = t.BaseAt(base_index);
-    std::string name = b.Name(Reflex::FINAL|Reflex::SCOPED);
-    return cppstring_to_cstring(name);
-}
-
-int cppyy_is_subtype(cppyy_type_t derived_handle, cppyy_type_t base_handle) {
-    Reflex::Type derived_type = type_from_handle(derived_handle);
-    Reflex::Type base_type = type_from_handle(base_handle);
-    return (int)derived_type.HasBase(base_type);
-}
-
-ptrdiff_t cppyy_base_offset(cppyy_type_t derived_handle, cppyy_type_t base_handle,
-                       cppyy_object_t address, int direction) {
-    Reflex::Type derived_type = type_from_handle(derived_handle);
-    Reflex::Type base_type = type_from_handle(base_handle);
-
-    // when dealing with virtual inheritance the only (reasonably) well-defined info is
-    // in a Reflex internal base table, that contains all offsets within the hierarchy
-    Reflex::Member getbases = derived_type.FunctionMemberByName(
-           "__getBasesTable", Reflex::Type(), 0, Reflex::INHERITEDMEMBERS_NO, Reflex::DELAYEDLOAD_OFF);
-    if (getbases) {
-        typedef std::vector<std::pair<Reflex::Base, int> > Bases_t;
-        Bases_t* bases;
-        Reflex::Object bases_holder(Reflex::Type::ByTypeInfo(typeid(Bases_t)), &bases);
-        getbases.Invoke(&bases_holder);
-
-        // if direction is down-cast, perform the cast in C++ first in order to ensure
-        // we have a derived object for accessing internal offset pointers
-        if (direction < 0) {
-           Reflex::Object o(base_type, (void*)address);
-           address = (cppyy_object_t)o.CastObject(derived_type).Address();
-        }
-
-        for (Bases_t::iterator ibase = bases->begin(); ibase != bases->end(); ++ibase) {
-            if (ibase->first.ToType() == base_type) {
-                long offset = (long)ibase->first.Offset((void*)address);
-                if (direction < 0)
-                    return (ptrdiff_t) -offset;  // note negative; rolls over
-                return (ptrdiff_t)offset;
-            }
-        }
-
-        // contrary to typical invoke()s, the result of the internal getbases function
-        // is a pointer to a function static, so no delete
-    }
-
-    return 0;
-}
-
-
-/* method/function reflection information --------------------------------- */
-int cppyy_num_methods(cppyy_scope_t handle) {
-    Reflex::Scope s = scope_from_handle(handle);
-    return s.FunctionMemberSize();
-}
-
-cppyy_index_t cppyy_method_index_at(cppyy_scope_t scope, int imeth) {
-    return (cppyy_index_t)imeth;
-}
-
-cppyy_index_t* cppyy_method_indices_from_name(cppyy_scope_t handle, const char* name) {
-    std::vector<cppyy_index_t> result;
-    Reflex::Scope s = scope_from_handle(handle);
-    // the following appears dumb, but the internal storage for Reflex is an
-    // unsorted std::vector anyway, so there's no gain to be had in using the
-    // Scope::FunctionMemberByName() function
-    int num_meth = s.FunctionMemberSize();
-    for (int imeth = 0; imeth < num_meth; ++imeth) {
-        Reflex::Member m = s.FunctionMemberAt(imeth);
-        if (m.Name() == name) {
-            if (m.IsPublic())
-                result.push_back((cppyy_index_t)imeth);
-        }
-    }
-    if (result.empty())
-        return (cppyy_index_t*)0;
-    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;
-}
-
-char* cppyy_method_name(cppyy_scope_t handle, cppyy_index_t method_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.FunctionMemberAt(method_index);
-    std::string name;
-    if (m.IsConstructor())
-        name = s.Name(Reflex::FINAL);   // to get proper name for templates
-    else if (m.IsTemplateInstance()) {
-        name = m.Name();
-        std::string::size_type pos = name.find('<');
-        name = name.substr(0, pos);     // strip template argument portion for overload
-    } else
-        name = m.Name();
-    return cppstring_to_cstring(name);
-}
-
-char* cppyy_method_result_type(cppyy_scope_t handle, cppyy_index_t method_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.FunctionMemberAt(method_index);
-    if (m.IsConstructor())
-        return cppstring_to_cstring("constructor");
-    Reflex::Type rt = m.TypeOf().ReturnType();
-    std::string name = rt.Name(Reflex::FINAL|Reflex::SCOPED|Reflex::QUALIFIED);
-    return cppstring_to_cstring(name);
-}
-
-int cppyy_method_num_args(cppyy_scope_t handle, cppyy_index_t method_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.FunctionMemberAt(method_index);
-    return m.FunctionParameterSize();
-}
-
-int cppyy_method_req_args(cppyy_scope_t handle, cppyy_index_t method_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.FunctionMemberAt(method_index);
-    return m.FunctionParameterSize(true);
-}
-
-char* cppyy_method_arg_type(cppyy_scope_t handle, cppyy_index_t method_index, int arg_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.FunctionMemberAt(method_index);
-    Reflex::Type at = m.TypeOf().FunctionParameterAt(arg_index);
-    std::string name = at.Name(Reflex::FINAL|Reflex::SCOPED|Reflex::QUALIFIED);
-    return cppstring_to_cstring(name);
-}
-
-char* cppyy_method_arg_default(cppyy_scope_t handle, cppyy_index_t method_index, int arg_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.FunctionMemberAt(method_index);
-    std::string dflt = m.FunctionParameterDefaultAt(arg_index);
-    return cppstring_to_cstring(dflt);
-}
-
-char* cppyy_method_signature(cppyy_scope_t handle, cppyy_index_t method_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.FunctionMemberAt(method_index);
-    Reflex::Type mt = m.TypeOf();
-    std::ostringstream sig;
-    if (!m.IsConstructor())
-        sig << mt.ReturnType().Name() << " ";
-    sig << s.Name(Reflex::SCOPED) << "::" << m.Name() << "(";
-    int nArgs = m.FunctionParameterSize();
-    for (int iarg = 0; iarg < nArgs; ++iarg) {
-        sig << mt.FunctionParameterAt(iarg).Name(Reflex::SCOPED|Reflex::QUALIFIED);
-        if (iarg != nArgs-1)
-            sig << ", ";
-    }
-    sig << ")" << std::ends;
-    return cppstring_to_cstring(sig.str());
-}
-
-
-int cppyy_method_is_template(cppyy_scope_t handle, cppyy_index_t method_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.FunctionMemberAt(method_index);
-    return m.IsTemplateInstance();
-}
-
-int cppyy_method_num_template_args(cppyy_scope_t handle, cppyy_index_t method_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.FunctionMemberAt(method_index);
-    assert(m.IsTemplateInstance());
-    return m.TemplateArgumentSize();
-}
-
-char* cppyy_method_template_arg_name(
-        cppyy_scope_t handle, cppyy_index_t method_index, cppyy_index_t iarg) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.FunctionMemberAt(method_index);
-    assert(m.IsTemplateInstance());
-    return cppstring_to_cstring(
-       m.TemplateArgumentAt(iarg).Name(Reflex::SCOPED|Reflex::QUALIFIED));
-}
-
-
-cppyy_method_t cppyy_get_method(cppyy_scope_t handle, cppyy_index_t method_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.FunctionMemberAt(method_index);
-    return (cppyy_method_t)m.Stubfunction();
-}
-
-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);
-
-    if (!lct || !rct || !nss) 
-        return (cppyy_index_t)-1;  // (void*)-1 is in kernel space, so invalid as a method handle
-
-    std::string lcname = lct.Name(Reflex::SCOPED|Reflex::FINAL);
-    std::string rcname = rct.Name(Reflex::SCOPED|Reflex::FINAL);
-
-    std::string opname = "operator";
-    opname += op;
-
-    for (int idx = 0; idx < (int)nss.FunctionMemberSize(); ++idx) {
-        Reflex::Member m = nss.FunctionMemberAt(idx);
-        if (m.FunctionParameterSize() != 2)
-            continue;
-
-        if (m.Name() == opname) {
-            Reflex::Type mt = m.TypeOf();
-            if (lcname == mt.FunctionParameterAt(0).Name(Reflex::SCOPED|Reflex::FINAL) &&
-                rcname == mt.FunctionParameterAt(1).Name(Reflex::SCOPED|Reflex::FINAL)) {
-                return (cppyy_index_t)idx;
-            }
-        }
-    }
-
-    return (cppyy_index_t)-1;  
-}
-
-
-/* method properties -----------------------------------------------------  */
-int cppyy_is_constructor(cppyy_type_t handle, cppyy_index_t method_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.FunctionMemberAt(method_index);
-    return m.IsConstructor();
-}
-
-int cppyy_is_staticmethod(cppyy_type_t handle, cppyy_index_t method_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.FunctionMemberAt(method_index);
-    return m.IsStatic();
-}
-
-
-/* data member reflection information ------------------------------------- */
-int cppyy_num_datamembers(cppyy_scope_t handle) {
-    Reflex::Scope s = scope_from_handle(handle);
-    // fix enum representation by adding them to the containing scope as per C++
-    // TODO: this (relatively harmlessly) dupes data members when updating in the
-    //       case s is a namespace
-    for (int isub = 0; isub < (int)s.ScopeSize(); ++isub) {
-        Reflex::Scope sub = s.SubScopeAt(isub);
-        if (sub.IsEnum()) {
-            for (int idata = 0;  idata < (int)sub.DataMemberSize(); ++idata) {
-                Reflex::Member m = sub.DataMemberAt(idata);
-                s.AddDataMember(m.Name().c_str(), sub, 0,
-                                Reflex::PUBLIC|Reflex::STATIC|Reflex::ARTIFICIAL,
-                                (char*)m.Offset());
-            }
-        }
-    }
-    return s.DataMemberSize();
-}
-
-char* cppyy_datamember_name(cppyy_scope_t handle, int datamember_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.DataMemberAt(datamember_index);
-    std::string name = m.Name();
-    return cppstring_to_cstring(name);
-}
-
-char* cppyy_datamember_type(cppyy_scope_t handle, int datamember_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.DataMemberAt(datamember_index);
-    std::string name = m.TypeOf().Name(Reflex::FINAL|Reflex::SCOPED|Reflex::QUALIFIED);
-    return cppstring_to_cstring(name);
-}
-
-ptrdiff_t cppyy_datamember_offset(cppyy_scope_t handle, int datamember_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.DataMemberAt(datamember_index);
-    if (m.IsArtificial() && m.TypeOf().IsEnum())
-        return (ptrdiff_t)&m.InterpreterOffset();
-    return (ptrdiff_t)m.Offset();
-}
-
-int cppyy_datamember_index(cppyy_scope_t handle, const char* name) {
-    Reflex::Scope s = scope_from_handle(handle);
-    // the following appears dumb, but the internal storage for Reflex is an
-    // unsorted std::vector anyway, so there's no gain to be had in using the
-    // Scope::DataMemberByName() function (which returns Member, not an index)
-    int num_dm = cppyy_num_datamembers(handle);
-    for (int idm = 0; idm < num_dm; ++idm) {
-        Reflex::Member m = s.DataMemberAt(idm);
-        if (m.Name() == name || m.Name(Reflex::FINAL) == name) {
-            if (m.IsPublic())
-                return idm;
-            return -1;
-        }
-    }
-    return -1;
-}
-
-
-/* data member properties ------------------------------------------------  */
-int cppyy_is_publicdata(cppyy_scope_t handle, int datamember_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.DataMemberAt(datamember_index);
-    return m.IsPublic();
-}
-
-int cppyy_is_staticdata(cppyy_scope_t handle, int datamember_index) {
-    Reflex::Scope s = scope_from_handle(handle);
-    Reflex::Member m = s.DataMemberAt(datamember_index);
-    return m.IsStatic();
-}
-
-
-/* misc helpers ----------------------------------------------------------- */
-long long cppyy_strtoll(const char* str) {
-    return strtoll(str, NULL, 0);
-}
-
-extern "C" unsigned long long cppyy_strtoull(const char* str) {
-    return strtoull(str, NULL, 0);
-}
-
-void cppyy_free(void* ptr) {
-    free(ptr);
-}
-
-cppyy_object_t cppyy_charp2stdstring(const char* str) {
-    void* arena = new char[sizeof(std::string)];
-    new (arena) std::string(str);
-    return (cppyy_object_t)arena;
-}
-
-cppyy_object_t cppyy_stdstring2stdstring(cppyy_object_t ptr) {
-    void* arena = new char[sizeof(std::string)];
-    new (arena) std::string(*(std::string*)ptr);
-    return (cppyy_object_t)arena;
-}


More information about the pypy-commit mailing list