diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-09-01 22:34:00 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-09-01 23:05:50 -0300 |
commit | c5f22026676c907eb91442754a7d4cfe0486f045 (patch) | |
tree | 0a152f8c88444387038a8fbe3af72dec8fec7323 /tests | |
parent | 06ebb031b31d1c37eb7f2888d38356a2f083cd81 (diff) |
Changed generator to convert the method call results on wrapped methods
at each possible call, instead of receiving the return value in the C++
type and converting it later. Having the result value as a PyObject
pointer avoids the problem of declaring the return value variable with
a class that do not have a simple constructor.
Example: "Foo resultValue;" is a problem when the only constructor for
"Foo" is "Foo(int)".
The above described problem is made worse with the addition of OddBool
and OddBoolUser cases to the sample library. OddBool is registered as a
primitive (and convertible) type, registered this way it is only
available as a TypeEntry and a suitable constructor cannot possibly
be found. This is different from Value and Object types for they
become AbstractMetaClass objects and all constructor signatures
can be queried.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libsample/oddbool.h | 47 | ||||
-rw-r--r-- | tests/samplebinding/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/samplebinding/global.h | 1 | ||||
-rw-r--r-- | tests/samplebinding/oddbool_conversions.h | 13 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 28 |
5 files changed, 82 insertions, 8 deletions
diff --git a/tests/libsample/oddbool.h b/tests/libsample/oddbool.h new file mode 100644 index 000000000..783e3ca2a --- /dev/null +++ b/tests/libsample/oddbool.h @@ -0,0 +1,47 @@ + +#ifndef ODDBOOL_H +#define ODDBOOL_H + +class OddBool +{ + +public: + inline explicit OddBool(bool b) : m_value(b) {} + bool value() { return m_value; } + + inline OddBool operator!() const { return OddBool(!m_value); } + +private: + bool m_value; +}; + +inline bool operator==(OddBool b1, bool b2) { return !b1 == !b2; } +inline bool operator==(bool b1, OddBool b2) { return !b1 == !b2; } +inline bool operator==(OddBool b1, OddBool b2) { return !b1 == !b2; } +inline bool operator!=(OddBool b1, bool b2) { return !b1 != !b2; } +inline bool operator!=(bool b1, OddBool b2) { return !b1 != !b2; } +inline bool operator!=(OddBool b1, OddBool b2) { return !b1 != !b2; } + +class OddBoolUser +{ +public: + OddBoolUser() : m_oddbool(OddBool(false)) {}; + + OddBool oddBool() { return m_oddbool; } + void setOddBool(OddBool oddBool) { m_oddbool = oddBool; } + + virtual OddBool invertedOddBool() + { + return !m_oddbool; + } + + OddBool callInvertedOddBool() + { + return invertedOddBool(); + } + +private: + OddBool m_oddbool; +}; + +#endif diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt index 0486ec925..3d80ff9c0 100644 --- a/tests/samplebinding/CMakeLists.txt +++ b/tests/samplebinding/CMakeLists.txt @@ -13,6 +13,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/listuser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/modifications_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/mapuser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/nondefaultctor_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/oddbooluser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/pairuser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/point_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/privatedtor_wrapper.cpp diff --git a/tests/samplebinding/global.h b/tests/samplebinding/global.h index 90e9b863f..5717f7e14 100644 --- a/tests/samplebinding/global.h +++ b/tests/samplebinding/global.h @@ -14,4 +14,5 @@ #include "reference.h" #include "virtualmethods.h" #include "nondefaultctor.h" +#include "oddbool.h" #include "privatedtor.h" diff --git a/tests/samplebinding/oddbool_conversions.h b/tests/samplebinding/oddbool_conversions.h new file mode 100644 index 000000000..726b008c8 --- /dev/null +++ b/tests/samplebinding/oddbool_conversions.h @@ -0,0 +1,13 @@ +template <> +struct Converter<OddBool> +{ + static PyObject* toPython(ValueHolder<OddBool> holder) + { + return PyBool_FromLong(holder.value.value()); + } + static OddBool toCpp(PyObject* pyobj) + { + return OddBool(pyobj == Py_True); + } +}; + diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index e8bce2fe1..b2378aaae 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -7,6 +7,12 @@ <primitive-type name="Complex" target-lang-api-name="PyComplex"> <conversion-rule file="complex_conversions.h"/> + <include file-name="complex.h" location="global"/> + </primitive-type> + + <primitive-type name="OddBool" target-lang-api-name="PyBool"> + <conversion-rule file="oddbool_conversions.h"/> + <include file-name="oddbool.h" location="global"/> </primitive-type> <container-type name="std::pair" type="pair"> @@ -49,21 +55,24 @@ <template name="boolptr_at_end_fix_beginning"> bool __ok__; - %0 = ((%TYPE*) ((Shiboken::PyBaseWrapper*) self)->cptr)-> - %TYPE::%FUNCTION_NAME(%ARGUMENT_NAMES, &__ok__); + %0 = Shiboken::Converter< %RETURN_TYPE >::toPython(Shiboken::ValueHolder< %RETURN_TYPE > + ( + ((%TYPE*) ((Shiboken::PyBaseWrapper*) self)->cptr)->%TYPE::%FUNCTION_NAME(%ARGUMENT_NAMES, &__ok__) + )); </template> <template name="boolptr_at_start_fix_beginning"> bool __ok__; - %0 = ((%TYPE*) ((Shiboken::PyBaseWrapper*) self)->cptr)-> - %TYPE::%FUNCTION_NAME(&__ok__, %ARGUMENT_NAMES); + %0 = Shiboken::Converter< %RETURN_TYPE >::toPython(Shiboken::ValueHolder< %RETURN_TYPE > + ( + ((%TYPE*) ((Shiboken::PyBaseWrapper*) self)->cptr)->%TYPE::%FUNCTION_NAME(&__ok__, %ARGUMENT_NAMES) + )); </template> <template name="boolptr_fix_end"> PyObject* _item_; PyObject* _tuple_ = PyTuple_New(2); - _item_ = Shiboken::Converter< %RETURN_TYPE >::toPython(Shiboken::ValueHolder< %RETURN_TYPE >(%0)); - PyTuple_SET_ITEM(_tuple_, 0, _item_); + PyTuple_SET_ITEM(_tuple_, 0, %0); _item_ = Shiboken::Converter<bool>::toPython(Shiboken::ValueHolder<bool>(__ok__)); PyTuple_SET_ITEM(_tuple_, 1, _item_); return _tuple_; @@ -76,8 +85,10 @@ <remove-argument/> </modify-argument> <inject-code class="native" position="beginning"> - %0 = ((%TYPE*) ((Shiboken::PyBaseWrapper*) self)->cptr)-> - %TYPE::%FUNCTION_NAME(%1, true, %3, %4); + %0 = Shiboken::Converter< %RETURN_TYPE >::toPython(Shiboken::ValueHolder< %RETURN_TYPE > + ( + ((%TYPE*) ((Shiboken::PyBaseWrapper*) self)->cptr)->%TYPE::%FUNCTION_NAME(%1, true, %3, %4) + )); </inject-code> </modify-function> @@ -209,6 +220,7 @@ <value-type name="PairUser"/> <value-type name="ListUser"/> <value-type name="NonDefaultCtor" /> + <value-type name="OddBoolUser" /> <object-type name="PrivateDtor" /> <rejection class="ListUser" function-name="createList()"/> |