From b71a7511d8b76922b738c0f8102a85d27b673b8e Mon Sep 17 00:00:00 2001 From: Renato Filho Date: Tue, 18 May 2010 11:40:04 -0300 Subject: API fixes. * Export enums without macro * Declare virtual destructor on all classes with virtual functions * Fix extern "C" declaration scope Reviewer: Hugo Parente Lima , Marcelo Lira --- libshiboken/basewrapper.cpp | 251 +++++++++++++++++++++++--------------------- libshiboken/pyenum.cpp | 5 + libshiboken/pyenum.h | 6 +- 3 files changed, 138 insertions(+), 124 deletions(-) (limited to 'libshiboken') 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 #include #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("__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(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("__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 #include "shibokenmacros.h" @@ -71,5 +71,5 @@ LIBSHIBOKEN_API PyObject* SbkEnumObject_New(PyTypeObject *instanceType, } // namespace Shiboken -#endif // PYENUM_H +#endif // SKB_PYENUM_H -- cgit v1.2.3