forked from GitHub/gf-core
readPGF in the Python runtime now throws "No such file or directory" exception if the grammar is missing
This commit is contained in:
@@ -91,8 +91,11 @@ gu_exn_clear(GuExn* err) {
|
|||||||
GuType*
|
GuType*
|
||||||
gu_exn_caught(GuExn* err);
|
gu_exn_caught(GuExn* err);
|
||||||
|
|
||||||
const void*
|
inline const void*
|
||||||
gu_exn_caught_data(GuExn* err);
|
gu_exn_caught_data(GuExn* err)
|
||||||
|
{
|
||||||
|
return err->data.data;
|
||||||
|
}
|
||||||
|
|
||||||
/// Temporarily block a raised exception.
|
/// Temporarily block a raised exception.
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -1640,7 +1640,12 @@ pgf_readPGF(PyObject *self, PyObject *args)
|
|||||||
// Read the PGF grammar.
|
// Read the PGF grammar.
|
||||||
py_pgf->pgf = pgf_read(fpath, py_pgf->pool, err);
|
py_pgf->pgf = pgf_read(fpath, py_pgf->pool, err);
|
||||||
if (!gu_ok(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);
|
Py_DECREF(py_pgf);
|
||||||
gu_pool_free(tmp_pool);
|
gu_pool_free(tmp_pool);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user