From d2470e4f9cbcc55ae633d6beea8246f78a97119c Mon Sep 17 00:00:00 2001 From: Bruno da Silva de Oliveira Date: Thu, 27 Mar 2003 23:24:40 +0000 Subject: [PATCH] - Fixed bug where virtual methods could end exported twice in the wrapper. [SVN r18116] --- pyste/example/virtual2.h | 8 +++++++- pyste/example/virtual2.pyste | 3 ++- pyste/src/ClassExporter.py | 8 +++++++- pyste/src/pyste.py | 2 +- pyste/tests/example_virtual2.py | 9 +++++++-- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pyste/example/virtual2.h b/pyste/example/virtual2.h index de746f5e..c02cd2cd 100644 --- a/pyste/example/virtual2.h +++ b/pyste/example/virtual2.h @@ -3,19 +3,25 @@ namespace virtual2 { struct A { + virtual int f() { return 0; } virtual int f1() { return 10; } }; struct B: A { + virtual int f() { return 1; } virtual int f2() { return 20; } }; -int call(A*a) +int call_fs(A*a) { int r = a->f1(); B* b = dynamic_cast(a); return r + b->f2(); } +int call_f(A* a) +{ + return a->f(); +} } diff --git a/pyste/example/virtual2.pyste b/pyste/example/virtual2.pyste index 7e9a4602..2ca567e6 100644 --- a/pyste/example/virtual2.pyste +++ b/pyste/example/virtual2.pyste @@ -1,3 +1,4 @@ Class('virtual2::A', 'virtual2.h') Class('virtual2::B', 'virtual2.h') -Function('virtual2::call', 'virtual2.h') +Function('virtual2::call_fs', 'virtual2.h') +Function('virtual2::call_f', 'virtual2.h') diff --git a/pyste/src/ClassExporter.py b/pyste/src/ClassExporter.py index 1de4bf51..18a74fc6 100644 --- a/pyste/src/ClassExporter.py +++ b/pyste/src/ClassExporter.py @@ -698,7 +698,13 @@ class _VirtualWrapperGenerator(object): for base_member in base.members: base_member.class_ = self.class_.FullName() all_members.append(base_member) - self.virtual_methods = [m for m in all_members if IsVirtual(m)] + # extract the virtual methods, avoiding duplications + self.virtual_methods = [] + already_added = {} + for member in all_members: + if IsVirtual(member) and not member.FullName() in already_added: + self.virtual_methods.append(member) + already_added[member.FullName()] = 0 def IsMethodUnique(self, method): diff --git a/pyste/src/pyste.py b/pyste/src/pyste.py index e826a319..c7122792 100644 --- a/pyste/src/pyste.py +++ b/pyste/src/pyste.py @@ -26,7 +26,7 @@ import settings from policies import * from CppParser import CppParser, CppParserError -__VERSION__ = '0.6.1' +__VERSION__ = '0.6.2' def GetDefaultIncludes(): if 'INCLUDE' in os.environ: diff --git a/pyste/tests/example_virtual2.py b/pyste/tests/example_virtual2.py index d68ec454..6bf6f47f 100644 --- a/pyste/tests/example_virtual2.py +++ b/pyste/tests/example_virtual2.py @@ -9,14 +9,19 @@ class Virtual2Test(unittest.TestCase): b = B() self.assertEqual(b.f1(), 10) self.assertEqual(b.f2(), 20) - self.assertEqual(call(b), 30) + self.assertEqual(call_fs(b), 30) + self.assertEqual(call_f(a), 0) + self.assertEqual(call_f(b), 1) class C(B): def f1(self): return 1 def f2(self): return 2 + def f(self): return 100 c = C() - self.assertEqual(call(c), 3) + self.assertEqual(call_fs(c), 3) + self.assertEqual(call_fs(c), 3) + self.assertEqual(call_f(c), 100) if __name__ == '__main__':