Cleanup: use our utility function to create a PyUnicode from a std:str

This commit is contained in:
Campbell Barton
2025-04-01 12:33:56 +11:00
parent e3d6051181
commit 7ae020ecd1
7 changed files with 19 additions and 26 deletions

View File

@@ -357,7 +357,7 @@ PyDoc_STRVAR(
static PyObject *pygpu_interface_info_name_get(BPyGPUStageInterfaceInfo *self, void * /*closure*/)
{
StageInterfaceInfo *interface = reinterpret_cast<StageInterfaceInfo *>(self->interface);
return PyUnicode_FromString(interface->name.c_str());
return PyC_UnicodeFromStdStr(interface->name);
}
static PyGetSetDef pygpu_interface_info__tp_getseters[] = {

View File

@@ -27,6 +27,8 @@
#include "bpy_geometry_set.hh"
#include "bpy_rna.hh"
#include "../generic/py_capi_utils.hh"
using blender::bke::GeometrySet;
extern PyTypeObject bpy_geometry_set_Type;
@@ -155,7 +157,7 @@ static PyObject *BPy_GeometrySet_repr(BPy_GeometrySet *self)
std::stringstream ss;
ss << self->geometry;
std::string str = ss.str();
return PyUnicode_FromString(str.c_str());
return PyC_UnicodeFromStdStr(str);
}
PyDoc_STRVAR(
@@ -247,7 +249,7 @@ PyDoc_STRVAR(
":type: str\n");
static PyObject *BPy_GeometrySet_get_name(BPy_GeometrySet *self, void * /*closure*/)
{
return PyUnicode_FromString(self->geometry.name.c_str());
return PyC_UnicodeFromStdStr(self->geometry.name);
}
static int BPy_GeometrySet_set_name(BPy_GeometrySet *self, PyObject *value, void * /*closure*/)

View File

@@ -314,8 +314,6 @@ static PyObject *pyop_as_string(PyObject * /*self*/, PyObject *args)
bool macro_args = true;
int error_val = 0;
PyObject *pybuf;
bContext *C = BPY_context_get();
if (C == nullptr) {
@@ -381,14 +379,7 @@ static PyObject *pyop_as_string(PyObject * /*self*/, PyObject *args)
return nullptr;
}
if (!op_string.empty()) {
pybuf = PyUnicode_FromString(op_string.c_str());
}
else {
pybuf = PyUnicode_FromString("");
}
return pybuf;
return PyC_UnicodeFromStdStr(op_string);
}
static PyObject *pyop_dir(PyObject * /*self*/)

View File

@@ -3933,7 +3933,6 @@ static PyObject *pyrna_struct_path_from_id(BPy_StructRNA *self, PyObject *args)
{
const char *name = nullptr;
PropertyRNA *prop;
PyObject *ret;
PYRNA_STRUCT_CHECK_OBJ(self);
@@ -3973,9 +3972,7 @@ static PyObject *pyrna_struct_path_from_id(BPy_StructRNA *self, PyObject *args)
return nullptr;
}
ret = PyUnicode_FromString(path->c_str());
return ret;
return PyC_UnicodeFromStdStr(path.value());
}
PyDoc_STRVAR(
@@ -3990,7 +3987,6 @@ PyDoc_STRVAR(
static PyObject *pyrna_prop_path_from_id(BPy_PropertyRNA *self)
{
PropertyRNA *prop = self->prop;
PyObject *ret;
const std::optional<std::string> path = RNA_path_from_ID_to_property(&self->ptr.value(),
self->prop);
@@ -4003,9 +3999,7 @@ static PyObject *pyrna_prop_path_from_id(BPy_PropertyRNA *self)
return nullptr;
}
ret = PyUnicode_FromString(path->c_str());
return ret;
return PyC_UnicodeFromStdStr(path.value());
}
PyDoc_STRVAR(
@@ -4574,7 +4568,7 @@ static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname)
ret = PyTuple_New(3);
PyTuple_SET_ITEMS(ret,
pyrna_struct_CreatePyObject(base_ptr),
PyUnicode_FromString(path_str->c_str()),
PyC_UnicodeFromStdStr(path_str.value()),
PyLong_FromLong(newindex));
}
else {