diff options
author | Renato Filho <renato.filho@openbossa.org> | 2010-07-29 18:08:42 -0300 |
---|---|---|
committer | Renato Filho <renato.filho@openbossa.org> | 2010-07-29 19:28:18 -0300 |
commit | 9cba9a581d503accb04e517d982d734b7795139f (patch) | |
tree | d162d49eefc6b183d5d7c87b8b55fb673ec878fb | |
parent | 6bb544de68ee3af71e27ccead37b10788f16dd8a (diff) |
Fixed reference leak on shiboken make tuple.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r-- | libshiboken/bindingmanager.cpp | 6 | ||||
-rw-r--r-- | libshiboken/helper.h | 28 |
2 files changed, 21 insertions, 13 deletions
diff --git a/libshiboken/bindingmanager.cpp b/libshiboken/bindingmanager.cpp index e8c549542..1a3190117 100644 --- a/libshiboken/bindingmanager.cpp +++ b/libshiboken/bindingmanager.cpp @@ -43,6 +43,8 @@ namespace Shiboken typedef google::dense_hash_map<const void*, PyObject*> WrapperMap; + +#ifndef NDEBUG static void showWrapperMap(const WrapperMap& wrapperMap) { printf("-------------------------------\n"); @@ -52,6 +54,7 @@ static void showWrapperMap(const WrapperMap& wrapperMap) printf("key: %p, value: %p (%s)\n", iter->first, iter->second, iter->second->ob_type->tp_name); printf("-------------------------------\n"); } +#endif struct BindingManager::BindingManagerPrivate { WrapperMap wrapperMapper; @@ -85,6 +88,9 @@ BindingManager::BindingManager() BindingManager::~BindingManager() { +#ifndef NDEBUG + showWrapperMap(m_d->wrapperMapper); +#endif assert(m_d->wrapperMapper.size() == 0); delete m_d; } diff --git a/libshiboken/helper.h b/libshiboken/helper.h index 3bda34a7b..a3a974b99 100644 --- a/libshiboken/helper.h +++ b/libshiboken/helper.h @@ -38,6 +38,7 @@ #include <Python.h> #include "shibokenmacros.h" #include "conversions.h" +#include "autodecref.h" namespace Shiboken { @@ -45,34 +46,35 @@ namespace Shiboken template<typename A, typename B> inline PyObject* makeTuple(const A& a, const B& b) { - return PyTuple_Pack(2, Converter<A>::toPython(a), Converter<B>::toPython(b)); + return PyTuple_Pack(2, AutoDecRef(Converter<A>::toPython(a)).object(), + AutoDecRef(Converter<B>::toPython(b)).object()); } template<typename A, typename B, typename C> inline PyObject* makeTuple(const A& a, const B& b, const C& c) { - return PyTuple_Pack(3, Converter<A>::toPython(a), - Converter<B>::toPython(b), - Converter<C>::toPython(c)); + return PyTuple_Pack(3, AutoDecRef(Converter<A>::toPython(a)).object(), + AutoDecRef(Converter<B>::toPython(b)).object(), + AutoDecRef(Converter<C>::toPython(c)).object()); } template<typename A, typename B, typename C, typename D> inline PyObject* makeTuple(const A& a, const B& b, const C& c, const D& d) { - return PyTuple_Pack(4, Converter<A>::toPython(a), - Converter<B>::toPython(b), - Converter<C>::toPython(c), - Converter<D>::toPython(d)); + return PyTuple_Pack(4, AutoDecRef(Converter<A>::toPython(a)).object(), + AutoDecRef(Converter<B>::toPython(b)).object(), + AutoDecRef(Converter<C>::toPython(c)).object(), + AutoDecRef(Converter<D>::toPython(d)).object()); } template<typename A, typename B, typename C, typename D, typename E> inline PyObject* makeTuple(const A& a, const B& b, const C& c, const D& d, const E& e) { - return PyTuple_Pack(5, Converter<A>::toPython(a), - Converter<B>::toPython(b), - Converter<C>::toPython(c), - Converter<D>::toPython(d), - Converter<E>::toPython(e)); + return PyTuple_Pack(5, AutoDecRef(Converter<A>::toPython(a)).object(), + AutoDecRef(Converter<B>::toPython(b)).object(), + AutoDecRef(Converter<C>::toPython(c)).object(), + AutoDecRef(Converter<D>::toPython(d)).object(), + AutoDecRef(Converter<E>::toPython(e)).object()); } /** |