From: Pavel Rochnyack Date: Fri, 20 Oct 2017 12:10:48 +0000 (+0700) Subject: python plugin: Passed through clang-format X-Git-Tag: collectd-5.8.0~33^2~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=07c09de5e28055a5a0f43067d51211e97039fa82;p=collectd.git python plugin: Passed through clang-format --- diff --git a/src/cpython.h b/src/cpython.h index 5389e7e8..69a4298d 100644 --- a/src/cpython.h +++ b/src/cpython.h @@ -144,17 +144,21 @@ void cpy_log_exception(const char *context); /* Python object declarations. */ typedef struct { + // clang-format off PyObject_HEAD /* No semicolon! */ - PyObject *parent; /* Config */ + PyObject *parent; /* Config */ PyObject *key; /* String */ PyObject *values; /* Sequence */ PyObject *children; /* Sequence */ + // clang-format on } Config; extern PyTypeObject ConfigType; typedef struct { + // clang-format off PyObject_HEAD /* No semicolon! */ double time; + // clang-format on char host[DATA_MAX_NAME_LEN]; char plugin[DATA_MAX_NAME_LEN]; char plugin_instance[DATA_MAX_NAME_LEN]; diff --git a/src/python.c b/src/python.c index ac4b1335..32c5847d 100644 --- a/src/python.c +++ b/src/python.c @@ -325,14 +325,14 @@ void cpy_log_exception(const char *context) { typename = "NamelessException"; if (message == NULL) message = "N/A"; - Py_BEGIN_ALLOW_THREADS + Py_BEGIN_ALLOW_THREADS; if (collectd_error) { WARNING("%s in %s: %s", typename, context, message); } else { - ERROR("Unhandled python exception in %s: %s: %s", - context, typename, message); + ERROR("Unhandled python exception in %s: %s: %s", context, typename, + message); } - Py_END_ALLOW_THREADS + Py_END_ALLOW_THREADS; Py_XDECREF(tn); Py_XDECREF(m); if (!cpy_format_exception || !traceback || collectd_error) { @@ -369,9 +369,9 @@ void cpy_log_exception(const char *context) { if (cpy[strlen(cpy) - 1] == '\n') cpy[strlen(cpy) - 1] = 0; - Py_BEGIN_ALLOW_THREADS + Py_BEGIN_ALLOW_THREADS; ERROR("%s", cpy); - Py_END_ALLOW_THREADS + Py_END_ALLOW_THREADS; free(cpy); } @@ -424,9 +424,9 @@ static int cpy_write_callback(const data_set_t *ds, PyList_SetItem( list, i, PyLong_FromUnsignedLongLong(value_list->values[i].absolute)); } else { - Py_BEGIN_ALLOW_THREADS + Py_BEGIN_ALLOW_THREADS; ERROR("cpy_write_callback: Unknown value type %d.", ds->ds[i].type); - Py_END_ALLOW_THREADS + Py_END_ALLOW_THREADS; Py_DECREF(list); CPY_RETURN_FROM_THREADS 0; } @@ -683,9 +683,9 @@ static PyObject *cpy_flush(PyObject *self, PyObject *args, PyObject *kwds) { if (PyArg_ParseTupleAndKeywords(args, kwds, "|etiet", kwlist, NULL, &plugin, &timeout, NULL, &identifier) == 0) return NULL; - Py_BEGIN_ALLOW_THREADS + Py_BEGIN_ALLOW_THREADS; plugin_flush(plugin, timeout, identifier); - Py_END_ALLOW_THREADS + Py_END_ALLOW_THREADS; PyMem_Free(plugin); PyMem_Free(identifier); Py_RETURN_NONE; @@ -820,9 +820,9 @@ static PyObject *cpy_error(PyObject *self, PyObject *args) { char *text; if (PyArg_ParseTuple(args, "et", NULL, &text) == 0) return NULL; - Py_BEGIN_ALLOW_THREADS + Py_BEGIN_ALLOW_THREADS; plugin_log(LOG_ERR, "%s", text); - Py_END_ALLOW_THREADS + Py_END_ALLOW_THREADS; PyMem_Free(text); Py_RETURN_NONE; } @@ -831,9 +831,9 @@ static PyObject *cpy_warning(PyObject *self, PyObject *args) { char *text; if (PyArg_ParseTuple(args, "et", NULL, &text) == 0) return NULL; - Py_BEGIN_ALLOW_THREADS + Py_BEGIN_ALLOW_THREADS; plugin_log(LOG_WARNING, "%s", text); - Py_END_ALLOW_THREADS + Py_END_ALLOW_THREADS; PyMem_Free(text); Py_RETURN_NONE; } @@ -842,9 +842,9 @@ static PyObject *cpy_notice(PyObject *self, PyObject *args) { char *text; if (PyArg_ParseTuple(args, "et", NULL, &text) == 0) return NULL; - Py_BEGIN_ALLOW_THREADS + Py_BEGIN_ALLOW_THREADS; plugin_log(LOG_NOTICE, "%s", text); - Py_END_ALLOW_THREADS + Py_END_ALLOW_THREADS; PyMem_Free(text); Py_RETURN_NONE; } @@ -853,9 +853,9 @@ static PyObject *cpy_info(PyObject *self, PyObject *args) { char *text; if (PyArg_ParseTuple(args, "et", NULL, &text) == 0) return NULL; - Py_BEGIN_ALLOW_THREADS + Py_BEGIN_ALLOW_THREADS; plugin_log(LOG_INFO, "%s", text); - Py_END_ALLOW_THREADS + Py_END_ALLOW_THREADS; PyMem_Free(text); Py_RETURN_NONE; } @@ -865,9 +865,9 @@ static PyObject *cpy_debug(PyObject *self, PyObject *args) { char *text; if (PyArg_ParseTuple(args, "et", NULL, &text) == 0) return NULL; - Py_BEGIN_ALLOW_THREADS + Py_BEGIN_ALLOW_THREADS; plugin_log(LOG_DEBUG, "%s", text); - Py_END_ALLOW_THREADS + Py_END_ALLOW_THREADS; PyMem_Free(text); #endif Py_RETURN_NONE; @@ -1050,12 +1050,12 @@ static int cpy_shutdown(void) { } PyErr_Print(); - Py_BEGIN_ALLOW_THREADS + Py_BEGIN_ALLOW_THREADS; cpy_unregister_list(&cpy_config_callbacks); cpy_unregister_list(&cpy_init_callbacks); cpy_unregister_list(&cpy_shutdown_callbacks); cpy_shutdown_triggered = 1; - Py_END_ALLOW_THREADS + Py_END_ALLOW_THREADS; if (!cpy_num_callbacks) { Py_Finalize(); @@ -1227,7 +1227,9 @@ static int cpy_init_python(void) { UnsignedType.tp_base = &PyLong_Type; PyType_Ready(&UnsignedType); errordict = PyDict_New(); - PyDict_SetItemString(errordict, "__doc__", cpy_string_to_unicode_or_bytes(CollectdError_doc)); /* New reference. */ + PyDict_SetItemString( + errordict, "__doc__", + cpy_string_to_unicode_or_bytes(CollectdError_doc)); /* New reference. */ CollectdError = PyErr_NewException("collectd.CollectdError", NULL, errordict); sys = PyImport_ImportModule("sys"); /* New reference. */ if (sys == NULL) { @@ -1259,7 +1261,8 @@ static int cpy_init_python(void) { PyModule_AddObject(module, "Unsigned", (void *)&UnsignedType); /* Steals a reference. */ Py_XINCREF(CollectdError); - PyModule_AddObject(module, "CollectdError", CollectdError); /* Steals a reference. */ + PyModule_AddObject(module, "CollectdError", + CollectdError); /* Steals a reference. */ PyModule_AddIntConstant(module, "LOG_DEBUG", LOG_DEBUG); PyModule_AddIntConstant(module, "LOG_INFO", LOG_INFO); PyModule_AddIntConstant(module, "LOG_NOTICE", LOG_NOTICE);