Skip to content

Commit 1af4c4c

Browse files
committed
Solve bugs in python loader exception.
1 parent 799acd5 commit 1af4c4c

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

source/loaders/py_loader/source/py_loader_impl.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ value py_loader_impl_capi_to_value(loader_impl impl, PyObject *obj, type_id id)
13781378
{
13791379
PyObject *tb = PyException_GetTraceback(obj);
13801380

1381-
v = py_loader_impl_error_value_from_exception(loader_impl_get(impl), (PyObject *)Py_TYPE(obj), obj, tb);
1381+
v = py_loader_impl_error_value_from_exception(loader_impl_get(impl), (PyObject *)Py_TYPE(obj), obj, tb ? tb : Py_None);
13821382

13831383
Py_XDECREF(tb);
13841384
}
@@ -2908,21 +2908,20 @@ void py_loader_impl_module_destroy(loader_impl_py_handle_module module)
29082908
if (module->name != NULL)
29092909
{
29102910
PyObject *system_modules = PySys_GetObject("modules");
2911-
PyObject *item = PyObject_GetItem(system_modules, module->name);
2912-
2913-
if (item != NULL)
2914-
{
2915-
Py_DECREF(item);
2916-
PyObject_DelItem(system_modules, module->name);
2917-
}
29182911

29192912
// TODO: Sometimes this fails, seems that sys.modules does not contain the item.
29202913
// Probably is because of the new import system which is using importlib, but
29212914
// it does not seem something problematic although it will be interesting
29222915
// to check it out so we are sure there's no leaked memory
2923-
if (PyErr_Occurred() != NULL)
2916+
if (PyObject_HasAttr(system_modules, module->name) == 1)
29242917
{
2925-
PyErr_Clear();
2918+
PyObject *item = PyObject_GetItem(system_modules, module->name);
2919+
2920+
if (item != NULL)
2921+
{
2922+
Py_DECREF(item);
2923+
PyObject_DelItem(system_modules, module->name);
2924+
}
29262925
}
29272926

29282927
Py_DECREF(module->name);

0 commit comments

Comments
 (0)