aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generator/cppgenerator.cpp34
-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
6 files changed, 65 insertions, 21 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index cd7f14eca..8e805ea7d 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -29,6 +29,7 @@
#include <QtCore/QTextStream>
#include <QtCore/QDebug>
+// utiliy functions
inline CodeSnipList getConversionRule(TypeSystem::Language lang, const AbstractMetaFunction *function)
{
CodeSnipList list;
@@ -50,7 +51,6 @@ inline CodeSnipList getConversionRule(TypeSystem::Language lang, const AbstractM
return list;
}
-// utiliy functions
inline CodeSnipList getReturnConversionRule(TypeSystem::Language lang,
const AbstractMetaFunction *function,
const QString& inputName,
@@ -73,6 +73,17 @@ inline CodeSnipList getReturnConversionRule(TypeSystem::Language lang,
return list;
}
+inline AbstractMetaType* getTypeWithoutContainer(AbstractMetaType* arg)
+{
+ if (arg && arg->typeEntry()->isContainer()) {
+ AbstractMetaTypeList lst = arg->instantiations();
+ // only support containers with 1 type
+ if (lst.size() == 1)
+ return lst[0];
+ }
+ return arg;
+}
+
CppGenerator::CppGenerator() : m_currentErrorCode(0)
{
@@ -1778,20 +1789,25 @@ QString CppGenerator::argumentNameFromIndex(const AbstractMetaFunction* func, in
pyArgName = QString("self");
*wrappedClass = func->implementingClass();
} else if (argIndex == 0) {
- if (func->type()) {
+ AbstractMetaType* returnType = getTypeWithoutContainer(func->type());
+ if (returnType) {
pyArgName = PYTHON_RETURN_VAR;
- *wrappedClass = classes().findClass(func->type()->typeEntry()->name());
+ *wrappedClass = classes().findClass(returnType->typeEntry()->name());
} else {
ReportHandler::warning("Invalid Argument index on function modification: " + func->name());
}
} else {
int realIndex = argIndex - 1 - OverloadData::numberOfRemovedArguments(func, argIndex - 1);
- *wrappedClass = classes().findClass(func->arguments().at(realIndex)->type()->typeEntry()->name());
- if (argIndex == 1
- && OverloadData::isSingleArgument(getFunctionGroups(func->implementingClass())[func->name()]))
- pyArgName = QString("arg");
- else
- pyArgName = QString("pyargs[%1]").arg(argIndex - 1);
+ AbstractMetaType* argType = getTypeWithoutContainer(func->arguments().at(realIndex)->type());
+
+ if (argType) {
+ *wrappedClass = classes().findClass(argType->typeEntry()->name());
+ if (argIndex == 1
+ && OverloadData::isSingleArgument(getFunctionGroups(func->implementingClass())[func->name()]))
+ pyArgName = QString("arg");
+ else
+ pyArgName = QString("pyargs[%1]").arg(argIndex - 1);
+ }
}
return pyArgName;
}
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);