Changes needed to compile QtCore with libshiboken v1.0

This commit is contained in:
Hugo Parente Lima 2010-11-10 17:22:32 -02:00
commit 92dcb7ae3a
13 changed files with 57 additions and 59 deletions

View file

@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 2.6)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Macros/ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Macros/
${CMAKE_MODULE_PATH}) ${CMAKE_MODULE_PATH})
find_package(GeneratorRunner 0.6.3 REQUIRED) find_package(GeneratorRunner 0.6.3 REQUIRED)
find_package(Shiboken 0.5.2 REQUIRED) find_package(Shiboken 1.0.0 REQUIRED)
find_package(Qt4 4.5.0 REQUIRED) find_package(Qt4 4.5.0 REQUIRED)
include(FindQt4Extra) include(FindQt4Extra)

View file

@ -15,7 +15,7 @@ static Py_ssize_t SbkQByteArray_segcountproc(PyObject* self, Py_ssize_t* lenp)
static Py_ssize_t SbkQByteArray_readbufferproc(PyObject* self, Py_ssize_t segment, void** ptrptr) static Py_ssize_t SbkQByteArray_readbufferproc(PyObject* self, Py_ssize_t segment, void** ptrptr)
{ {
if (segment || Shiboken::cppObjectIsInvalid(self)) if (segment || !Shiboken::Wrapper::isValid(self))
return -1; return -1;
QByteArray* cppSelf = Converter<QByteArray*>::toCpp(self); QByteArray* cppSelf = Converter<QByteArray*>::toCpp(self);

View file

@ -2,7 +2,7 @@
static int QCoreApplicationArgCount; static int QCoreApplicationArgCount;
static char** QCoreApplicationArgValues; static char** QCoreApplicationArgValues;
int SbkQCoreApplication_Init(PyObject* self, PyObject* args, PyObject*) int Sbk_QCoreApplication_Init(PyObject* self, PyObject* args, PyObject*)
{ {
if (Shiboken::isUserType(self) && !Shiboken::canCallConstructor(self->ob_type, Shiboken::SbkType<QApplication >())) if (Shiboken::isUserType(self) && !Shiboken::canCallConstructor(self->ob_type, Shiboken::SbkType<QApplication >()))
return -1; return -1;
@ -19,20 +19,21 @@ int SbkQCoreApplication_Init(PyObject* self, PyObject* args, PyObject*)
return -1; return -1;
} }
if (!PySequenceToArgcArgv(PyTuple_GET_ITEM(args, 0), &QCoreApplicationArgCount, &QCoreApplicationArgValues, "PySideApp")) { if (!Shiboken::sequenceToArgcArgv(PyTuple_GET_ITEM(args, 0), &QCoreApplicationArgCount, &QCoreApplicationArgValues, "PySideApp")) {
PyErr_BadArgument(); PyErr_BadArgument();
return -1; return -1;
} }
SbkObject* sbkSelf = reinterpret_cast<SbkObject*>(self);
QCoreApplicationWrapper* cptr = new QCoreApplicationWrapper(QCoreApplicationArgCount, QCoreApplicationArgValues); QCoreApplicationWrapper* cptr = new QCoreApplicationWrapper(QCoreApplicationArgCount, QCoreApplicationArgValues);
Shiboken::setCppPointer(reinterpret_cast<SbkBaseWrapper*>(self), Shiboken::Wrapper::setCppPointer(sbkSelf,
Shiboken::SbkType<QCoreApplication>(), Shiboken::SbkType<QCoreApplication>(),
cptr); cptr);
SbkBaseWrapper_setValidCppObject(self, 1); Shiboken::Wrapper::setValidCpp(sbkSelf, true);
SbkBaseWrapper *sbkSelf = reinterpret_cast<SbkBaseWrapper*>(self); Shiboken::Wrapper::setHasCppWrapper(sbkSelf, true);
sbkSelf->containsCppWrapper = 1; Shiboken::Wrapper::releaseOwnership(sbkSelf);
sbkSelf->hasOwnership = 0;
Shiboken::BindingManager::instance().registerWrapper(sbkSelf, cptr); Shiboken::BindingManager::instance().registerWrapper(sbkSelf, cptr);
PySide::Signal::updateSourceObject(self); PySide::Signal::updateSourceObject(self);
cptr->metaObject(); cptr->metaObject();

View file

@ -66,7 +66,7 @@ static bool qobjectConnectCallback(QObject* source, const char* signal, PyObject
const char* slot = callbackSig.constData(); const char* slot = callbackSig.constData();
int slotIndex = metaObject->indexOfSlot(slot); int slotIndex = metaObject->indexOfSlot(slot);
if (slotIndex == -1) { if (slotIndex == -1) {
if (!usingGlobalReceiver && self && !((SbkBaseWrapper*)self)->containsCppWrapper) { if (!usingGlobalReceiver && self && !Shiboken::Wrapper::hasCppWrapper((SbkObject*)self)) {
qWarning() << "You can't add dynamic slots on an object originated from C++."; qWarning() << "You can't add dynamic slots on an object originated from C++.";
return false; return false;
} }

View file

@ -16,8 +16,8 @@ struct Converter<QVariant>
static QByteArray resolveMetaType(PyTypeObject* type, int &typeId) static QByteArray resolveMetaType(PyTypeObject* type, int &typeId)
{ {
if (PyObject_TypeCheck(type, &Shiboken::SbkBaseWrapperType_Type)) { if (PyObject_TypeCheck(type, &SbkObjectType_Type)) {
Shiboken::SbkBaseWrapperType *sbkType = reinterpret_cast<Shiboken::SbkBaseWrapperType*>(type); SbkObjectType* sbkType = reinterpret_cast<SbkObjectType*>(type);
const char* typeName = sbkType->original_name; const char* typeName = sbkType->original_name;
int obTypeId = QMetaType::type(typeName); int obTypeId = QMetaType::type(typeName);
@ -82,7 +82,7 @@ struct Converter<QVariant>
} else { } else {
// a class supported by QVariant? // a class supported by QVariant?
if (Shiboken::isShibokenType(pyObj) && !Shiboken::isUserType(pyObj)) { if (Shiboken::isShibokenType(pyObj) && !Shiboken::isUserType(pyObj)) {
Shiboken::SbkBaseWrapperType *objType = reinterpret_cast<Shiboken::SbkBaseWrapperType*>(pyObj->ob_type); SbkObjectType* objType = reinterpret_cast<SbkObjectType*>(pyObj->ob_type);
int typeCode = 0; int typeCode = 0;
QByteArray typeName = resolveMetaType(reinterpret_cast<PyTypeObject*>(objType), typeCode); QByteArray typeName = resolveMetaType(reinterpret_cast<PyTypeObject*>(objType), typeCode);
if (typeCode) { if (typeCode) {

View file

@ -26,8 +26,8 @@ struct Converter<QVariant::Type>
else if (pyObj == reinterpret_cast<PyObject*>(&PyLong_Type)) else if (pyObj == reinterpret_cast<PyObject*>(&PyLong_Type))
typeName = "int"; // long is a UserType in QVariant. typeName = "int"; // long is a UserType in QVariant.
else if (PyType_Check(pyObj)) { else if (PyType_Check(pyObj)) {
if (pyObj->ob_type == &Shiboken::SbkBaseWrapperType_Type) if (pyObj->ob_type == &SbkObjectType_Type)
typeName = reinterpret_cast<Shiboken::SbkBaseWrapperType*>(pyObj)->original_name; typeName = reinterpret_cast<SbkObjectType*>(pyObj)->original_name;
else else
typeName = reinterpret_cast<PyTypeObject*>(pyObj)->tp_name; typeName = reinterpret_cast<PyTypeObject*>(pyObj)->tp_name;
} }

View file

@ -1061,7 +1061,7 @@
<add-function signature="__setitem__"> <add-function signature="__setitem__">
<inject-code class="target" position="beginning"> <inject-code class="target" position="beginning">
PyObject* args = Py_BuildValue("(iiO)", _i, 1, _value); PyObject* args = Py_BuildValue("(iiO)", _i, 1, _value);
PyObject* result = SbkQBitArrayFunc_setBit(self, args); PyObject* result = Sbk_QBitArrayFunc_setBit(self, args);
Py_DECREF(args); Py_DECREF(args);
Py_XDECREF(result); Py_XDECREF(result);
return !result ? -1 : 0; return !result ? -1 : 0;
@ -1700,7 +1700,7 @@
<inject-code class="target" position="beginning"> <inject-code class="target" position="beginning">
%CPPSELF.remove(_i, 1); %CPPSELF.remove(_i, 1);
PyObject* args = Py_BuildValue("(nO)", _i, _value); PyObject* args = Py_BuildValue("(nO)", _i, _value);
PyObject* result = SbkQByteArrayFunc_insert(self, args); PyObject* result = Sbk_QByteArrayFunc_insert(self, args);
Py_DECREF(args); Py_DECREF(args);
Py_XDECREF(result); Py_XDECREF(result);
return !result ? -1 : 0; return !result ? -1 : 0;
@ -1940,7 +1940,7 @@
%3) %3)
); );
// invalidate to avoid use of python object // invalidate to avoid use of python object
Shiboken::BindingManager::instance().destroyWrapper((Shiboken::SbkBaseWrapper *)pyTimer); Shiboken::BindingManager::instance().destroyWrapper((SbkObject*)pyTimer);
timer->setSingleShot(true); timer->setSingleShot(true);
timer->connect(timer, SIGNAL("timeout()"), timer, SLOT("deleteLater()")); timer->connect(timer, SIGNAL("timeout()"), timer, SLOT("deleteLater()"));
timer->start(%1); timer->start(%1);
@ -1978,7 +1978,7 @@
pyargs[1]) pyargs[1])
); );
} }
Shiboken::BindingManager::instance().destroyWrapper((Shiboken::SbkBaseWrapper *)pyTimer); Shiboken::BindingManager::instance().destroyWrapper((SbkObject*)pyTimer);
timer->start(%1); timer->start(%1);
</inject-code> </inject-code>
</add-function> </add-function>
@ -2680,7 +2680,7 @@
// Check bug #362 for more information on this // Check bug #362 for more information on this
// http://bugs.openbossa.org/show_bug.cgi?id=362 // http://bugs.openbossa.org/show_bug.cgi?id=362
if (!PyObject_TypeCheck(%1, &amp;PySideSignalInstanceType)) if (!PyObject_TypeCheck(%1, &amp;PySideSignalInstanceType))
goto Sbk%TYPEFunc_%FUNCTION_NAME_TypeError; goto Sbk_%TYPEFunc_%FUNCTION_NAME_TypeError;
PySideSignalInstance* signalInstance = reinterpret_cast&lt;PySideSignalInstance*&gt;(%1); PySideSignalInstance* signalInstance = reinterpret_cast&lt;PySideSignalInstance*&gt;(%1);
QObject* sender = %CONVERTTOCPP[QObject*](PySide::Signal::getObject(signalInstance)); QObject* sender = %CONVERTTOCPP[QObject*](PySide::Signal::getObject(signalInstance));
%PYARG_0 = %CONVERTTOPYTHON[QSignalTransition*](%CPPSELF->%FUNCTION_NAME(sender, PySide::Signal::getSignature(signalInstance), %2)); %PYARG_0 = %CONVERTTOPYTHON[QSignalTransition*](%CPPSELF->%FUNCTION_NAME(sender, PySide::Signal::getSignature(signalInstance), %2));

View file

@ -110,15 +110,15 @@ void destroyQCoreApplication()
return; return;
Shiboken::BindingManager& bm = Shiboken::BindingManager::instance(); Shiboken::BindingManager& bm = Shiboken::BindingManager::instance();
PyObject* pyQApp = bm.retrieveWrapper(app); SbkObject* pyQApp = bm.retrieveWrapper(app);
PyTypeObject* pyQObjectType = Shiboken::TypeResolver::get("QObject*")->pythonType(); PyTypeObject* pyQObjectType = Shiboken::TypeResolver::get("QObject*")->pythonType();
assert(pyQObjectType); assert(pyQObjectType);
foreach (PyObject* pyObj, bm.getAllPyObjects()) { foreach (SbkObject* pyObj, bm.getAllPyObjects()) {
if (pyObj != pyQApp && PyObject_TypeCheck(pyObj, pyQObjectType)) { if (pyObj != pyQApp && PyObject_TypeCheck(pyObj, pyQObjectType)) {
if (SbkBaseWrapper_hasOwnership(pyObj)) { if (Shiboken::Wrapper::hasOwnership(pyObj)) {
bm.destroyWrapper(pyObj); bm.destroyWrapper(pyObj);
delete static_cast<QObject*>(Shiboken::getCppPointer(pyObj, Shiboken::SbkType<QObject*>())); delete static_cast<QObject*>(Shiboken::Wrapper::cppPointer(pyObj, Shiboken::SbkType<QObject*>()));
} }
} }
} }

View file

@ -73,7 +73,7 @@ struct QtDictConverter
static inline QtDict toCpp(PyObject* pyobj) static inline QtDict toCpp(PyObject* pyobj)
{ {
if (PyObject_TypeCheck(pyobj, Shiboken::SbkType<QtDict>())) if (PyObject_TypeCheck(pyobj, Shiboken::SbkType<QtDict>()))
return *reinterpret_cast<QtDict*>(Shiboken::getCppPointer(pyobj, Shiboken::SbkType<QtDict>())); return *reinterpret_cast<QtDict*>(Shiboken::Wrapper::cppPointer((SbkObject*)pyobj, Shiboken::SbkType<QtDict>()));
QtDict result; QtDict result;
@ -150,7 +150,7 @@ struct QtMultiMapConverter
static inline MultiMap toCpp(PyObject* pyObj) static inline MultiMap toCpp(PyObject* pyObj)
{ {
if (PyObject_TypeCheck(pyObj, Shiboken::SbkType<MultiMap>())) if (PyObject_TypeCheck(pyObj, Shiboken::SbkType<MultiMap>()))
return *reinterpret_cast<MultiMap*>(Shiboken::getCppPointer(pyObj, Shiboken::SbkType<MultiMap>())); return *reinterpret_cast<MultiMap*>(Shiboken::Wrapper::cppPointer((SbkObject*)pyObj, Shiboken::SbkType<MultiMap>()));
MultiMap result; MultiMap result;
@ -199,7 +199,7 @@ struct QSequenceConverter
static T toCpp(PyObject* pyobj) static T toCpp(PyObject* pyobj)
{ {
if (PyObject_TypeCheck(pyobj, Shiboken::SbkType<T>())) if (PyObject_TypeCheck(pyobj, Shiboken::SbkType<T>()))
return *reinterpret_cast<T*>(Shiboken::getCppPointer(pyobj, Shiboken::SbkType<T>())); return *reinterpret_cast<T*>(Shiboken::Wrapper::cppPointer((SbkObject*)pyobj, Shiboken::SbkType<T>()));
Shiboken::AutoDecRef fastSequence(PySequence_Fast(pyobj, "Invalid sequence object")); Shiboken::AutoDecRef fastSequence(PySequence_Fast(pyobj, "Invalid sequence object"));
T result; T result;
@ -240,7 +240,7 @@ struct QFlagsConverter
static inline T toCpp(PyObject* pyObj) static inline T toCpp(PyObject* pyObj)
{ {
if (Shiboken::isShibokenEnum(pyObj)) if (Shiboken::isShibokenEnum(pyObj))
return T(QFlag(reinterpret_cast<Shiboken::SbkEnumObject*>(pyObj)->ob_ival)); return T(QFlag(Shiboken::Enum::getValue(pyObj)));
else else
return T(QFlag(reinterpret_cast<PyIntObject*>(pyObj)->ob_ival)); return T(QFlag(reinterpret_cast<PyIntObject*>(pyObj)->ob_ival));
} }

View file

@ -493,8 +493,8 @@ char* getTypeName(PyObject* type)
{ {
if (PyType_Check(type)) { if (PyType_Check(type)) {
char *typeName = NULL; char *typeName = NULL;
if (type->ob_type == &Shiboken::SbkBaseWrapperType_Type) { if (type->ob_type == &SbkObjectType_Type) {
Shiboken::SbkBaseWrapperType *objType = reinterpret_cast<Shiboken::SbkBaseWrapperType*>(type); SbkObjectType* objType = reinterpret_cast<SbkObjectType*>(type);
Q_ASSERT(objType->original_name); Q_ASSERT(objType->original_name);
typeName = strdup(objType->original_name); typeName = strdup(objType->original_name);
} else { } else {
@ -670,7 +670,7 @@ PyObject* buildQtCompatible(const char* signature)
return ret; return ret;
} }
void addSignalToWrapper(Shiboken::SbkBaseWrapperType* wrapperType, const char* signalName, PySideSignal* signal) void addSignalToWrapper(SbkObjectType* wrapperType, const char* signalName, PySideSignal* signal)
{ {
PyObject* typeDict = wrapperType->super.ht_type.tp_dict; PyObject* typeDict = wrapperType->super.ht_type.tp_dict;
PyObject* homonymousMethod; PyObject* homonymousMethod;

View file

@ -30,10 +30,7 @@
#include <pysidemacros.h> #include <pysidemacros.h>
#include <Python.h> #include <Python.h>
namespace Shiboken struct SbkObjectType;
{
struct SbkBaseWrapperType;
}
extern "C" extern "C"
{ {
@ -111,7 +108,7 @@ PYSIDE_API void updateSourceObject(PyObject* source);
* @param self The Signal object * @param self The Signal object
* @return Return the signal signature * @return Return the signal signature
**/ **/
PYSIDE_API void addSignalToWrapper(Shiboken::SbkBaseWrapperType* wrapperType, const char* signalName, PySideSignal* signal); PYSIDE_API void addSignalToWrapper(SbkObjectType* wrapperType, const char* signalName, PySideSignal* signal);
/** /**
* This function verify if the signature is a QtSignal base on SIGNAL flag * This function verify if the signature is a QtSignal base on SIGNAL flag

View file

@ -251,7 +251,7 @@ int SignalManager::qt_metacall(QObject* object, QMetaObject::Call call, int id,
return id - metaObject->methodCount(); return id - metaObject->methodCount();
Shiboken::GilState gil; Shiboken::GilState gil;
pySelf = Shiboken::BindingManager::instance().retrieveWrapper(object); pySelf = (PyObject*)Shiboken::BindingManager::instance().retrieveWrapper(object);
Q_ASSERT(pySelf); Q_ASSERT(pySelf);
pp_name = PyString_FromString(mp.name()); pp_name = PyString_FromString(mp.name());
pp = Property::getObject(pySelf, pp_name); pp = Property::getObject(pySelf, pp_name);
@ -334,7 +334,7 @@ static int PySide::callMethod(QObject* object, int id, void** args)
// call python slot // call python slot
Shiboken::GilState gil; Shiboken::GilState gil;
QList<QByteArray> paramTypes = method.parameterTypes(); QList<QByteArray> paramTypes = method.parameterTypes();
PyObject* self = Shiboken::BindingManager::instance().retrieveWrapper(object); PyObject* self = (PyObject*)Shiboken::BindingManager::instance().retrieveWrapper(object);
PyObject* preparedArgs = NULL; PyObject* preparedArgs = NULL;
Py_ssize_t args_size = paramTypes.count(); Py_ssize_t args_size = paramTypes.count();
@ -378,8 +378,8 @@ bool SignalManager::registerMetaMethod(QObject* source, const char* signature, Q
int methodIndex = metaObject->indexOfMethod(signature); int methodIndex = metaObject->indexOfMethod(signature);
// Create the dynamic signal is needed // Create the dynamic signal is needed
if (methodIndex == -1) { if (methodIndex == -1) {
Shiboken::SbkBaseWrapper* self = (Shiboken::SbkBaseWrapper*) Shiboken::BindingManager::instance().retrieveWrapper(source); SbkObject* self = Shiboken::BindingManager::instance().retrieveWrapper(source);
if (!self->containsCppWrapper) { if (!Shiboken::Wrapper::hasCppWrapper(self)) {
qWarning() << "Invalid Signal signature:" << signature; qWarning() << "Invalid Signal signature:" << signature;
return false; return false;
} else { } else {

View file

@ -96,7 +96,7 @@ QWidget *PyCustomWidget::createWidget(QWidget *parent)
PyObject* pyParent; PyObject* pyParent;
bool unkowParent = false; bool unkowParent = false;
if (parent) { if (parent) {
pyParent = Shiboken::BindingManager::instance().retrieveWrapper(parent); pyParent = reinterpret_cast<PyObject*>(Shiboken::BindingManager::instance().retrieveWrapper(parent));
if (!pyParent) { if (!pyParent) {
pyParent = Shiboken::Converter<QWidget*>::toPython(parent); pyParent = Shiboken::Converter<QWidget*>::toPython(parent);
unkowParent = true; unkowParent = true;
@ -112,16 +112,16 @@ QWidget *PyCustomWidget::createWidget(QWidget *parent)
PyTuple_SET_ITEM(pyArgs, 0, pyParent); //tuple will keep pyParent reference PyTuple_SET_ITEM(pyArgs, 0, pyParent); //tuple will keep pyParent reference
//Call python constructor //Call python constructor
PyObject* result = PyObject_CallObject(m_data->pyObject, pyArgs); SbkObject* result = reinterpret_cast<SbkObject*>(PyObject_CallObject(m_data->pyObject, pyArgs));
QWidget* widget = 0; QWidget* widget = 0;
if (result) { if (result) {
if (unkowParent) //if parent does not exists in python, transfer the ownership to cpp if (unkowParent) //if parent does not exists in python, transfer the ownership to cpp
Shiboken::BindingManager::instance().transferOwnershipToCpp(result); Shiboken::BindingManager::instance().transferOwnershipToCpp(result);
else else
Shiboken::setParent(pyParent, result); Shiboken::setParent(pyParent, reinterpret_cast<PyObject*>(result));
widget = reinterpret_cast<QWidget*>(Shiboken::getCppPointer(result, result->ob_type)); widget = reinterpret_cast<QWidget*>(Shiboken::Wrapper::cppPointer(result, result->ob_type));
} }
return widget; return widget;