summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: abe4a7e)
raw | patch | inline | side by side (parent: abe4a7e)
author | Sven Trenkel <collectd@semidefinite.de> | |
Sat, 2 Jan 2010 19:51:22 +0000 (20:51 +0100) | ||
committer | Florian Forster <octo@noris.net> | |
Tue, 5 Jan 2010 10:03:15 +0000 (11:03 +0100) |
src/cpython.h | patch | blob | history | |
src/pyconfig.c | patch | blob | history | |
src/python.c | patch | blob | history | |
src/pyvalues.c | patch | blob | history |
diff --git a/src/cpython.h b/src/cpython.h
index 8c7ad653f71cd5f8ec878274bd69dd4e2f5abae4..3e80cb0c4ee9223dc7a0959db571b6a503a973b3 100644 (file)
--- a/src/cpython.h
+++ b/src/cpython.h
#define PyInt_FromLong PyLong_FromLong
#define CPY_INIT_TYPE PyVarObject_HEAD_INIT(NULL, 0)
#define IS_BYTES_OR_UNICODE(o) (PyUnicode_Check(o) || PyBytes_Check(o))
-#define CPY_STRCAT PyUnicode_Concat
+#define CPY_STRCAT_AND_DEL(a, b) do {\
+ CPY_STRCAT((a), (b));\
+ Py_XDECREF((b));\
+} while (0)
+static inline void CPY_STRCAT(PyObject **a, PyObject *b) {
+ PyObject *ret;
+
+ if (!a || !*a)
+ return;
+
+ ret = PyUnicode_Concat(*a, b);
+ Py_DECREF(*a);
+ *a = ret;
+}
#else
#define CPY_INIT_TYPE PyObject_HEAD_INIT(NULL) 0,
#define IS_BYTES_OR_UNICODE(o) (PyUnicode_Check(o) || PyString_Check(o))
+#define CPY_STRCAT_AND_DEL PyString_ConcatAndDel
#define CPY_STRCAT PyString_Concat
#endif
Py_DECREF(*o);
*o = tmp;
}
+#ifdef IS_PY3K
return PyBytes_AsString(*o);
+#else
+ return PyString_AsString(*o);
+#endif
}
static inline PyObject *cpy_string_to_unicode_or_bytes(const char *buf) {
if (ret != NULL)
return ret;
PyErr_Clear();
-#endif
return PyBytes_FromString(buf);
+#else
+ return PyString_FromString(buf);
+#endif
}
/* Python object declarations. */
diff --git a/src/pyconfig.c b/src/pyconfig.c
index 258d31fb75bff8b0209c162c15ebf83deb34c569..b5c01aaf1d5481256bf872e6d078c6e4b74dc15c 100644 (file)
--- a/src/pyconfig.c
+++ b/src/pyconfig.c
ret = PyObject_Str(self->key);
CPY_SUBSTITUTE(PyObject_Repr, ret, ret);
if (self->parent == NULL || self->parent == Py_None)
- CPY_SUBSTITUTE(CPY_STRCAT, ret, root_prefix, ret);
+ CPY_STRCAT(&ret, root_prefix);
else
- CPY_SUBSTITUTE(CPY_STRCAT, ret, node_prefix, ret);
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, ending);
+ CPY_STRCAT(&ret, node_prefix);
+ CPY_STRCAT(&ret, ending);
return ret;
}
diff --git a/src/python.c b/src/python.c
index 25681b6649e049f723107dc67ee298ca7761ecde..5664b0c6390095072abcba72faf249e090a1b36d 100644 (file)
--- a/src/python.c
+++ b/src/python.c
@@ -691,18 +691,18 @@ static PyObject *cpy_unregister_generic_userdata(cpy_unregister_function_t *unre
PyErr_Clear();
if (!PyCallable_Check(arg)) {
PyErr_SetString(PyExc_TypeError, "This function needs a string or a callable object as its only parameter.");
- Py_DECREF(&arg);
+ Py_DECREF(arg);
return NULL;
}
cpy_build_name(buf, sizeof(buf), arg, NULL);
name = buf;
}
if (unreg(name) == 0) {
- Py_DECREF(&arg);
+ Py_DECREF(arg);
Py_RETURN_NONE;
}
PyErr_Format(PyExc_RuntimeError, "Unable to unregister %s callback '%s'.", desc, name);
- Py_DECREF(&arg);
+ Py_DECREF(arg);
return NULL;
}
@@ -895,6 +895,7 @@ static PyObject *cpy_oconfig_to_pyconfig(oconfig_item_t *ci, PyObject *parent) {
return item;
}
+#ifdef IS_PY3K
static struct PyModuleDef collectdmodule = {
PyModuleDef_HEAD_INIT,
"collectd", /* name of module */
PyMODINIT_FUNC PyInit_collectd(void) {
return PyModule_Create(&collectdmodule);
}
+#endif
static int cpy_config(oconfig_item_t *ci) {
int i;
diff --git a/src/pyvalues.c b/src/pyvalues.c
index 3fb68cf21af49d12456b8299257c84c9fd2d7a37..a632dc16061d0005130cdff6f76a83bb5fe1beb8 100644 (file)
--- a/src/pyvalues.c
+++ b/src/pyvalues.c
ret = cpy_string_to_unicode_or_bytes(s->ob_type->tp_name);
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_type);
+ CPY_STRCAT(&ret, l_type);
tmp = cpy_string_to_unicode_or_bytes(self->type);
CPY_SUBSTITUTE(PyObject_Repr, tmp, tmp);
- if (tmp)
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, tmp);
- Py_XDECREF(tmp);
+ CPY_STRCAT_AND_DEL(&ret, tmp);
if (self->type_instance[0] != 0) {
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_type_instance);
+ CPY_STRCAT(&ret, l_type_instance);
tmp = cpy_string_to_unicode_or_bytes(self->type_instance);
CPY_SUBSTITUTE(PyObject_Repr, tmp, tmp);
- if (tmp)
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, tmp);
- Py_XDECREF(tmp);
+ CPY_STRCAT_AND_DEL(&ret, tmp);
}
if (self->plugin[0] != 0) {
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_plugin);
+ CPY_STRCAT(&ret, l_plugin);
tmp = cpy_string_to_unicode_or_bytes(self->plugin);
CPY_SUBSTITUTE(PyObject_Repr, tmp, tmp);
- if (tmp)
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, tmp);
- Py_XDECREF(tmp);
+ CPY_STRCAT_AND_DEL(&ret, tmp);
}
if (self->plugin_instance[0] != 0) {
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_plugin_instance);
+ CPY_STRCAT(&ret, l_plugin_instance);
tmp = cpy_string_to_unicode_or_bytes(self->plugin_instance);
CPY_SUBSTITUTE(PyObject_Repr, tmp, tmp);
- if (tmp)
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, tmp);
- Py_XDECREF(tmp);
+ CPY_STRCAT_AND_DEL(&ret, tmp);
}
if (self->host[0] != 0) {
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_host);
+ CPY_STRCAT(&ret, l_host);
tmp = cpy_string_to_unicode_or_bytes(self->host);
CPY_SUBSTITUTE(PyObject_Repr, tmp, tmp);
- if (tmp)
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, tmp);
- Py_XDECREF(tmp);
+ CPY_STRCAT_AND_DEL(&ret, tmp);
}
if (self->time != 0) {
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_time);
+ CPY_STRCAT(&ret, l_time);
tmp = PyInt_FromLong(self->time);
CPY_SUBSTITUTE(PyObject_Repr, tmp, tmp);
- if (tmp)
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, tmp);
- Py_XDECREF(tmp);
+ CPY_STRCAT_AND_DEL(&ret, tmp);
}
return ret;
}
return NULL;
ret = cpy_common_repr(s);
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_closing);
+ CPY_STRCAT(&ret, l_closing);
return ret;
}
ret = cpy_common_repr(s);
if (self->interval != 0) {
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_interval);
+ CPY_STRCAT(&ret, l_interval);
tmp = PyInt_FromLong(self->interval);
CPY_SUBSTITUTE(PyObject_Repr, tmp, tmp);
- if (tmp)
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, tmp);
- Py_XDECREF(tmp);
+ CPY_STRCAT_AND_DEL(&ret, tmp);
}
if (self->values != NULL && PySequence_Length(self->values) > 0) {
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_values);
+ CPY_STRCAT(&ret, l_values);
tmp = PyObject_Repr(self->values);
- if (tmp)
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, tmp);
- Py_XDECREF(tmp);
+ CPY_STRCAT_AND_DEL(&ret, tmp);
}
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_closing);
+ CPY_STRCAT(&ret, l_closing);
return ret;
}
ret = cpy_common_repr(s);
if (self->severity != 0) {
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_severity);
+ CPY_STRCAT(&ret, l_severity);
tmp = PyInt_FromLong(self->severity);
CPY_SUBSTITUTE(PyObject_Repr, tmp, tmp);
- if (tmp)
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, tmp);
- Py_XDECREF(tmp);
+ CPY_STRCAT_AND_DEL(&ret, tmp);
}
if (self->message[0] != 0) {
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_message);
+ CPY_STRCAT(&ret, l_message);
tmp = cpy_string_to_unicode_or_bytes(self->message);
CPY_SUBSTITUTE(PyObject_Repr, tmp, tmp);
- if (tmp)
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, tmp);
- Py_XDECREF(tmp);
+ CPY_STRCAT_AND_DEL(&ret, tmp);
}
- CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_closing);
+ CPY_STRCAT(&ret, l_closing);
return ret;
}