From df92c120cb6dce4b25e2b0e5128f5e75005f1ef5 Mon Sep 17 00:00:00 2001 From: maximusron Date: Fri, 12 Jul 2024 14:40:27 +0200 Subject: [PATCH] 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 745c7713..a34e4da0 100644 --- a/src/Converters.cxx +++ b/src/Converters.cxx @@ -3349,11 +3349,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 @@ -3589,6 +3589,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 b5261ee9..6a7265c5 100644 --- a/src/ProxyWrappers.cxx +++ b/src/ProxyWrappers.cxx @@ -384,7 +384,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 31b5e76e..f396a349 100644 --- a/src/Pythonize.cxx +++ b/src/Pythonize.cxx @@ -1846,7 +1846,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); @@ -1867,12 +1867,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);