aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2011-07-05 11:59:33 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:15:27 -0300
commit219ee31ce4cf9c45b9a53cd267df3e8e7b53b0f2 (patch)
tree5619e8d5e5f66dc8b5e234b1589e0ba35e556bdd
parent878c6c81a7469335e70856f77142473bb358051d (diff)
Now the generated code stores the enum cpp name on the PyThon type.
This is necessary for finding out the enum name during the signal match function. Fixed the signal register function for signals with default values. Fixes bug #903. Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--generator/cppgenerator.cpp11
-rw-r--r--libshiboken/sbkenum.cpp37
-rw-r--r--libshiboken/sbkenum.h6
3 files changed, 40 insertions, 14 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index 25c3db030..9e542b4e9 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -3233,7 +3233,8 @@ void CppGenerator::writeEnumInitialization(QTextStream& s, const AbstractMetaEnu
if (!cppEnum->isAnonymous()) {
- s << INDENT << "PyTypeObject* " << cpythonName << " = Shiboken::Enum::newType(\"" << getClassTargetFullName(cppEnum) << "\");" << endl;
+ s << INDENT << "PyTypeObject* " << cpythonName << " = Shiboken::Enum::newTypeWithName(\"" << getClassTargetFullName(cppEnum) << "\", \""
+ << (cppEnum->enclosingClass() ? cppEnum->enclosingClass()->qualifiedCppName() + "::" : "") << cppEnum->name() << "\");" << endl;
if (cppEnum->typeEntry()->flags())
s << INDENT << cpythonName << "->tp_as_number = &" << cpythonName << "_as_number;" << endl;
@@ -3332,9 +3333,6 @@ void CppGenerator::writeSignalInitialization(QTextStream& s, const AbstractMetaC
if (cppSignal->declaringClass() == metaClass) {
if (cppSignal->arguments().count()) {
for (int i = 0; i < cppSignal->arguments().count(); ++i) {
- if (i > 0)
- signature += ", ";
-
AbstractMetaArgument* arg = cppSignal->arguments().at(i);
AbstractMetaType* type = arg->type();
@@ -3370,7 +3368,8 @@ void CppGenerator::writeSignalInitialization(QTextStream& s, const AbstractMetaC
<< originalType << " >"
<< "(\"" << skipNamespace(signalTypeName) << "\");" << endl;
}
-
+ if (i>0)
+ signature += ", ";
signature += SBK_NORMALIZED_TYPE(signalTypeName.toAscii());
}
} else {
@@ -3390,7 +3389,7 @@ void CppGenerator::writeSignalInitialization(QTextStream& s, const AbstractMetaC
foreach(QString funcName, signatures.keys()) {
s << INDENT << "signal_item = PySide::Signal::newObject(\"" << funcName <<"\"";
foreach(QString signature, signatures[funcName])
- s << ", \"" + signature << "\"";
+ s << ", \"" << signature << "\"";
s << ", NULL);" << endl;
s << INDENT << "PySide::Signal::addSignalToWrapper(&" + cpythonTypeName(metaClass) + ", \"";
s << funcName << "\", signal_item);" << endl;
diff --git a/libshiboken/sbkenum.cpp b/libshiboken/sbkenum.cpp
index 804f4480e..e128a059a 100644
--- a/libshiboken/sbkenum.cpp
+++ b/libshiboken/sbkenum.cpp
@@ -21,6 +21,7 @@
*/
#include "sbkenum.h"
+#include <string.h>
#include <cstring>
#include <list>
#include "sbkdbg.h"
@@ -147,11 +148,13 @@ public:
DeclaredEnumTypes();
~DeclaredEnumTypes();
static DeclaredEnumTypes& instance();
- void addEnumType(PyTypeObject* type);
+ void addEnumType(PyTypeObject* type, const char* cppName);
+ const char* getCppName(PyTypeObject* type);
+
private:
DeclaredEnumTypes(const DeclaredEnumTypes&);
DeclaredEnumTypes& operator=(const DeclaredEnumTypes&);
- std::list<PyTypeObject*> m_enumTypes;
+ std::map<PyTypeObject*, std::string> m_enumTypes;
};
namespace Enum {
@@ -204,8 +207,14 @@ PyObject* newItem(PyTypeObject* enumType, long itemValue, const char* itemName)
return reinterpret_cast<PyObject*>(enumObj);
}
+
PyTypeObject* newType(const char* name)
{
+ return newTypeWithName(name, "");
+}
+
+PyTypeObject* newTypeWithName(const char* name, const char* cppName)
+{
PyTypeObject* type = new PyTypeObject;
::memset(type, 0, sizeof(PyTypeObject));
type->ob_type = &SbkEnumType_Type;
@@ -219,10 +228,15 @@ PyTypeObject* newType(const char* name)
type->tp_getset = SbkEnumGetSetList;
type->tp_new = SbkEnum_tp_new;
- DeclaredEnumTypes::instance().addEnumType(type);
+ DeclaredEnumTypes::instance().addEnumType(type, cppName);
return type;
}
+const char* getCppName(PyTypeObject* enumType)
+{
+ return DeclaredEnumTypes::instance().getCppName(enumType);
+}
+
long int getValue(PyObject* enumItem)
{
return reinterpret_cast<SbkEnumObject*>(enumItem)->ob_ival;
@@ -242,15 +256,24 @@ DeclaredEnumTypes::DeclaredEnumTypes()
DeclaredEnumTypes::~DeclaredEnumTypes()
{
- std::list<PyTypeObject*>::const_iterator it = m_enumTypes.begin();
+ std::map<PyTypeObject*, std::string>::const_iterator it = m_enumTypes.begin();
for (; it != m_enumTypes.end(); ++it)
- delete *it;
+ delete (*it).first;
m_enumTypes.clear();
}
-void DeclaredEnumTypes::addEnumType(PyTypeObject* type)
+void DeclaredEnumTypes::addEnumType(PyTypeObject* type, const char* cppName)
+{
+ m_enumTypes[type] = cppName;
+}
+
+const char* DeclaredEnumTypes::getCppName(PyTypeObject* type)
{
- m_enumTypes.push_back(type);
+ std::map<PyTypeObject*, std::string>::const_iterator it = m_enumTypes.find(type);
+ if (it != m_enumTypes.end())
+ return it->second.c_str();
+ else
+ return "";
}
}
diff --git a/libshiboken/sbkenum.h b/libshiboken/sbkenum.h
index 95b500ca4..c61afed91 100644
--- a/libshiboken/sbkenum.h
+++ b/libshiboken/sbkenum.h
@@ -44,7 +44,11 @@ inline bool isShibokenEnum(PyObject* pyObj)
namespace Enum
{
LIBSHIBOKEN_API PyObject* newItem(PyTypeObject* enumType, long itemValue, const char* itemName = 0);
- LIBSHIBOKEN_API PyTypeObject* newType(const char* name);
+
+ LIBSHIBOKEN_API PyTypeObject* newType(const char* name); //Deprecated use 'newTypeWithName'
+ LIBSHIBOKEN_API PyTypeObject* newTypeWithName(const char* name, const char* cppName);
+ LIBSHIBOKEN_API const char* getCppName(PyTypeObject* type);
+
LIBSHIBOKEN_API long getValue(PyObject* enumItem);
LIBSHIBOKEN_API PyObject* getEnumItemFromValue(PyTypeObject* enumType, long itemValue);
}