mirror of
https://github.com/boostorg/python.git
synced 2026-01-26 06:42:27 +00:00
- Fixed bug where virtual methods could end exported twice in the wrapper.
[SVN r18116]
This commit is contained in:
@@ -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<B*>(a);
|
||||
return r + b->f2();
|
||||
}
|
||||
|
||||
int call_f(A* a)
|
||||
{
|
||||
return a->f();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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__':
|
||||
|
||||
Reference in New Issue
Block a user