Skip to content

Commit d7812b6

Browse files
committed
Improve converters and basic_string support in Pythonisations
1 parent 098f455 commit d7812b6

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/Converters.cxx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3349,11 +3349,11 @@ CPyCppyy::Converter* CPyCppyy::CreateConverter(Cppyy::TCppType_t type, cdims_t d
33493349

33503350
if (!result && cpd == "&&") {
33513351
// for builtin, can use const-ref for r-ref
3352-
h = gConvFactories.find("const " + realTypeStr + " &");
3352+
h = gConvFactories.find("const " + realTypeStr + "&");
33533353
if (h != gConvFactories.end())
33543354
return (h->second)(dims);
3355-
std::string temp ="const " + realUnresolvedTypeStr + " &";
3356-
h = gConvFactories.find("const " + realUnresolvedTypeStr + " &");
3355+
std::string temp ="const " + realUnresolvedTypeStr + "&";
3356+
h = gConvFactories.find("const " + realUnresolvedTypeStr + "&");
33573357
if (h != gConvFactories.end())
33583358
return (h->second)(dims);
33593359
// else, unhandled moves
@@ -3589,6 +3589,11 @@ static struct InitConvFactories_t {
35893589
gf["std::basic_string<char>&&"] = (cf_t)+[](cdims_t) { return new STLStringMoveConverter{}; };
35903590
gf["const std::basic_string<char> &"] = gf["std::basic_string<char>"];
35913591
gf["std::basic_string<char> &&"] = (cf_t)+[](cdims_t) { return new STLStringMoveConverter{}; };
3592+
3593+
gf["basic_string<char>"] = gf["std::basic_string<char>"];
3594+
gf["const basic_string<char>&"] = gf["const std::basic_string<char>&"];
3595+
gf["basic_string<char>&&"] = gf["std::basic_string<char>&&"];
3596+
gf["basic_string<char> &&"] = gf["std::basic_string<char> &&"];
35923597
#if __cplusplus > 201402L
35933598
gf["std::basic_string_view<char>"] = (cf_t)+[](cdims_t) { return new STLStringViewConverter{}; };
35943599
gf[STRINGVIEW] = gf["std::basic_string_view<char>"];

src/ProxyWrappers.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static int BuildScopeProxyDict(Cppyy::TCppScope_t scope, PyObject* pyclass, cons
385385
// two options: this is a static variable, or it is the enum value, the latter
386386
// already exists, so check for it and move on if set
387387
PyObject* eset = PyObject_GetAttrString(pyclass,
388-
const_cast<char*>(Cppyy::GetFinalName(datamember).c_str()));
388+
const_cast<char*>(Cppyy::GetScopedFinalName(datamember).c_str()));
389389
if (eset) {
390390
Py_DECREF(eset);
391391
continue;

src/Pythonize.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,7 @@ bool CPyCppyy::Pythonize(PyObject* pyclass, Cppyy::TCppScope_t scope)
18471847
Utility::AddToClass(pyclass, "__iter__", (PyCFunction)PyObject_SelfIter, METH_NOARGS);
18481848
}
18491849

1850-
else if (name == "std::basic_string<char>") { // TODO: ask backend as well
1850+
else if (name == "std::basic_string<char>" || name == "basic_string<char>") { // TODO: ask backend as well
18511851
Utility::AddToClass(pyclass, "__repr__", (PyCFunction)STLStringRepr, METH_NOARGS);
18521852
Utility::AddToClass(pyclass, "__str__", (PyCFunction)STLStringStr, METH_NOARGS);
18531853
Utility::AddToClass(pyclass, "__bytes__", (PyCFunction)STLStringBytes, METH_NOARGS);
@@ -1868,12 +1868,12 @@ bool CPyCppyy::Pythonize(PyObject* pyclass, Cppyy::TCppScope_t scope)
18681868
((PyTypeObject*)pyclass)->tp_hash = (hashfunc)STLStringHash;
18691869
}
18701870

1871-
else if (name == "std::basic_string_view<char>") {
1871+
else if (name == "std::basic_string_view<char>" || name == "basic_string_view<char>") {
18721872
Utility::AddToClass(pyclass, "__real_init", "__init__");
18731873
Utility::AddToClass(pyclass, "__init__", (PyCFunction)StringViewInit, METH_VARARGS | METH_KEYWORDS);
18741874
}
18751875

1876-
else if (name == "std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >") {
1876+
else if (name == "std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >" || name == "basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >") {
18771877
Utility::AddToClass(pyclass, "__repr__", (PyCFunction)STLWStringRepr, METH_NOARGS);
18781878
Utility::AddToClass(pyclass, "__str__", (PyCFunction)STLWStringStr, METH_NOARGS);
18791879
Utility::AddToClass(pyclass, "__bytes__", (PyCFunction)STLWStringBytes, METH_NOARGS);

0 commit comments

Comments
 (0)