mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-22 19:22:50 -06:00
PGF.embed can now augment existing modules
This commit is contained in:
@@ -399,9 +399,26 @@ pgf_embed_funs(PgfItor* fn, PgfText* name, object value, PgfExn* err)
|
|||||||
static PyObject*
|
static PyObject*
|
||||||
PGF_embed(PGFObject* self, PyObject *modname)
|
PGF_embed(PGFObject* self, PyObject *modname)
|
||||||
{
|
{
|
||||||
PyObject *m = PyImport_AddModuleObject(modname);
|
PyObject *m = PyImport_Import(modname);
|
||||||
if (m == NULL)
|
if (m == NULL) {
|
||||||
return NULL;
|
PyObject *globals = PyEval_GetGlobals();
|
||||||
|
if (globals != NULL) {
|
||||||
|
PyObject *exc = PyDict_GetItemString(globals, "ModuleNotFoundError");
|
||||||
|
if (exc != NULL) {
|
||||||
|
if (PyErr_ExceptionMatches(exc)) {
|
||||||
|
PyErr_Clear();
|
||||||
|
m = PyImport_AddModuleObject(modname);
|
||||||
|
Py_INCREF(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (m == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (PyModule_AddObjectRef(m, "__pgf__", (PyObject*) self) != 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
PgfExn err;
|
PgfExn err;
|
||||||
PyPGFClosure clo = { { pgf_embed_funs }, self, m };
|
PyPGFClosure clo = { { pgf_embed_funs }, self, m };
|
||||||
@@ -411,7 +428,6 @@ PGF_embed(PGFObject* self, PyObject *modname)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(m);
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user