X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fpython.c;h=64db6985ad4fa301663058c935794c9c73ba8a3a;hp=32c5847df6133e329b1d42b1996395c37f720c3a;hb=06a86a60a7dabc685bdbd81ce3d36ea5f7e2c2d4;hpb=07c09de5e28055a5a0f43067d51211e97039fa82 diff --git a/src/python.c b/src/python.c index 32c5847d..64db6985 100644 --- a/src/python.c +++ b/src/python.c @@ -241,7 +241,7 @@ static char CollectdError_doc[] = static pthread_t main_thread; static PyOS_sighandler_t python_sigint_handler; -static _Bool do_interactive = 0; +static bool do_interactive; /* This is our global thread state. Python saves some stuff in thread-local * storage. So if we allow the interpreter to run in the background @@ -257,8 +257,8 @@ static cpy_callback_t *cpy_init_callbacks; static cpy_callback_t *cpy_shutdown_callbacks; /* Make sure to hold the GIL while modifying these. */ -static int cpy_shutdown_triggered = 0; -static int cpy_num_callbacks = 0; +static int cpy_shutdown_triggered; +static int cpy_num_callbacks; static void cpy_destroy_user_data(void *data) { cpy_callback_t *c = data; @@ -438,7 +438,7 @@ static int cpy_write_callback(const data_set_t *ds, } dict = PyDict_New(); /* New reference. */ if (value_list->meta) { - char **table; + char **table = NULL; meta_data_t *meta = value_list->meta; int num = meta_data_toc(meta, &table); @@ -448,7 +448,7 @@ static int cpy_write_callback(const data_set_t *ds, int64_t si; uint64_t ui; double d; - _Bool b; + bool b; type = meta_data_type(meta, table[i]); if (type == MD_TYPE_STRING) { @@ -461,19 +461,21 @@ static int cpy_write_callback(const data_set_t *ds, } else if (type == MD_TYPE_SIGNED_INT) { if (meta_data_get_signed_int(meta, table[i], &si)) continue; - temp = PyObject_CallFunctionObjArgs((void *)&SignedType, - PyLong_FromLongLong(si), + PyObject *sival = PyLong_FromLongLong(si); /* New reference */ + temp = PyObject_CallFunctionObjArgs((void *)&SignedType, sival, (void *)0); /* New reference. */ PyDict_SetItemString(dict, table[i], temp); Py_XDECREF(temp); + Py_XDECREF(sival); } else if (type == MD_TYPE_UNSIGNED_INT) { if (meta_data_get_unsigned_int(meta, table[i], &ui)) continue; - temp = PyObject_CallFunctionObjArgs((void *)&UnsignedType, - PyLong_FromUnsignedLongLong(ui), + PyObject *uval = PyLong_FromUnsignedLongLong(ui); /* New reference */ + temp = PyObject_CallFunctionObjArgs((void *)&UnsignedType, uval, (void *)0); /* New reference. */ PyDict_SetItemString(dict, table[i], temp); Py_XDECREF(temp); + Py_XDECREF(uval); } else if (type == MD_TYPE_DOUBLE) { if (meta_data_get_double(meta, table[i], &d)) continue; @@ -525,6 +527,39 @@ static int cpy_notification_callback(const notification_t *notification, Notification *n; CPY_LOCK_THREADS + PyObject *dict = PyDict_New(); /* New reference. */ + for (notification_meta_t *meta = notification->meta; meta != NULL; + meta = meta->next) { + PyObject *temp = NULL; + if (meta->type == NM_TYPE_STRING) { + temp = cpy_string_to_unicode_or_bytes( + meta->nm_value.nm_string); /* New reference. */ + PyDict_SetItemString(dict, meta->name, temp); + Py_XDECREF(temp); + } else if (meta->type == NM_TYPE_SIGNED_INT) { + PyObject *sival = PyLong_FromLongLong(meta->nm_value.nm_signed_int); + temp = PyObject_CallFunctionObjArgs((void *)&SignedType, sival, + (void *)0); /* New reference. */ + PyDict_SetItemString(dict, meta->name, temp); + Py_XDECREF(temp); + Py_XDECREF(sival); + } else if (meta->type == NM_TYPE_UNSIGNED_INT) { + PyObject *uval = + PyLong_FromUnsignedLongLong(meta->nm_value.nm_unsigned_int); + temp = PyObject_CallFunctionObjArgs((void *)&UnsignedType, uval, + (void *)0); /* New reference. */ + PyDict_SetItemString(dict, meta->name, temp); + Py_XDECREF(temp); + Py_XDECREF(uval); + } else if (meta->type == NM_TYPE_DOUBLE) { + temp = PyFloat_FromDouble(meta->nm_value.nm_double); /* New reference. */ + PyDict_SetItemString(dict, meta->name, temp); + Py_XDECREF(temp); + } else if (meta->type == NM_TYPE_BOOLEAN) { + PyDict_SetItemString(dict, meta->name, + meta->nm_value.nm_boolean ? Py_True : Py_False); + } + } notify = Notification_New(); /* New reference. */ n = (Notification *)notify; sstrncpy(n->data.host, notification->host, sizeof(n->data.host)); @@ -537,6 +572,8 @@ static int cpy_notification_callback(const notification_t *notification, n->data.time = CDTIME_T_TO_DOUBLE(notification->time); sstrncpy(n->message, notification->message, sizeof(n->message)); n->severity = notification->severity; + Py_CLEAR(n->meta); + n->meta = dict; /* Steals a reference. */ ret = PyObject_CallFunctionObjArgs(c->callback, n, c->data, (void *)0); /* New reference. */ Py_XDECREF(notify); @@ -1325,7 +1362,7 @@ static int cpy_config(oconfig_item_t *ci) { #endif sfree(encoding); } else if (strcasecmp(item->key, "LogTraces") == 0) { - _Bool log_traces; + bool log_traces; if (cf_util_get_boolean(item, &log_traces) != 0) { status = 1; continue;