Skip to content

Commit 628221f

Browse files
jcfrmrbean-bremen
authored andcommitted
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 224ff69 commit 628221f

File tree

6 files changed

+19
-21
lines changed

6 files changed

+19
-21
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) {
@@ -1978,7 +1978,7 @@ QString PythonQt::getReturnTypeOfWrappedMethodHelper(const PythonQtObjectPtr& va
19781978
if (typeInfo && typeInfo->pythonQtClassWrapper()) {
19791979
PyObject* s = PyObject_GetAttrString(typeInfo->pythonQtClassWrapper(), "__module__");
19801980
Q_ASSERT(PyString_Check(s));
1981-
type = QString(PyString_AsString(s)) + "." + type;
1981+
type = QString(PyUnicode_AsUTF8(s)) + "." + type;
19821982
Py_DECREF(s);
19831983
}
19841984
}
@@ -2309,7 +2309,7 @@ const QMetaObject* PythonQtPrivate::buildDynamicMetaObject(PythonQtClassWrapper*
23092309
// A signal object, register with the meta object
23102310
PythonQtSignalFunctionObject* signal = (PythonQtSignalFunctionObject*)value;
23112311
if (signal->_dynamicInfo) {
2312-
signal->_dynamicInfo->name = PyString_AsString(key);
2312+
signal->_dynamicInfo->name = PyUnicode_AsUTF8(key);
23132313
for (const QByteArray& sig : qAsConst(signal->_dynamicInfo->signatures)) {
23142314
builder.addSignal(signal->_dynamicInfo->name + "(" + sig + ")");
23152315
needsMetaObject = true;
@@ -2325,7 +2325,7 @@ const QMetaObject* PythonQtPrivate::buildDynamicMetaObject(PythonQtClassWrapper*
23252325
if (PythonQtProperty_Check(value)) {
23262326
needsMetaObject = true;
23272327
PythonQtProperty* prop = (PythonQtProperty*)value;
2328-
QMetaPropertyBuilder newProp = builder.addProperty(PyString_AsString(key), prop->data->cppType);
2328+
QMetaPropertyBuilder newProp = builder.addProperty(PyUnicode_AsUTF8(key), prop->data->cppType);
23292329
newProp.setReadable(true);
23302330
newProp.setWritable(prop->data->fset != nullptr);
23312331
newProp.setResettable(prop->data->freset != nullptr);
@@ -2355,7 +2355,7 @@ const QMetaObject* PythonQtPrivate::buildDynamicMetaObject(PythonQtClassWrapper*
23552355
Py_ssize_t count = PyList_Size(signatures);
23562356
for (Py_ssize_t i = 0; i < count; i++) {
23572357
PyObject* signature = PyList_GET_ITEM(signatures, i);
2358-
QByteArray sig = PyString_AsString(signature);
2358+
QByteArray sig = PyUnicode_AsUTF8(signature);
23592359
// Split the return type and the rest of the signature,
23602360
// no spaces should be in the rest of the signature...
23612361
QList<QByteArray> parts = sig.split(' ');
@@ -2474,14 +2474,14 @@ QString PythonQtPrivate::getSignature(PyObject* object)
24742474
QString docstr;
24752475
PyObject* doc = PyObject_GetAttrString(object, "__doc__");
24762476
if (doc) {
2477-
docstr = PyString_AsString(doc);
2477+
docstr = PyUnicode_AsUTF8(doc);
24782478
Py_DECREF(doc);
24792479
}
24802480

24812481
PyObject* s = PyObject_GetAttrString(object, "__name__");
24822482
if (s) {
24832483
Q_ASSERT(PyString_Check(s));
2484-
signature = PyString_AsString(s);
2484+
signature = PyUnicode_AsUTF8(s);
24852485
if (docstr.startsWith(signature + "(")) {
24862486
signature = docstr;
24872487
} else {
@@ -2500,14 +2500,14 @@ QString PythonQtPrivate::getSignature(PyObject* object)
25002500
PyObject* s = PyObject_GetAttrString((PyObject*)func, "__name__");
25012501
if (s) {
25022502
Q_ASSERT(PyString_Check(s));
2503-
funcName = PyString_AsString(s);
2503+
funcName = PyUnicode_AsUTF8(s);
25042504
Py_DECREF(s);
25052505
}
25062506
if (method && funcName == "__init__") {
25072507
PyObject* s = PyObject_GetAttrString(object, "__name__");
25082508
if (s) {
25092509
Q_ASSERT(PyString_Check(s));
2510-
funcName = PyString_AsString(s);
2510+
funcName = PyUnicode_AsUTF8(s);
25112511
Py_DECREF(s);
25122512
}
25132513
}
@@ -2526,18 +2526,18 @@ QString PythonQtPrivate::getSignature(PyObject* object)
25262526
for (int i=0; i<nargs; i++) {
25272527
PyObject* name = PyTuple_GetItem(co_varnames, i);
25282528
Q_ASSERT(PyString_Check(name));
2529-
arguments << PyString_AsString(name);
2529+
arguments << PyUnicode_AsUTF8(name);
25302530
}
25312531
if (code->co_flags & CO_VARARGS) {
25322532
PyObject* s = PyTuple_GetItem(co_varnames, nargs);
25332533
Q_ASSERT(PyString_Check(s));
2534-
varargs = PyString_AsString(s);
2534+
varargs = PyUnicode_AsUTF8(s);
25352535
nargs += 1;
25362536
}
25372537
if (code->co_flags & CO_VARKEYWORDS) {
25382538
PyObject* s = PyTuple_GetItem(co_varnames, nargs);
25392539
Q_ASSERT(PyString_Check(s));
2540-
varkeywords = PyString_AsString(s);
2540+
varkeywords = PyUnicode_AsUTF8(s);
25412541
}
25422542
Py_DECREF(co_varnames);
25432543
}
@@ -2549,7 +2549,7 @@ QString PythonQtPrivate::getSignature(PyObject* object)
25492549
PyObject* d = PyTuple_GetItem(defaultsTuple, i);
25502550
PyObject* s = PyObject_Repr(d);
25512551
Q_ASSERT(PyString_Check(s));
2552-
defaults << PyString_AsString(s);
2552+
defaults << PyUnicode_AsUTF8(s);
25532553
Py_DECREF(s);
25542554
}
25552555
}

src/PythonQtClassWrapper.cpp

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

451-
if ((attributeName = PyString_AsString(name)) == nullptr) {
451+
if ((attributeName = PyUnicode_AsUTF8(name)) == nullptr) {
452452
return nullptr;
453453
}
454454
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/PythonQtPythonInclude.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,13 @@
121121
#define PY3K
122122
// Helper defines to facilitate porting
123123
#define PyString_FromString PyUnicode_FromString
124-
#define PyString_AsString PyUnicode_AsUTF8
125124
#define PyString_FromFormat PyUnicode_FromFormat
126125
#define PyString_Check PyUnicode_Check
127126

128127
#else
129128
// Defines to use Python 3 names in Python 2 code
130129
#define PyBytes_Type PyString_Type
131130
#define PyBytes_Check PyString_Check
132-
#define PyBytes_AsString PyString_AsString
133131
#define PyBytes_GET_SIZE PyString_GET_SIZE
134132
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
135133
#endif

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)