On 05/23/2011 08:38 PM, Denys Vlasenko wrote:
On Fri, 2011-05-20 at 18:29 +0200, Jiri Moskovcak wrote:
> It's a really quick hack to make the example work, needs some tuning..
>
> how I test it:
> cd src/report-python/.libs
> $ python
>
> and run:
>
> import _pyreport
>
> pd = _pyreport.problem_data()
> pd.add("foo", "bar")
> pd.add("description", "python-libreport test bug")
>
> _pyreport.report(pd)
+static PyObject *p_report(PyObject *pself, PyObject *problem_data)
+{
+ p_problem_data *p_pd = (p_problem_data*)problem_data;
+ printf("%p\n", p_pd);
+ report(p_pd->cd);
+ printf("%p\n", p_pd);
+ Py_RETURN_NONE;
+}
...
static PyMethodDef module_methods[] = {
/* method_name, func, flags, doc_string */
{ "dd_opendir" , p_dd_opendir , METH_VARARGS },
{ "dd_create" , p_dd_create , METH_VARARGS },
{ "delete_dump_dir", p_delete_dump_dir, METH_VARARGS },
+ { "report" , p_report, METH_O},
{ NULL }
};
This creates a Python wrapper around *part of* include/report/report.h
C API: only report(pd) function. Three more functions, and constants,
are not exported.
- I know, as I said on the beginning of this email, this is just a quick
hack proof that it works
I propose to adopt a rule that wrappers expose entire C API.
IOW: Python should not be a second-class, "limited" citizen.
- I will expose the rest of the API later today (and hopefully finish
this week)
I also propose to keep Python wrappers for report/FOO.h in the
source
file named src/report-python/FOO.c. src/report-python/reportmodule.c
is the "glue", it contains no wrappers per se.
IOW: I propose creating src/report-python/report.c and moving p_report()
wrapper into it, with only likes like
+ { "report" , p_report, METH_O},
added in reportmodule.c (and with corresponding decl in common.h).
(I had to document it better when I created Python wrappers... bad Denys)
- ok, will do
Somewhat unrelated note:
I have a feeling than function named just "report" is bound to cause
name collisions. Not in Python, but in C, where there are no namespaces
to guard against that. Consider that our own code _already_
has such collision! src/cli/report.{c,h} has
int report(const char *dump_dir_name, int flags)!
We need different name...
- how about report_problem() ?
- but I would still like to keep at least the python compat version
(which we can mark as obsolete and push people to use the new name in
new code)
+#if 0 //not used, so compiler complains
+/*
+the old report library has report() function like this:
+
+rc = report.report(signature, report.io.TextIO.TextIO())
+
+- since we're trying to be more clever and guess the right UI, so we don't
+ need the io parameter, but to keep the compatibility we provide function which
+ takes the parameter and ignores it
+ FIXME: expose it as a module function
+*/
+
+static PyObject *p_report_compat(PyObject *pself, PyObject *args)
+{
+ PyObject *p_pd;
+ PyObject *io;
+ if (!PyArg_ParseTuple(args, "oo",&p_pd,&io))
+ {
+ //FIXME: error here
+ Py_RETURN_NONE;
+ }
+ p_report(pself, p_pd);
+ Py_RETURN_NONE;
+}
+#endif
Look into existing __init__.py: it provides such compat layer,
purely in Python.
- this patch is old, it was already removed and the compat layer moved
to the __init__.py in my last commit yesterday