Skip to content

Commit e499c73

Browse files
committed
chore(PythonQt): replace PyString_AsString with PyUnicode_AsUTF8
Port remaining conversions to the Unicode API and drop reliance on the macro alias in `PythonQtPythonInclude.h`. No functional change intended.
1 parent 5f49d78 commit e499c73

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

src/PythonQt.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ QStringList PythonQt::introspectObject(PyObject* object, ObjectType type)
12301230
} else {
12311231
PyObject* doc = PyObject_GetAttrString(object, "__doc__");
12321232
if (doc) {
1233-
QString docString = QString::fromUtf8(PyString_AsString(doc));
1233+
QString docString = QString::fromUtf8(PyUnicode_AsUTF8(doc));
12341234
Py_DECREF(doc);
12351235
int idx = docString.indexOf("\n");
12361236
if (idx != -1) {
@@ -1266,7 +1266,7 @@ QStringList PythonQt::introspectObject(PyObject* object, ObjectType type)
12661266
value = PyObject_GetAttr(object, key);
12671267
}
12681268
if (!value) continue;
1269-
keystr = PyString_AsString(key);
1269+
keystr = PyUnicode_AsUTF8(key);
12701270
static const QString underscoreStr("__tmp");
12711271
if (!keystr.startsWith(underscoreStr)) {
12721272
switch (type) {
@@ -1977,7 +1977,7 @@ QString PythonQt::getReturnTypeOfWrappedMethodHelper(const PythonQtObjectPtr& va
19771977
if (typeInfo && typeInfo->pythonQtClassWrapper()) {
19781978
PyObject* s = PyObject_GetAttrString(typeInfo->pythonQtClassWrapper(), "__module__");
19791979
Q_ASSERT(PyString_Check(s));
1980-
type = QString(PyString_AsString(s)) + "." + type;
1980+
type = QString(PyUnicode_AsUTF8(s)) + "." + type;
19811981
Py_DECREF(s);
19821982
}
19831983
}
@@ -2308,7 +2308,7 @@ const QMetaObject* PythonQtPrivate::buildDynamicMetaObject(PythonQtClassWrapper*
23082308
// A signal object, register with the meta object
23092309
PythonQtSignalFunctionObject* signal = (PythonQtSignalFunctionObject*)value;
23102310
if (signal->_dynamicInfo) {
2311-
signal->_dynamicInfo->name = PyString_AsString(key);
2311+
signal->_dynamicInfo->name = PyUnicode_AsUTF8(key);
23122312
foreach(QByteArray sig, signal->_dynamicInfo->signatures) {
23132313
builder.addSignal(signal->_dynamicInfo->name + "(" + sig + ")");
23142314
needsMetaObject = true;
@@ -2324,7 +2324,7 @@ const QMetaObject* PythonQtPrivate::buildDynamicMetaObject(PythonQtClassWrapper*
23242324
if (PythonQtProperty_Check(value)) {
23252325
needsMetaObject = true;
23262326
PythonQtProperty* prop = (PythonQtProperty*)value;
2327-
QMetaPropertyBuilder newProp = builder.addProperty(PyString_AsString(key), prop->data->cppType);
2327+
QMetaPropertyBuilder newProp = builder.addProperty(PyUnicode_AsUTF8(key), prop->data->cppType);
23282328
newProp.setReadable(true);
23292329
newProp.setWritable(prop->data->fset != nullptr);
23302330
newProp.setResettable(prop->data->freset != nullptr);
@@ -2354,7 +2354,7 @@ const QMetaObject* PythonQtPrivate::buildDynamicMetaObject(PythonQtClassWrapper*
23542354
Py_ssize_t count = PyList_Size(signatures);
23552355
for (Py_ssize_t i = 0; i < count; i++) {
23562356
PyObject* signature = PyList_GET_ITEM(signatures, i);
2357-
QByteArray sig = PyString_AsString(signature);
2357+
QByteArray sig = PyUnicode_AsUTF8(signature);
23582358
// Split the return type and the rest of the signature,
23592359
// no spaces should be in the rest of the signature...
23602360
QList<QByteArray> parts = sig.split(' ');
@@ -2473,14 +2473,14 @@ QString PythonQtPrivate::getSignature(PyObject* object)
24732473
QString docstr;
24742474
PyObject* doc = PyObject_GetAttrString(object, "__doc__");
24752475
if (doc) {
2476-
docstr = PyString_AsString(doc);
2476+
docstr = PyUnicode_AsUTF8(doc);
24772477
Py_DECREF(doc);
24782478
}
24792479

24802480
PyObject* s = PyObject_GetAttrString(object, "__name__");
24812481
if (s) {
24822482
Q_ASSERT(PyString_Check(s));
2483-
signature = PyString_AsString(s);
2483+
signature = PyUnicode_AsUTF8(s);
24842484
if (docstr.startsWith(signature + "(")) {
24852485
signature = docstr;
24862486
} else {
@@ -2499,14 +2499,14 @@ QString PythonQtPrivate::getSignature(PyObject* object)
24992499
PyObject* s = PyObject_GetAttrString((PyObject*)func, "__name__");
25002500
if (s) {
25012501
Q_ASSERT(PyString_Check(s));
2502-
funcName = PyString_AsString(s);
2502+
funcName = PyUnicode_AsUTF8(s);
25032503
Py_DECREF(s);
25042504
}
25052505
if (method && funcName == "__init__") {
25062506
PyObject* s = PyObject_GetAttrString(object, "__name__");
25072507
if (s) {
25082508
Q_ASSERT(PyString_Check(s));
2509-
funcName = PyString_AsString(s);
2509+
funcName = PyUnicode_AsUTF8(s);
25102510
Py_DECREF(s);
25112511
}
25122512
}
@@ -2525,18 +2525,18 @@ QString PythonQtPrivate::getSignature(PyObject* object)
25252525
for (int i=0; i<nargs; i++) {
25262526
PyObject* name = PyTuple_GetItem(co_varnames, i);
25272527
Q_ASSERT(PyString_Check(name));
2528-
arguments << PyString_AsString(name);
2528+
arguments << PyUnicode_AsUTF8(name);
25292529
}
25302530
if (code->co_flags & CO_VARARGS) {
25312531
PyObject* s = PyTuple_GetItem(co_varnames, nargs);
25322532
Q_ASSERT(PyString_Check(s));
2533-
varargs = PyString_AsString(s);
2533+
varargs = PyUnicode_AsUTF8(s);
25342534
nargs += 1;
25352535
}
25362536
if (code->co_flags & CO_VARKEYWORDS) {
25372537
PyObject* s = PyTuple_GetItem(co_varnames, nargs);
25382538
Q_ASSERT(PyString_Check(s));
2539-
varkeywords = PyString_AsString(s);
2539+
varkeywords = PyUnicode_AsUTF8(s);
25402540
}
25412541
Py_DECREF(co_varnames);
25422542
}
@@ -2548,7 +2548,7 @@ QString PythonQtPrivate::getSignature(PyObject* object)
25482548
PyObject* d = PyTuple_GetItem(defaultsTuple, i);
25492549
PyObject* s = PyObject_Repr(d);
25502550
Q_ASSERT(PyString_Check(s));
2551-
defaults << PyString_AsString(s);
2551+
defaults << PyUnicode_AsUTF8(s);
25522552
Py_DECREF(s);
25532553
}
25542554
}

src/PythonQtClassWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static PyObject *PythonQtClassWrapper_getattro(PyObject *obj, PyObject *name)
447447
const char *attributeName;
448448
PythonQtClassWrapper *wrapper = (PythonQtClassWrapper *)obj;
449449

450-
if ((attributeName = PyString_AsString(name)) == nullptr) {
450+
if ((attributeName = PyUnicode_AsUTF8(name)) == nullptr) {
451451
return nullptr;
452452
}
453453
if (obj == (PyObject*)&PythonQtInstanceWrapper_Type) {

src/PythonQtInstanceWrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name)
399399
const char *attributeName;
400400
PythonQtInstanceWrapper *wrapper = (PythonQtInstanceWrapper *)obj;
401401

402-
if ((attributeName = PyString_AsString(name)) == nullptr) {
402+
if ((attributeName = PyUnicode_AsUTF8(name)) == nullptr) {
403403
return nullptr;
404404
}
405405

@@ -631,7 +631,7 @@ static int PythonQtInstanceWrapper_setattro(PyObject *obj,PyObject *name,PyObjec
631631
const char *attributeName;
632632
PythonQtInstanceWrapper *wrapper = (PythonQtInstanceWrapper *)obj;
633633

634-
if ((attributeName = PyString_AsString(name)) == nullptr)
634+
if ((attributeName = PyUnicode_AsUTF8(name)) == nullptr)
635635
return -1;
636636

637637
PythonQtMemberInfo member = wrapper->classInfo()->member(attributeName);

src/PythonQtSlot.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ meth_get__doc__(PythonQtSlotFunctionObject * m, void * /*closure*/)
571571
if (returnTypeClassInfo && returnTypeClassInfo->pythonQtClassWrapper()) {
572572
PyObject* s = PyObject_GetAttrString(returnTypeClassInfo->pythonQtClassWrapper(), "__module__");
573573
if (s) {
574-
pyReturnType = QByteArray(PyString_AsString(s)) + "." + returnType;
574+
pyReturnType = QByteArray(PyUnicode_AsUTF8(s)) + "." + returnType;
575575
Py_DECREF(s);
576576
}
577577
}

src/PythonQtSlotDecorator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ PyObject* PythonQtSlotDecorator_call(PyObject* object, PyObject* args, PyObject*
9191

9292
if (PyFunction_Check(function)) {
9393
PyObject* funcName = ((PyFunctionObject*)function)->func_name;
94-
QByteArray slotName = PyString_AsString(funcName);
94+
QByteArray slotName = PyUnicode_AsUTF8(funcName);
9595

9696
QByteArray returnType = QMetaObject::normalizedType(self->returnType->constData());
9797
QByteArray signature = returnType + " " + slotName + "(" + *self->args + ")";

0 commit comments

Comments
 (0)