summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulo Alcantara <pcacjr@gmail.com>2012-01-09 18:24:56 -0300
committerPaulo Alcantara <pcacjr@gmail.com>2012-01-11 14:30:38 -0300
commit7ae059fbb6882174c4da3aeb2017390afffa11fe (patch)
tree168e3494b3c6253ce20e4affc55ee4fc71609a29
parentfa103c2a088a92fd14f614c8c08e2b2bc34ad10d (diff)
downloadshiboken-7ae059fbb6882174c4da3aeb2017390afffa11fe.tar.gz
shiboken-7ae059fbb6882174c4da3aeb2017390afffa11fe.tar.xz
shiboken-7ae059fbb6882174c4da3aeb2017390afffa11fe.zip
Fix BUG #1105 - "Spyder fails with HEAD"
When handling typedef'd primitive types we don't need to create indices for them, nor converters. Instead, we must use the underlying primitive type converters. See http://bugs.pyside.org/show_bug.cgi?id=1105. Signed-off-by: Paulo Alcantara <pcacjr@gmail.com> Reviewed-by: Marcelo Lira <marcelo.lira@openbossa.org> Reviewed-by: Hugo Parente Lima <hugo.pl@gmail.com>
-rw-r--r--generator/headergenerator.cpp12
-rw-r--r--generator/shibokengenerator.cpp14
-rw-r--r--generator/shibokengenerator.h8
-rw-r--r--tests/libsample/handle.cpp9
-rw-r--r--tests/libsample/handle.h20
-rw-r--r--tests/samplebinding/handleholder_test.py18
-rw-r--r--tests/samplebinding/typesystem_sample.xml2
7 files changed, 61 insertions, 22 deletions
diff --git a/generator/headergenerator.cpp b/generator/headergenerator.cpp
index 95fde92e..9be27206 100644
--- a/generator/headergenerator.cpp
+++ b/generator/headergenerator.cpp
@@ -1,7 +1,7 @@
/*
* This file is part of the Shiboken Python Bindings Generator project.
*
- * Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2009-2012 Nokia Corporation and/or its subsidiary(-ies).
*
* Contact: PySide team <contact@pyside.org>
*
@@ -306,10 +306,14 @@ void HeaderGenerator::finishGeneration()
QList<const PrimitiveTypeEntry*> primitives = primitiveTypes();
int pCount = 0;
foreach (const PrimitiveTypeEntry* ptype, primitives) {
- if (!ptype->generateCode() || !isUserPrimitive(ptype))
+ /* Note: do not generate indices for typedef'd primitive types
+ * as they'll use the primitive type converters instead, so we
+ * don't need to create any other.
+ */
+ if (!ptype->generateCode() || !ptype->customConversion())
continue;
- _writeTypeIndexDefineLine(macrosStream, getTypeIndexVariableName(ptype), pCount);
- pCount++;
+
+ _writeTypeIndexDefineLine(macrosStream, getTypeIndexVariableName(ptype), pCount++);
}
foreach (const AbstractMetaType* container, instantiatedContainers()) {
diff --git a/generator/shibokengenerator.cpp b/generator/shibokengenerator.cpp
index 2cf28bd2..2ae213db 100644
--- a/generator/shibokengenerator.cpp
+++ b/generator/shibokengenerator.cpp
@@ -1,7 +1,7 @@
/*
* This file is part of the Shiboken Python Bindings Generator project.
*
- * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2009-2012 Nokia Corporation and/or its subsidiary(-ies).
*
* Contact: PySide team <contact@pyside.org>
*
@@ -703,14 +703,24 @@ QString ShibokenGenerator::converterObject(const AbstractMetaType* type)
return "Shiboken::Conversions::PrimitiveTypeConverter<void*>()";
if (type->typeEntry()->isContainer())
return QString("%1[%2]").arg(convertersVariableName(type->typeEntry()->targetLangPackage())).arg(getTypeIndexVariableName(type));
+
return converterObject(type->typeEntry());
}
+
QString ShibokenGenerator::converterObject(const TypeEntry* type)
{
if (isCppPrimitive(type))
return QString("Shiboken::Conversions::PrimitiveTypeConverter<%1>()").arg(type->qualifiedCppName());
if (isWrapperType(type) || type->isEnum() || type->isFlags())
return QString("SBK_CONVERTER(%1)").arg(cpythonTypeNameExt(type));
+
+ /* the typedef'd primitive types case */
+ const PrimitiveTypeEntry* pte = reinterpret_cast<const PrimitiveTypeEntry*>(type);
+ if (pte->basicAliasedTypeEntry())
+ pte = pte->basicAliasedTypeEntry();
+ if (pte->isPrimitive() && !pte->isCppPrimitive() && !pte->customConversion())
+ return QString("Shiboken::Conversions::PrimitiveTypeConverter<%1>()").arg(pte->qualifiedCppName());
+
return QString("%1[%2]").arg(convertersVariableName(type->targetLangPackage())).arg(getTypeIndexVariableName(type));
}
@@ -1353,6 +1363,7 @@ QList<const CustomConversion*> ShibokenGenerator::getPrimitiveCustomConversions(
foreach (const PrimitiveTypeEntry* type, primitiveTypes()) {
if (!shouldGenerateTypeEntry(type) || !isUserPrimitive(type) || !type->customConversion())
continue;
+
conversions << type->customConversion();
}
return conversions;
@@ -2428,6 +2439,7 @@ void ShibokenGenerator::writeMinimalConstructorExpression(QTextStream& s, const
qFatal(qPrintable(QString(MIN_CTOR_ERROR_MSG).arg(type->cppSignature())), NULL);
s << " = " << ctor;
}
+
void ShibokenGenerator::writeMinimalConstructorExpression(QTextStream& s, const TypeEntry* type, const QString& defaultCtor)
{
if (defaultCtor.isEmpty() && isCppPrimitive(type))
diff --git a/generator/shibokengenerator.h b/generator/shibokengenerator.h
index cd273ead..4a73cbc9 100644
--- a/generator/shibokengenerator.h
+++ b/generator/shibokengenerator.h
@@ -1,7 +1,7 @@
/*
* This file is part of the Shiboken Python Bindings Generator project.
*
- * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2009-2012 Nokia Corporation and/or its subsidiary(-ies).
*
* Contact: PySide team <contact@pyside.org>
*
@@ -359,7 +359,7 @@ public:
QString guessCPythonCheckFunction(const QString& type, AbstractMetaType** metaType);
QString cpythonIsConvertibleFunction(const TypeEntry* type, bool genericNumberType = false, bool checkExact = false);
QString cpythonIsConvertibleFunction(const AbstractMetaType* metaType, bool genericNumberType = false);
- QString cpythonIsConvertibleFunction(const AbstractMetaArgument* metaArg, bool genericNumberType = false)
+ inline QString cpythonIsConvertibleFunction(const AbstractMetaArgument* metaArg, bool genericNumberType = false)
{
return cpythonIsConvertibleFunction(metaArg->type(), genericNumberType);
}
@@ -386,13 +386,13 @@ public:
QString guessScopeForDefaultValue(const AbstractMetaFunction* func, const AbstractMetaArgument* arg);
QString cpythonEnumName(const EnumTypeEntry* enumEntry);
- QString cpythonEnumName(const AbstractMetaEnum* metaEnum)
+ inline QString cpythonEnumName(const AbstractMetaEnum* metaEnum)
{
return cpythonEnumName(metaEnum->typeEntry());
}
QString cpythonFlagsName(const FlagsTypeEntry* flagsEntry);
- QString cpythonFlagsName(const AbstractMetaEnum* metaEnum)
+ inline QString cpythonFlagsName(const AbstractMetaEnum* metaEnum)
{
FlagsTypeEntry* flags = metaEnum->typeEntry()->flags();
if (!flags)
diff --git a/tests/libsample/handle.cpp b/tests/libsample/handle.cpp
index 3fe91124..60d2ef81 100644
--- a/tests/libsample/handle.cpp
+++ b/tests/libsample/handle.cpp
@@ -1,7 +1,7 @@
/*
* This file is part of the Shiboken Python Binding Generator project.
*
- * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2011-2012 Nokia Corporation and/or its subsidiary(-ies).
*
* Contact: PySide team <contact@pyside.org>
*
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "handle.h"
@@ -31,3 +31,8 @@ bool HandleHolder::compare(HandleHolder* other)
{
return other->m_handle == m_handle;
}
+
+bool HandleHolder::compare2(HandleHolder* other)
+{
+ return other->m_handle2 == m_handle2;
+}
diff --git a/tests/libsample/handle.h b/tests/libsample/handle.h
index c75f3e46..15fcc36d 100644
--- a/tests/libsample/handle.h
+++ b/tests/libsample/handle.h
@@ -1,7 +1,7 @@
/*
* This file is part of the Shiboken Python Binding Generator project.
*
- * Copyright (C) 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2010-2012 Nokia Corporation and/or its subsidiary(-ies).
*
* Contact: PySide team <contact@pyside.org>
*
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef HANDLE_H
@@ -25,6 +25,11 @@
#include "libsamplemacros.h"
+/* See http://bugs.pyside.org/show_bug.cgi?id=1105. */
+namespace Foo {
+ typedef unsigned long HANDLE;
+}
+
class LIBSAMPLE_API OBJ
{
};
@@ -35,13 +40,20 @@ class LIBSAMPLE_API HandleHolder
{
public:
explicit HandleHolder(HANDLE ptr = 0) : m_handle(ptr) {}
- void set(HANDLE ptr) { m_handle = m_handle; }
- HANDLE get() { return m_handle; }
+ explicit HandleHolder(Foo::HANDLE val = 0): m_handle2(val) {}
+
+ inline void set(HANDLE ptr) { m_handle = m_handle; }
+ inline void set(const Foo::HANDLE& val) { m_handle2 = val; }
+ inline HANDLE handle() { return m_handle; }
+ inline Foo::HANDLE handle2() { return m_handle2; }
static HANDLE createHandle();
bool compare(HandleHolder* other);
+ bool compare2(HandleHolder* other);
+
private:
HANDLE m_handle;
+ Foo::HANDLE m_handle2;
};
struct LIBSAMPLE_API PrimitiveStruct {};
diff --git a/tests/samplebinding/handleholder_test.py b/tests/samplebinding/handleholder_test.py
index 65f3d0cc..a7a64bdb 100644
--- a/tests/samplebinding/handleholder_test.py
+++ b/tests/samplebinding/handleholder_test.py
@@ -3,7 +3,7 @@
#
# This file is part of the Shiboken Python Bindings Generator project.
#
-# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+# Copyright (C) 2010-2012 Nokia Corporation and/or its subsidiary(-ies).
#
# Contact: PySide team <contact@pyside.org>
#
@@ -21,17 +21,17 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-# 02110-1301 USA
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-'''Test case for a class that holds a unknown handle object.'''
+''' Test case for a class that holds a unknown handle object.
+ Test case for BUG #1105.
+'''
import unittest
from sample import HandleHolder
class HandleHolderTest(unittest.TestCase):
-
def testCreation(self):
holder = HandleHolder(HandleHolder.createHandle())
holder2 = HandleHolder(HandleHolder.createHandle())
@@ -39,9 +39,13 @@ class HandleHolderTest(unittest.TestCase):
def testTransfer(self):
holder = HandleHolder()
- holder2 = HandleHolder(holder.get())
+ holder2 = HandleHolder(holder.handle())
self.assertTrue(holder.compare(holder2))
+ def testUseDefinedType(self):
+ holder = HandleHolder(8)
+ holder2 = HandleHolder(holder.handle2())
+ self.assertTrue(holder.compare2(holder2))
+
if __name__ == '__main__':
unittest.main()
-
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index 0389d852..ac9202a1 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -24,6 +24,8 @@
<primitive-type name="unsigned long"/>
<primitive-type name="std::string"/>
+ <primitive-type name="Foo::HANDLE" target-lang-api-name="PyLong"/>
+
<primitive-type name="std::size_t" target-lang-api-name="PyLong">
<conversion-rule>
<native-to-target>