diff options
| author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-12-15 06:18:07 +0100 |
|---|---|---|
| committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-12-15 06:18:07 +0100 |
| commit | 544804d5e19cd8890c069273bd93801689e6f8e7 (patch) | |
| tree | b390aecd238221e8b5e11119b0680c7ab2bbf711 /src/report-python | |
| parent | 2fa1f3ac7f960e4bf306e53c1aac06fe0e31a4ba (diff) | |
| download | abrt-544804d5e19cd8890c069273bd93801689e6f8e7.tar.gz abrt-544804d5e19cd8890c069273bd93801689e6f8e7.tar.xz abrt-544804d5e19cd8890c069273bd93801689e6f8e7.zip | |
python wrappers: add dump_dir wrapper
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src/report-python')
| -rw-r--r-- | src/report-python/Makefile.am | 1 | ||||
| -rw-r--r-- | src/report-python/common.h | 3 | ||||
| -rw-r--r-- | src/report-python/crash_dump.c | 44 | ||||
| -rw-r--r-- | src/report-python/dump_dir.c | 170 | ||||
| -rw-r--r-- | src/report-python/reportmodule.c | 15 |
5 files changed, 205 insertions, 28 deletions
diff --git a/src/report-python/Makefile.am b/src/report-python/Makefile.am index 75d0c1d8..650ae45b 100644 --- a/src/report-python/Makefile.am +++ b/src/report-python/Makefile.am @@ -7,6 +7,7 @@ pyreportexec_LTLIBRARIES = _pyreport.la _pyreport_la_SOURCES = \ reportmodule.c \ crash_dump.c \ + dump_dir.c \ common.h _pyreport_la_CPPFLAGS = \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ diff --git a/src/report-python/common.h b/src/report-python/common.h index b3ae61b4..b0a384c0 100644 --- a/src/report-python/common.h +++ b/src/report-python/common.h @@ -21,5 +21,6 @@ /* exception object */ extern PyObject *ReportError; -/* crash_data type object */ +/* type objects */ extern PyTypeObject p_crash_data_type; +extern PyTypeObject p_dump_dir_type; diff --git a/src/report-python/crash_dump.c b/src/report-python/crash_dump.c index 64cc89d5..c56db087 100644 --- a/src/report-python/crash_dump.c +++ b/src/report-python/crash_dump.c @@ -35,26 +35,23 @@ p_crash_data_dealloc(PyObject *pself) p_crash_data *self = (p_crash_data*)pself; free_crash_data(self->cd); self->cd = NULL; - self->ob_type->tp_free((PyObject*)self); + self->ob_type->tp_free(pself); } static PyObject * p_crash_data_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - p_crash_data *self; - - self = (p_crash_data *)type->tp_alloc(type, 0); - if (self != NULL) + p_crash_data *self = (p_crash_data *)type->tp_alloc(type, 0); + if (self) self->cd = new_crash_data(); - return (PyObject *)self; } -static int -p_crash_data_init(PyObject *pself, PyObject *args, PyObject *kwds) -{ - return 0; -} +//static int +//p_crash_data_init(PyObject *pself, PyObject *args, PyObject *kwds) +//{ +// return 0; +//} /* void add_to_crash_data_ext(crash_data_t *crash_data, @@ -62,7 +59,6 @@ void add_to_crash_data_ext(crash_data_t *crash_data, const char *content, unsigned flags); */ - static PyObject *p_crash_data_add_ext(PyObject *pself, PyObject *args) { p_crash_data *self = (p_crash_data*)pself; @@ -79,9 +75,10 @@ static PyObject *p_crash_data_add_ext(PyObject *pself, PyObject *args) } add_to_crash_data_ext(self->cd, name, content, FLAGS); - /* every function returns PyObject to return void we need to do this */ + /* 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) { p_crash_data *self = (p_crash_data*)pself; @@ -94,17 +91,11 @@ static PyObject *p_crash_data_add(PyObject *pself, PyObject *args) } add_to_crash_data(self->cd, name, content); - /* every function returns PyObject to return void we need to do this */ + /* every function returns PyObject, to return void we need to do this */ Py_RETURN_NONE; } -/* -static inline struct crash_item *get_crash_data_item_or_NULL(crash_data_t *crash_data, const char *key) -{ - return (struct crash_item *)g_hash_table_lookup(crash_data, key); -} -*/ - +/* struct crash_item *get_crash_data_item_or_NULL(crash_data_t *crash_data, const char *key); */ static PyObject *p_get_crash_data_item(PyObject *pself, PyObject *args) { p_crash_data *self = (p_crash_data*)pself; @@ -117,7 +108,6 @@ static PyObject *p_get_crash_data_item(PyObject *pself, PyObject *args) return Py_BuildValue("sI", ci->content, ci->flags); } - static PyObject *p_create_crash_dump_dir(PyObject *pself, PyObject *args) { p_crash_data *self = (p_crash_data*)pself; @@ -132,9 +122,9 @@ static PyObject *p_create_crash_dump_dir(PyObject *pself, PyObject *args) Py_RETURN_NONE; } -static PyMemberDef p_crash_data_members[] = { - { NULL } -}; +//static PyMemberDef p_crash_data_members[] = { +// { NULL } +//}; static PyMethodDef p_crash_data_methods[] = { { "add" , p_crash_data_add, METH_VARARGS, "Adds item to the crash data using default flags" }, @@ -152,7 +142,7 @@ PyTypeObject p_crash_data_type = { .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .tp_doc = "crash_data objects", .tp_methods = p_crash_data_methods, - .tp_members = p_crash_data_members, - .tp_init = p_crash_data_init, + //.tp_members = p_crash_data_members, + //.tp_init = p_crash_data_init, .tp_new = p_crash_data_new, }; diff --git a/src/report-python/dump_dir.c b/src/report-python/dump_dir.c new file mode 100644 index 00000000..71daa088 --- /dev/null +++ b/src/report-python/dump_dir.c @@ -0,0 +1,170 @@ +/* + On-disk storage of crash dumps + + Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) + Copyright (C) 2009 RedHat inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#include <Python.h> +#include <structmember.h> + +#include <errno.h> +#include "crash_dump.h" +#include "dump_dir.h" +#include "common.h" + +typedef struct { + PyObject_HEAD + struct dump_dir *dd; +} p_dump_dir; + +static void +p_dump_dir_dealloc(PyObject *pself) +{ + p_dump_dir *self = (p_dump_dir*)pself; + dd_close(self->dd); + self->dd = NULL; + self->ob_type->tp_free(pself); +} + +static PyObject * +p_dump_dir_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + p_dump_dir *self = (p_dump_dir *)type->tp_alloc(type, 0); + if (self) + self->dd = NULL; + return (PyObject *)self; +} + +//static int +//p_dump_dir_init(PyObject *pself, PyObject *args, PyObject *kwds) +//{ +// return 0; +//} + + +/* void dd_close(struct dump_dir *dd); */ +static PyObject *p_dd_close(PyObject *pself, PyObject *args) +{ + p_dump_dir *self = (p_dump_dir*)pself; + dd_close(self->dd); + self->dd = NULL; + Py_RETURN_NONE; +} + +/* void dd_delete(struct dump_dir *dd); */ +static PyObject *p_dd_delete(PyObject *pself, PyObject *args) +{ + p_dump_dir *self = (p_dump_dir*)pself; + dd_delete(self->dd); + self->dd = NULL; + Py_RETURN_NONE; +} + +/* int dd_exist(struct dump_dir *dd, const char *path); */ +static PyObject *p_dd_exist(PyObject *pself, PyObject *args) +{ + p_dump_dir *self = (p_dump_dir*)pself; + const char *path; + if (!PyArg_ParseTuple(args, "s", &path)) + { + return NULL; + } + return Py_BuildValue("i", dd_exist(self->dd, path)); +} + +/* DIR *dd_init_next_file(struct dump_dir *dd); */ +//static PyObject *p_dd_init_next_file(PyObject *pself, PyObject *args); +/* int dd_get_next_file(struct dump_dir *dd, char **short_name, char **full_name); */ +//static PyObject *p_dd_get_next_file(PyObject *pself, PyObject *args); + +/* char* dd_load_text_ext(const struct dump_dir *dd, const char *name, unsigned flags); */ +/* char* dd_load_text(const struct dump_dir *dd, const char *name); */ +static PyObject *p_dd_load_text_ext(PyObject *pself, PyObject *args) +{ + p_dump_dir *self = (p_dump_dir*)pself; + const char *name; + int flags = 0; + if (!PyArg_ParseTuple(args, "s|i", &name, &flags)) + { + return NULL; + } + char *val = dd_load_text_ext(self->dd, name, flags); + PyObject *obj = Py_BuildValue("s", val); /* NB: if val is NULL, obj is None */ + free(val); + return obj; +} + +/* void dd_save_text(struct dump_dir *dd, const char *name, const char *data); */ +static PyObject *p_dd_save_text(PyObject *pself, PyObject *args) +{ + p_dump_dir *self = (p_dump_dir*)pself; + const char *name; + const char *data; + if (!PyArg_ParseTuple(args, "ss", &name, &data)) + { + return NULL; + } + dd_save_text(self->dd, name, data); + Py_RETURN_NONE; +} + +/* void dd_save_binary(struct dump_dir *dd, const char *name, const char *data, unsigned size); */ +static PyObject *p_dd_save_binary(PyObject *pself, PyObject *args) +{ + p_dump_dir *self = (p_dump_dir*)pself; + const char *name; + const char *data; + unsigned size; + if (!PyArg_ParseTuple(args, "ssI", &name, &data, &size)) + { + return NULL; + } + dd_save_binary(self->dd, name, data, size); + Py_RETURN_NONE; +} + +static PyMethodDef p_dump_dir_methods[] = { + { "close" , p_dd_close, METH_NOARGS, NULL }, + { "delete" , p_dd_delete, METH_NOARGS, NULL }, + { "exist" , p_dd_exist, METH_VARARGS, NULL }, + { "load_text" , p_dd_load_text_ext, METH_VARARGS, NULL }, + { "save_text" , p_dd_save_text, METH_VARARGS, NULL }, + { "save_binary", p_dd_save_binary, METH_VARARGS, NULL }, + { NULL } +}; + +PyTypeObject p_dump_dir_type = { + PyObject_HEAD_INIT(NULL) + .tp_name = "report.dump_dir", + .tp_basicsize = sizeof(p_dump_dir), + .tp_dealloc = p_dump_dir_dealloc, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_doc = "dump_dir objects", + .tp_methods = p_dump_dir_methods, + //.tp_members = p_dump_dir_members, + //.tp_init = p_dump_dir_init, + .tp_new = p_dump_dir_new, +}; + + +/* struct dump_dir *dd_opendir(const char *dir, int flags); */ +//static PyObject *p_dd_opendir(PyObject *pself, PyObject *args); +/* struct dump_dir *dd_create(const char *dir, uid_t uid); */ +//static PyObject *p_dd_create(PyObject *pself, PyObject *args); + +/* void delete_crash_dump_dir(const char *dd_dir); */ +//static PyObject *p_delete_crash_dump_dir(PyObject *pself, PyObject *args); diff --git a/src/report-python/reportmodule.c b/src/report-python/reportmodule.c index 6d44d493..f98ba75e 100644 --- a/src/report-python/reportmodule.c +++ b/src/report-python/reportmodule.c @@ -21,6 +21,13 @@ PyObject *ReportError; +//static PyMethodDef module_methods[] = { +// { "dd_opendir" , p_dd_opendir, METH_VARARGS, NULL }; +// { "dd_create" , p_dd_create, METH_VARARGS, NULL }; +// { "delete_crash_dump_dir", p_delete_crash_dump_dir, METH_VARARGS, NULL }, +// { NULL } +//}; + #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ #define PyMODINIT_FUNC void #endif @@ -34,6 +41,11 @@ init_pyreport(void) printf("PyType_Ready(&p_crash_data_type) < 0\n"); return; } + if (PyType_Ready(&p_dump_dir_type) < 0) + { + printf("PyType_Ready(&p_dump_dir_type) < 0\n"); + return; + } m = Py_InitModule3("_pyreport", /*module_methods:*/ NULL, "Python wrapper for libreport"); if (m == NULL) @@ -49,4 +61,7 @@ init_pyreport(void) Py_INCREF(&p_crash_data_type); PyModule_AddObject(m, "crash_data", (PyObject *)&p_crash_data_type); + + Py_INCREF(&p_dump_dir_type); + PyModule_AddObject(m, "dump_dir", (PyObject *)&p_dump_dir_type); } |
