Author: Wim Lavrijsen <wlavrij...@lbl.gov> Branch: cling-support Changeset: r85717:14334ff3d976 Date: 2016-07-14 15:20 -0700 http://bitbucket.org/pypy/pypy/changeset/14334ff3d976/
Log: implement lookup of global operators 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 @@ -1095,9 +1095,10 @@ try: # TODO: expecting w_other to be an W_CPPInstance is too limiting other = self.space.interp_w(W_CPPInstance, w_other, can_be_None=False) - for name in ["", "__gnu_cxx"]: + for name in ["", "__gnu_cxx", "__1"]: nss = scope_byname(self.space, name) - meth_idx = capi.c_get_global_operator(self.space, nss, self.cppclass, other.cppclass, "==") + meth_idx = capi.c_get_global_operator( + self.space, nss, self.cppclass, other.cppclass, "operator==") if meth_idx != -1: f = nss._make_cppfunction("operator==", meth_idx) ol = W_CPPOverload(self.space, nss, [f]) diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx b/pypy/module/cppyy/src/clingcwrapper.cxx --- a/pypy/module/cppyy/src/clingcwrapper.cxx +++ b/pypy/module/cppyy/src/clingcwrapper.cxx @@ -112,10 +112,10 @@ } 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; +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; } @@ -863,9 +863,23 @@ } Cppyy::TCppIndex_t Cppyy::GetGlobalOperator( - TCppScope_t /* scope */, TCppType_t /* lc */, TCppType_t /* rc */, const std::string& /* op */ ) + TCppScope_t scope, TCppType_t lc, TCppType_t rc, const std::string& opname ) { - return (TCppIndex_t)0; +// Find a global operator function with a matching signature + std::string proto = GetScopedFinalName(lc) + ", " + GetScopedFinalName(rc); + if ( scope == (cppyy_scope_t)GLOBAL_HANDLE ) { + TFunction* func = gROOT->GetGlobalFunctionWithPrototype( opname.c_str(), proto.c_str() ); + if (func) return (TCppIndex_t)func; + } else { + TClassRef& cr = type_from_handle( scope ); + if ( cr.GetClass() ) { + TFunction* func = cr->GetMethodWithPrototype( opname.c_str(), proto.c_str() ); + if ( func ) return (TCppIndex_t)cr->GetListOfMethods()->IndexOf( func ); + } + } + +// failure ... + return (TCppIndex_t)-1; } // method properties --------------------------------------------------------- _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit