From 23308534a393a9186e1d64a9c0a6a82086cb0a57 Mon Sep 17 00:00:00 2001 From: Sven Trenkel Date: Wed, 16 Jun 2010 14:01:18 +0200 Subject: [PATCH] python plugin: Switch back to calling the type object to create a new object like in collectd-4.9. PyObject_New should not be used. This should fix a compile problem with some versions of Python. --- src/cpython.h | 4 ++++ src/python.c | 16 ++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/cpython.h b/src/cpython.h index 2a14ce07..46e2301a 100644 --- a/src/cpython.h +++ b/src/cpython.h @@ -182,6 +182,7 @@ typedef struct { char type_instance[DATA_MAX_NAME_LEN]; } PluginData; PyTypeObject PluginDataType; +#define PluginData_New() PyObject_CallFunctionObjArgs((PyObject *) &PluginDataType, (void *) 0) typedef struct { PluginData data; @@ -190,6 +191,7 @@ typedef struct { int interval; } Values; PyTypeObject ValuesType; +#define Values_New() PyObject_CallFunctionObjArgs((PyObject *) &ValuesType, (void *) 0) typedef struct { PluginData data; @@ -197,9 +199,11 @@ typedef struct { char message[NOTIF_MAX_MSG_LEN]; } Notification; PyTypeObject NotificationType; +#define Notification_New() PyObject_CallFunctionObjArgs((PyObject *) &NotificationType, (void *) 0) typedef PyLongObject Signed; PyTypeObject SignedType; typedef PyLongObject Unsigned; PyTypeObject UnsignedType; + diff --git a/src/python.c b/src/python.c index 6be727ef..8772cd1f 100644 --- a/src/python.c +++ b/src/python.c @@ -335,7 +335,7 @@ static int cpy_read_callback(user_data_t *data) { static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_list, user_data_t *data) { int i; cpy_callback_t *c = data->data; - PyObject *ret, *list, *temp, *dict = NULL; + PyObject *ret, *list, *temp, *dict = NULL, *val; Values *v; CPY_LOCK_THREADS @@ -428,7 +428,8 @@ static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_li } free(table); } - v = PyObject_New(Values, (void *) &ValuesType); /* New reference. */ + val = Values_New(); /* New reference. */ + v = (Values *) val; sstrncpy(v->data.host, value_list->host, sizeof(v->data.host)); sstrncpy(v->data.type, value_list->type, sizeof(v->data.type)); sstrncpy(v->data.type_instance, value_list->type_instance, sizeof(v->data.type_instance)); @@ -436,10 +437,12 @@ static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_li sstrncpy(v->data.plugin_instance, value_list->plugin_instance, sizeof(v->data.plugin_instance)); v->data.time = value_list->time; v->interval = value_list->interval; + Py_CLEAR(v->values); v->values = list; + Py_CLEAR(v->meta); v->meta = dict; ret = PyObject_CallFunctionObjArgs(c->callback, v, c->data, (void *) 0); /* New reference. */ - Py_XDECREF(v); + Py_XDECREF(val); if (ret == NULL) { cpy_log_exception("write callback"); } else { @@ -451,11 +454,12 @@ static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_li static int cpy_notification_callback(const notification_t *notification, user_data_t *data) { cpy_callback_t *c = data->data; - PyObject *ret; + PyObject *ret, *notify; Notification *n; CPY_LOCK_THREADS - n = PyObject_New(Notification, (void *) &NotificationType); /* New reference. */ + notify = Notification_New(); /* New reference. */ + n = (Notification *) notify; sstrncpy(n->data.host, notification->host, sizeof(n->data.host)); sstrncpy(n->data.type, notification->type, sizeof(n->data.type)); sstrncpy(n->data.type_instance, notification->type_instance, sizeof(n->data.type_instance)); @@ -465,7 +469,7 @@ static int cpy_notification_callback(const notification_t *notification, user_da sstrncpy(n->message, notification->message, sizeof(n->message)); n->severity = notification->severity; ret = PyObject_CallFunctionObjArgs(c->callback, n, c->data, (void *) 0); /* New reference. */ - Py_XDECREF(n); + Py_XDECREF(notify); if (ret == NULL) { cpy_log_exception("notification callback"); } else { -- 2.11.0