aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
authorrenatofilho <renato.filho@openbossa.org>2010-09-29 11:02:40 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:07:19 -0300
commit822bd79f87ad237b9e24b53f9048308200f06859 (patch)
tree17cb35ed6e334396725edb75c18ce750c85b7986 /libshiboken
parent1f1fc9f504285c916785dd9daec557e24b332135 (diff)
Implement support to object list on ownserhsip functions.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/basewrapper.cpp16
-rw-r--r--libshiboken/basewrapper.h5
-rw-r--r--libshiboken/basewrapper_p.h4
-rw-r--r--libshiboken/bindingmanager.cpp16
-rw-r--r--libshiboken/bindingmanager.h11
5 files changed, 40 insertions, 12 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index 6e8848bbc..189e211c0 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -35,7 +35,6 @@ namespace Shiboken
static void SbkBaseWrapperType_dealloc(PyObject* pyObj);
static PyObject* SbkBaseWrapperType_TpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds);
-static std::list<PyObject*> splitPyObject(PyObject* pyObj);
static void incRefPyObject(PyObject* pyObj);
static void decRefPyObjectlist(const std::list<PyObject*> &pyObj);
@@ -659,7 +658,7 @@ bool canCallConstructor(PyTypeObject* myType, PyTypeObject* ctorType)
return true;
}
-static std::list<PyObject*> splitPyObject(PyObject* pyObj)
+std::list<PyObject*> splitPyObject(PyObject* pyObj)
{
std::list<PyObject*> result;
if (PySequence_Check(pyObj)) {
@@ -693,6 +692,19 @@ static void decRefPyObjectlist(const std::list<PyObject*> &lst)
}
}
+void SbkBaseWrapper_setOwnership(SbkBaseWrapper* pyobj, bool owner)
+{
+ pyobj->hasOwnership = owner;
+}
+
+void SbkBaseWrapper_setOwnership(PyObject* pyobj, bool owner)
+{
+ std::list<PyObject*> objs = splitPyObject(pyobj);
+ std::list<PyObject*>::const_iterator it;
+ for(it=objs.begin(); it != objs.end(); it++)
+ SbkBaseWrapper_setOwnership(reinterpret_cast<SbkBaseWrapper*>(*it), owner);
+}
+
} // namespace Shiboken
diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h
index 96f9ad82b..2440a98c2 100644
--- a/libshiboken/basewrapper.h
+++ b/libshiboken/basewrapper.h
@@ -190,7 +190,6 @@ LIBSHIBOKEN_API bool canCallConstructor(PyTypeObject* myType, PyTypeObject* ctor
#define SbkBaseWrapper_instanceDict(pyobj) (((Shiboken::SbkBaseWrapper*)pyobj)->ob_dict)
#define SbkBaseWrapper_setInstanceDict(pyobj,d) (((Shiboken::SbkBaseWrapper*)pyobj)->ob_dict = d)
#define SbkBaseWrapper_hasOwnership(pyobj) (((Shiboken::SbkBaseWrapper*)pyobj)->hasOwnership)
-#define SbkBaseWrapper_setOwnership(pyobj,o) (((Shiboken::SbkBaseWrapper*)pyobj)->hasOwnership = o)
#define SbkBaseWrapper_hasParentInfo(pyobj) (((Shiboken::SbkBaseWrapper*)pyobj)->parentInfo)
#define SbkBaseWrapper_containsCppWrapper(pyobj) (((Shiboken::SbkBaseWrapper*)pyobj)->containsCppWrapper)
#define SbkBaseWrapper_setContainsCppWrapper(pyobj,o)(((Shiboken::SbkBaseWrapper*)pyobj)->containsCppWrapper = o)
@@ -238,6 +237,10 @@ LIBSHIBOKEN_API void deallocWrapperWithPrivateDtor(PyObject* self);
LIBSHIBOKEN_API bool importModule(const char* moduleName, PyTypeObject*** cppApiPtr);
LIBSHIBOKEN_API void setErrorAboutWrongArguments(PyObject* args, const char* funcName, const char** cppOverloads);
+/// Support sequence protocol
+LIBSHIBOKEN_API void SbkBaseWrapper_setOwnership(PyObject* pyobj, bool owner);
+LIBSHIBOKEN_API void SbkBaseWrapper_setOwnership(SbkBaseWrapper* pyobj, bool owner);
+
} // namespace Shiboken
#endif // BASEWRAPPER_H
diff --git a/libshiboken/basewrapper_p.h b/libshiboken/basewrapper_p.h
index 1357c89a6..20476d3a1 100644
--- a/libshiboken/basewrapper_p.h
+++ b/libshiboken/basewrapper_p.h
@@ -28,6 +28,10 @@
namespace Shiboken
{
+/**
+ * Utility function uset to transform PyObject which suppot sequence protocol in a std::list
+ **/
+std::list<PyObject*> splitPyObject(PyObject* pyObj);
struct SbkBaseWrapperType;
diff --git a/libshiboken/bindingmanager.cpp b/libshiboken/bindingmanager.cpp
index 47fd77d71..36a5abc72 100644
--- a/libshiboken/bindingmanager.cpp
+++ b/libshiboken/bindingmanager.cpp
@@ -245,6 +245,15 @@ PyObject* BindingManager::getOverride(const void* cptr, const char* methodName)
return 0;
}
+
+void BindingManager::invalidateWrapper(PyObject* pyobj)
+{
+ std::list<PyObject*> objs = splitPyObject(pyobj);
+ std::list<PyObject*>::const_iterator it;
+ for(it=objs.begin(); it != objs.end(); it++)
+ invalidateWrapper(reinterpret_cast<SbkBaseWrapper*>(*it));
+}
+
void BindingManager::invalidateWrapper(SbkBaseWrapper* wrapper)
{
if (!wrapper || ((PyObject*)wrapper == Py_None) || !SbkBaseWrapper_validCppObject(wrapper))
@@ -302,6 +311,13 @@ void BindingManager::destroyWrapper(SbkBaseWrapper* wrapper)
m_d->destroying = false;
}
+void BindingManager::transferOwnershipToCpp(PyObject* wrapper)
+{
+ std::list<PyObject*> objs = splitPyObject(wrapper);
+ std::list<PyObject*>::const_iterator it;
+ for(it=objs.begin(); it != objs.end(); it++)
+ transferOwnershipToCpp(reinterpret_cast<SbkBaseWrapper*>(*it));
+}
void BindingManager::transferOwnershipToCpp(SbkBaseWrapper* wrapper)
{
diff --git a/libshiboken/bindingmanager.h b/libshiboken/bindingmanager.h
index 2f486829f..cec4a78ff 100644
--- a/libshiboken/bindingmanager.h
+++ b/libshiboken/bindingmanager.h
@@ -47,21 +47,14 @@ public:
/// Invalidate the Python wrapper and removes the relations from C++ pointers to the Python wrapper.
void invalidateWrapper(SbkBaseWrapper* wrapper);
/// Convenience method to call invalidateWrapper with a properly cast SbkBaseWrapper.
- inline void invalidateWrapper(PyObject* wrapper)
- {
- invalidateWrapper(reinterpret_cast<SbkBaseWrapper*>(wrapper));
- }
+ void invalidateWrapper(PyObject* wrapper);
/// Convenience method to invalidate the Python wrapper for a C++ wrapped object. Do nothing if C++ pointer has no Python wrapper.
void invalidateWrapper(const void* cptr);
/// Transfers the ownership of a Python wrapper to C++.
void transferOwnershipToCpp(SbkBaseWrapper* wrapper);
/// Convenience method to call transferOwnershipToCpp with a properly cast SbkBaseWrapper.
- inline void transferOwnershipToCpp(PyObject* wrapper)
- {
- transferOwnershipToCpp(reinterpret_cast<SbkBaseWrapper*>(wrapper));
- }
-
+ void transferOwnershipToCpp(PyObject* wrapper);
void addClassInheritance(SbkBaseWrapperType* parent, SbkBaseWrapperType* child);
SbkBaseWrapperType* resolveType(void* cptr, SbkBaseWrapperType* type);