From 2fa1f3ac7f960e4bf306e53c1aac06fe0e31a4ba Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 15 Dec 2010 06:15:27 +0100 Subject: simplify python wrapper code Signed-off-by: Denys Vlasenko --- src/report-python/crash_dump.c | 99 +++++++++++++----------------------------- 1 file changed, 29 insertions(+), 70 deletions(-) (limited to 'src/report-python/crash_dump.c') diff --git a/src/report-python/crash_dump.c b/src/report-python/crash_dump.c index 4ca7cf22..64cc89d5 100644 --- a/src/report-python/crash_dump.c +++ b/src/report-python/crash_dump.c @@ -21,7 +21,8 @@ #include #include "crash_dump.h" -#include "pyreport_common.h" +#include "dump_dir.h" +#include "common.h" typedef struct { PyObject_HEAD @@ -31,7 +32,7 @@ typedef struct { static void p_crash_data_dealloc(PyObject *pself) { - p_crash_data* self = (p_crash_data*)pself; + p_crash_data *self = (p_crash_data*)pself; free_crash_data(self->cd); self->cd = NULL; self->ob_type->tp_free((PyObject*)self); @@ -62,16 +63,18 @@ void add_to_crash_data_ext(crash_data_t *crash_data, unsigned flags); */ -static PyObject *p_crash_data_add_ext(PyObject *pself, PyObject *args, PyObject *kwds) +static PyObject *p_crash_data_add_ext(PyObject *pself, PyObject *args) { p_crash_data *self = (p_crash_data*)pself; const char *name; const char *content; int FLAGS; - if(!PyArg_ParseTuple(args, "ssi", &name, &content, &FLAGS)) + if (!PyArg_ParseTuple(args, "ssi", &name, &content, &FLAGS)) { - PyErr_SetString(ReportError, strerror(errno)); + /* PyArg_ParseTuple raises the exception saying why it fails + * eg: TypeError: function takes exactly 2 arguments (1 given) + */ return NULL; } add_to_crash_data_ext(self->cd, name, content, FLAGS); @@ -79,17 +82,14 @@ static PyObject *p_crash_data_add_ext(PyObject *pself, PyObject *args, PyObject /* every function returns PyObject to return void we need to do this */ Py_RETURN_NONE; } -static PyObject *p_crash_data_add(PyObject *pself, PyObject *args, PyObject *kwds) +static PyObject *p_crash_data_add(PyObject *pself, PyObject *args) { p_crash_data *self = (p_crash_data*)pself; const char *name; const char *content; - if(!PyArg_ParseTuple(args, "ss", &name, &content)) + if (!PyArg_ParseTuple(args, "ss", &name, &content)) { - /* PyArg_ParseTuple raises the exception saying why it fails - * eg: TypeError: function takes exactly 2 arguments (1 given) - */ return NULL; } add_to_crash_data(self->cd, name, content); @@ -105,12 +105,11 @@ static inline struct crash_item *get_crash_data_item_or_NULL(crash_data_t *crash } */ -static PyObject *p_get_crash_data_item(PyObject *pself, PyObject *args, PyObject *kwds) +static PyObject *p_get_crash_data_item(PyObject *pself, PyObject *args) { p_crash_data *self = (p_crash_data*)pself; - const char *key; - if(!PyArg_ParseTuple(args, "s", &key)) + if (!PyArg_ParseTuple(args, "s", &key)) { return NULL; } @@ -123,77 +122,37 @@ static PyObject *p_create_crash_dump_dir(PyObject *pself, PyObject *args) { p_crash_data *self = (p_crash_data*)pself; struct dump_dir *dd = create_crash_dump_dir(self->cd); - if(dd == NULL) + if (dd == NULL) { PyErr_SetString(ReportError, "Can't create the dump dir"); return NULL; } //FIXME: return a python representation of dump_dir, when we have it.. + dd_close(dd); Py_RETURN_NONE; } static PyMemberDef p_crash_data_members[] = { - {NULL} /* Sentinel */ + { NULL } }; static PyMethodDef p_crash_data_methods[] = { - {"add", (PyCFunction)p_crash_data_add, METH_VARARGS, - "Adds item to the crash data using default flags" - }, - {"add_ext", (PyCFunction)p_crash_data_add_ext, METH_VARARGS, - "Adds item to the crash data" - }, - {"get", (PyCFunction)p_get_crash_data_item, METH_VARARGS, - "Gets the value of item indexed by the key" - }, - {"to_dump_dir", (PyCFunction)p_create_crash_dump_dir, METH_NOARGS, - "Saves the crash_data to"LOCALSTATEDIR"/run/abrt/tmp--