Skip to content

Commit ae53d17

Browse files
committed
Consistently use pyref::string for temporary Python string creation
1 parent b1c2475 commit ae53d17

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

c++/cpp2py/py_converter.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ namespace cpp2py {
103103
sptr = std::make_shared<conv_table_t>();
104104

105105
// Now register the pointer in __main__
106-
PyObject *mod = PyImport_GetModule(PyUnicode_FromString("__main__"));
106+
PyObject *mod = PyImport_GetModule(pyref::string("__main__"));
107107
auto *p = new std::shared_ptr<conv_table_t>{sptr};
108108
pyref c = PyCapsule_New((void *)p, "__main__.__cpp2py_table", (PyCapsule_Destructor)_table_destructor);
109109
pyref s = PyUnicode_FromString("__cpp2py_table");

c++/cpp2py/pyref.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ namespace cpp2py {
101101
/// Import the module and returns a pyref to it
102102
static pyref module(std::string const &module_name) {
103103
// Maybe the module was already imported?
104-
pyref mod_name = PyUnicode_FromString(module_name.c_str());
105-
PyObject *mod = PyImport_GetModule(mod_name);
104+
PyObject *mod = PyImport_GetModule(pyref::string(module_name));
106105

107106
// If not, import normally
108107
if (mod == nullptr) mod = PyImport_ImportModule(module_name.c_str());

cpp2py/mako/wrap.cxx

+5-5
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ template <> struct py_converter<${en.c_name}> {
594594
PyErr_Fetch(&ptype, &err, &ptraceback);
595595
// catch here all non defined errors and print instead generic warning
596596
if (err == NULL) {
597-
errors[${n_overload}] = pyref{PyUnicode_FromString("unkown error check converter")};
597+
errors[${n_overload}] = pyref::string("unkown error check converter");
598598
} else {
599599
errors[${n_overload}] = pyref{err};
600600
}
@@ -1039,10 +1039,10 @@ PyObject* ${c.py_type}___iter__(PyObject *self) {
10391039
static const char * ens = "${repr( [ (en.c_name_absolute, en.c_namespace, en.values) for en in module.enums] )}";
10401040
static const char * inclu = "${repr( module.include_list)}";
10411041

1042-
PyDict_SetItemString(d, "classes", pyref(PyUnicode_FromString(cls)));
1043-
PyDict_SetItemString(d, "enums", pyref(PyUnicode_FromString(ens)));
1044-
PyDict_SetItemString(d, "module_name", pyref(PyUnicode_FromString("${module.full_name}")));
1045-
PyDict_SetItemString(d, "includes", pyref(PyUnicode_FromString(inclu)));
1042+
PyDict_SetItemString(d, "classes", pyref::string(cls));
1043+
PyDict_SetItemString(d, "enums", pyref::string(ens));
1044+
PyDict_SetItemString(d, "module_name", pyref::string("${module.full_name}"));
1045+
PyDict_SetItemString(d, "includes", pyref::string(inclu));
10461046

10471047
return d;
10481048
}

0 commit comments

Comments
 (0)