Skip to content

Commit 882ada7

Browse files
committed
Duplicate the code instead
1 parent 3c448e8 commit 882ada7

File tree

5 files changed

+146
-101
lines changed

5 files changed

+146
-101
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 38 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/abstract_interp_cases.c.h

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ dummy_func(
12861286
}
12871287
}
12881288

1289-
op(_LOAD_LOCALS, ( -- locals)) {
1289+
inst(LOAD_LOCALS, ( -- locals)) {
12901290
locals = LOCALS();
12911291
if (locals == NULL) {
12921292
_PyErr_SetString(tstate, PyExc_SystemError,
@@ -1296,9 +1296,7 @@ dummy_func(
12961296
Py_INCREF(locals);
12971297
}
12981298

1299-
macro(LOAD_LOCALS) = _LOAD_LOCALS;
1300-
1301-
op(_LOAD_FROM_DICT_OR_GLOBALS, (mod_or_class_dict -- v)) {
1299+
inst(LOAD_FROM_DICT_OR_GLOBALS, (mod_or_class_dict -- v)) {
13021300
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
13031301
if (PyMapping_GetOptionalItem(mod_or_class_dict, name, &v) < 0) {
13041302
goto error;
@@ -1326,9 +1324,38 @@ dummy_func(
13261324
Py_DECREF(mod_or_class_dict);
13271325
}
13281326

1329-
macro(LOAD_NAME) = _LOAD_LOCALS + _LOAD_FROM_DICT_OR_GLOBALS;
1330-
1331-
macro(LOAD_FROM_DICT_OR_GLOBALS) = _LOAD_FROM_DICT_OR_GLOBALS;
1327+
inst(LOAD_NAME, (-- v)) {
1328+
PyObject *mod_or_class_dict = LOCALS();
1329+
if (mod_or_class_dict == NULL) {
1330+
_PyErr_SetString(tstate, PyExc_SystemError,
1331+
"no locals found");
1332+
ERROR_IF(true, error);
1333+
}
1334+
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
1335+
if (PyMapping_GetOptionalItem(mod_or_class_dict, name, &v) < 0) {
1336+
goto error;
1337+
}
1338+
if (v == NULL) {
1339+
v = PyDict_GetItemWithError(GLOBALS(), name);
1340+
if (v != NULL) {
1341+
Py_INCREF(v);
1342+
}
1343+
else if (_PyErr_Occurred(tstate)) {
1344+
goto error;
1345+
}
1346+
else {
1347+
if (PyMapping_GetOptionalItem(BUILTINS(), name, &v) < 0) {
1348+
goto error;
1349+
}
1350+
if (v == NULL) {
1351+
_PyEval_FormatExcCheckArg(
1352+
tstate, PyExc_NameError,
1353+
NAME_ERROR_MSG, name);
1354+
goto error;
1355+
}
1356+
}
1357+
}
1358+
}
13321359

13331360
family(LOAD_GLOBAL, INLINE_CACHE_ENTRIES_LOAD_GLOBAL) = {
13341361
LOAD_GLOBAL_MODULE,

Python/executor_cases.c.h

Lines changed: 39 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 27 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)