From 025733e0dffea04f22ea16e370bdfb3a4c9f2be4 Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Fri, 15 Nov 2024 09:45:18 +0530 Subject: [PATCH] fix type converters function resolution changes to make sure `dm_set` is called when assigning a value to an enum resulting in raising TypeError --- src/CPPScope.cxx | 15 +++++---------- src/Converters.cxx | 5 ++--- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/CPPScope.cxx b/src/CPPScope.cxx index b72b3f6..0058f12 100644 --- a/src/CPPScope.cxx +++ b/src/CPPScope.cxx @@ -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" @@ -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); diff --git a/src/Converters.cxx b/src/Converters.cxx index fc940b2..6dac020 100644 --- a/src/Converters.cxx +++ b/src/Converters.cxx @@ -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