diff --git a/modules/python/python_iface.c b/modules/python/python_iface.c index 4e0fc234215..01b1d633deb 100644 --- a/modules/python/python_iface.c +++ b/modules/python/python_iface.c @@ -19,13 +19,13 @@ * */ +#include + #include "../../action.h" #include "../../dprint.h" #include "../../route_struct.h" #include "python_exec.h" -#include - /* Return the number of arguments of the application command line */ static PyObject* opensips_LM_ERR(PyObject *self, PyObject *args) diff --git a/modules/python/python_mod.c b/modules/python/python_mod.c index d77afb52262..8619907ff9c 100644 --- a/modules/python/python_mod.c +++ b/modules/python/python_mod.c @@ -19,6 +19,8 @@ * */ +#include + #include "../../str.h" #include "../../sr_module.h" @@ -27,7 +29,6 @@ #include "python_msgobj.h" #include "python_support.h" -#include #include static int mod_init(void); diff --git a/modules/python/python_msgobj.c b/modules/python/python_msgobj.c index 59ff3757dc2..4291e79318c 100644 --- a/modules/python/python_msgobj.c +++ b/modules/python/python_msgobj.c @@ -19,14 +19,14 @@ * */ +#include +#include "structmember.h" + #include "../../action.h" #include "../../mem/mem.h" #include "../../sr_module.h" #include "../../parser/msg_parser.h" -#include -#include "structmember.h" - #ifndef Py_TYPE #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) #endif @@ -40,6 +40,11 @@ static PyTypeObject MSGtype; #define is_msgobject(v) ((v)->ob_type == &MSGtype) +void set_Py_Type(PyObject *obj, struct _typeobject *type) +{ + obj->ob_type = type; +} + msgobject * newmsgobject(struct sip_msg *msg) { @@ -476,51 +481,30 @@ static PyGetSetDef msg_getseters[] = { {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; -static PyTypeObject MSGtype = { +int +python_msgobj_init(void) +{ + /* HEAD initialization */ #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 6 - PyVarObject_HEAD_INIT(NULL, 0) + PyVarObject obj = { PyVarObject_HEAD_INIT(NULL, 0) }; + + memcpy(((PyVarObject *)&MSGtype), &obj, sizeof obj); #else - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ + PyObject obj = { PyObject_HEAD_INIT(NULL) }; + + memcpy(((PyObject *)&MSGtype), &obj, sizeof obj); #endif - "OpenSIPS.msg", /*tp_name*/ - sizeof(msgobject), /*tp_size*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor)msg_dealloc, /*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*/ - Py_TPFLAGS_DEFAULT, /*tp_flags*/ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - msg_methods, /*tp_methods*/ - 0, /*tp_members*/ - msg_getseters, /*tp_getset*/ -}; -int -python_msgobj_init(void) -{ + MSGtype.tp_name = "OpenSIPS.msg"; + MSGtype.tp_basicsize = sizeof(msgobject); + MSGtype.tp_dealloc = (destructor)msg_dealloc; + MSGtype.tp_flags = Py_TPFLAGS_DEFAULT; + MSGtype.tp_methods = msg_methods; + MSGtype.tp_getset = msg_getseters; + set_Py_Type((PyObject *)&MSGtype, &PyType_Type); + + if (PyType_Ready(&MSGtype) < 0) + return -1; - Py_TYPE(&MSGtype) = &PyType_Type; - if (PyType_Ready(&MSGtype) < 0) - return -1; - return 0; + return 0; } diff --git a/modules/python/python_support.c b/modules/python/python_support.c index 31d94c3d118..0f62514b7f4 100644 --- a/modules/python/python_support.c +++ b/modules/python/python_support.c @@ -19,11 +19,12 @@ * */ +#include + #include "../../dprint.h" #include "python_mod.h" #include -#include void python_handle_exception(const char *fname)