Remove/replace old conditional python code.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/16/head
Michele Calgaro 1 year ago
parent 6054548c25
commit 1c362264d3
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -210,7 +210,7 @@ public:
sipIsErr = 1;
else
for (int a = 0; a < argc; ++a)
if (PyList_SetItem(sipRes,a,SIPBytes_FromString(sipCpp -> argv()[a])) < 0)
if (PyList_SetItem(sipRes,a,PyBytes_FromString(sipCpp -> argv()[a])) < 0)
{
Py_DECREF(sipRes);
sipIsErr = 1;
@ -376,9 +376,9 @@ static char **pyArgvToC(PyObject *argvlist,int &argc)
{
arg = tqstrdup(sipString_AsUTF8String(&argObject));
}
else if (SIPBytes_Check(argObject))
else if (PyBytes_Check(argObject))
{
arg = tqstrdup(SIPBytes_AS_STRING(argObject));
arg = tqstrdup(PyBytes_AS_STRING(argObject));
}
else
{

@ -115,11 +115,7 @@ static PyObject* TQByteArray_To_String(TQByteArray *ba)
if (data)
{
#if PY_MAJOR_VERSION >= 3
return PyUnicode_FromStringAndSize(data, len);
#else
return SIPBytes_FromStringAndSize(data, len);
#endif
}
else
{
@ -178,7 +174,7 @@ public:
if (res == Py_None)
{
sipRes = SIPBytes_FromString("");
sipRes = PyBytes_FromString("");
}
else
{
@ -191,7 +187,7 @@ public:
// Allow a Python string whenever a TQByteArray is expected.
if (sipIsErr == NULL)
return (SIPBytes_Check(sipPy) ||
return (PyBytes_Check(sipPy) ||
PyUnicode_Check(sipPy) ||
sipCanConvertToInstance(sipPy,sipClass_TQByteArray,SIP_NO_CONVERTORS));
@ -210,7 +206,6 @@ public:
return sipGetState(sipTransferObj);
}
#if PY_VERSION_HEX >= 0x02060000
else if (PyByteArray_Check(sipPy))
{
Py_BEGIN_ALLOW_THREADS
@ -223,13 +218,12 @@ public:
return sipGetState(sipTransferObj);
}
#endif
else if (SIPBytes_Check(sipPy))
else if (PyBytes_Check(sipPy))
{
Py_BEGIN_ALLOW_THREADS
TQByteArray *ba = new TQByteArray();
ba -> duplicate(SIPBytes_AS_STRING(sipPy),SIPBytes_GET_SIZE(sipPy));
ba -> duplicate(PyBytes_AS_STRING(sipPy),PyBytes_GET_SIZE(sipPy));
*sipCppPtr = ba;
Py_END_ALLOW_THREADS

@ -193,19 +193,19 @@ public:
if (s == NULL)
s = "";
sipRes = SIPBytes_FromString(s);
sipRes = PyBytes_FromString(s);
%End
%ConvertToTypeCode
// Allow a Python string whenever a TQCString is expected.
if (sipIsErr == NULL)
return (SIPBytes_Check(sipPy) ||
return (PyBytes_Check(sipPy) ||
sipCanConvertToInstance(sipPy,sipClass_TQCString,SIP_NO_CONVERTORS));
if (SIPBytes_Check(sipPy))
if (PyBytes_Check(sipPy))
{
*sipCppPtr = new TQCString(SIPBytes_AS_STRING(sipPy));
*sipCppPtr = new TQCString(PyBytes_AS_STRING(sipPy));
return sipGetState(sipTransferObj);
}

@ -215,11 +215,7 @@ public:
TQStringList operator[](SIP_PYSLICE) const;
%MethodCode
#if PY_VERSION_HEX >= 0x02050000
Py_ssize_t len, start, stop, step, slicelength, i;
#else
int len, start, stop, step, slicelength, i;
#endif
Py_BEGIN_ALLOW_THREADS
len = sipCpp -> count();

@ -136,7 +136,7 @@ public:
Py_INCREF(Py_None);
sipRes = Py_None;
}
else if ((sipRes = SIPBytes_FromStringAndSize(buf,actlen)) == NULL)
else if ((sipRes = PyBytes_FromStringAndSize(buf,actlen)) == NULL)
sipIsErr = 1;
sipFree((void *)buf);
@ -171,7 +171,7 @@ public:
}
else
{
sipRes = SIPBytes_FromStringAndSize(buf,actlen);
sipRes = PyBytes_FromStringAndSize(buf,actlen);
sipFree((void *)buf);

@ -139,7 +139,7 @@ public:
}
else
{
sipRes = SIPBytes_FromStringAndSize(buf,actlen);
sipRes = PyBytes_FromStringAndSize(buf,actlen);
sipFree((void *)buf);
@ -159,15 +159,15 @@ public:
if (buf == Py_None)
sipRes = -1L;
else if (!SIPBytes_Check(buf))
else if (!PyBytes_Check(buf))
{
sipBadCatcherResult(sipMethod);
sipIsErr = 1;
}
else
{
memcpy(a0,SIPBytes_AS_STRING(buf),SIPBytes_GET_SIZE(buf));
sipRes = SIPBytes_GET_SIZE(buf);
memcpy(a0,PyBytes_AS_STRING(buf),PyBytes_GET_SIZE(buf));
sipRes = PyBytes_GET_SIZE(buf);
}
Py_DECREF(buf);
@ -201,7 +201,7 @@ public:
}
else
{
sipRes = SIPBytes_FromStringAndSize(buf,actlen);
sipRes = PyBytes_FromStringAndSize(buf,actlen);
sipFree((void *)buf);
@ -221,15 +221,15 @@ public:
if (buf == Py_None)
sipRes = -1L;
else if (!SIPBytes_Check(buf))
else if (!PyBytes_Check(buf))
{
sipBadCatcherResult(sipMethod);
sipIsErr = 1;
}
else
{
memcpy(a0,SIPBytes_AS_STRING(buf),SIPBytes_GET_SIZE(buf));
sipRes = SIPBytes_GET_SIZE(buf);
memcpy(a0,PyBytes_AS_STRING(buf),PyBytes_GET_SIZE(buf));
sipRes = PyBytes_GET_SIZE(buf);
}
Py_DECREF(buf);

@ -337,11 +337,7 @@ public:
// the true (Python) class name.
SIP_PYOBJECT className() const;
%MethodCode
#if PY_MAJOR_VERSION >= 3
sipRes = PyUnicode_FromString(sipSelf->ob_type->tp_name);
#else
sipRes = sipClassName(sipSelf);
#endif
%End
// Note that tr() and trUtf8() are really static methods. We pretend
@ -621,11 +617,11 @@ SIP_PYOBJECT SLOT(const char * /Encoding="ASCII"/) /TypeHint="QT_SLOT"/;
{
int len = strlen(a0);
if ((sipRes = SIPBytes_FromStringAndSize(NULL,1 + len)) == NULL)
if ((sipRes = PyBytes_FromStringAndSize(NULL,1 + len)) == NULL)
sipIsErr = 1;
else
{
char *dp = SIPBytes_AS_STRING(sipRes);
char *dp = PyBytes_AS_STRING(sipRes);
*dp++ = '1';
@ -646,11 +642,11 @@ SIP_PYOBJECT SIGNAL(const char * /Encoding="ASCII"/) /TypeHint="QT_SIGNAL"/;
{
int len = strlen(a0);
if ((sipRes = SIPBytes_FromStringAndSize(NULL,1 + len)) == NULL)
if ((sipRes = PyBytes_FromStringAndSize(NULL,1 + len)) == NULL)
sipIsErr = 1;
else
{
char *dp = SIPBytes_AS_STRING(sipRes);
char *dp = PyBytes_AS_STRING(sipRes);
*dp++ = '2';
@ -671,11 +667,11 @@ SIP_PYOBJECT PYSIGNAL(const char * /Encoding="ASCII"/);
{
int len = strlen(a0);
if ((sipRes = SIPBytes_FromStringAndSize(NULL,1 + len)) == NULL)
if ((sipRes = PyBytes_FromStringAndSize(NULL,1 + len)) == NULL)
sipIsErr = 1;
else
{
char *dp = SIPBytes_AS_STRING(sipRes);
char *dp = PyBytes_AS_STRING(sipRes);
*dp++ = '9';
@ -736,12 +732,7 @@ extern "C" {
// The meta-type for PyTQt classes. It is just a marker type so that we can
// safely cast to get access to PyTQt3-specific data structures.
PyTypeObject pyqtWrapperType_Type = {
#if PY_MAJOR_VERSION >= 3
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
#endif
"qt.pyqtWrapperType", /* tp_name */
sizeof (sipWrapperType), /* tp_basicsize */
0, /* tp_itemsize */
@ -755,10 +746,8 @@ PyTypeObject pyqtWrapperType_Type = {
0, /* tp_setattr */
#if PY_VERSION_HEX >= 0x03050000
0, /* tp_as_async */
#elif PY_VERSION_HEX >= 0x03010000
0, /* tp_reserved */
#else
0, /* tp_compare */
0, /* tp_reserved */
#endif
0, /* tp_repr */
0, /* tp_as_number */
@ -797,16 +786,14 @@ PyTypeObject pyqtWrapperType_Type = {
0, /* tp_subclasses */
0, /* tp_weaklist */
0, /* tp_del */
#if PY_VERSION_HEX >= 0x02060000
0, /* tp_version_tag */
#endif
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
#if PY_VERSION_HEX >= 0x03080000
0, /* tp_vectorcall */
#endif
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 8
#if PY_VERSION_HEX == 0x03080000
0, /* tp_print (deprecated) */
#endif
};
@ -963,12 +950,7 @@ static sipWrapperType pyqtWrapper_Type = {
{
#endif
{
#if PY_MAJOR_VERSION >= 3
PyVarObject_HEAD_INIT(&pyqtWrapperType_Type, 0)
#else
PyObject_HEAD_INIT(&pyqtWrapperType_Type)
0, /* ob_size */
#endif
"qt.pyqtWrapper", /* tp_name */
sizeof (pyqtWrapper), /* tp_basicsize */
0, /* tp_itemsize */
@ -982,10 +964,8 @@ static sipWrapperType pyqtWrapper_Type = {
0, /* tp_setattr */
#if PY_VERSION_HEX >= 0x03050000
0, /* tp_as_async */
#elif PY_VERSION_HEX >= 0x03010000
0, /* tp_reserved */
#else
0, /* tp_compare */
0, /* tp_reserved */
#endif
0, /* tp_repr */
0, /* tp_as_number */
@ -1024,16 +1004,14 @@ static sipWrapperType pyqtWrapper_Type = {
0, /* tp_subclasses */
0, /* tp_weaklist */
0, /* tp_del */
#if PY_VERSION_HEX >= 0x02060000
0, /* tp_version_tag */
#endif
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
#if PY_VERSION_HEX >= 0x03080000
0, /* tp_vectorcall */
#endif
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 8
#if PY_VERSION_HEX == 0x03080000
0, /* tp_print (deprecated) */
#endif
},
@ -1286,13 +1264,13 @@ bool UniversalSlot::tqt_invoke(int id, TQUObject *qargs)
case char_sat:
case schar_sat:
case uchar_sat:
arg = SIPBytes_FromStringAndSize((char *)static_QUType_ptr.get(qargs), 1);
arg = PyBytes_FromStringAndSize((char *)static_QUType_ptr.get(qargs), 1);
break;
case string_sat:
case sstring_sat:
case ustring_sat:
arg = SIPBytes_FromString((char *)static_QUType_ptr.get(qargs));
arg = PyBytes_FromString((char *)static_QUType_ptr.get(qargs));
break;
case short_sat:
@ -2097,11 +2075,7 @@ PyObject *pyqt3GetSender()
Py_FatalError("qt: Failed to register pyqtWrapperType type");
// Initialise the super-type.
#if PY_VERSION_HEX >= 0x02050000
pyqtWrapper_Type.super.ht_type.tp_base = sipWrapper_Type;
#else
pyqtWrapper_Type.super.type.tp_base = sipWrapper_Type;
#endif
if (PyType_Ready((PyTypeObject *)&pyqtWrapper_Type) < 0)
Py_FatalError("qt: Failed to initialise pyqtWrapper type");

@ -604,11 +604,7 @@ public:
TQString operator[](SIP_PYSLICE) const;
%MethodCode
#if PY_VERSION_HEX >= 0x02050000
Py_ssize_t len, start, stop, step, slicelength, i;
#else
int len, start, stop, step, slicelength, i;
#endif
len = sipCpp -> length();
@ -651,7 +647,7 @@ public:
// expected.
if (sipIsErr == NULL)
return (SIPBytes_Check(sipPy) ||
return (PyBytes_Check(sipPy) ||
PyUnicode_Check(sipPy) ||
sipCanConvertToInstance(sipPy,sipClass_TQString,SIP_NO_CONVERTORS));
@ -717,7 +713,7 @@ public:
enc = codec->fromUnicode(*sipCpp);
if ((encobj = SIPBytes_FromString(enc.data())) != NULL)
if ((encobj = PyBytes_FromString(enc.data())) != NULL)
{
*sipPtrPtr = (void *)PyString_AS_STRING(encobj);
sipRes = PyString_GET_SIZE(encobj);
@ -870,14 +866,8 @@ TQString *PyTQt_qt_PyObject_AsTQString(PyObject *obj)
}
else if (PyBytes_Check(obj))
{
return new TQString(SIPBytes_AS_STRING(obj));
}
#if PY_MAJOR_VERSION < 3
else if (PyString_Check(obj))
{
return new TQString(PyString_AS_STRING(obj));
return new TQString(PyBytes_AS_STRING(obj));
}
#endif
return NULL;
}
@ -917,11 +907,7 @@ const char *PyTQt_qt_encode(PyObject **s, TQApplication::Encoding encoding)
TQByteArray ba = codec->fromUnicode(qs);
delete qstr;
#if PY_MAJOR_VERSION >= 3
obj = PyBytes_FromStringAndSize(ba.data(), ba.size());
#else
obj = PyString_FromStringAndSize(ba.data(), ba.size());
#endif
}
else
{
@ -931,26 +917,14 @@ const char *PyTQt_qt_encode(PyObject **s, TQApplication::Encoding encoding)
if (obj)
{
#if PY_MAJOR_VERSION >= 3
es = PyBytes_AS_STRING(obj);
#else
es = PyString_AS_STRING(obj);
#endif
}
}
#if PY_MAJOR_VERSION >= 3
else if (PyBytes_Check(obj))
{
es = PyBytes_AS_STRING(obj);
Py_INCREF(obj);
}
#else
else if (PyString_Check(obj))
{
es = PyString_AS_STRING(obj);
Py_INCREF(obj);
}
#endif
else if (PyObject_AsCharBuffer(obj, &es, &sz) >= 0)
{
Py_INCREF(obj);

@ -105,11 +105,7 @@ public:
void __setitem__(SIP_PYSLICE,const TQStringList &);
%MethodCode
#if PY_VERSION_HEX >= 0x02050000
Py_ssize_t len, start, stop, step, slicelength, i;
#else
int len, start, stop, step, slicelength, i;
#endif
len = sipCpp -> count();
@ -152,11 +148,7 @@ public:
void __delitem__(SIP_PYSLICE);
%MethodCode
#if PY_VERSION_HEX >= 0x02050000
Py_ssize_t len, start, stop, step, slicelength, i;
#else
int len, start, stop, step, slicelength, i;
#endif
len = sipCpp -> count();
@ -184,11 +176,7 @@ public:
TQStringList operator[](SIP_PYSLICE slice);
%MethodCode
#if PY_VERSION_HEX >= 0x02050000
Py_ssize_t len, start, stop, step, slicelength, i;
#else
int len, start, stop, step, slicelength, i;
#endif
len = sipCpp -> count();

@ -57,7 +57,7 @@ is used instead.
{
PyObject *ps;
if ((ps = SIPBytes_FromString(s)) == NULL || PyList_SetItem(l,i,ps) < 0)
if ((ps = PyBytes_FromString(s)) == NULL || PyList_SetItem(l,i,ps) < 0)
{
Py_XDECREF(ps);
Py_DECREF(l);

@ -121,7 +121,7 @@ public:
Py_INCREF(Py_None);
sipRes = Py_None;
}
else if ((sipRes = SIPBytes_FromStringAndSize(buf,actlen)) == NULL)
else if ((sipRes = PyBytes_FromStringAndSize(buf,actlen)) == NULL)
sipIsErr = 1;
sipFree((void *)buf);

@ -218,7 +218,7 @@ public:
Py_INCREF(Py_None);
sipRes = Py_None;
}
else if ((sipRes = SIPBytes_FromStringAndSize(buf,actlen)) == NULL)
else if ((sipRes = PyBytes_FromStringAndSize(buf,actlen)) == NULL)
sipIsErr = 1;
sipFree((void *)buf);

@ -164,7 +164,7 @@ public:
}
else
{
sipRes = SIPBytes_FromStringAndSize(buf,actlen);
sipRes = PyBytes_FromStringAndSize(buf,actlen);
sipFree((void *)buf);
@ -200,7 +200,7 @@ public:
}
else
{
sipRes = SIPBytes_FromStringAndSize(buf,actlen);
sipRes = PyBytes_FromStringAndSize(buf,actlen);
sipFree((void *)buf);

@ -123,7 +123,7 @@ public:
Py_INCREF(Py_None);
sipRes = Py_None;
}
else if ((sipRes = SIPBytes_FromStringAndSize(buf,actlen)) == NULL)
else if ((sipRes = PyBytes_FromStringAndSize(buf,actlen)) == NULL)
sipIsErr = 1;
sipFree((void *)buf);

Loading…
Cancel
Save