From d5ac67324004464c23e0c2815bf21675077004e9 2013-07-30 13:36:06 From: Orochimarufan Date: 2013-07-30 13:36:06 Subject: [PATCH] Modify typesystems to #ifdef PyString --- diff --git a/generator/shellimplgenerator.cpp b/generator/shellimplgenerator.cpp index cbe4a82..fd0c97b 100644 --- a/generator/shellimplgenerator.cpp +++ b/generator/shellimplgenerator.cpp @@ -125,7 +125,7 @@ void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla AbstractMetaArgumentList args = fun->arguments(); s << "if (_wrapper && (_wrapper->ob_refcnt > 0)) {" << endl; - s << " static PyObject* name = PyString_FromString(\"" << fun->name() << "\");" << endl; + s << "#ifdef PY3K\n static PyObject* name = PyUnicode_FromString(\"" << fun->name() << "\");\n#else\n static PyObject* name = PyString_FromString(\"" << fun->name() << "\");\n#endif" << endl; s << " PyObject* obj = PyBaseObject_Type.tp_getattro((PyObject*)_wrapper, name);" << endl; s << " if (obj) {" << endl; s << " static const char* argumentList[] ={\""; diff --git a/generator/typesystem_core-qtscript.xml b/generator/typesystem_core-qtscript.xml index 2d2049d..ea51d04 100644 --- a/generator/typesystem_core-qtscript.xml +++ b/generator/typesystem_core-qtscript.xml @@ -353,7 +353,11 @@ PyObject* data(QByteArray* b) { if (b->data()) { +#ifdef PY3K + return PyUnicode_FromStringAndSize(b->data(), b->size()); +#else return PyString_FromStringAndSize(b->data(), b->size()); +#endif } else { Py_INCREF(Py_None); return Py_None; diff --git a/generator/typesystem_core.xml b/generator/typesystem_core.xml index d3b82f4..ec43a11 100644 --- a/generator/typesystem_core.xml +++ b/generator/typesystem_core.xml @@ -1163,7 +1163,11 @@ PyObject* data(QByteArray* b) { +#ifdef PY3K + return PyUnicode_FromStringAndSize(b->data(), b->size()); +#else return PyString_FromStringAndSize(b->data(), b->size()); +#endif } @@ -1948,7 +1952,11 @@ r.resize(len); int result = d->readRawData(r.data(), r.size()); if (result>=0) { +#ifdef PY3K + return PyUnicode_FromStringAndSize(r.data(), result); +#else return PyString_FromStringAndSize(r.data(), result); +#endif } else { Py_INCREF(Py_None); return Py_None; diff --git a/generator_50/typesystem_core-qtscript.xml b/generator_50/typesystem_core-qtscript.xml index e80279e..3fd4f71 100644 --- a/generator_50/typesystem_core-qtscript.xml +++ b/generator_50/typesystem_core-qtscript.xml @@ -356,16 +356,20 @@ - - PyObject* data(QByteArray* b) { - if (b->data()) { - return PyString_FromStringAndSize(b->data(), b->size()); - } else { - Py_INCREF(Py_None); - return Py_None; - } - } - + + PyObject* data(QByteArray* b) { + if (b->data()) { +#ifdef PY3K + return PyUnicode_FromStringAndSize(b->data(), b->size()); +#else + return PyString_FromStringAndSize(b->data(), b->size()); +#endif + } else { + Py_INCREF(Py_None); + return Py_None; + } + } + Q_DECLARE_METATYPE(QScriptValue) diff --git a/generator_50/typesystem_core.xml b/generator_50/typesystem_core.xml index 5de2425..fe0f3de 100644 --- a/generator_50/typesystem_core.xml +++ b/generator_50/typesystem_core.xml @@ -1174,7 +1174,11 @@ PyObject* data(QByteArray* b) { if (b->data()) { +#ifdef PY3K + return PyUnicode_FromStringAndSize(b->data(), b->size()); +#else return PyString_FromStringAndSize(b->data(), b->size()); +#endif } else { Py_INCREF(Py_None); return Py_None;