diff options
-rw-r--r-- | cppgenerator.cpp | 3 | ||||
-rw-r--r-- | headergenerator.cpp | 8 | ||||
-rw-r--r-- | libshiboken/basewrapper.cpp | 251 | ||||
-rw-r--r-- | libshiboken/pyenum.cpp | 5 | ||||
-rw-r--r-- | libshiboken/pyenum.h | 6 | ||||
-rw-r--r-- | shibokengenerator.cpp | 1 | ||||
-rw-r--r-- | tests/libsample/derived.h | 2 | ||||
-rw-r--r-- | tests/libsample/functions.h | 4 | ||||
-rw-r--r-- | tests/libsample/listuser.h | 2 | ||||
-rw-r--r-- | tests/libsample/mapuser.h | 2 | ||||
-rw-r--r-- | tests/libsample/modifications.h | 4 | ||||
-rw-r--r-- | tests/libsample/multiple_derived.h | 10 | ||||
-rw-r--r-- | tests/libsample/nondefaultctor.h | 2 | ||||
-rw-r--r-- | tests/libsample/oddbool.h | 3 | ||||
-rw-r--r-- | tests/libsample/pairuser.h | 2 | ||||
-rw-r--r-- | tests/libsample/reference.h | 2 | ||||
-rw-r--r-- | tests/libsample/samplenamespace.h | 8 | ||||
-rw-r--r-- | tests/libsample/virtualmethods.h | 2 |
18 files changed, 169 insertions, 148 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp index c47d00b63..35e6eae6a 100644 --- a/cppgenerator.cpp +++ b/cppgenerator.cpp @@ -1916,7 +1916,7 @@ void CppGenerator::writeClassDefinition(QTextStream& s, const AbstractMetaClass* tp_hash = '&' + cpythonBaseName(metaClass) + "_HashFunc"; s << "// Class Definition -----------------------------------------------" << endl; - + s << "extern \"C\" {" << endl; s << "static SbkBaseWrapperType " << className + "_Type" << " = { { {" << endl; s << INDENT << "PyObject_HEAD_INIT(&Shiboken::SbkBaseWrapperType_Type)" << endl; s << INDENT << "/*ob_size*/ 0," << endl; @@ -1976,6 +1976,7 @@ void CppGenerator::writeClassDefinition(QTextStream& s, const AbstractMetaClass* s << INDENT << "/*is_multicpp*/ 0," << endl; s << INDENT << "/*is_user_type*/ 0" << endl; s << "};" << endl; + s << "} //extern" << endl; } diff --git a/headergenerator.cpp b/headergenerator.cpp index 27086bc99..3310227f3 100644 --- a/headergenerator.cpp +++ b/headergenerator.cpp @@ -83,11 +83,15 @@ void HeaderGenerator::generateClass(QTextStream& s, const AbstractMetaClass* met if (isCopyable(metaClass)) writeCopyCtor(s, metaClass); - foreach (AbstractMetaFunction *func, filterFunctions(metaClass)) + bool hasVirtualFunction = false; + foreach (AbstractMetaFunction *func, filterFunctions(metaClass)) { + if (func->isVirtual()) + hasVirtualFunction = true; writeFunction(s, func); + } //destructor - s << INDENT << (metaClass->hasVirtualDestructor() ? "virtual " : "") << "~" << wrapperName << "();" << endl; + s << INDENT << (metaClass->hasVirtualDestructor() || hasVirtualFunction ? "virtual " : "") << "~" << wrapperName << "();" << endl; writeCodeSnips(s, metaClass->typeEntry()->codeSnips(), CodeSnip::Declaration, TypeSystem::NativeCode); diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp index 88ea8225f..9c2abe1f8 100644 --- a/libshiboken/basewrapper.cpp +++ b/libshiboken/basewrapper.cpp @@ -34,6 +34,7 @@ #include "basewrapper.h" #include "basewrapper_p.h" +#include "pyenum.h" #include <cstddef> #include <algorithm> #include "autodecref.h" @@ -44,6 +45,134 @@ namespace Shiboken { +static void SbkBaseWrapperType_dealloc(PyObject* pyObj); +static PyObject* SbkBaseWrapperType_TpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds); + +extern "C" +{ + +PyTypeObject SbkBaseWrapperType_Type = { + PyObject_HEAD_INIT(0) + /*ob_size*/ 0, + /*tp_name*/ "Shiboken.BaseWrapperType", + /*tp_basicsize*/ sizeof(SbkBaseWrapperType), + /*tp_itemsize*/ 0, + /*tp_dealloc*/ SbkBaseWrapperType_dealloc, + /*tp_print*/ 0, + /*tp_getattr*/ 0, + /*tp_setattr*/ 0, + /*tp_compare*/ 0, + /*tp_repr*/ 0, + /*tp_as_number*/ 0, + /*tp_as_sequence*/ 0, + /*tp_as_mapping*/ 0, + /*tp_hash*/ 0, + /*tp_call*/ 0, + /*tp_str*/ 0, + /*tp_getattro*/ 0, + /*tp_setattro*/ 0, + /*tp_as_buffer*/ 0, + /*tp_flags*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, + /*tp_doc*/ 0, + /*tp_traverse*/ 0, + /*tp_clear*/ 0, + /*tp_richcompare*/ 0, + /*tp_weaklistoffset*/ 0, + /*tp_iter*/ 0, + /*tp_iternext*/ 0, + /*tp_methods*/ 0, + /*tp_members*/ 0, + /*tp_getset*/ 0, + /*tp_base*/ &PyType_Type, + /*tp_dict*/ 0, + /*tp_descr_get*/ 0, + /*tp_descr_set*/ 0, + /*tp_dictoffset*/ 0, + /*tp_init*/ 0, + /*tp_alloc*/ 0, + /*tp_new*/ SbkBaseWrapperType_TpNew, + /*tp_free*/ 0, + /*tp_is_gc*/ 0, + /*tp_bases*/ 0, + /*tp_mro*/ 0, + /*tp_cache*/ 0, + /*tp_subclasses*/ 0, + /*tp_weaklist*/ 0 +}; + +static PyObject* SbkBaseWrapper_get_dict(SbkBaseWrapper* obj) +{ + if (!obj->ob_dict) + obj->ob_dict = PyDict_New(); + if (!obj->ob_dict) + return 0; + Py_INCREF(obj->ob_dict); + return obj->ob_dict; +} + +static PyGetSetDef SbkBaseWrapper_getsetlist[] = { + {const_cast<char*>("__dict__"), (getter)SbkBaseWrapper_get_dict, 0}, + {0} // Sentinel +}; + +SbkBaseWrapperType SbkBaseWrapper_Type = { { { + PyObject_HEAD_INIT(&SbkBaseWrapperType_Type) + /*ob_size*/ 0, + /*tp_name*/ "Shiboken.BaseWrapper", + /*tp_basicsize*/ sizeof(SbkBaseWrapper), + /*tp_itemsize*/ 0, + /*tp_dealloc*/ 0, + /*tp_print*/ 0, + /*tp_getattr*/ 0, + /*tp_setattr*/ 0, + /*tp_compare*/ 0, + /*tp_repr*/ 0, + /*tp_as_number*/ 0, + /*tp_as_sequence*/ 0, + /*tp_as_mapping*/ 0, + /*tp_hash*/ 0, + /*tp_call*/ 0, + /*tp_str*/ 0, + /*tp_getattro*/ 0, + /*tp_setattro*/ 0, + /*tp_as_buffer*/ 0, + /*tp_flags*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, + /*tp_doc*/ 0, + /*tp_traverse*/ 0, + /*tp_clear*/ 0, + /*tp_richcompare*/ 0, + /*tp_weaklistoffset*/ offsetof(SbkBaseWrapper, weakreflist), + /*tp_iter*/ 0, + /*tp_iternext*/ 0, + /*tp_methods*/ 0, + /*tp_members*/ 0, + /*tp_getset*/ SbkBaseWrapper_getsetlist, + /*tp_base*/ 0, + /*tp_dict*/ 0, + /*tp_descr_get*/ 0, + /*tp_descr_set*/ 0, + /*tp_dictoffset*/ offsetof(SbkBaseWrapper, ob_dict), + /*tp_init*/ 0, + /*tp_alloc*/ 0, + /*tp_new*/ 0, + /*tp_free*/ 0, + /*tp_is_gc*/ 0, + /*tp_bases*/ 0, + /*tp_mro*/ 0, + /*tp_cache*/ 0, + /*tp_subclasses*/ 0, + /*tp_weaklist*/ 0 +}, }, + /*mi_offsets*/ 0, + /*mi_init*/ 0, + /*mi_specialcast*/ 0, + /*type_name_func*/ 0, + /*ext_isconvertible*/ 0, + /*ext_tocpp*/ 0 +}; + +} //extern "C" + void removeParent(SbkBaseWrapper* child) { if (!child->parentInfo->parent) @@ -355,8 +484,7 @@ void SbkBaseWrapperType_dealloc(PyObject* pyObj) } } -static PyObject* -SbkBaseWrapperType_TpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds) +PyObject* SbkBaseWrapperType_TpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds) { // The meta type creates a new type when the Python programmer extends a wrapped C++ class. SbkBaseWrapperType* newType = reinterpret_cast<SbkBaseWrapperType*>(PyType_Type.tp_new(metatype, args, kwds)); @@ -397,125 +525,6 @@ SbkBaseWrapperType_TpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds) -PyTypeObject SbkBaseWrapperType_Type = { - PyObject_HEAD_INIT(0) - /*ob_size*/ 0, - /*tp_name*/ "Shiboken.BaseWrapperType", - /*tp_basicsize*/ sizeof(SbkBaseWrapperType), - /*tp_itemsize*/ 0, - /*tp_dealloc*/ SbkBaseWrapperType_dealloc, - /*tp_print*/ 0, - /*tp_getattr*/ 0, - /*tp_setattr*/ 0, - /*tp_compare*/ 0, - /*tp_repr*/ 0, - /*tp_as_number*/ 0, - /*tp_as_sequence*/ 0, - /*tp_as_mapping*/ 0, - /*tp_hash*/ 0, - /*tp_call*/ 0, - /*tp_str*/ 0, - /*tp_getattro*/ 0, - /*tp_setattro*/ 0, - /*tp_as_buffer*/ 0, - /*tp_flags*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, - /*tp_doc*/ 0, - /*tp_traverse*/ 0, - /*tp_clear*/ 0, - /*tp_richcompare*/ 0, - /*tp_weaklistoffset*/ 0, - /*tp_iter*/ 0, - /*tp_iternext*/ 0, - /*tp_methods*/ 0, - /*tp_members*/ 0, - /*tp_getset*/ 0, - /*tp_base*/ &PyType_Type, - /*tp_dict*/ 0, - /*tp_descr_get*/ 0, - /*tp_descr_set*/ 0, - /*tp_dictoffset*/ 0, - /*tp_init*/ 0, - /*tp_alloc*/ 0, - /*tp_new*/ SbkBaseWrapperType_TpNew, - /*tp_free*/ 0, - /*tp_is_gc*/ 0, - /*tp_bases*/ 0, - /*tp_mro*/ 0, - /*tp_cache*/ 0, - /*tp_subclasses*/ 0, - /*tp_weaklist*/ 0 -}; - -static PyObject* SbkBaseWrapper_get_dict(SbkBaseWrapper* obj) -{ - if (!obj->ob_dict) - obj->ob_dict = PyDict_New(); - if (!obj->ob_dict) - return 0; - Py_INCREF(obj->ob_dict); - return obj->ob_dict; -} - -static PyGetSetDef SbkBaseWrapper_getsetlist[] = { - {const_cast<char*>("__dict__"), (getter)SbkBaseWrapper_get_dict, 0}, - {0} // Sentinel -}; - -SbkBaseWrapperType SbkBaseWrapper_Type = { { { - PyObject_HEAD_INIT(&SbkBaseWrapperType_Type) - /*ob_size*/ 0, - /*tp_name*/ "Shiboken.BaseWrapper", - /*tp_basicsize*/ sizeof(SbkBaseWrapper), - /*tp_itemsize*/ 0, - /*tp_dealloc*/ 0, - /*tp_print*/ 0, - /*tp_getattr*/ 0, - /*tp_setattr*/ 0, - /*tp_compare*/ 0, - /*tp_repr*/ 0, - /*tp_as_number*/ 0, - /*tp_as_sequence*/ 0, - /*tp_as_mapping*/ 0, - /*tp_hash*/ 0, - /*tp_call*/ 0, - /*tp_str*/ 0, - /*tp_getattro*/ 0, - /*tp_setattro*/ 0, - /*tp_as_buffer*/ 0, - /*tp_flags*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, - /*tp_doc*/ 0, - /*tp_traverse*/ 0, - /*tp_clear*/ 0, - /*tp_richcompare*/ 0, - /*tp_weaklistoffset*/ offsetof(SbkBaseWrapper, weakreflist), - /*tp_iter*/ 0, - /*tp_iternext*/ 0, - /*tp_methods*/ 0, - /*tp_members*/ 0, - /*tp_getset*/ SbkBaseWrapper_getsetlist, - /*tp_base*/ 0, - /*tp_dict*/ 0, - /*tp_descr_get*/ 0, - /*tp_descr_set*/ 0, - /*tp_dictoffset*/ offsetof(SbkBaseWrapper, ob_dict), - /*tp_init*/ 0, - /*tp_alloc*/ 0, - /*tp_new*/ 0, - /*tp_free*/ 0, - /*tp_is_gc*/ 0, - /*tp_bases*/ 0, - /*tp_mro*/ 0, - /*tp_cache*/ 0, - /*tp_subclasses*/ 0, - /*tp_weaklist*/ 0 -}, }, - /*mi_offsets*/ 0, - /*mi_init*/ 0, - /*mi_specialcast*/ 0, - /*type_name_func*/ 0, - /*ext_isconvertible*/ 0, - /*ext_tocpp*/ 0 -}; void initShiboken() { diff --git a/libshiboken/pyenum.cpp b/libshiboken/pyenum.cpp index 7b9d05d03..bbd2c2786 100644 --- a/libshiboken/pyenum.cpp +++ b/libshiboken/pyenum.cpp @@ -37,6 +37,9 @@ namespace Shiboken { +extern "C" +{ + PyTypeObject SbkEnumType_Type = { PyObject_HEAD_INIT(0) /*ob_size*/ 0, @@ -86,6 +89,8 @@ PyTypeObject SbkEnumType_Type = { /*tp_weaklist*/ 0 }; +} + PyObject* SbkEnumObject_New(PyTypeObject *type, long item_value, PyObject* item_name) { diff --git a/libshiboken/pyenum.h b/libshiboken/pyenum.h index a29a7f1c5..43a8d5142 100644 --- a/libshiboken/pyenum.h +++ b/libshiboken/pyenum.h @@ -32,8 +32,8 @@ * 02110-1301 USA */ -#ifndef PYENUM_H -#define PYENUM_H +#ifndef SBK_PYENUM_H +#define SBK_PYENUM_H #include <Python.h> #include "shibokenmacros.h" @@ -71,5 +71,5 @@ LIBSHIBOKEN_API PyObject* SbkEnumObject_New(PyTypeObject *instanceType, } // namespace Shiboken -#endif // PYENUM_H +#endif // SKB_PYENUM_H diff --git a/shibokengenerator.cpp b/shibokengenerator.cpp index 5753dcc09..64976d3dd 100644 --- a/shibokengenerator.cpp +++ b/shibokengenerator.cpp @@ -156,7 +156,6 @@ QString ShibokenGenerator::translateTypeForWrapperMethod(const AbstractMetaType* const AbstractMetaClass* context) const { QString result; - const TypeEntry* tentry = cType->typeEntry(); if (cType->isArray()) result = translateTypeForWrapperMethod(cType->arrayElementType(), context) + "[]"; diff --git a/tests/libsample/derived.h b/tests/libsample/derived.h index e6d3f0fb3..58c3b2109 100644 --- a/tests/libsample/derived.h +++ b/tests/libsample/derived.h @@ -38,7 +38,7 @@ #include "libsamplemacros.h" #include "abstract.h" -enum LIBSAMPLE_API OverloadedFuncEnum { +enum OverloadedFuncEnum { OverloadedFunc_ii, OverloadedFunc_d }; diff --git a/tests/libsample/functions.h b/tests/libsample/functions.h index 136f9c517..8c93d7c98 100644 --- a/tests/libsample/functions.h +++ b/tests/libsample/functions.h @@ -41,14 +41,14 @@ #include "complex.h" #include "objecttype.h" -enum LIBSAMPLE_API GlobalEnum { +enum GlobalEnum { NoThing, FirstThing, SecondThing, ThirdThing }; -enum LIBSAMPLE_API GlobalOverloadFuncEnum { +enum GlobalOverloadFuncEnum { GlobalOverloadFunc_i, GlobalOverloadFunc_d }; diff --git a/tests/libsample/listuser.h b/tests/libsample/listuser.h index 52dea8bda..67dc95e44 100644 --- a/tests/libsample/listuser.h +++ b/tests/libsample/listuser.h @@ -48,7 +48,7 @@ public: ListUser() {} ListUser(const ListUser& other) : m_lst(other.m_lst) {} - ~ListUser() {} + virtual ~ListUser() {} virtual std::list<int> createList(); std::list<int> callCreateList(); diff --git a/tests/libsample/mapuser.h b/tests/libsample/mapuser.h index 743a7e533..78cc4f34c 100644 --- a/tests/libsample/mapuser.h +++ b/tests/libsample/mapuser.h @@ -46,7 +46,7 @@ class LIBSAMPLE_API MapUser { public: MapUser() {} - ~MapUser() {} + virtual ~MapUser() {} virtual std::map<const char*, std::pair<Complex, int> > createMap(); std::map<const char*, std::pair<Complex, int> > callCreateMap(); diff --git a/tests/libsample/modifications.h b/tests/libsample/modifications.h index 2014b7ecf..d5c6d8ebf 100644 --- a/tests/libsample/modifications.h +++ b/tests/libsample/modifications.h @@ -43,7 +43,7 @@ class LIBSAMPLE_API Modifications { public: Modifications() {} - ~Modifications() {} + virtual ~Modifications() {} enum OverloadedModFunc { OverloadedNone, @@ -111,7 +111,7 @@ class LIBSAMPLE_API AbstractModifications : public Modifications { public: AbstractModifications() {} - ~AbstractModifications() {} + virtual ~AbstractModifications() {} bool invert(bool value) { return !value; } diff --git a/tests/libsample/multiple_derived.h b/tests/libsample/multiple_derived.h index 92023f4fa..6154086d2 100644 --- a/tests/libsample/multiple_derived.h +++ b/tests/libsample/multiple_derived.h @@ -41,7 +41,7 @@ class LIBSAMPLE_API Base1 { public: Base1() : m_value(1) {} - ~Base1() {} + virtual ~Base1() {} virtual int base1Method() { return m_value; } private: int m_value; @@ -51,7 +51,7 @@ class LIBSAMPLE_API Base2 { public: Base2() : m_value(2) {} - ~Base2() {} + virtual ~Base2() {} virtual int base2Method() { return m_value; } private: int m_value; @@ -114,7 +114,7 @@ class LIBSAMPLE_API Base5 { public: Base5() : m_value(5) {} - ~Base5() {} + virtual ~Base5() {} virtual int base5Method() { return m_value; } private: int m_value; @@ -124,7 +124,7 @@ class LIBSAMPLE_API Base6 { public: Base6() : m_value(6) {} - ~Base6() {} + virtual ~Base6() {} virtual int base6Method() { return m_value; } private: int m_value; @@ -184,7 +184,7 @@ class LIBSAMPLE_API MDerived5 : public Base3, public Base4 { public: MDerived5(); - ~MDerived5() {} + virtual ~MDerived5() {} virtual int mderived5Method() { return 0; } diff --git a/tests/libsample/nondefaultctor.h b/tests/libsample/nondefaultctor.h index 9a0a98f72..cd4f6eace 100644 --- a/tests/libsample/nondefaultctor.h +++ b/tests/libsample/nondefaultctor.h @@ -74,6 +74,8 @@ public: { return returnMyselfVirtual(); } + + virtual ~NonDefaultCtor() {} }; #endif diff --git a/tests/libsample/oddbool.h b/tests/libsample/oddbool.h index 60cf6a37d..47f0edb9e 100644 --- a/tests/libsample/oddbool.h +++ b/tests/libsample/oddbool.h @@ -60,7 +60,8 @@ inline bool operator!=(OddBool b1, OddBool b2) { return !b1 != !b2; } class LIBSAMPLE_API OddBoolUser { public: - OddBoolUser() : m_oddbool(OddBool(false)) {}; + OddBoolUser() : m_oddbool(OddBool(false)) {} + virtual ~OddBoolUser() {} OddBool oddBool() { return m_oddbool; } void setOddBool(OddBool oddBool) { m_oddbool = oddBool; } diff --git a/tests/libsample/pairuser.h b/tests/libsample/pairuser.h index b3b958460..8a3cb7a94 100644 --- a/tests/libsample/pairuser.h +++ b/tests/libsample/pairuser.h @@ -44,7 +44,7 @@ class LIBSAMPLE_API PairUser { public: PairUser() {} - ~PairUser() {} + virtual ~PairUser() {} virtual std::pair<int, int> createPair(); std::pair<int, int> callCreatePair(); diff --git a/tests/libsample/reference.h b/tests/libsample/reference.h index 5c9e8c99a..1a95ad2c7 100644 --- a/tests/libsample/reference.h +++ b/tests/libsample/reference.h @@ -42,7 +42,7 @@ class LIBSAMPLE_API Reference public: explicit Reference(int objId = -1) : m_objId(objId) {} - ~Reference() {} + virtual ~Reference() {} int objId() { return m_objId; } void setObjId(int objId) { m_objId = objId; } diff --git a/tests/libsample/samplenamespace.h b/tests/libsample/samplenamespace.h index ae1f58dde..b050bd558 100644 --- a/tests/libsample/samplenamespace.h +++ b/tests/libsample/samplenamespace.h @@ -40,19 +40,19 @@ namespace SampleNamespace { -enum LIBSAMPLE_API Option { +enum Option { None, RandomNumber, UnixTime }; -enum LIBSAMPLE_API InValue { +enum InValue { ZeroIn, OneIn, TwoIn }; -enum LIBSAMPLE_API OutValue { +enum OutValue { ZeroOut, OneOut, TwoOut @@ -77,7 +77,7 @@ public: class OkThisIsRecursiveEnough { public: - ~OkThisIsRecursiveEnough() {} + virtual ~OkThisIsRecursiveEnough() {} enum NiceEnum { NiceValue1, NiceValue2 }; diff --git a/tests/libsample/virtualmethods.h b/tests/libsample/virtualmethods.h index de4149a85..022453876 100644 --- a/tests/libsample/virtualmethods.h +++ b/tests/libsample/virtualmethods.h @@ -46,7 +46,7 @@ class LIBSAMPLE_API VirtualMethods { public: VirtualMethods(Str name = "VirtualMethods") : m_name(name) {} - ~VirtualMethods() {} + virtual ~VirtualMethods() {} virtual double virtualMethod0(Point pt, int val, Complex cpx, bool b); double callVirtualMethod0(Point pt, int val, Complex cpx, bool b) |