Skip to content

Commit

Permalink
fix type converters function resolution
Browse files Browse the repository at this point in the history
changes to make sure `dm_set` is called when assigning a value to an enum resulting in raising TypeError
  • Loading branch information
Vipul-Cariappa authored and aaronj0 committed Nov 15, 2024
1 parent c4367c6 commit 529f920
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
15 changes: 5 additions & 10 deletions src/CPPScope.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,7 @@ static PyObject* meta_getattro(PyObject* pyclass, PyObject* pyname)
if (attr) {
// cache the result
if (CPPDataMember_Check(attr)) {
if (Cppyy::IsClass(scope))
PyType_Type.tp_setattro(pyclass, pyname, attr);
else
PyType_Type.tp_setattro((PyObject*)Py_TYPE(pyclass), pyname, attr);
PyType_Type.tp_setattro((PyObject*)Py_TYPE(pyclass), pyname, attr);

Py_DECREF(attr);
// The call below goes through "dm_get"
Expand Down Expand Up @@ -531,13 +528,11 @@ static int meta_setattro(PyObject* pyclass, PyObject* pyname, PyObject* pyval)
// the C++ side, b/c there is no descriptor yet. This triggers the creation for
// for such data as necessary. The many checks to narrow down the specific case
// are needed to prevent unnecessary lookups and recursion.
if (((CPPScope*)pyclass)->fFlags & CPPScope::kIsNamespace) {
// skip if the given pyval is a descriptor already, or an unassignable class
if (!CPyCppyy::CPPDataMember_Check(pyval) && !CPyCppyy::CPPScope_Check(pyval)) {
std::string name = CPyCppyy_PyText_AsString(pyname);
if (Cppyy::GetNamed(name, ((CPPScope*)pyclass)->fCppType))
meta_getattro(pyclass, pyname); // triggers creation
}
if (!CPyCppyy::CPPDataMember_Check(pyval) && !CPyCppyy::CPPScope_Check(pyval)) {
std::string name = CPyCppyy_PyText_AsString(pyname);
if (Cppyy::GetNamed(name, ((CPPScope*)pyclass)->fCppType))
meta_getattro(pyclass, pyname); // triggers creation
}

return PyType_Type.tp_setattro(pyclass, pyname, pyval);
Expand Down
5 changes: 2 additions & 3 deletions src/Converters.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3447,11 +3447,10 @@ CPyCppyy::Converter* CPyCppyy::CreateConverter(Cppyy::TCppType_t type, cdims_t d

if (!result && cpd == "&&") {
// for builtin, can use const-ref for r-ref
h = gConvFactories.find("const " + realTypeStr + " &");
h = gConvFactories.find("const " + realTypeStr + "&");
if (h != gConvFactories.end())
return (h->second)(dims);
std::string temp ="const " + realUnresolvedTypeStr + " &";
h = gConvFactories.find("const " + realUnresolvedTypeStr + " &");
h = gConvFactories.find("const " + realUnresolvedTypeStr + "&");
if (h != gConvFactories.end())
return (h->second)(dims);
// else, unhandled moves
Expand Down

0 comments on commit 529f920

Please sign in to comment.