Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Address Mark's reviews
Co-Authored-By: Mark Shannon <mark@hotpy.org>
  • Loading branch information
Fidget-Spinner and markshannon committed Jan 24, 2022
commit d905928e87898fca711e286b454d27f2a499003b
18 changes: 9 additions & 9 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2121,11 +2121,6 @@ def clear_ignored_deprecations(*tokens: object) -> None:
warnings._filters_mutated()


# This number should be CPython internal "hot" (C macro QUICKENING_WARMUP_DELAY)
# count + 1.
CPYTHON_WARMUP_COUNT = 8+1


def repeat_cpython_adaptative(f):
"""Runs a test multiple times. First with PEP 659 adaptive opcodes, then
with specialized opcodes once the opcodes turn "hot". This catches bugs
Expand All @@ -2134,12 +2129,17 @@ def repeat_cpython_adaptative(f):
See bpo-46465 for an example bug affecting only specialized opcodes,
due to a missing CHECK_EVAL_BREAKER.
"""
if check_impl_detail(cpython=True):
# _co_warmedup is only available in CPython
if check_impl_detail(cpython=True) and hasattr(f.__code__, "_co_warmedup"):
@functools.wraps(f)
def wrapper(self):
for i in range(CPYTHON_WARMUP_COUNT):
with self.subTest(cpython_warmup_iter=i):
return f(self)
done = False
while not done:
is_warmedup = f.__code__._co_warmedup
if is_warmedup:
done = True
with self.subTest(cpython_is_warmedup=is_warmedup):
f(self)
return wrapper
else:
return f
12 changes: 12 additions & 0 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1542,13 +1542,25 @@ code_getfreevars(PyCodeObject *code, void *closure)
return _PyCode_GetFreevars(code);
}

static PyObject *
code_iswarmedup(PyCodeObject *code, void *closure)
{
if (code->co_quickened != NULL) {
Py_RETURN_TRUE;
}
else {
Py_RETURN_FALSE;
}
}

static PyGetSetDef code_getsetlist[] = {
{"co_lnotab", (getter)code_getlnotab, NULL, NULL},
// The following old names are kept for backward compatibility.
{"co_nlocals", (getter)code_getnlocals, NULL, NULL},
{"co_varnames", (getter)code_getvarnames, NULL, NULL},
{"co_cellvars", (getter)code_getcellvars, NULL, NULL},
{"co_freevars", (getter)code_getfreevars, NULL, NULL},
{"_co_warmedup", (getter)code_iswarmedup, NULL, NULL},
{0}
};

Expand Down
3 changes: 0 additions & 3 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -4731,7 +4731,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
Py_DECREF(callable);
Py_DECREF(obj);
SET_TOP(res);
CHECK_EVAL_BREAKER();
DISPATCH();
}

Expand Down Expand Up @@ -4855,7 +4854,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
if (res == NULL) {
goto error;
}
CHECK_EVAL_BREAKER();
DISPATCH();
}

Expand Down Expand Up @@ -4912,7 +4910,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
STACK_SHRINK(2);
SET_TOP(Py_None);
Py_DECREF(callable);
CHECK_EVAL_BREAKER();
DISPATCH();
}

Expand Down