X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=bindings%2Fpython%2Frrdtoolmodule.c;h=6f5b36c50e70aebf3027695a89a23e4b6e8a1520;hb=87660d355500ac4c8090a917dc28182aebffde98;hp=3413be7e8a349825ed86433f24f5b83fd3bb6312;hpb=e117f6452baa5a8d28156c279840a9f6d8f03d30;p=rrdtool.git diff --git a/bindings/python/rrdtoolmodule.c b/bindings/python/rrdtoolmodule.c index 3413be7..6f5b36c 100644 --- a/bindings/python/rrdtoolmodule.c +++ b/bindings/python/rrdtoolmodule.c @@ -28,6 +28,15 @@ * */ +#ifdef UNUSED +#elif defined(__GNUC__) +# define UNUSED(x) x __attribute__((unused)) +#elif defined(__LCLINT__) +# define UNUSED(x) /*@unused@*/ x +#else +# define UNUSED(x) x +#endif + static const char *__version__ = "$Revision: 1.14 $"; #include "Python.h" @@ -35,7 +44,11 @@ static const char *__version__ = "$Revision: 1.14 $"; #include "rrd_extra.h" static PyObject *ErrorObject; -extern int optind, opterr; +extern int optind; +extern int opterr; + +/* forward declaration to keep compiler happy */ +void initrrdtool(void); static int create_args(char *command, PyObject *args, int *argc, char ***argv) @@ -81,7 +94,7 @@ static char PyRRD_create__doc__[] = [RRA:CF:xff:steps:rows]"; static PyObject * -PyRRD_create(PyObject *self, PyObject *args) +PyRRD_create(PyObject UNUSED(*self), PyObject *args) { PyObject *r; char **argv; @@ -109,7 +122,7 @@ static char PyRRD_update__doc__[] = "N|timestamp:value[:value...] [timestamp:value[:value...] ...]"; static PyObject * -PyRRD_update(PyObject *self, PyObject *args) +PyRRD_update(PyObject UNUSED(*self), PyObject *args) { PyObject *r; char **argv; @@ -137,7 +150,7 @@ static char PyRRD_fetch__doc__[] = "[--start|-s start] [--end|-e end]"; static PyObject * -PyRRD_fetch(PyObject *self, PyObject *args) +PyRRD_fetch(PyObject UNUSED(*self), PyObject *args) { PyObject *r; rrd_value_t *data, *datai; @@ -158,7 +171,7 @@ PyRRD_fetch(PyObject *self, PyObject *args) /* Return : ((start, end, step), (name1, name2, ...), [(data1, data2, ..), ...]) */ PyObject *range_tup, *dsnam_tup, *data_list, *t; - int i, j, row; + unsigned long i, j, row; rrd_value_t dv; row = ((end - start) / step + 1); @@ -228,7 +241,7 @@ static char PyRRD_graph__doc__[] = "[STACK:vname[#rrggbb[:legend]]]"; static PyObject * -PyRRD_graph(PyObject *self, PyObject *args) +PyRRD_graph(PyObject UNUSED(*self), PyObject *args) { PyObject *r; char **argv, **calcpr; @@ -277,7 +290,7 @@ static char PyRRD_tune__doc__[] = "[--data-source-type|-d ds-name:DST] [--data-source-rename|-r old-name:new-name]"; static PyObject * -PyRRD_tune(PyObject *self, PyObject *args) +PyRRD_tune(PyObject UNUSED(*self), PyObject *args) { PyObject *r; char **argv; @@ -299,11 +312,35 @@ PyRRD_tune(PyObject *self, PyObject *args) return r; } +static char PyRRD_first__doc__[] = +"first(filename): Return the timestamp of the first data sample in an RRD"; + +static PyObject * +PyRRD_first(PyObject UNUSED(*self), PyObject *args) +{ + PyObject *r; + int argc, ts; + char **argv; + + if (create_args("first", args, &argc, &argv) < 0) + return NULL; + + if ((ts = rrd_first(argc, argv)) == -1) { + PyErr_SetString(ErrorObject, rrd_get_error()); + rrd_clear_error(); + r = NULL; + } else + r = PyInt_FromLong((long)ts); + + destroy_args(&argv); + return r; +} + static char PyRRD_last__doc__[] = "last(filename): Return the timestamp of the last data sample in an RRD"; static PyObject * -PyRRD_last(PyObject *self, PyObject *args) +PyRRD_last(PyObject UNUSED(*self), PyObject *args) { PyObject *r; int argc, ts; @@ -328,7 +365,7 @@ static char PyRRD_resize__doc__[] = " resize filename rra-num GROW|SHRINK rows"; static PyObject * -PyRRD_resize(PyObject *self, PyObject *args) +PyRRD_resize(PyObject UNUSED(*self), PyObject *args) { PyObject *r; char **argv; @@ -354,13 +391,13 @@ static char PyRRD_info__doc__[] = "info(filename): extract header information from an rrd"; static PyObject * -PyRRD_info(PyObject *self, PyObject *args) +PyRRD_info(PyObject UNUSED(*self), PyObject *args) { PyObject *r, *t, *ds; rrd_t rrd; FILE *in_file; char *filename; - int i, j; + unsigned long i, j; if (! PyArg_ParseTuple(args, "s:info", &filename)) return NULL; @@ -456,16 +493,17 @@ PyRRD_info(PyObject *self, PyObject *args) /* List of methods defined in the module */ #define meth(name, func, doc) {name, (PyCFunction)func, METH_VARARGS, doc} -static struct PyMethodDef _rrdtool_methods[] = { +static PyMethodDef _rrdtool_methods[] = { meth("create", PyRRD_create, PyRRD_create__doc__), meth("update", PyRRD_update, PyRRD_update__doc__), meth("fetch", PyRRD_fetch, PyRRD_fetch__doc__), meth("graph", PyRRD_graph, PyRRD_graph__doc__), meth("tune", PyRRD_tune, PyRRD_tune__doc__), + meth("first", PyRRD_first, PyRRD_first__doc__), meth("last", PyRRD_last, PyRRD_last__doc__), meth("resize", PyRRD_resize, PyRRD_resize__doc__), meth("info", PyRRD_info, PyRRD_info__doc__), - {NULL, NULL}, + {NULL, NULL,0,NULL} }; #define SET_INTCONSTANT(dict, value) \ @@ -490,7 +528,7 @@ initrrdtool(void) d = PyModule_GetDict(m); SET_STRCONSTANT(d, __version__); - ErrorObject = PyErr_NewException("_rrdtool.error", NULL, NULL); + ErrorObject = PyErr_NewException("rrdtool.error", NULL, NULL); PyDict_SetItemString(d, "error", ErrorObject); /* Check for errors */