diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2011-05-11 18:15:40 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:15:22 -0300 |
commit | 587bac87604aadd4d7aedba2a911bfcac9671fe3 (patch) | |
tree | d47b703a57350790647875fd89f9f4709baf9fa1 | |
parent | bdd992a76956f86166256649f8bb3d42ce7439a2 (diff) |
Replaced "isUserType" test for the correct "hasCppWrapper" before method calls.
Also added an unit test for infinite recursion when duck punching a
virtual method.
Reviewed by Hugo Parente <hugo.lima@openbossa.org>
Reviewed by Renato Araújo <renato.filho@openbossa.org>
-rw-r--r-- | generator/cppgenerator.cpp | 4 | ||||
-rw-r--r-- | tests/samplebinding/duck_punching_test.py | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp index 07b2111ed..dbc2a9456 100644 --- a/generator/cppgenerator.cpp +++ b/generator/cppgenerator.cpp @@ -2212,8 +2212,8 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f virtualCall = virtualCall.replace("%CLASS_NAME", func->ownerClass()->qualifiedCppName()); normalCall = normalCall.replace("::%CLASS_NAME::", ""); methodCall = ""; - mc << "(Shiboken::Object::isUserType(self) ? "; - mc << virtualCall << " : " << normalCall << ")"; + mc << "Shiboken::Object::hasCppWrapper(reinterpret_cast<SbkObject*>(self)) ? "; + mc << virtualCall << " : " << normalCall; } } } diff --git a/tests/samplebinding/duck_punching_test.py b/tests/samplebinding/duck_punching_test.py index 013e36468..2870b8c47 100644 --- a/tests/samplebinding/duck_punching_test.py +++ b/tests/samplebinding/duck_punching_test.py @@ -45,6 +45,7 @@ class DuckPunchingTest(unittest.TestCase): def setUp(self): self.multiplier = 2.0 self.duck_method_called = False + self.call_counter = 0 def testMonkeyPatchOnVirtualMethod(self): '''Injects new 'virtualMethod0' on a VirtualMethods instance and makes C++ call it.''' @@ -147,6 +148,17 @@ class DuckPunchingTest(unittest.TestCase): monkey.exists = None + def testForInfiniteRecursion(self): + def myVirtualMethod0(obj, pt, val, cpx, b): + self.call_counter += 1 + return VirtualMethods.virtualMethod0(obj, pt, val, cpx, b) + vm = VirtualMethods() + vm.virtualMethod0 = types.MethodType(myVirtualMethod0, vm, VirtualMethods) + pt, val, cpx, b = Point(1.1, 2.2), 4, complex(3.3, 4.4), True + vm.virtualMethod0(pt, val, cpx, b) + self.assertEqual(self.call_counter, 1) + + if __name__ == '__main__': unittest.main() |