Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
249 changes: 106 additions & 143 deletions CMakeLists.txt

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/PythonQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ PythonQtClassWrapper* PythonQtPrivate::createNewPythonQtClassWrapper(PythonQtCla
// create the new type object by calling the type
result = (PythonQtClassWrapper *)PyObject_Call((PyObject *)&PythonQtClassWrapper_Type, args, nullptr);

Py_DECREF(moduleName);
Py_DECREF(baseClasses);
Py_DECREF(typeDict);
Py_DECREF(moduleName);
Expand Down Expand Up @@ -857,6 +858,7 @@ PyObject* PythonQtPrivate::createNewPythonQtEnumWrapper(const char* enumName, Py
// create the new int derived type object by calling the core type
result = PyObject_Call((PyObject *)&PyType_Type, args, nullptr);

Py_DECREF(module);
Py_DECREF(baseClasses);
Py_DECREF(module);
Py_DECREF(typeDict);
Expand Down Expand Up @@ -1548,7 +1550,7 @@ PythonQtClassInfo* PythonQtPrivate::currentClassInfoForClassWrapperCreation()

void PythonQtPrivate::addDecorators(QObject* o, int decoTypes)
{
if (o == nullptr)
if (!o)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/PythonQt.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ class PYTHONQT_EXPORT PythonQt : public QObject {
//@{

//! get access to internal data (should not be used on the public API, but is used by some C functions)
static PythonQtPrivate* priv() { return _self ? _self->_p : nullptr; }
static PythonQtPrivate* priv() { return _self ? _self->_p : NULL; }

//! clear all NotFound entries on all class infos, to ensure that
//! newly loaded wrappers can add methods even when the object was wrapped by PythonQt before the wrapper was loaded
Expand Down
2 changes: 1 addition & 1 deletion src/PythonQtObjectPtr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ PythonQtObjectPtr::PythonQtObjectPtr(PythonQtSafeObjectPtr &&p) :_object(p.takeO

PythonQtObjectPtr::~PythonQtObjectPtr()
{
if (Py_IsInitialized()) Py_XDECREF(_object);
if (_object && Py_IsInitialized()) Py_XDECREF(_object);
}

void PythonQtObjectPtr::setNewRef(PyObject* o)
Expand Down
22 changes: 22 additions & 0 deletions src/PythonQtPythonInclude.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,27 @@
#undef toupper
#endif

/*
* The following undefs for C standard library macros prevent
* build errors of the following type on mac ox 10.7.4 and XCode 4.3.3
*
/usr/include/c++/4.2.1/bits/localefwd.h:57:21: error: too many arguments provided to function-like macro invocation
isspace(_CharT, const locale&);
^
/usr/include/c++/4.2.1/bits/localefwd.h:56:5: error: 'inline' can only appear on functions
inline bool
^
/usr/include/c++/4.2.1/bits/localefwd.h:57:5: error: variable 'isspace' declared as a template
isspace(_CharT, const locale&);
^
*/
#undef isspace
#undef isupper
#undef islower
#undef isalpha
#undef isalnum
#undef toupper
#undef tolower

#endif

44 changes: 9 additions & 35 deletions tests/PythonQtTestCleanup.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "PythonQtTestCleanup.h"
#include "PythonQt.h"
#include "PythonQt_QtAll.h"
#include "PythonQt_QtBindings.h"

void PythonQtTestCleanup::initTestCase()
{
Expand All @@ -15,7 +15,7 @@ void PythonQtTestCleanup::init()
// Initialize before each test

PythonQt::init(PythonQt::IgnoreSiteModule);
PythonQt_QtAll::init();
PythonQt_init_QtBindings();

_helper = new PythonQtTestCleanupHelper();
PythonQtObjectPtr main = PythonQt::self()->getMainModule();
Expand All @@ -24,15 +24,16 @@ void PythonQtTestCleanup::init()

void PythonQtTestCleanup::cleanup()
{
// Cleanup PythonQt resources before finalizing Python
PythonQt::cleanup();
// Finalize and cleanup after each test

if (Py_IsInitialized()) {
Py_Finalize();
}

PythonQt::cleanup();

delete _helper;
_helper = nullptr;
_helper = NULL;
}

void PythonQtTestCleanup::testQtEnum()
Expand All @@ -44,7 +45,7 @@ void PythonQtTestCleanup::testQtEnum()
));
}

void PythonQtTestCleanup::testCallQtMethodInDestructorOwnedQTimer()
void PythonQtTestCleanup::testCallQtMethodInDel()
{
QVERIFY(_helper->runScript(
"import PythonQt.QtCore\n" \
Expand All @@ -54,23 +55,6 @@ void PythonQtTestCleanup::testCallQtMethodInDestructorOwnedQTimer()
" def __del__(self):\n" \
" self.timer.setSingleShot(True)\n" \
"x = TimerWrapper()\n" \
"del x\n" \
"obj.setPassed()\n"
));
}

void PythonQtTestCleanup::testCallQtMethodInDestructorWeakRefGuarded()
{
QVERIFY(_helper->runScript(
"import weakref\n" \
"import PythonQt.QtCore\n" \
"class TimerWrapper(object):\n" \
" def __init__(self):\n" \
" self.timerWeakRef = weakref.ref(PythonQt.QtCore.QTimer())\n" \
" def __del__(self):\n" \
" if self.timerWeakRef():\n" \
" self.timerWeakRef().setSingleShot(True)\n" \
"x = TimerWrapper()\n" \
"obj.setPassed()\n"
));
}
Expand All @@ -81,21 +65,11 @@ void PythonQtTestCleanup::testSignalReceiverCleanup()

// Test that PythonQtSignalReceiver is cleaned up properly,
// i.e. PythonQt::cleanup() doesn't segfault
QVERIFY(_helper->runScript(
main.evalScript(
"import PythonQt.QtCore\n" \
"timer = PythonQt.QtCore.QTimer(obj)\n" \
"timer.connect('destroyed()', obj.onDestroyed)\n" \
"obj.setPassed()\n"
));
}

void PythonQtTestCleanup::testPyFinalizeThenPythonQtCleanup()
{
if (Py_IsInitialized()) {
Py_Finalize();
}

PythonQt::cleanup();
);
}

bool PythonQtTestCleanupHelper::runScript(const char* script)
Expand Down
5 changes: 2 additions & 3 deletions tests/PythonQtTestCleanup.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef _PYTHONQTTESTCLEANUP_H
#define _PYTHONQTTESTCLEANUP_H

#include "PythonQt.h"
#include <QtTest/QtTest>

class PythonQtTestCleanupHelper;
Expand All @@ -17,10 +18,8 @@ private Q_SLOTS:
void cleanup();

void testQtEnum();
void testCallQtMethodInDestructorOwnedQTimer();
void testCallQtMethodInDestructorWeakRefGuarded();
void testCallQtMethodInDel();
void testSignalReceiverCleanup();
void testPyFinalizeThenPythonQtCleanup();

private:
PythonQtTestCleanupHelper* _helper;
Expand Down
6 changes: 6 additions & 0 deletions tests/PythonQtTestMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,17 @@ int main(int argc, char *argv[])
Py_Finalize();
}

#ifdef PythonQt_Wrap_Qtcore
PythonQtTestCleanup cleanup;
failCount += QTest::qExec(&cleanup, argc, argv);

if (failCount) {
std::cerr << "Tests failed: " << failCount << std::endl;
} else {
std::cout << "All tests passed successfully." << std::endl;
}
#endif

return failCount != 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}