summaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-10-31 14:51:12 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2011-12-09 20:28:07 -0300
commitd427000699fe74f7f0b1d1fdf1907a0d40f83ba8 (patch)
tree0039180f695e56cea54d16f61b986ecaa401bbcf /libshiboken
parentfd348188ebb79dd98dab0cbb5c3b06905978cc22 (diff)
downloadshiboken-d427000699fe74f7f0b1d1fdf1907a0d40f83ba8.tar.gz
shiboken-d427000699fe74f7f0b1d1fdf1907a0d40f83ba8.tar.xz
shiboken-d427000699fe74f7f0b1d1fdf1907a0d40f83ba8.zip
Added functions to the new converters API to check if a type is value or object.
Comes with unit tests.
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/basewrapper.cpp2
-rw-r--r--libshiboken/basewrapper_p.h2
-rw-r--r--libshiboken/sbkconverter.cpp11
-rw-r--r--libshiboken/sbkconverter.h6
-rw-r--r--libshiboken/sbkconverter_p.h6
-rw-r--r--libshiboken/typeresolver.cpp1
6 files changed, 23 insertions, 5 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index 7d67c732..382012f5 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -832,7 +832,7 @@ void releaseOwnership(SbkObject* self)
{
// skip if the ownership have already moved to c++
SbkObjectType* selfType = reinterpret_cast<SbkObjectType*>(Py_TYPE(self));
- if (!self->d->hasOwnership || selfType->d->type_behaviour == BEHAVIOUR_VALUETYPE)
+ if (!self->d->hasOwnership || Shiboken::Conversions::pythonTypeIsValueType(selfType->d->converter))
return;
// remove object ownership
diff --git a/libshiboken/basewrapper_p.h b/libshiboken/basewrapper_p.h
index 64e290bf..64cfedd4 100644
--- a/libshiboken/basewrapper_p.h
+++ b/libshiboken/basewrapper_p.h
@@ -92,6 +92,7 @@ struct SbkObjectPrivate
}
};
+// TODO-CONVERTERS: to be deprecated/removed
/// The type behaviour was not defined yet
#define BEHAVIOUR_UNDEFINED 0
/// The type is a value type
@@ -115,6 +116,7 @@ struct SbkObjectTypePrivate
/// True if this type was defined by the user.
int is_user_type : 1;
/// Tells is the type is a value type or an object-type, see BEHAVIOUR_* constants.
+ // TODO-CONVERTERS: to be deprecated/removed
int type_behaviour : 2;
/// C++ name
char* original_name;
diff --git a/libshiboken/sbkconverter.cpp b/libshiboken/sbkconverter.cpp
index 3a32bec5..32d43507 100644
--- a/libshiboken/sbkconverter.cpp
+++ b/libshiboken/sbkconverter.cpp
@@ -438,4 +438,15 @@ PyTypeObject* getPythonTypeObject(const char* typeName)
return getPythonTypeObject(getConverter(typeName));
}
+bool pythonTypeIsValueType(SbkConverter* converter)
+{
+ assert(converter);
+ return converter->pointerToPython && converter->copyToPython;
+}
+
+bool pythonTypeIsObjectType(SbkConverter* converter)
+{
+ return converter->pointerToPython && !converter->copyToPython;
+}
+
} } // namespace Shiboken::Conversions
diff --git a/libshiboken/sbkconverter.h b/libshiboken/sbkconverter.h
index f760e82f..b0868598 100644
--- a/libshiboken/sbkconverter.h
+++ b/libshiboken/sbkconverter.h
@@ -248,6 +248,12 @@ LIBSHIBOKEN_API PyTypeObject* getPythonTypeObject(SbkConverter* converter);
/// Returns the Python type object for the given \p typeName.
LIBSHIBOKEN_API PyTypeObject* getPythonTypeObject(const char* typeName);
+/// Returns true if the Python type associated with the converter is a value type.
+LIBSHIBOKEN_API bool pythonTypeIsValueType(SbkConverter* converter);
+
+/// Returns true if the Python type associated with the converter is an object type.
+LIBSHIBOKEN_API bool pythonTypeIsObjectType(SbkConverter* converter);
+
#define SBK_PY_LONG_LONG_IDX 0
#define SBK_BOOL_IDX 1
#define SBK_CHAR_IDX 2
diff --git a/libshiboken/sbkconverter_p.h b/libshiboken/sbkconverter_p.h
index d12f1edc..b1d40ee6 100644
--- a/libshiboken/sbkconverter_p.h
+++ b/libshiboken/sbkconverter_p.h
@@ -44,8 +44,6 @@ typedef std::list<ToCppConversion> ToCppConversionList;
struct SbkConverter
{
/**
- * TODO: it certainly will be empty in some cases, like with PyDate.
- * TODO: probably a setPythonType(SbkConverter*, PyTypeObject*) function will be required.
* Python type associated with this converter. If the type is a Shiboken
* wrapper, then it must be a SbkObjectType; otherwise it will be the
* Python type to which the C++ value will be converted (note that the
@@ -62,8 +60,8 @@ struct SbkConverter
CppToPythonFunc pointerToPython;
/**
* This function converts a C++ object to a Python object of the type
- * indicated in pythonType. The identity of the is not kept, because a
- * new instance of the C++ object is created.
+ * indicated in pythonType. The identity of the object is not kept,
+ * because a new instance of the C++ object is created.
* It is used to convert objects passed by value, or reference, if said
* reference can't be traced to an object that already has a Python
* wrapper assigned for it.
diff --git a/libshiboken/typeresolver.cpp b/libshiboken/typeresolver.cpp
index 83fcd69c..52c9f16a 100644
--- a/libshiboken/typeresolver.cpp
+++ b/libshiboken/typeresolver.cpp
@@ -78,6 +78,7 @@ TypeResolver* TypeResolver::createTypeResolver(const char* typeName,
*/
if (pyType && PyType_IsSubtype(pyType, reinterpret_cast<PyTypeObject*>(&SbkObject_Type))) {
SbkObjectType* sbkType = reinterpret_cast<SbkObjectType*>(pyType);
+ // TODO-CONVERTERS: to be deprecated
if (!sbkType->d->type_behaviour) {
int len = strlen(typeName);
sbkType->d->type_behaviour = typeName[len -1] == '*' ? BEHAVIOUR_OBJECTTYPE : BEHAVIOUR_VALUETYPE;