summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2bdaa47)
raw | patch | inline | side by side (parent: 2bdaa47)
author | Sven Trenkel <collectd@semidefinite.de> | |
Wed, 16 Jun 2010 12:01:18 +0000 (14:01 +0200) | ||
committer | Sven Trenkel <collectd@semidefinite.de> | |
Wed, 16 Jun 2010 12:01:18 +0000 (14:01 +0200) |
PyObject_New should not be used.
This should fix a compile problem with some versions of Python.
This should fix a compile problem with some versions of Python.
src/cpython.h | patch | blob | history | |
src/python.c | patch | blob | history |
diff --git a/src/cpython.h b/src/cpython.h
index 2a14ce071795ab50c68c2eabcc058bb227e56f5f..46e2301a1874f566098c15d54774fb1925b786de 100644 (file)
--- a/src/cpython.h
+++ b/src/cpython.h
char type_instance[DATA_MAX_NAME_LEN];
} PluginData;
PyTypeObject PluginDataType;
+#define PluginData_New() PyObject_CallFunctionObjArgs((PyObject *) &PluginDataType, (void *) 0)
typedef struct {
PluginData data;
int interval;
} Values;
PyTypeObject ValuesType;
+#define Values_New() PyObject_CallFunctionObjArgs((PyObject *) &ValuesType, (void *) 0)
typedef struct {
PluginData data;
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 6be727efb1305601a853bb6c16a4e281dc845ba2..8772cd1fc23623d52f8ab8d96042ee86b18bc2bb 100644 (file)
--- a/src/python.c
+++ b/src/python.c
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 {