Skip to content

Commit c25d9e1

Browse files
Always load the missing module in XI data situations.
1 parent 293a4dc commit c25d9e1

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

Modules/_interpchannelsmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ _get_current_module_state(void)
254254
{
255255
PyObject *mod = _get_current_module();
256256
if (mod == NULL) {
257-
// XXX import it?
258-
PyErr_SetString(PyExc_RuntimeError,
259-
MODULE_NAME_STR " module not imported yet");
260-
return NULL;
257+
mod = PyImport_ImportModule(MODULE_NAME_STR);
258+
if (mod == NULL) {
259+
return NULL;
260+
}
261261
}
262262
module_state *state = get_module_state(mod);
263263
Py_DECREF(mod);

Modules/_interpqueuesmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,10 +1356,10 @@ _queueobj_from_xid(_PyXIData_t *data)
13561356

13571357
PyObject *mod = _get_current_module();
13581358
if (mod == NULL) {
1359-
// XXX import it?
1360-
PyErr_SetString(PyExc_RuntimeError,
1361-
MODULE_NAME_STR " module not imported yet");
1362-
return NULL;
1359+
mod = PyImport_ImportModule(MODULE_NAME_STR);
1360+
if (mod == NULL) {
1361+
return NULL;
1362+
}
13631363
}
13641364

13651365
PyTypeObject *cls = get_external_queue_type(mod);

Modules/_interpretersmodule.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,10 @@ get_module_state(PyObject *mod)
316316
}
317317

318318
static module_state *
319-
_get_current_module_state(int force)
319+
_get_current_module_state(void)
320320
{
321321
PyObject *mod = _get_current_module();
322322
if (mod == NULL) {
323-
if (!force) {
324-
PyErr_SetString(PyExc_RuntimeError,
325-
MODULE_NAME_STR " module not imported yet");
326-
return NULL;
327-
}
328323
mod = PyImport_ImportModule(MODULE_NAME_STR);
329324
if (mod == NULL) {
330325
return NULL;
@@ -357,8 +352,7 @@ clear_module_state(module_state *state)
357352
static PyTypeObject *
358353
_get_current_xibufferview_type(void)
359354
{
360-
int force = 1;
361-
module_state *state = _get_current_module_state(force);
355+
module_state *state = _get_current_module_state();
362356
if (state == NULL) {
363357
return NULL;
364358
}

Python/import.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3964,8 +3964,10 @@ PyImport_Import(PyObject *module_name)
39643964
if (globals != NULL) {
39653965
Py_INCREF(globals);
39663966
builtins = PyObject_GetItem(globals, &_Py_ID(__builtins__));
3967-
if (builtins == NULL)
3967+
if (builtins == NULL) {
3968+
// XXX Fall back to interp->builtins or sys.modules['builtins']?
39683969
goto err;
3970+
}
39693971
}
39703972
else {
39713973
/* No globals -- use standard builtins, and fake globals */

0 commit comments

Comments
 (0)