summaryrefslogtreecommitdiffstats
path: root/sip/qt/qbytearray.sip
diff options
context:
space:
mode:
Diffstat (limited to 'sip/qt/qbytearray.sip')
-rw-r--r--sip/qt/qbytearray.sip115
1 files changed, 81 insertions, 34 deletions
diff --git a/sip/qt/qbytearray.sip b/sip/qt/qbytearray.sip
index db5d266..d975472 100644
--- a/sip/qt/qbytearray.sip
+++ b/sip/qt/qbytearray.sip
@@ -98,6 +98,36 @@ class TQByteArray
#include <tqstring.h>
%End
+%TypeCode
+// Convert a TQByteArray to a Python string or Py_None if there's
+// no data
+static PyObject* TQByteArray_To_String(TQByteArray *ba)
+{
+ // TQByteArrays aren't '\0' terminated so set the size
+ // explicitly.
+ char *data;
+ uint len;
+
+ Py_BEGIN_ALLOW_THREADS
+ data = ba->data();
+ len = ba->size();
+ Py_END_ALLOW_THREADS
+
+ if (data)
+ {
+#if PY_MAJOR_VERSION >= 3
+ return PyUnicode_FromStringAndSize(data, len);
+#else
+ return SIPBytes_FromStringAndSize(data, len);
+#endif
+ }
+ else
+ {
+ return Py_None;
+ }
+}
+%End
+
public:
TQByteArray();
TQByteArray(int);
@@ -105,27 +135,20 @@ public:
SIP_PYOBJECT data() const;
%MethodCode
- // TQByteArrays aren't '\0' terminated so set the size
- // explicitly.
-
- char *res;
- uint len;
-
- Py_BEGIN_ALLOW_THREADS
- res = sipCpp -> data();
- len = sipCpp -> size();
- Py_END_ALLOW_THREADS
+ PyObject* res = TQByteArray_To_String(sipCpp);
- if (res)
+ if (res == Py_None)
{
- if ((sipRes = PyString_FromStringAndSize(res,len)) == NULL)
- sipIsErr = 1;
+ Py_INCREF(Py_None);
}
- else
+ else if (res == NULL)
{
- Py_INCREF(Py_None);
- sipRes = Py_None;
+ sipIsErr = 1;
}
+ else
+ {
+ sipRes = res;
+ }
%End
// These are actually in TQMemArray, which isn't implemented so pretend
@@ -151,36 +174,62 @@ public:
SIP_PYOBJECT __str__();
%MethodCode
- // TQByteArrays aren't '\0' terminated so set the size
- // explicitly.
+ PyObject* res = TQByteArray_To_String(sipCpp);
- char *data;
- uint len;
-
- Py_BEGIN_ALLOW_THREADS
- data = sipCpp -> data();
- len = sipCpp -> size();
- Py_END_ALLOW_THREADS
-
- if (data == NULL)
- sipRes = PyString_FromString("");
+ if (res == Py_None)
+ {
+ sipRes = SIPBytes_FromString("");
+ }
else
- sipRes = PyString_FromStringAndSize(data,len);
+ {
+ sipRes = res;
+ }
%End
+
%ConvertToTypeCode
// Allow a Python string whenever a TQByteArray is expected.
if (sipIsErr == NULL)
- return (PyString_Check(sipPy) ||
+ return (SIPBytes_Check(sipPy) ||
+ PyUnicode_Check(sipPy) ||
sipCanConvertToInstance(sipPy,sipClass_TQByteArray,SIP_NO_CONVERTORS));
- if (PyString_Check(sipPy))
+ if (PyUnicode_Check(sipPy))
+ {
+ Py_BEGIN_ALLOW_THREADS
+ TQByteArray *ba = new TQByteArray();
+
+#if PY_VERSION_HEX >= 0x03030000
+ ba -> duplicate((char *)PyUnicode_1BYTE_DATA(sipPy),PyUnicode_GET_SIZE(sipPy));
+#else
+ ba -> duplicate((char *)PyUnicode_AS_DATA(sipPy),PyUnicode_GET_SIZE(sipPy));
+#endif
+ *sipCppPtr = ba;
+ Py_END_ALLOW_THREADS
+
+ return sipGetState(sipTransferObj);
+ }
+#if PY_VERSION_HEX >= 0x02060000
+ else if (PyByteArray_Check(sipPy))
{
Py_BEGIN_ALLOW_THREADS
TQByteArray *ba = new TQByteArray();
- ba -> duplicate(PyString_AS_STRING(sipPy),PyString_GET_SIZE(sipPy));
+ ba -> duplicate(PyByteArray_AS_STRING(sipPy),PyByteArray_GET_SIZE(sipPy));
+
+ *sipCppPtr = ba;
+ Py_END_ALLOW_THREADS
+
+ return sipGetState(sipTransferObj);
+ }
+#endif
+ else if (SIPBytes_Check(sipPy))
+ {
+ Py_BEGIN_ALLOW_THREADS
+ TQByteArray *ba = new TQByteArray();
+
+ ba -> duplicate(SIPBytes_AS_STRING(sipPy),SIPBytes_GET_SIZE(sipPy));
*sipCppPtr = ba;
Py_END_ALLOW_THREADS
@@ -195,9 +244,7 @@ public:
};
-%If (TQt_3_1_0 -)
TQByteArray tqCompress(const uchar * /Array/,int /ArraySize/);
TQByteArray tqCompress(const TQByteArray &);
TQByteArray tqUncompress(const uchar * /Array/,int /ArraySize/);
TQByteArray tqUncompress(const TQByteArray &);
-%End