Skip to content

Commit

Permalink
fix according to Cppyy::GetGlobalOperator's implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Vipul-Cariappa committed Jan 6, 2025
1 parent 373d3fb commit f82be28
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/Cppyy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions src/Utility.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit f82be28

Please sign in to comment.