From 96601f788e10698db043b343236c169ba4e42a13 Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Mon, 16 Dec 2024 15:37:02 +0530 Subject: [PATCH] fix according to `Cppyy::GetGlobalOperator`'s implementation --- src/Cppyy.h | 5 +++-- src/Utility.cxx | 9 +++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Cppyy.h b/src/Cppyy.h index 4d01f75..6821ec1 100644 --- a/src/Cppyy.h +++ b/src/Cppyy.h @@ -286,8 +286,9 @@ namespace Cppyy { TCppScope_t scope, const std::string& name, const std::string& proto); CPPYY_IMPORT - TCppIndex_t GetGlobalOperator( - TCppType_t scope, const std::string& lc, const std::string& rc, const std::string& op); + TCppMethod_t GetGlobalOperator(TCppType_t scope, const std::string &lc, + const std::string &rc, + const std::string &op); // method properties --------------------------------------------------------- CPPYY_IMPORT diff --git a/src/Utility.cxx b/src/Utility.cxx index 809ca15..7c6f65a 100644 --- a/src/Utility.cxx +++ b/src/Utility.cxx @@ -265,14 +265,11 @@ CPyCppyy::PyCallable* BuildOperator(const std::string& lcname, const std::string const char* op, Cppyy::TCppScope_t scope, bool reverse=false) { // Helper to find a function with matching signature in 'funcs'. - std::string opname = "operator"; - opname += op; - Cppyy::TCppIndex_t idx = Cppyy::GetGlobalOperator(scope, lcname, rcname, opname); - if (idx == (Cppyy::TCppIndex_t)-1) + Cppyy::TCppMethod_t meth = Cppyy::GetGlobalOperator(scope, lcname, rcname, op); + if (!meth) return nullptr; - Cppyy::TCppMethod_t meth = Cppyy::GetMethod(scope, idx); if (!reverse) return new CPyCppyy::CPPFunction(scope, meth); return new CPyCppyy::CPPReverseBinary(scope, meth); @@ -331,7 +328,7 @@ CPyCppyy::PyCallable* CPyCppyy::Utility::FindBinaryOperator( if (!scope) { // TODO: the following should remain sync with what clingwrapper does in its // type remapper; there must be a better way? - if (lcname == "str" || lcname == "unicode" || lcname == "complex") + if (lcname == "str" || lcname == "unicode" || lcname == "complex" || lcname.find("std::") == 0) scope = Cppyy::GetScope("std"); else scope = Cppyy::GetScope(TypeManip::extract_namespace(lcname)); }