aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatti Airas <matti.p.airas@nokia.com>2010-03-17 17:09:15 -0300
committerMatti Airas <matti.p.airas@nokia.com>2010-03-17 17:09:15 -0300
commit21bcdc289ba9ece35780369a5e86a68498a6ddae (patch)
treead2a151f4f810eb8a6e8fc96acb994b3e202cae4
parentf9b62c6a5b3f7232bb00a5ab39fd8037fc9c7d81 (diff)
added support for pure virtual methods returning void ptrs
the return statements now have correct values for pure virtual methods returning void pointers. also added a dummy test for this (can't really test it properly until the semantics of casting the python return value into a void pointer is properly defined -- if ever).
-rw-r--r--cppgenerator.cpp5
-rw-r--r--tests/libother/otherderived.cpp6
-rw-r--r--tests/libother/otherderived.h1
-rw-r--r--tests/libsample/abstract.h1
-rw-r--r--tests/libsample/derived.cpp7
-rw-r--r--tests/libsample/derived.h1
-rwxr-xr-xtests/samplebinding/abstract_test.py11
7 files changed, 30 insertions, 2 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp
index 5a4e6a131..b5c2d8709 100644
--- a/cppgenerator.cpp
+++ b/cppgenerator.cpp
@@ -435,9 +435,8 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
s << INDENT << "PyErr_SetString(PyExc_NotImplementedError, \"pure virtual method '";
s << func->ownerClass()->name() << '.' << func->name();
s << "()' not implemented.\");" << endl;
- s << INDENT << "return";
+ s << INDENT << "return ";
if (func->type()) {
- s << ' ';
writeMinimalConstructorCallArguments(s, func->type());
}
} else {
@@ -783,6 +782,8 @@ void CppGenerator::writeMinimalConstructorCallArguments(QTextStream& s, const Ab
s << type->name() << "(0)";
} else if (type->isContainer() || type->isFlags() || type->isEnum()){
s << metaType->cppSignature() << "()";
+ } else if (metaType->isNativePointer() && type->isVoid()) {
+ s << "0";
} else {
// this is slowwwww, FIXME: Fix the API od APIExtractor, these things should be easy!
foreach (AbstractMetaClass* metaClass, classes()) {
diff --git a/tests/libother/otherderived.cpp b/tests/libother/otherderived.cpp
index 10529ee2d..5659fe0cf 100644
--- a/tests/libother/otherderived.cpp
+++ b/tests/libother/otherderived.cpp
@@ -54,6 +54,12 @@ OtherDerived::pureVirtual()
{
}
+void*
+OtherDerived::pureVirtualReturningVoidPtr()
+{
+ return 0;
+}
+
void
OtherDerived::unpureVirtual()
{
diff --git a/tests/libother/otherderived.h b/tests/libother/otherderived.h
index ff425da53..4aae12aa9 100644
--- a/tests/libother/otherderived.h
+++ b/tests/libother/otherderived.h
@@ -49,6 +49,7 @@ public:
OtherDerived(int id = -1);
virtual ~OtherDerived();
virtual void pureVirtual();
+ virtual void* pureVirtualReturningVoidPtr();
virtual void unpureVirtual();
virtual PrintFormat returnAnEnum() { return Short; }
diff --git a/tests/libsample/abstract.h b/tests/libsample/abstract.h
index 008570560..cdfbb30fb 100644
--- a/tests/libsample/abstract.h
+++ b/tests/libsample/abstract.h
@@ -70,6 +70,7 @@ public:
static int getObjectId(Abstract* obj) { return obj->id(); }
virtual void pureVirtual() = 0;
+ virtual void* pureVirtualReturningVoidPtr() = 0;
virtual void unpureVirtual();
virtual PrintFormat returnAnEnum() = 0;
diff --git a/tests/libsample/derived.cpp b/tests/libsample/derived.cpp
index 1a19fe137..1e8303692 100644
--- a/tests/libsample/derived.cpp
+++ b/tests/libsample/derived.cpp
@@ -57,6 +57,12 @@ Derived::pureVirtual()
{
}
+void*
+Derived::pureVirtualReturningVoidPtr()
+{
+ return 0;
+}
+
void
Derived::unpureVirtual()
{
@@ -100,6 +106,7 @@ Derived::otherOverloaded(int a, double b)
struct SecretClass : public Abstract {
virtual void pureVirtual() {}
+ virtual void* pureVirtualReturningVoidPtr() { return 0; }
virtual PrintFormat returnAnEnum() { return Short; }
};
diff --git a/tests/libsample/derived.h b/tests/libsample/derived.h
index c5acb9488..e6d3f0fb3 100644
--- a/tests/libsample/derived.h
+++ b/tests/libsample/derived.h
@@ -61,6 +61,7 @@ public:
Derived(int id = -1);
virtual ~Derived();
virtual void pureVirtual();
+ virtual void* pureVirtualReturningVoidPtr();
virtual void unpureVirtual();
virtual PrintFormat returnAnEnum() { return Short; }
diff --git a/tests/samplebinding/abstract_test.py b/tests/samplebinding/abstract_test.py
index 2488c6542..6c2f43f41 100755
--- a/tests/samplebinding/abstract_test.py
+++ b/tests/samplebinding/abstract_test.py
@@ -44,6 +44,9 @@ class Concrete(Abstract):
def pureVirtual(self):
self.pure_virtual_called = True
+ def pureVirtualReturningVoidPtr(self):
+ return 42
+
def unpureVirtual(self):
self.unpure_virtual_called = True
@@ -67,6 +70,14 @@ class AbstractTest(unittest.TestCase):
i = Incomplete()
self.assertRaises(NotImplementedError, i.pureVirtual)
+ def testPureVirtualReturningVoidPtrReturnValue(self):
+ '''Test if a pure virtual method returning void ptr can be properly reimplemented'''
+ # Note that the semantics of reimplementing the pure virtual method in
+ # Python and calling it from C++ is undefined until it's decided how to
+ # cast the Python data types to void pointers
+ c = Concrete()
+ self.assertEqual(c.pureVirtualReturningVoidPtr(),42)
+
def testReimplementedVirtualMethodCall(self):
'''Test if instanciation of an abstract class raises the correct exception.'''
i = Concrete()