summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-03-18 17:35:16 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2011-03-18 18:36:56 -0300
commitcaec0092e785137612f441f3ea3e7142da95ae8e (patch)
treeb16dc436a00c3b2e0d8cc68dc77026ec2c524d33
parentf76a944c0a78b898115c8acf0a8f413b1d92bd3f (diff)
downloadshiboken-caec0092e785137612f441f3ea3e7142da95ae8e.tar.gz
shiboken-caec0092e785137612f441f3ea3e7142da95ae8e.tar.xz
shiboken-caec0092e785137612f441f3ea3e7142da95ae8e.zip
Fix bug 693 - "Heap corruption or double free reported on program exit"
Reviewer: Renato Ara├║jo <renato.filho@openbossa.org> Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--libshiboken/basewrapper.cpp3
-rw-r--r--libshiboken/basewrapper_p.h8
-rw-r--r--libshiboken/typeresolver.cpp18
3 files changed, 28 insertions, 1 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index d4c6c749..185b05fa 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -687,7 +687,8 @@ void getOwnership(PyObject* pyObj)
void releaseOwnership(SbkObject* self)
{
// skip if the ownership have already moved to c++
- if (!self->d->hasOwnership)
+ SbkObjectType* selfType = reinterpret_cast<SbkObjectType*>(self->ob_type);
+ if (!self->d->hasOwnership || selfType->d->type_behaviour == BEHAVIOUR_VALUETYPE)
return;
// remove object ownership
diff --git a/libshiboken/basewrapper_p.h b/libshiboken/basewrapper_p.h
index f6f29734..c70589a6 100644
--- a/libshiboken/basewrapper_p.h
+++ b/libshiboken/basewrapper_p.h
@@ -82,6 +82,12 @@ struct SbkObjectPrivate
Shiboken::RefCountMap* referredObjects;
};
+/// The type behaviour was not defined yet
+#define BEHAVIOUR_UNDEFINED 0
+/// The type is a value type
+#define BEHAVIOUR_VALUETYPE 1
+/// The type is a object type
+#define BEHAVIOUR_OBJECTTYPE 2
struct SbkObjectTypePrivate
{
@@ -101,6 +107,8 @@ struct SbkObjectTypePrivate
int is_multicpp:1;
/// True if this type was definied by the user.
int is_user_type:1;
+ /// Tells is the type is a value type or an object-type, see BEHAVIOUR_* constants.
+ int type_behaviour:2;
/// C++ name
char* original_name;
/// Type user data
diff --git a/libshiboken/typeresolver.cpp b/libshiboken/typeresolver.cpp
index a195c8f0..343fe31a 100644
--- a/libshiboken/typeresolver.cpp
+++ b/libshiboken/typeresolver.cpp
@@ -25,6 +25,7 @@
#include "sbkdbg.h"
#include <cstdlib>
#include <string>
+#include "basewrapper_p.h"
using namespace Shiboken;
@@ -68,6 +69,23 @@ TypeResolver* TypeResolver::createTypeResolver(const char* typeName,
tr->m_d->cppToPython = cppToPy;
tr->m_d->pythonToCpp = pyToCpp;
tr->m_d->pyType = pyType;
+
+ /*
+ * Note:
+ *
+ * Value types are also registered as object types, but the generator *always* first register the value
+ * type version in the TypeResolver and it *must* always do it! otherwise this code wont work.
+ *
+ * All this to not enter in this if several times, running all characters in the typeName string, etc...
+ * in other words... the nano seconds!!! somebody need to save them!
+ */
+ if (pyType && PyType_IsSubtype(pyType, reinterpret_cast<PyTypeObject*>(&SbkObject_Type))) {
+ SbkObjectType* sbkType = reinterpret_cast<SbkObjectType*>(pyType);
+ if (!sbkType->d->type_behaviour) {
+ int len = strlen(typeName);
+ sbkType->d->type_behaviour = typeName[len -1] == '*' ? BEHAVIOUR_OBJECTTYPE : BEHAVIOUR_VALUETYPE;
+ }
+ }
}
return tr;
}