Skip to content

Commit

Permalink
fix python2 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Mar 19, 2015
1 parent cb427c9 commit 83e47b8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 49 deletions.
4 changes: 2 additions & 2 deletions modules/python/python_iface.c
Expand Up @@ -19,13 +19,13 @@
*
*/

#include <Python.h>

#include "../../action.h"
#include "../../dprint.h"
#include "../../route_struct.h"
#include "python_exec.h"

#include <Python.h>

/* Return the number of arguments of the application command line */
static PyObject*
opensips_LM_ERR(PyObject *self, PyObject *args)
Expand Down
3 changes: 2 additions & 1 deletion modules/python/python_mod.c
Expand Up @@ -19,6 +19,8 @@
*
*/

#include <Python.h>

#include "../../str.h"
#include "../../sr_module.h"

Expand All @@ -27,7 +29,6 @@
#include "python_msgobj.h"
#include "python_support.h"

#include <Python.h>
#include <libgen.h>

static int mod_init(void);
Expand Down
74 changes: 29 additions & 45 deletions modules/python/python_msgobj.c
Expand Up @@ -19,14 +19,14 @@
*
*/

#include <Python.h>
#include "structmember.h"

#include "../../action.h"
#include "../../mem/mem.h"
#include "../../sr_module.h"
#include "../../parser/msg_parser.h"

#include <Python.h>
#include "structmember.h"

#ifndef Py_TYPE
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
#endif
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
}
3 changes: 2 additions & 1 deletion modules/python/python_support.c
Expand Up @@ -19,11 +19,12 @@
*
*/

#include <Python.h>

#include "../../dprint.h"
#include "python_mod.h"

#include <stdio.h>
#include <Python.h>

void
python_handle_exception(const char *fname)
Expand Down

0 comments on commit 83e47b8

Please sign in to comment.