.ngf files should have priority when importing a grammar module

This commit is contained in:
Krasimir Angelov
2023-03-24 12:43:05 +01:00
parent 5d205a06e8
commit beef722f2c

View File

@@ -1256,22 +1256,6 @@ GrammarImporter_find_spec(PyTypeObject *class, PyObject *args)
if (dir == NULL)
break;
{
PyObject *py_fpath =
(PyUnicode_GET_LENGTH(dir) == 0) ? PyUnicode_FromFormat("%U.pgf", name)
: PyUnicode_FromFormat("%U/%U.pgf", dir, name);
const char *fpath = PyUnicode_AsUTF8(py_fpath);
if (access(fpath, F_OK) == 0) {
py_importer = (GrammarImporterObject *)class->tp_alloc(class, 0);
py_importer->package_path = get_package_path(dir,name);
py_importer->grammar_path = py_fpath;
py_importer->is_pgf = 1;
Py_DECREF(dir);
break;
}
Py_DECREF(py_fpath);
}
{
PyObject *py_fpath =
(PyUnicode_GET_LENGTH(dir) == 0) ? PyUnicode_FromFormat("%U.ngf", name)
@@ -1288,6 +1272,22 @@ GrammarImporter_find_spec(PyTypeObject *class, PyObject *args)
Py_DECREF(py_fpath);
}
{
PyObject *py_fpath =
(PyUnicode_GET_LENGTH(dir) == 0) ? PyUnicode_FromFormat("%U.pgf", name)
: PyUnicode_FromFormat("%U/%U.pgf", dir, name);
const char *fpath = PyUnicode_AsUTF8(py_fpath);
if (access(fpath, F_OK) == 0) {
py_importer = (GrammarImporterObject *)class->tp_alloc(class, 0);
py_importer->package_path = get_package_path(dir,name);
py_importer->grammar_path = py_fpath;
py_importer->is_pgf = 1;
Py_DECREF(dir);
break;
}
Py_DECREF(py_fpath);
}
Py_DECREF(dir);
}