diff options
author | Christoph Reiter <reiter.christoph@gmail.com> | 2018-12-08 18:26:47 +0100 |
---|---|---|
committer | Christoph Reiter <reiter.christoph@gmail.com> | 2018-12-08 22:45:17 +0100 |
commit | f9a873a0881e189a2d20e4904d40bb0c5cbf0d94 (patch) | |
tree | 71b78f9ddc8cc45198ce560acded84da90b094cb /giscanner/giscannermodule.c | |
parent | 0f4dd5e39a86e9ae749b3b4627488e19d18dd8a5 (diff) | |
download | gobject-introspection-f9a873a0881e189a2d20e4904d40bb0c5cbf0d94.tar.gz |
sourcescanner: collect error messages and expose them
It just printed errors to stderr and always returns success even if parsing
fails. This prevents us to write any tests for it.
As a first step collect all lexing/parsing error messages and print them to stderr after
the scanner is done. This allows us to add some regression tests for !78.
In the future we probably want to raise an exception with those errors if parsing
fails.
Diffstat (limited to 'giscanner/giscannermodule.c')
-rw-r--r-- | giscanner/giscannermodule.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c index 45701d17..24b84050 100644 --- a/giscanner/giscannermodule.c +++ b/giscanner/giscannermodule.c @@ -81,7 +81,7 @@ typedef struct { NEW_CLASS (PyGISourceSymbol, "SourceSymbol", GISourceSymbol, 10); NEW_CLASS (PyGISourceType, "SourceType", GISourceType, 9); -NEW_CLASS (PyGISourceScanner, "SourceScanner", GISourceScanner, 8); +NEW_CLASS (PyGISourceScanner, "SourceScanner", GISourceScanner, 9); /* Symbol */ @@ -508,6 +508,26 @@ pygi_source_scanner_get_symbols (PyGISourceScanner *self, G_GNUC_UNUSED PyObject } static PyObject * +pygi_source_scanner_get_errors (PyGISourceScanner *self, G_GNUC_UNUSED PyObject *unused) +{ + GSList *l, *errors; + PyObject *list; + int i = 0; + + errors = gi_source_scanner_get_errors (self->scanner); + list = PyList_New (g_slist_length (errors)); + + for (l = errors; l; l = l->next) + { + PyObject *item = PyUnicode_FromString (l->data); + PyList_SetItem (list, i++, item); + } + + g_slist_free (errors); + return list; +} + +static PyObject * pygi_source_scanner_get_comments (PyGISourceScanner *self, G_GNUC_UNUSED PyObject *unused) { GSList *l, *comments; @@ -563,6 +583,7 @@ pygi_source_scanner_get_comments (PyGISourceScanner *self, G_GNUC_UNUSED PyObjec } static const PyMethodDef _PyGISourceScanner_methods[] = { + { "get_errors", (PyCFunction) pygi_source_scanner_get_errors, METH_NOARGS }, { "get_comments", (PyCFunction) pygi_source_scanner_get_comments, METH_NOARGS }, { "get_symbols", (PyCFunction) pygi_source_scanner_get_symbols, METH_NOARGS }, { "append_filename", (PyCFunction) pygi_source_scanner_append_filename, METH_VARARGS }, |