diff options
-rw-r--r-- | cppgenerator.cpp | 10 | ||||
-rw-r--r-- | tests/libsample/objecttype.cpp | 8 | ||||
-rw-r--r-- | tests/libsample/objecttype.h | 19 | ||||
-rw-r--r-- | tests/samplebinding/CMakeLists.txt | 1 | ||||
-rwxr-xr-x | tests/samplebinding/objecttype_test.py | 21 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 8 |
6 files changed, 63 insertions, 4 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp index 37a3fa5b5..adb4757d4 100644 --- a/cppgenerator.cpp +++ b/cppgenerator.cpp @@ -369,6 +369,16 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu s << "PyObject* method_result = "; s << "PyObject_Call(method, args, NULL);" << endl; s << INDENT << "PyGILState_Release(gil_state);" << endl << endl; + + foreach (FunctionModification func_mod, functionModifications(func)) { + foreach (ArgumentModification arg_mod, func_mod.argument_mods) { + if (!arg_mod.resetAfterUse) + continue; + s << INDENT << "PyBaseWrapper_setValidCppObject(PyTuple_GET_ITEM(args, "; + s << (arg_mod.index - 1) << "), false);" << endl; + } + } + s << INDENT << "Py_XDECREF(args);" << endl; s << INDENT << "Py_XDECREF(method);" << endl; diff --git a/tests/libsample/objecttype.cpp b/tests/libsample/objecttype.cpp index cc4733040..e6a42d6d8 100644 --- a/tests/libsample/objecttype.cpp +++ b/tests/libsample/objecttype.cpp @@ -84,7 +84,13 @@ ObjectType::objectName() const return *m_objectName; } -bool ObjectType::event() +bool ObjectType::causeEvent(Event::EventType eventType) +{ + Event e(eventType); + return this->event(&e); +} + +bool ObjectType::event(Event* event) { return true; } diff --git a/tests/libsample/objecttype.h b/tests/libsample/objecttype.h index e5383524b..f75bbeb35 100644 --- a/tests/libsample/objecttype.h +++ b/tests/libsample/objecttype.h @@ -38,6 +38,20 @@ #include <list> #include "str.h" +struct Event +{ + enum EventType { + NO_EVENT, + BASIC_EVENT, + SOME_EVENT, + ANY_EVENT + }; + Event(EventType eventType) : m_eventType(eventType) {} + EventType eventType() { return m_eventType; } +private: + EventType m_eventType; +}; + class ObjectType { public: @@ -53,7 +67,10 @@ public: Str objectName() const; void setObjectName(const Str& name); - virtual bool event(); + bool causeEvent(Event::EventType eventType); + + // Returns true if the event is processed. + virtual bool event(Event* event); private: ObjectType(const ObjectType&); diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt index 7e946d5b2..af73a6bdb 100644 --- a/tests/samplebinding/CMakeLists.txt +++ b/tests/samplebinding/CMakeLists.txt @@ -10,6 +10,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/abstract_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/collector_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/derived_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/echo_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/event_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/implicitconv_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/intwrapper_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/injectcode_wrapper.cpp diff --git a/tests/samplebinding/objecttype_test.py b/tests/samplebinding/objecttype_test.py index 6b310265c..c442ec7e8 100755 --- a/tests/samplebinding/objecttype_test.py +++ b/tests/samplebinding/objecttype_test.py @@ -29,7 +29,19 @@ import sys import unittest -from sample import ObjectType, Str +from sample import ObjectType, Event, Str + + +class ExtObjectType(ObjectType): + def __init__(self): + ObjectType.__init__(self) + self.type_of_last_event = None + self.last_event = None + def event(self, event): + self.last_event = event + self.type_of_last_event = event.eventType() + return True + class ObjectTypeTest(unittest.TestCase): '''Test cases ObjectType class of object-type with privates copy constructor and = operator.''' @@ -54,6 +66,13 @@ class ObjectTypeTest(unittest.TestCase): o.setObjectName('object name') self.assertEqual(str(o.objectName()), 'object name') + def testInvalidateAfterUse(self): + '''In ObjectType.event(Event*) the wrapper object created for Event must me marked as invalid after the method is called.''' + o = ExtObjectType() + o.causeEvent(Event.SOME_EVENT) + self.assertEqual(o.type_of_last_event, Event.SOME_EVENT) + self.assertRaises(RuntimeError, o.last_event.eventType) + if __name__ == '__main__': unittest.main() diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 56774bd15..9196e0b96 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -50,6 +50,7 @@ <enum-type name="GlobalOverloadFuncEnum"/> <enum-type name="Overload::FunctionEnum"/> <enum-type name="Overload::ParamEnum"/> + <enum-type name="Event::EventType"/> <namespace-type name="SampleNamespace"/> @@ -59,7 +60,12 @@ <object-type name="Derived"/> - <object-type name="ObjectType"/> + <object-type name="ObjectType"> + <modify-function signature="event(Event*)"> + <modify-argument index="1" invalidate-after-use="yes"/> + </modify-function> + </object-type> + <value-type name="Event"/> <template name="boolptr_at_end_fix_beginning"> bool __ok__; |