Skip to content

Commit f9858cd

Browse files
author
florianlink
committed
removed extra incref on PyObject* that are returned from slots. The ref-count needs to be increased by slots returning a PyObject (or by returning a new PyObject, which already has its initial ref count)
git-svn-id: http://svn.code.sf.net/p/pythonqt/code/trunk@393 ea8d5007-eb21-0410-b261-ccb3ea6e24a9
1 parent a1fc69f commit f9858cd

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/PythonQt.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,9 @@ PyObject* PythonQtPrivate::wrapPtr(void* ptr, const QByteArray& name, bool passO
519519
if (!info) {
520520
// maybe it is a PyObject, which we can return directly
521521
if (name == "PyObject") {
522-
PyObject* p = (PyObject*)ptr;
523-
Py_INCREF(p);
524-
return p;
522+
// do not increment its ref-count, it is the job of the slot returning the value
523+
// to ensure an extra ref on return.
524+
return (PyObject*)ptr;
525525
}
526526

527527
// we do not know the metaobject yet, but we might know it by its name:

src/PythonQt.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ typedef void* PythonQtPolymorphicHandlerCB(const void *ptr, const char **class_n
7575

7676
typedef void PythonQtShellSetInstanceWrapperCB(void* object, PythonQtInstanceWrapper* wrapper);
7777

78-
template<class T> void PythonQtSetInstanceWrapperOnShell(void* object, PythonQtInstanceWrapper* wrapper) {
78+
template<class T> void PythonQtSetInstanceWrapperOnShell(void* object, PythonQtInstanceWrapper* wrapper) {
7979
(reinterpret_cast<T*>(object))->_wrapper = wrapper;
8080
}
8181

@@ -133,7 +133,7 @@ class PythonQtNewOwnerOfThis
133133

134134
//! returns the offset that needs to be added to upcast an object of type T1 to T2
135135
template<class T1, class T2> int PythonQtUpcastingOffset() {
136-
return ((reinterpret_cast<char*>(static_cast<T2*>(reinterpret_cast<T1*>(0x100))))
136+
return ((reinterpret_cast<char*>(static_cast<T2*>(reinterpret_cast<T1*>(0x100))))
137137
- (reinterpret_cast<char*>(reinterpret_cast<T1*>(0x100))));
138138
}
139139

@@ -396,9 +396,9 @@ class PYTHONQT_EXPORT PythonQt : public QObject {
396396
//! returns the found callable object or NULL
397397
//! @return new reference
398398
PythonQtObjectPtr lookupCallable(PyObject* object, const QString& name);
399-
399+
400400
//! returns the return type of the method of a wrapped c++ object referenced by \c objectname
401-
QString getReturnTypeOfWrappedMethod(PyObject* module, const QString& objectname);
401+
QString getReturnTypeOfWrappedMethod(PyObject* module, const QString& objectname);
402402
//! returns the return type of the method \c methodName of a wrapped c++ type referenced by \c typeName
403403
QString getReturnTypeOfWrappedMethod(const QString& typeName, const QString& methodName);
404404
//@}
@@ -533,7 +533,7 @@ class PYTHONQT_EXPORT PythonQt : public QObject {
533533
//! The error is currently just output to the python stderr, future version might implement better trace printing
534534
bool handleError();
535535

536-
//! return \a true if \a handleError() has been called and an error occured.
536+
//! return \a true if \a handleError() has been called and an error occurred.
537537
bool hadError()const;
538538

539539
//! reset error flag. After calling this, hadError() will return false.
@@ -584,9 +584,9 @@ class PYTHONQT_EXPORT PythonQt : public QObject {
584584

585585
private:
586586
void initPythonQtModule(bool redirectStdOut, const QByteArray& pythonQtModuleName);
587-
587+
588588
QString getReturnTypeOfWrappedMethodHelper(const PythonQtObjectPtr& variableObject, const QString& methodName, const QString& context);
589-
589+
590590
PyObject* getObjectByType(const QString& typeName);
591591

592592
//! callback for stdout redirection, emits pythonStdOut signal
@@ -729,10 +729,10 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject {
729729

730730
//! returns the profiling callback, which may be NULL
731731
PythonQt::ProfilingCB* profilingCB() const { return _profilingCB; }
732-
732+
733733
//! determines the signature of the given callable object (similar as pydoc)
734734
QString getSignature(PyObject* object);
735-
735+
736736
//! returns true if the object is a method descriptor (same as inspect.ismethoddescriptor() in inspect.py)
737737
bool isMethodDescriptor(PyObject* object) const;
738738

0 commit comments

Comments
 (0)