diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2011-09-16 18:23:51 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:17:15 -0300 |
commit | cbfebc05a591a2370c3fad044e7a45a305c8ba4a (patch) | |
tree | a21742a87815907bfa004813dfa98bbf63ae8af4 | |
parent | 2cc05efe4c28c90d5dd6126d251f5ca9a9ebde07 (diff) |
Use PyBytes instead of PyString on generated code.
-rw-r--r-- | generator/cppgenerator.cpp | 8 | ||||
-rw-r--r-- | libshiboken/sbkpython.h | 2 |
2 files changed, 7 insertions, 3 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp index d54a02ab6..2a1badf0e 100644 --- a/generator/cppgenerator.cpp +++ b/generator/cppgenerator.cpp @@ -1441,6 +1441,8 @@ void CppGenerator::writeErrorSection(QTextStream& s, OverloadData& overloadData) strArg = "unicode"; else if (strArg == "PyString") strArg = "str"; + else if (strArg == "PyBytes") + strArg = "\"SBK_STR_NAME\""; else if (strArg == "PySequece") strArg = "list"; else if (strArg == "PyTuple") @@ -3705,7 +3707,7 @@ void CppGenerator::writeGetattroFunction(QTextStream& s, const AbstractMetaClass } s << INDENT << '}' << endl; - s << INDENT << "const char* cname = PyString_AS_STRING(name);" << endl; + s << INDENT << "const char* cname = PyBytes_AS_STRING(name);" << endl; foreach (const AbstractMetaFunction* func, getMethodsWithBothStaticAndNonStaticMethods(metaClass)) { s << INDENT << "if (strcmp(cname, \"" << func->name() << "\") == 0)" << endl; Indentation indent(INDENT); @@ -4195,12 +4197,12 @@ QString CppGenerator::writeReprFunction(QTextStream& s, const AbstractMetaClass* s << INDENT << "if (mod)" << endl; { Indentation indent(INDENT); - s << INDENT << "return PyString_FromFormat(\"<%s.%s at %p>\", PyString_AS_STRING(mod), str.constData(), self);" << endl; + s << INDENT << "return PyBytes_FromFormat(\"<%s.%s at %p>\", PyBytes_AS_STRING(mod), str.constData(), self);" << endl; } s << INDENT << "else" << endl; { Indentation indent(INDENT); - s << INDENT << "return PyString_FromFormat(\"<%s at %p>\", str.constData(), self);" << endl; + s << INDENT << "return PyBytes_FromFormat(\"<%s at %p>\", str.constData(), self);" << endl; } s << '}' << endl; s << "} // extern C" << endl << endl;; diff --git a/libshiboken/sbkpython.h b/libshiboken/sbkpython.h index 85a097b2a..d1653d792 100644 --- a/libshiboken/sbkpython.h +++ b/libshiboken/sbkpython.h @@ -37,10 +37,12 @@ #define SbkNumber_Check PyNumber_Check #define Py_TPFLAGS_CHECKTYPES 0 + #define SBK_STR_NAME "bytes" #else // Note: if there wasn't for the old-style classes, only a PyNumber_Check would suffice. #define SbkNumber_Check(X) \ (PyNumber_Check(X) && (!PyInstance_Check(X) || PyObject_HasAttrString(X, "__trunc__"))) + #define SBK_STR_NAME "str" #endif #endif |