|
3 | 3 | #include "Python.h" |
4 | 4 | #include "pycore_audit.h" // _PySys_Audit() |
5 | 5 | #include "pycore_ceval.h" |
| 6 | +#include "pycore_dict.h" // _PyDict_Contains_KnownHash() |
6 | 7 | #include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION() |
7 | 8 | #include "pycore_hashtable.h" // _Py_hashtable_new_full() |
8 | 9 | #include "pycore_import.h" // _PyImport_BootstrapImp() |
@@ -3822,7 +3823,8 @@ _PyImport_LoadLazyImportTstate(PyThreadState *tstate, PyObject *lazy_import) |
3822 | 3823 | } |
3823 | 3824 | } |
3824 | 3825 |
|
3825 | | - int is_loading = PySet_Contains(importing, lazy_import); |
| 3826 | + assert(PyAnySet_CheckExact(importing)); |
| 3827 | + int is_loading = _PySet_Contains((PySetObject *)importing, lazy_import); |
3826 | 3828 | if (is_loading < 0) { |
3827 | 3829 | _PyImport_ReleaseLock(interp); |
3828 | 3830 | return NULL; |
@@ -4215,7 +4217,7 @@ static PyObject * |
4215 | 4217 | get_mod_dict(PyObject *module) |
4216 | 4218 | { |
4217 | 4219 | if (PyModule_Check(module)) { |
4218 | | - return Py_XNewRef(PyModule_GetDict(module)); |
| 4220 | + return Py_NewRef(_PyModule_GetDict(module)); |
4219 | 4221 | } |
4220 | 4222 |
|
4221 | 4223 | return PyObject_GetAttr(module, &_Py_ID(__dict__)); |
@@ -4291,6 +4293,7 @@ register_lazy_on_parent(PyThreadState *tstate, PyObject *name, PyObject *builtin |
4291 | 4293 | goto done; |
4292 | 4294 | } |
4293 | 4295 | } |
| 4296 | + assert(PyAnySet_CheckExact(lazy_submodules)); |
4294 | 4297 | if (PySet_Add(lazy_submodules, child) < 0) { |
4295 | 4298 | Py_DECREF(lazy_submodules); |
4296 | 4299 | goto done; |
@@ -4387,6 +4390,7 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate, |
4387 | 4390 | // Add the module name to sys.lazy_modules set (PEP 810) |
4388 | 4391 | PyObject *lazy_modules_set = interp->imports.lazy_modules_set; |
4389 | 4392 | if (lazy_modules_set != NULL) { |
| 4393 | + assert(PyAnySet_CheckExact(lazy_modules_set)); |
4390 | 4394 | if (PySet_Add(lazy_modules_set, abs_name) < 0) { |
4391 | 4395 | Py_DECREF(res); |
4392 | 4396 | Py_DECREF(abs_name); |
@@ -5418,11 +5422,12 @@ _imp__set_lazy_attributes_impl(PyObject *module, PyObject *child_module, |
5418 | 5422 | if (child_dict == NULL || !PyDict_CheckExact(child_dict)) { |
5419 | 5423 | goto done; |
5420 | 5424 | } |
| 5425 | + assert(PyAnySet_CheckExact(lazy_submodules)); |
5421 | 5426 | PyObject *attr_name; |
5422 | 5427 | Py_ssize_t pos = 0; |
5423 | 5428 | Py_hash_t hash; |
5424 | 5429 | while (_PySet_NextEntry(lazy_submodules, &pos, &attr_name, &hash)) { |
5425 | | - if (PyDict_Contains(child_dict, attr_name)) { |
| 5430 | + if (_PyDict_Contains_KnownHash(child_dict, attr_name, hash)) { |
5426 | 5431 | continue; |
5427 | 5432 | } |
5428 | 5433 | PyObject *builtins = _PyEval_GetBuiltins(tstate); |
|
0 commit comments