summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2009-11-25 18:46:33 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2009-11-25 19:08:26 -0300
commitffbb8bb1df621ab3f31f859e62d21e06f9ed8a80 (patch)
tree870de0043ce4c492987767c319caac3baca197a3
parent9f228238498dea95db7eb8c2f0b21186ea98d206 (diff)
downloadshiboken-ffbb8bb1df621ab3f31f859e62d21e06f9ed8a80.tar.gz
shiboken-ffbb8bb1df621ab3f31f859e62d21e06f9ed8a80.tar.xz
shiboken-ffbb8bb1df621ab3f31f859e62d21e06f9ed8a80.zip
Added the invalidateWrapper method to BindingManager.
It sets the wrapper as invalid and removes the relation of C++ objects to the Python wrapper from the mappings. Moved BindingManager::releaseWrapper(void*) to BindingManagerPrivate, since it should only be used by releaseWrapper(PyObject*). Modified includes on conversions.h to use quotes instead of < and >. Reviewed by Hugo Lima <hugo.lima@openbossa.org>
-rw-r--r--cppgenerator.cpp4
-rw-r--r--libshiboken/bindingmanager.cpp26
-rw-r--r--libshiboken/bindingmanager.h4
-rw-r--r--libshiboken/conversions.h6
4 files changed, 25 insertions, 15 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp
index 06051dbb..6ffbfe99 100644
--- a/cppgenerator.cpp
+++ b/cppgenerator.cpp
@@ -396,8 +396,8 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
foreach (ArgumentModification arg_mod, func_mod.argument_mods) {
if (!arg_mod.resetAfterUse)
continue;
- s << INDENT << "PyBaseWrapper_setValidCppObject(PyTuple_GET_ITEM(pyargs, ";
- s << (arg_mod.index - 1) << "), false);" << endl;
+ s << INDENT << "BindingManager::instance().invalidateWrapper(PyTuple_GET_ITEM(pyargs, ";
+ s << (arg_mod.index - 1) << "));" << endl;
}
}
diff --git a/libshiboken/bindingmanager.cpp b/libshiboken/bindingmanager.cpp
index fc48348f..dd9fdbc7 100644
--- a/libshiboken/bindingmanager.cpp
+++ b/libshiboken/bindingmanager.cpp
@@ -43,8 +43,16 @@ typedef google::dense_hash_map<const void*, PyObject*> WrapperMap;
struct BindingManager::BindingManagerPrivate {
WrapperMap wrapperMapper;
+ void releaseWrapper(void* cptr);
};
+void BindingManager::BindingManagerPrivate::releaseWrapper(void* cptr)
+{
+ WrapperMap::iterator iter = wrapperMapper.find(cptr);
+ if (iter != wrapperMapper.end())
+ wrapperMapper.erase(iter);
+}
+
BindingManager::BindingManager()
{
m_d = new BindingManager::BindingManagerPrivate;
@@ -76,22 +84,15 @@ void BindingManager::assignWrapper(PyObject* wrapper, const void* cptr)
iter->second = wrapper;
}
-void BindingManager::releaseWrapper(void *cptr)
-{
- WrapperMap::iterator iter = m_d->wrapperMapper.find(cptr);
- if (iter != m_d->wrapperMapper.end())
- m_d->wrapperMapper.erase(iter);
-}
-
void BindingManager::releaseWrapper(PyObject* wrapper)
{
void* cptr = PyBaseWrapper_cptr(wrapper);
- releaseWrapper(cptr);
+ m_d->releaseWrapper(cptr);
if (((ShiboTypeObject*) wrapper->ob_type)->mi_offsets) {
int* offset = ((ShiboTypeObject*) wrapper->ob_type)->mi_offsets;
while (*offset != -1) {
if (*offset > 0)
- BindingManager::instance().releaseWrapper((void*) ((size_t) cptr + (*offset)));
+ m_d->releaseWrapper((void*) ((size_t) cptr + (*offset)));
offset++;
}
}
@@ -130,4 +131,11 @@ PyObject* BindingManager::getOverride(const void* cptr, const char* methodName)
return 0;
}
+void BindingManager::invalidateWrapper(PyObject* wrapper)
+{
+ PyBaseWrapper_setValidCppObject(wrapper, false);
+ releaseWrapper(wrapper);
+}
+
} // namespace Shiboken
+
diff --git a/libshiboken/bindingmanager.h b/libshiboken/bindingmanager.h
index d082c7b5..aba264fd 100644
--- a/libshiboken/bindingmanager.h
+++ b/libshiboken/bindingmanager.h
@@ -48,11 +48,13 @@ public:
bool hasWrapper(const void *cptr);
void assignWrapper(PyObject* wrapper, const void* cptr);
- void releaseWrapper(void* cptr);
void releaseWrapper(PyObject* wrapper);
PyObject* retrieveWrapper(const void* cptr);
PyObject* getOverride(const void* cptr, const char* methodName);
+ /// Invalidate the Python wrapper and removes the relations from C++ objects the Python wrapper.
+ void invalidateWrapper(PyObject* wrapper);
+
private:
~BindingManager();
// disable copy
diff --git a/libshiboken/conversions.h b/libshiboken/conversions.h
index b69d0bba..9cc166cf 100644
--- a/libshiboken/conversions.h
+++ b/libshiboken/conversions.h
@@ -36,9 +36,9 @@
#define CONVERSIONS_H
#include <Python.h>
-#include <pyenum.h>
-#include <basewrapper.h>
-#include <bindingmanager.h>
+#include "pyenum.h"
+#include "basewrapper.h"
+#include "bindingmanager.h"
// When the user adds a function with an argument unknown for the typesystem, the generator writes type checks as
// TYPENAME_Check, so this macro allows users to add PyObject arguments to their added functions.