|
4 | 4 | #include <ctype.h>
|
5 | 5 | #include "pycore_ast.h" // _PyAST_Validate()
|
6 | 6 | #include "pycore_compile.h" // _PyAST_Compile()
|
| 7 | +#include "pycore_code.h" // Hydration |
7 | 8 | #include "pycore_object.h" // _Py_AddToAllObjects()
|
8 | 9 | #include "pycore_pyerrors.h" // _PyErr_NoMemory()
|
9 | 10 | #include "pycore_pystate.h" // _PyThreadState_GET()
|
@@ -967,8 +968,13 @@ builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
|
967 | 968 | if (PySys_Audit("exec", "O", source) < 0) {
|
968 | 969 | return NULL;
|
969 | 970 | }
|
970 |
| - |
971 |
| - if (PyCode_GetNumFree((PyCodeObject *)source) > 0) { |
| 971 | + PyCodeObject *code = (PyCodeObject *)source; |
| 972 | + if (!_PyCode_IsHydrated(code)) { |
| 973 | + if (!_PyCode_Hydrate(code)) { |
| 974 | + return NULL; |
| 975 | + } |
| 976 | + } |
| 977 | + if (PyCode_GetNumFree(code) > 0) { |
972 | 978 | PyErr_SetString(PyExc_TypeError,
|
973 | 979 | "code object passed to eval() may not contain free variables");
|
974 | 980 | return NULL;
|
@@ -1055,8 +1061,13 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
|
1055 | 1061 | if (PySys_Audit("exec", "O", source) < 0) {
|
1056 | 1062 | return NULL;
|
1057 | 1063 | }
|
1058 |
| - |
1059 |
| - if (PyCode_GetNumFree((PyCodeObject *)source) > 0) { |
| 1064 | + PyCodeObject *code = (PyCodeObject *)source; |
| 1065 | + if (!_PyCode_IsHydrated(code)) { |
| 1066 | + if (!_PyCode_Hydrate(code)) { |
| 1067 | + return NULL; |
| 1068 | + } |
| 1069 | + } |
| 1070 | + if (PyCode_GetNumFree(code) > 0) { |
1060 | 1071 | PyErr_SetString(PyExc_TypeError,
|
1061 | 1072 | "code object passed to exec() may not "
|
1062 | 1073 | "contain free variables");
|
|
0 commit comments