summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2013-05-29 10:49:56 +0000
committerkr.angelov <kr.angelov@gmail.com>2013-05-29 10:49:56 +0000
commit43bffd3f7d11036c7aa966d431ae475d02c86ce4 (patch)
treea969a8e82d47a4945d9bd492858867e77812bd93 /src
parentef2a875116a27a5ca070e05b0c63f8310d1d74c2 (diff)
readPGF in the Python runtime now throws "No such file or directory" exception if the grammar is missing
Diffstat (limited to 'src')
-rw-r--r--src/runtime/c/gu/exn.h7
-rw-r--r--src/runtime/python/pypgf.c7
2 files changed, 11 insertions, 3 deletions
diff --git a/src/runtime/c/gu/exn.h b/src/runtime/c/gu/exn.h
index 66ca107e3..36e52917f 100644
--- a/src/runtime/c/gu/exn.h
+++ b/src/runtime/c/gu/exn.h
@@ -91,8 +91,11 @@ gu_exn_clear(GuExn* err) {
GuType*
gu_exn_caught(GuExn* err);
-const void*
-gu_exn_caught_data(GuExn* err);
+inline const void*
+gu_exn_caught_data(GuExn* err)
+{
+ return err->data.data;
+}
/// Temporarily block a raised exception.
void
diff --git a/src/runtime/python/pypgf.c b/src/runtime/python/pypgf.c
index fa5103615..7fd6c5cdf 100644
--- a/src/runtime/python/pypgf.c
+++ b/src/runtime/python/pypgf.c
@@ -1640,7 +1640,12 @@ pgf_readPGF(PyObject *self, PyObject *args)
// Read the PGF grammar.
py_pgf->pgf = pgf_read(fpath, py_pgf->pool, err);
if (!gu_ok(err)) {
- PyErr_SetString(PGFError, "The grammar cannot be loaded");
+ if (gu_exn_caught(err) == gu_type(GuErrno)) {
+ errno = *((GuErrno*) gu_exn_caught_data(err));
+ PyErr_SetFromErrnoWithFilename(PyExc_IOError, fpath);
+ } else {
+ PyErr_SetString(PGFError, "The grammar cannot be loaded");
+ }
Py_DECREF(py_pgf);
gu_pool_free(tmp_pool);
return NULL;