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
|
|
@ -18,10 +18,14 @@ _PyLazyImport_New(PyObject *builtins, PyObject *from, PyObject *attr)
|
|||
PyErr_BadArgument();
|
||||
return NULL;
|
||||
}
|
||||
if (attr == Py_None) {
|
||||
if (attr == Py_None || attr == NULL) {
|
||||
attr = NULL;
|
||||
}
|
||||
assert(!attr || PyObject_IsTrue(attr));
|
||||
else if (!PyUnicode_Check(attr) && !PyTuple_Check(attr)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"lazy_import: fromlist must be None, a string, or a tuple");
|
||||
return NULL;
|
||||
}
|
||||
m = PyObject_GC_New(PyLazyImportObject, &PyLazyImport_Type);
|
||||
if (m == NULL) {
|
||||
return NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue