mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
Fix some crashes
```
import types
types.LazyImportType({}, "3", 0)
```
```
def f():
exec("lazy import json")
f()
```
This commit is contained in:
parent
a05b50dbca
commit
ac80f2d978
3 changed files with 73 additions and 3 deletions
|
|
@ -4358,7 +4358,12 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
|
|||
|
||||
PyInterpreterState *interp = tstate->interp;
|
||||
_PyInterpreterFrame *frame = _PyEval_GetFrame();
|
||||
assert(frame != NULL && frame->f_globals == frame->f_locals); // should only be called in global scope
|
||||
if (frame == NULL || frame->f_globals != frame->f_locals) {
|
||||
Py_DECREF(abs_name);
|
||||
PyErr_SetString(PyExc_SyntaxError,
|
||||
"'lazy import' is only allowed at module level");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Check if the filter disables the lazy import.
|
||||
// We must hold a reference to the filter while calling it to prevent
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue