On Mon, 2010-12-13 at 12:10 +0100, Denys Vlasenko wrote:
Only compile tested.
Updated patch. Now run tested with the following script:
#!/usr/bin/python
from report import *
cd = crash_data()
print cd
It prints:
HERE1
HERE2
HERE3
HERE4
HERE5
<crash_dump.crash_data object at 0x7f6a5a1600d8>
This patch compiles wrapper into _pyreport.so, and then loads it
from __init__.py via "from _pyreport import *". Currently,
only one of tree modules in reporl library (crash_dump.c)
is wrapped, two other ones (dump_dir.c and run_event.c)
are to be added in the following patches.
__init__.py and _pyreport.so are packaged into report-libs-python
and on package installation they go to
/usr/lib64/python2.6/site-packages/report.
Changes since v1:
- corrected init function name and module name
(and added comments explaining it)
- used more compact and readable static PyTypeObject p_crash_data_type
declaration
--
vda
diff -x '*.po' -d -urpN abrt.7/abrt.spec abrt.8/abrt.spec
--- abrt.7/abrt.spec 2010-12-09 14:14:40.270705183 +0100
+++ abrt.8/abrt.spec 2010-12-13 12:05:09.129593516 +0100
@@ -70,6 +70,14 @@ Group: System Environment/Libraries
Libraries providing API for reporting different problems in applications
to different bug targets like bugzilla, ftp, trac, etc...
+%package -n report-libs-python
+Summary: Python bindings for report-libs.
+# Is group correct here? -
+Group: System Environment/Libraries
+
+%description -n report-libs-python
+Python bindings for report-libs.
+
%package -n report-libs-devel
Summary: Development libraries and headers for report-libs.
Group: Development/Libraries
@@ -365,6 +373,10 @@ fi
%defattr(-,root,root,-)
%{_libdir}/libreport.so.*
+%files -n report-libs-python
+%defattr(-,root,root,-)
+%{python_sitearch}/report/*
+
%files -n report-libs-devel
%defattr(-,root,root,-)
%{_includedir}/report/*
diff -x '*.po' -d -urpN abrt.7/configure.ac abrt.8/configure.ac
--- abrt.7/configure.ac 2010-12-08 15:10:52.000000000 +0100
+++ abrt.8/configure.ac 2010-12-12 07:12:52.880065691 +0100
@@ -119,6 +119,7 @@ AC_CONFIG_FILES([
abrt.pc
src/include/Makefile
src/lib/Makefile
+ src/libpy/Makefile
src/plugins/Makefile
src/Makefile
src/btparser/Makefile
diff -x '*.po' -d -urpN abrt.7/src/libpy/crash_dump.c abrt.8/src/libpy/crash_dump.c
--- abrt.7/src/libpy/crash_dump.c 1970-01-01 01:00:00.000000000 +0100
+++ abrt.8/src/libpy/crash_dump.c 2010-12-14 11:57:38.572165536 +0100
@@ -0,0 +1,153 @@
+/*
+ Copyright (C) 2009 Abrt team.
+ 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 <stdio.h>
+#include "crash_dump.h"
+
+typedef struct {
+ PyObject_HEAD
+ crash_data_t *cd;
+} p_crash_data;
+
+static void
+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);
+}
+
+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)
+ self->cd = new_crash_data();
+
+ return (PyObject *)self;
+}
+
+static int
+p_crash_data_init(PyObject *pself, PyObject *args, PyObject *kwds)
+{
+ return 0;
+}
+
+static PyMemberDef p_crash_data_members[] = {
+ {NULL} /* Sentinel */
+};
+
+static PyMethodDef p_crash_data_methods[] = {
+ {NULL} /* Sentinel */
+};
+
+#if 0
+static PyTypeObject p_crash_data_type = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /*ob_size*/
+ "crash_dump.crash_data", /*tp_name*/
+ sizeof(p_crash_data), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ p_crash_data_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ "crash_data objects", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ p_crash_data_methods, /* tp_methods */
+ p_crash_data_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ p_crash_data_init, /* tp_init */
+ 0, /* tp_alloc */
+ p_crash_data_new, /* tp_new */
+};
+#else
+static PyTypeObject p_crash_data_type = {
+ PyObject_HEAD_INIT(NULL)
+ .tp_name = "crash_dump.crash_data",
+ .tp_basicsize = sizeof(p_crash_data),
+ .tp_dealloc = p_crash_data_dealloc,
+ .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_new = p_crash_data_new,
+};
+#endif
+
+static PyMethodDef module_methods[] = {
+ {NULL} /* Sentinel */
+};
+
+#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
+#define PyMODINIT_FUNC void
+#endif
+/* Name of this function must be initMODULENAME,
+ * where MODULENAME comes from MODULENAME.so
+ */
+PyMODINIT_FUNC
+init_pyreport(void)
+{
+ PyObject* m;
+
+ printf("HERE1\n");
+ if (PyType_Ready(&p_crash_data_type) < 0)
+ return;
+
+ printf("HERE2\n");
+ /* The name here, again, must match MODULENAME from MODULENAME.so */
+ m = Py_InitModule3("_pyreport", module_methods, "Python wrapper around crash_data_t");
+ if (m == NULL)
+ return;
+
+ printf("HERE3\n");
+ Py_INCREF(&p_crash_data_type);
+ printf("HERE4\n");
+ PyModule_AddObject(m, "crash_data", (PyObject *)&p_crash_data_type);
+
+ printf("HERE5\n");
+}
diff -x '*.po' -d -urpN abrt.7/src/libpy/__init__.py abrt.8/src/libpy/__init__.py
--- abrt.7/src/libpy/__init__.py 1970-01-01 01:00:00.000000000 +0100
+++ abrt.8/src/libpy/__init__.py 2010-12-10 15:54:21.905603608 +0100
@@ -0,0 +1 @@
+from _pyreport import *
diff -x '*.po' -d -urpN abrt.7/src/libpy/Makefile.am abrt.8/src/libpy/Makefile.am
--- abrt.7/src/libpy/Makefile.am 1970-01-01 01:00:00.000000000 +0100
+++ abrt.8/src/libpy/Makefile.am 2010-12-14 11:55:52.531166433 +0100
@@ -0,0 +1,26 @@
+pyreportexecdir = $(pyexecdir)/report
+
+pyreportexec_PYTHON = __init__.py
+
+pyreportexec_LTLIBRARIES = _pyreport.la
+
+_pyreport_la_SOURCES = \
+ crash_dump.c
+_pyreport_la_CPPFLAGS = \
+ -I$(srcdir)/../include/report -I$(srcdir)/../include \
+ -DDEBUG_DUMPS_DIR="$(DEBUG_DUMPS_DIR)" \
+ -DPLUGINS_LIB_DIR="$(PLUGINS_LIB_DIR)" \
+ -DPLUGINS_CONF_DIR="$(PLUGINS_CONF_DIR)" \
+ -DLOCALSTATEDIR='"$(localstatedir)"' \
+ -DCONF_DIR="$(CONF_DIR)" \
+ -DVAR_RUN="$(VAR_RUN)" \
+ $(GLIB_CFLAGS) \
+ -I$(PYTHON_PREFIX)/include/python$(PYTHON_VERSION) \
+ -D_GNU_SOURCE \
+ -Wall -Werror
+_pyreport_la_LDFLAGS = \
+ -module \
+ -avoid-version \
+ -export-symbols-regex init_pyreport
+_pyreport_la_LIBADD = \
+ ../lib/libreport.la
diff -x '*.po' -d -urpN abrt.7/src/Makefile.am abrt.8/src/Makefile.am
--- abrt.7/src/Makefile.am 2010-12-08 15:10:52.000000000 +0100
+++ abrt.8/src/Makefile.am 2010-12-12 05:36:01.697681185 +0100
@@ -1 +1 @@
-SUBDIRS = include lib hooks btparser daemon applet gui cli plugins
+SUBDIRS = include lib libpy hooks btparser daemon applet gui cli plugins