Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix type converters function resolution #65

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing the same as upstream.


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
Comment on lines 530 to +535
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sure that meta_getattro is called. Later tp_setattro calls dm_set. Raising the TypeError. Otherwise tp_setattro calls generic setattr.

}

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
Loading