From 6da0fdade325c2ce0f371e661801e6beb1e70cdb Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 15 Dec 2010 18:33:43 +0100 Subject: python wrappers: make crash_data.create_crash_dump_dir() work Signed-off-by: Denys Vlasenko --- src/report-python/common.h | 10 +++++++++ src/report-python/crash_dump.c | 14 +++++++----- src/report-python/dump_dir.c | 47 +++++++++++++++++++++++++++++++++------ src/report-python/reportmodule.c | 15 +++++++------ src/report-python/test_crash_data | 22 ++++++++++++++++++ src/report-python/test_dd_create | 20 +++++++++++++++++ 6 files changed, 109 insertions(+), 19 deletions(-) create mode 100644 src/report-python/test_crash_data create mode 100644 src/report-python/test_dd_create (limited to 'src/report-python') diff --git a/src/report-python/common.h b/src/report-python/common.h index b0a384c0..f0e8727a 100644 --- a/src/report-python/common.h +++ b/src/report-python/common.h @@ -24,3 +24,13 @@ extern PyObject *ReportError; /* type objects */ extern PyTypeObject p_crash_data_type; extern PyTypeObject p_dump_dir_type; + +/* module-level functions */ +PyObject *p_dd_opendir(PyObject *module, PyObject *args); +PyObject *p_dd_create(PyObject *module, PyObject *args); + +/* python objects' struct defs */ +typedef struct { + PyObject_HEAD + struct dump_dir *dd; +} p_dump_dir; diff --git a/src/report-python/crash_dump.c b/src/report-python/crash_dump.c index c56db087..868e97ec 100644 --- a/src/report-python/crash_dump.c +++ b/src/report-python/crash_dump.c @@ -108,18 +108,22 @@ static PyObject *p_get_crash_data_item(PyObject *pself, PyObject *args) return Py_BuildValue("sI", ci->content, ci->flags); } +/* struct dump_dir *create_crash_dump_dir(crash_data_t *crash_data); */ static PyObject *p_create_crash_dump_dir(PyObject *pself, PyObject *args) { p_crash_data *self = (p_crash_data*)pself; + p_dump_dir *new_dd = PyObject_New(p_dump_dir, &p_dump_dir_type); + if (!new_dd) + return NULL; struct dump_dir *dd = create_crash_dump_dir(self->cd); - if (dd == NULL) + if (!dd) { + PyObject_Del((PyObject*)new_dd); 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; + new_dd->dd = dd; + return (PyObject*)new_dd; } //static PyMemberDef p_crash_data_members[] = { @@ -130,7 +134,7 @@ static PyMethodDef p_crash_data_methods[] = { { "add" , p_crash_data_add, METH_VARARGS, "Adds item to the crash data using default flags" }, { "add_ext" , p_crash_data_add_ext, METH_VARARGS, "Adds item to the crash data" }, { "get" , p_get_crash_data_item, METH_VARARGS, "Gets the value of item indexed by the key" }, - { "to_dump_dir", p_create_crash_dump_dir, METH_NOARGS, "Saves the crash_data to"LOCALSTATEDIR"/run/abrt/tmp--