+/**
+ * collectd - src/pyvalues.c
+ * Copyright (C) 2009 Sven Trenkel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Sven Trenkel <collectd at semidefinite.de>
+ **/
+
#include <Python.h>
#include <structmember.h>
return 0;
}
-static PyObject *PluginData_repr(PyObject *s) {
+/*static PyObject *PluginData_repr(PyObject *s) {
PluginData *self = (PluginData *) s;
return PyString_FromFormat("collectd.Values(type='%s%s%s%s%s%s%s%s%s',time=%lu)", self->type,
*self->plugin_instance ? "',plugin_instance='" : "", self->plugin_instance,
*self->host ? "',host='" : "", self->host,
(long unsigned) self->time);
-}
+}*/
static PyMemberDef PluginData_members[] = {
{"time", T_DOUBLE, offsetof(PluginData, time), 0, time_doc},
};
static PyObject *PluginData_getstring(PyObject *self, void *data) {
- const char *value = ((char *) self) + (int) data;
+ const char *value = ((char *) self) + (intptr_t) data;
- return PyString_FromString(value);
+ return cpy_string_to_unicode_or_bytes(value);
}
static int PluginData_setstring(PyObject *self, PyObject *value, void *data) {
PyErr_SetString(PyExc_TypeError, "Cannot delete this attribute");
return -1;
}
- new = PyString_AsString(value);
- if (new == NULL) return -1;
- old = ((char *) self) + (int) data;
+ Py_INCREF(value);
+ new = cpy_unicode_or_bytes_to_string(&value);
+ if (new == NULL) {
+ Py_DECREF(value);
+ return -1;
+ }
+ old = ((char *) self) + (intptr_t) data;
sstrncpy(old, new, DATA_MAX_NAME_LEN);
+ Py_DECREF(value);
return 0;
}
PyErr_SetString(PyExc_TypeError, "Cannot delete this attribute");
return -1;
}
- new = PyString_AsString(value);
- if (new == NULL) return -1;
+ Py_INCREF(value);
+ new = cpy_unicode_or_bytes_to_string(&value);
+ if (new == NULL) {
+ Py_DECREF(value);
+ return -1;
+ }
if (plugin_get_ds(new) == NULL) {
PyErr_Format(PyExc_TypeError, "Dataset %s not found", new);
+ Py_DECREF(value);
return -1;
}
- old = ((char *) self) + (int) data;
+ old = ((char *) self) + (intptr_t) data;
sstrncpy(old, new, DATA_MAX_NAME_LEN);
+ Py_DECREF(value);
return 0;
}
};
PyTypeObject PluginDataType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* Always 0 */
+ CPY_INIT_TYPE
"collectd.PluginData", /* tp_name */
sizeof(PluginData), /* tp_basicsize */
0, /* Will be filled in later */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
- PluginData_repr, /* tp_repr */
+ 0/*PluginData_repr*/, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) {
int i, ret;
const data_set_t *ds;
- Py_ssize_t size;
+ int size;
value_t *value;
value_list_t value_list = VALUE_LIST_INIT;
PyObject *values = self->values;
PyErr_Format(PyExc_TypeError, "values must be list or tuple");
return NULL;
}
- size = PySequence_Length(values);
+ size = (int) PySequence_Length(values);
if (size != ds->ds_num) {
- PyErr_Format(PyExc_RuntimeError, "type %s needs %d values, got %zd", type, ds->ds_num, size);
+ PyErr_Format(PyExc_RuntimeError, "type %s needs %d values, got %i", type, ds->ds_num, size);
return NULL;
}
value = malloc(size * sizeof(*value));
static PyObject *Values_write(Values *self, PyObject *args, PyObject *kwds) {
int i, ret;
const data_set_t *ds;
- Py_ssize_t size;
+ int size;
value_t *value;
value_list_t value_list = VALUE_LIST_INIT;
PyObject *values = self->values;
PyErr_Format(PyExc_TypeError, "values must be list or tuple");
return NULL;
}
- size = PySequence_Length(values);
+ size = (int) PySequence_Length(values);
if (size != ds->ds_num) {
- PyErr_Format(PyExc_RuntimeError, "type %s needs %d values, got %zd", type, ds->ds_num, size);
+ PyErr_Format(PyExc_RuntimeError, "type %s needs %d values, got %i", type, ds->ds_num, size);
return NULL;
}
value = malloc(size * sizeof(*value));
Py_RETURN_NONE;
}
-static PyObject *Values_repr(PyObject *s) {
+/*static PyObject *Values_repr(PyObject *s) {
PyObject *ret, *valuestring = NULL;
Values *self = (Values *) s;
*self->data.plugin_instance ? "',plugin_instance='" : "", self->data.plugin_instance,
*self->data.host ? "',host='" : "", self->data.host,
(long unsigned) self->data.time, self->interval,
- valuestring ? PyString_AsString(valuestring) : "[]");
+ valuestring ? cpy_unicode_or_bytes_to_string(valuestring) : "[]");
Py_XDECREF(valuestring);
return ret;
-}
+}*/
static int Values_traverse(PyObject *self, visitproc visit, void *arg) {
Values *v = (Values *) self;
};
PyTypeObject ValuesType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* Always 0 */
+ CPY_INIT_TYPE
"collectd.Values", /* tp_name */
sizeof(Values), /* tp_basicsize */
0, /* Will be filled in later */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
- Values_repr, /* tp_repr */
+ 0/*Values_repr*/, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
PyErr_SetString(PyExc_TypeError, "Cannot delete this attribute");
return -1;
}
- new = PyString_AsString(value);
- if (new == NULL) return -1;
- old = ((char *) self) + (int) data;
+ Py_INCREF(value);
+ new = cpy_unicode_or_bytes_to_string(&value);
+ if (new == NULL) {
+ Py_DECREF(value);
+ return -1;
+ }
+ old = ((char *) self) + (intptr_t) data;
sstrncpy(old, new, NOTIF_MAX_MSG_LEN);
+ Py_DECREF(value);
return 0;
}
-static PyObject *Notification_repr(PyObject *s) {
+/*static PyObject *Notification_repr(PyObject *s) {
PyObject *ret;
Notification *self = (Notification *) s;
*self->message ? "',message='" : "", self->message,
(long unsigned) self->data.time, self->severity);
return ret;
-}
+}*/
static PyMethodDef Notification_methods[] = {
{"dispatch", (PyCFunction) Notification_dispatch, METH_VARARGS | METH_KEYWORDS, dispatch_doc},
};
PyTypeObject NotificationType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* Always 0 */
+ CPY_INIT_TYPE
"collectd.Notification", /* tp_name */
sizeof(Notification), /* tp_basicsize */
0, /* Will be filled in later */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
- Notification_repr, /* tp_repr */
+ 0/*Notification_repr*/, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */