From 28f8db36c0f2407af1cb86b218b7fde824bd35ed Mon Sep 17 00:00:00 2001 From: maximusron Date: Fri, 12 Jul 2024 14:40:27 +0200 Subject: [PATCH 1/4] Improve converters and basic_string support in Pythonisations --- src/Converters.cxx | 11 ++++++++--- src/ProxyWrappers.cxx | 2 +- src/Pythonize.cxx | 6 +++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Converters.cxx b/src/Converters.cxx index fc940b20..699299d0 100644 --- a/src/Converters.cxx +++ b/src/Converters.cxx @@ -3447,11 +3447,11 @@ 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 + " &"); + std::string temp ="const " + realUnresolvedTypeStr + "&"; + h = gConvFactories.find("const " + realUnresolvedTypeStr + "&"); if (h != gConvFactories.end()) return (h->second)(dims); // else, unhandled moves @@ -3707,6 +3707,11 @@ static struct InitConvFactories_t { gf["std::basic_string&&"] = (cf_t)+[](cdims_t) { return new STLStringMoveConverter{}; }; gf["const std::basic_string &"] = gf["std::basic_string"]; gf["std::basic_string &&"] = (cf_t)+[](cdims_t) { return new STLStringMoveConverter{}; }; + + gf["basic_string"] = gf["std::basic_string"]; + gf["const basic_string&"] = gf["const std::basic_string&"]; + gf["basic_string&&"] = gf["std::basic_string&&"]; + gf["basic_string &&"] = gf["std::basic_string &&"]; #if __cplusplus > 201402L gf["std::basic_string_view"] = (cf_t)+[](cdims_t) { return new STLStringViewConverter{}; }; gf[STRINGVIEW] = gf["std::basic_string_view"]; diff --git a/src/ProxyWrappers.cxx b/src/ProxyWrappers.cxx index 4e2150ce..5c4b33af 100644 --- a/src/ProxyWrappers.cxx +++ b/src/ProxyWrappers.cxx @@ -383,7 +383,7 @@ static int BuildScopeProxyDict(Cppyy::TCppScope_t scope, PyObject* pyclass, cons // two options: this is a static variable, or it is the enum value, the latter // already exists, so check for it and move on if set PyObject* eset = PyObject_GetAttrString(pyclass, - const_cast(Cppyy::GetFinalName(datamember).c_str())); + const_cast(Cppyy::GetScopedFinalName(datamember).c_str())); if (eset) { Py_DECREF(eset); continue; diff --git a/src/Pythonize.cxx b/src/Pythonize.cxx index d809a6b2..10fe6cb2 100644 --- a/src/Pythonize.cxx +++ b/src/Pythonize.cxx @@ -1881,7 +1881,7 @@ bool CPyCppyy::Pythonize(PyObject* pyclass, Cppyy::TCppScope_t scope) Utility::AddToClass(pyclass, "__iter__", (PyCFunction)PyObject_SelfIter, METH_NOARGS); } - else if (name == "std::basic_string") { // TODO: ask backend as well + else if (name == "std::basic_string" || name == "basic_string") { // TODO: ask backend as well Utility::AddToClass(pyclass, "__repr__", (PyCFunction)STLStringRepr, METH_NOARGS); Utility::AddToClass(pyclass, "__str__", (PyCFunction)STLStringStr, METH_NOARGS); Utility::AddToClass(pyclass, "__bytes__", (PyCFunction)STLStringBytes, METH_NOARGS); @@ -1902,12 +1902,12 @@ bool CPyCppyy::Pythonize(PyObject* pyclass, Cppyy::TCppScope_t scope) ((PyTypeObject*)pyclass)->tp_hash = (hashfunc)STLStringHash; } - else if (name == "std::basic_string_view") { + else if (name == "std::basic_string_view" || name == "basic_string_view") { Utility::AddToClass(pyclass, "__real_init", "__init__"); Utility::AddToClass(pyclass, "__init__", (PyCFunction)StringViewInit, METH_VARARGS | METH_KEYWORDS); } - else if (name == "std::basic_string,std::allocator >") { + else if (name == "std::basic_string,std::allocator >" || name == "basic_string,std::allocator >") { Utility::AddToClass(pyclass, "__repr__", (PyCFunction)STLWStringRepr, METH_NOARGS); Utility::AddToClass(pyclass, "__str__", (PyCFunction)STLWStringStr, METH_NOARGS); Utility::AddToClass(pyclass, "__bytes__", (PyCFunction)STLWStringBytes, METH_NOARGS); From 00f83cdb53ccb464f0117ff36213e5bfa839c985 Mon Sep 17 00:00:00 2001 From: Aaron Jomy <75925957+aaronj0@users.noreply.github.com> Date: Sun, 22 Sep 2024 15:05:25 +0200 Subject: [PATCH 2/4] Update Pythonize.cxx --- src/Pythonize.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Pythonize.cxx b/src/Pythonize.cxx index 10fe6cb2..d809a6b2 100644 --- a/src/Pythonize.cxx +++ b/src/Pythonize.cxx @@ -1881,7 +1881,7 @@ bool CPyCppyy::Pythonize(PyObject* pyclass, Cppyy::TCppScope_t scope) Utility::AddToClass(pyclass, "__iter__", (PyCFunction)PyObject_SelfIter, METH_NOARGS); } - else if (name == "std::basic_string" || name == "basic_string") { // TODO: ask backend as well + else if (name == "std::basic_string") { // TODO: ask backend as well Utility::AddToClass(pyclass, "__repr__", (PyCFunction)STLStringRepr, METH_NOARGS); Utility::AddToClass(pyclass, "__str__", (PyCFunction)STLStringStr, METH_NOARGS); Utility::AddToClass(pyclass, "__bytes__", (PyCFunction)STLStringBytes, METH_NOARGS); @@ -1902,12 +1902,12 @@ bool CPyCppyy::Pythonize(PyObject* pyclass, Cppyy::TCppScope_t scope) ((PyTypeObject*)pyclass)->tp_hash = (hashfunc)STLStringHash; } - else if (name == "std::basic_string_view" || name == "basic_string_view") { + else if (name == "std::basic_string_view") { Utility::AddToClass(pyclass, "__real_init", "__init__"); Utility::AddToClass(pyclass, "__init__", (PyCFunction)StringViewInit, METH_VARARGS | METH_KEYWORDS); } - else if (name == "std::basic_string,std::allocator >" || name == "basic_string,std::allocator >") { + else if (name == "std::basic_string,std::allocator >") { Utility::AddToClass(pyclass, "__repr__", (PyCFunction)STLWStringRepr, METH_NOARGS); Utility::AddToClass(pyclass, "__str__", (PyCFunction)STLWStringStr, METH_NOARGS); Utility::AddToClass(pyclass, "__bytes__", (PyCFunction)STLWStringBytes, METH_NOARGS); From 2951b91e5394f0846e930766647c3d01fe392f48 Mon Sep 17 00:00:00 2001 From: Aaron Jomy <75925957+aaronj0@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:32:17 +0200 Subject: [PATCH 3/4] Update ProxyWrappers.cxx --- src/ProxyWrappers.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProxyWrappers.cxx b/src/ProxyWrappers.cxx index 5c4b33af..4e2150ce 100644 --- a/src/ProxyWrappers.cxx +++ b/src/ProxyWrappers.cxx @@ -383,7 +383,7 @@ static int BuildScopeProxyDict(Cppyy::TCppScope_t scope, PyObject* pyclass, cons // two options: this is a static variable, or it is the enum value, the latter // already exists, so check for it and move on if set PyObject* eset = PyObject_GetAttrString(pyclass, - const_cast(Cppyy::GetScopedFinalName(datamember).c_str())); + const_cast(Cppyy::GetFinalName(datamember).c_str())); if (eset) { Py_DECREF(eset); continue; From 1cd6eef02736b1abc2e9cb2f2560b81675d7de56 Mon Sep 17 00:00:00 2001 From: Aaron Jomy <75925957+aaronj0@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:05:14 +0200 Subject: [PATCH 4/4] Revert extra converters --- src/Converters.cxx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Converters.cxx b/src/Converters.cxx index 699299d0..7dadbca9 100644 --- a/src/Converters.cxx +++ b/src/Converters.cxx @@ -3707,11 +3707,6 @@ static struct InitConvFactories_t { gf["std::basic_string&&"] = (cf_t)+[](cdims_t) { return new STLStringMoveConverter{}; }; gf["const std::basic_string &"] = gf["std::basic_string"]; gf["std::basic_string &&"] = (cf_t)+[](cdims_t) { return new STLStringMoveConverter{}; }; - - gf["basic_string"] = gf["std::basic_string"]; - gf["const basic_string&"] = gf["const std::basic_string&"]; - gf["basic_string&&"] = gf["std::basic_string&&"]; - gf["basic_string &&"] = gf["std::basic_string &&"]; #if __cplusplus > 201402L gf["std::basic_string_view"] = (cf_t)+[](cdims_t) { return new STLStringViewConverter{}; }; gf[STRINGVIEW] = gf["std::basic_string_view"];