summaryrefslogtreecommitdiffstats
path: root/Python/specialize.c
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2023-05-12 22:23:13 (GMT)
committerGitHub <noreply@github.com>2023-05-12 22:23:13 (GMT)
commit1eb950ca55b3e0b6524b3f03b0b519723916eca2 (patch)
tree05e29e59c4ba754e255f063eb47e42a9d6f9cce4 /Python/specialize.c
parenta10b026f0fdceac42c4b928917894d77da996555 (diff)
downloadcpython-1eb950ca55b3e0b6524b3f03b0b519723916eca2.zip
cpython-1eb950ca55b3e0b6524b3f03b0b519723916eca2.tar.gz
cpython-1eb950ca55b3e0b6524b3f03b0b519723916eca2.tar.bz2
GH-104405: Add missing PEP 523 checks (GH-104406)
Diffstat (limited to 'Python/specialize.c')
-rw-r--r--Python/specialize.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/Python/specialize.c b/Python/specialize.c
index 5071d8e..f168491 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -783,6 +783,10 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name)
if (version == 0) {
goto fail;
}
+ if (_PyInterpreterState_GET()->eval_frame) {
+ SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_OTHER);
+ goto fail;
+ }
write_u32(lm_cache->keys_version, version);
assert(type->tp_version_tag != 0);
write_u32(lm_cache->type_version, type->tp_version_tag);
@@ -845,6 +849,10 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name)
if (version == 0) {
goto fail;
}
+ if (_PyInterpreterState_GET()->eval_frame) {
+ SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_OTHER);
+ goto fail;
+ }
write_u32(lm_cache->keys_version, version);
/* borrowed */
write_obj(lm_cache->descr, descr);
@@ -1371,6 +1379,10 @@ _Py_Specialize_BinarySubscr(
SPECIALIZATION_FAIL(BINARY_SUBSCR, SPEC_FAIL_OUT_OF_VERSIONS);
goto fail;
}
+ if (_PyInterpreterState_GET()->eval_frame) {
+ SPECIALIZATION_FAIL(BINARY_SUBSCR, SPEC_FAIL_OTHER);
+ goto fail;
+ }
PyHeapTypeObject *ht = (PyHeapTypeObject *)container_type;
// This pointer is invalidated by PyType_Modified (see the comment on
// struct _specialization_cache):
@@ -2192,11 +2204,16 @@ _Py_Specialize_ForIter(PyObject *iter, _Py_CODEUNIT *instr, int oparg)
assert(instr[oparg + INLINE_CACHE_ENTRIES_FOR_ITER + 1].op.code == END_FOR ||
instr[oparg + INLINE_CACHE_ENTRIES_FOR_ITER + 1].op.code == INSTRUMENTED_END_FOR
);
+ if (_PyInterpreterState_GET()->eval_frame) {
+ SPECIALIZATION_FAIL(FOR_ITER, SPEC_FAIL_OTHER);
+ goto failure;
+ }
instr->op.code = FOR_ITER_GEN;
goto success;
}
SPECIALIZATION_FAIL(FOR_ITER,
_PySpecialization_ClassifyIterator(iter));
+failure:
STAT_INC(FOR_ITER, failure);
instr->op.code = FOR_ITER;
cache->counter = adaptive_counter_backoff(cache->counter);
@@ -2214,11 +2231,16 @@ _Py_Specialize_Send(PyObject *receiver, _Py_CODEUNIT *instr)
_PySendCache *cache = (_PySendCache *)(instr + 1);
PyTypeObject *tp = Py_TYPE(receiver);
if (tp == &PyGen_Type || tp == &PyCoro_Type) {
+ if (_PyInterpreterState_GET()->eval_frame) {
+ SPECIALIZATION_FAIL(SEND, SPEC_FAIL_OTHER);
+ goto failure;
+ }
instr->op.code = SEND_GEN;
goto success;
}
SPECIALIZATION_FAIL(SEND,
_PySpecialization_ClassifyIterator(receiver));
+failure:
STAT_INC(SEND, failure);
instr->op.code = SEND;
cache->counter = adaptive_counter_backoff(cache->counter);