Skip to content

Commit 0c1f2e6

Browse files
Merge remote-tracking branch 'upstream/main' into tidy-jit-invariants
2 parents 89b084b + e0fb278 commit 0c1f2e6

26 files changed

+247
-157
lines changed

Doc/c-api/apiabiversion.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ See :ref:`stable` for a discussion of API and ABI stability across versions.
3434
This can be ``0xA`` for alpha, ``0xB`` for beta, ``0xC`` for release
3535
candidate or ``0xF`` for final.
3636

37+
38+
.. c:namespace:: NULL
39+
.. c:macro:: PY_RELEASE_LEVEL_ALPHA
40+
:no-typesetting:
41+
.. c:macro:: PY_RELEASE_LEVEL_BETA
42+
:no-typesetting:
43+
.. c:macro:: PY_RELEASE_LEVEL_GAMMA
44+
:no-typesetting:
45+
.. c:macro:: PY_RELEASE_LEVEL_FINAL
46+
:no-typesetting:
47+
48+
For completeness, the values are available as macros:
49+
:c:macro:`!PY_RELEASE_LEVEL_ALPHA` (``0xA``),
50+
:c:macro:`!PY_RELEASE_LEVEL_BETA` (``0xB``),
51+
:c:macro:`!PY_RELEASE_LEVEL_GAMMA` (``0xC``), and
52+
:c:macro:`!PY_RELEASE_LEVEL_FINAL` (``0xF``).
53+
3754
.. c:macro:: PY_RELEASE_SERIAL
3855
3956
The ``2`` in ``3.4.1a2``. Zero for final releases.
@@ -46,6 +63,10 @@ See :ref:`stable` for a discussion of API and ABI stability across versions.
4663
Use this for numeric comparisons, for example,
4764
``#if PY_VERSION_HEX >= ...``.
4865

66+
.. c:macro:: PY_VERSION
67+
68+
The Python version as a string, for example, ``"3.4.1a2"``.
69+
4970

5071
Run-time version
5172
----------------

Doc/c-api/module.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,15 +820,18 @@ struct:
820820
.. versionadded:: 3.5
821821
822822
.. c:macro:: PYTHON_API_VERSION
823+
PYTHON_API_STRING
823824
824-
The C API version. Defined for backwards compatibility.
825+
The C API version, as an integer (``1013``) and string (``"1013"``), respectively.
826+
Defined for backwards compatibility.
825827
826828
Currently, this constant is not updated in new Python versions, and is not
827829
useful for versioning. This may change in the future.
828830
829831
.. c:macro:: PYTHON_ABI_VERSION
832+
PYTHON_ABI_STRING
830833
831-
Defined as ``3`` for backwards compatibility.
834+
Defined as ``3`` and ``"3"``, respectively, for backwards compatibility.
832835
833836
Currently, this constant is not updated in new Python versions, and is not
834837
useful for versioning. This may change in the future.

Include/internal/pycore_optimizer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ _PyJit_TryInitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame,
234234
int oparg);
235235

236236
void _PyJit_ResetTracing(PyThreadState *tstate);
237+
void _PyJit_TracerFree(_PyThreadStateImpl *_tstate);
237238

238239
void _PyJit_Tracer_InvalidateDependency(PyThreadState *old_tstate, void *obj);
239240

Include/internal/pycore_optimizer_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ extern "C" {
1010

1111
#include "pycore_uop.h" // UOP_MAX_TRACE_LENGTH
1212

13-
// Holds locals, stack, locals, stack ... co_consts (in that order)
14-
#define MAX_ABSTRACT_INTERP_SIZE 4096
13+
// Holds locals, stack, locals, stack ... (in that order)
14+
#define MAX_ABSTRACT_INTERP_SIZE 512
1515

1616
#define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * 5)
1717

Include/internal/pycore_tstate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ typedef struct _PyThreadStateImpl {
154154
Py_ssize_t reftotal; // this thread's total refcount operations
155155
#endif
156156
#if _Py_TIER2
157-
_PyJitTracerState jit_tracer_state;
157+
_PyJitTracerState *jit_tracer_state;
158158
#endif
159159
_PyPolicy policy;
160160
} _PyThreadStateImpl;

Lib/test/pickletester.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,6 +2438,7 @@ def test_reduce_None(self):
24382438
with self.assertRaises(TypeError):
24392439
self.dumps(c)
24402440

2441+
@support.skip_if_unlimited_stack_size
24412442
@no_tracing
24422443
def test_bad_getattr(self):
24432444
# Issue #3514: crash when there is an infinite loop in __getattr__

Lib/test/support/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"check__all__", "skip_if_buggy_ucrt_strfptime",
4646
"check_disallow_instantiation", "check_sanitizer", "skip_if_sanitizer",
4747
"requires_limited_api", "requires_specialization", "thread_unsafe",
48+
"skip_if_unlimited_stack_size",
4849
# sys
4950
"MS_WINDOWS", "is_jython", "is_android", "is_emscripten", "is_wasi",
5051
"is_apple_mobile", "check_impl_detail", "unix_shell", "setswitchinterval",
@@ -1771,6 +1772,25 @@ def skip_if_pgo_task(test):
17711772
return test if ok else unittest.skip(msg)(test)
17721773

17731774

1775+
def skip_if_unlimited_stack_size(test):
1776+
"""Skip decorator for tests not run when an unlimited stack size is configured.
1777+
1778+
Tests using support.infinite_recursion([...]) may otherwise run into
1779+
an infinite loop, running until the memory on the system is filled and
1780+
crashing due to OOM.
1781+
1782+
See https://github.com/python/cpython/issues/143460.
1783+
"""
1784+
if is_wasi or os.name == "nt":
1785+
return test
1786+
1787+
import resource
1788+
curlim, maxlim = resource.getrlimit(resource.RLIMIT_STACK)
1789+
unlimited_stack_size_cond = curlim == maxlim and curlim in (-1, 0xFFFF_FFFF_FFFF_FFFF)
1790+
reason = "Not run due to unlimited stack size"
1791+
return unittest.skipIf(unlimited_stack_size_cond, reason)(test)
1792+
1793+
17741794
def detect_api_mismatch(ref_api, other_api, *, ignore=()):
17751795
"""Returns the set of items in ref_api not in other_api, except for a
17761796
defined list of items to be ignored in this check.

Lib/test/test_ast/test_ast.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from test import support
2727
from test.support import os_helper
28-
from test.support import skip_emscripten_stack_overflow, skip_wasi_stack_overflow
28+
from test.support import skip_emscripten_stack_overflow, skip_wasi_stack_overflow, skip_if_unlimited_stack_size
2929
from test.support.ast_helper import ASTTestMixin
3030
from test.support.import_helper import ensure_lazy_imports
3131
from test.test_ast.utils import to_tuple
@@ -989,6 +989,7 @@ def next(self):
989989
enum._test_simple_enum(_Precedence, _ast_unparse._Precedence)
990990

991991
@support.cpython_only
992+
@skip_if_unlimited_stack_size
992993
@skip_wasi_stack_overflow()
993994
@skip_emscripten_stack_overflow()
994995
def test_ast_recursion_limit(self):
@@ -1127,6 +1128,7 @@ def test_pickling(self):
11271128
ast2 = pickle.loads(pickle.dumps(tree, protocol))
11281129
self.assertEqual(to_tuple(ast2), to_tuple(tree))
11291130

1131+
@skip_if_unlimited_stack_size
11301132
def test_copy_with_parents(self):
11311133
# gh-120108
11321134
code = """
@@ -1974,6 +1976,7 @@ def test_level_as_none(self):
19741976
exec(code, ns)
19751977
self.assertIn('sleep', ns)
19761978

1979+
@skip_if_unlimited_stack_size
19771980
@skip_emscripten_stack_overflow()
19781981
def test_recursion_direct(self):
19791982
e = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0, operand=ast.Constant(1))
@@ -1982,6 +1985,7 @@ def test_recursion_direct(self):
19821985
with support.infinite_recursion():
19831986
compile(ast.Expression(e), "<test>", "eval")
19841987

1988+
@skip_if_unlimited_stack_size
19851989
@skip_emscripten_stack_overflow()
19861990
def test_recursion_indirect(self):
19871991
e = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0, operand=ast.Constant(1))

Lib/test/test_float.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,24 @@ class F(float, H):
651651
value = F('nan')
652652
self.assertEqual(hash(value), object.__hash__(value))
653653

654+
def test_issue_gh143006(self):
655+
# When comparing negative non-integer float and int with the
656+
# same number of bits in the integer part, __neg__() in the
657+
# int subclass returning not an int caused an assertion error.
658+
class EvilInt(int):
659+
def __neg__(self):
660+
return ""
661+
662+
i = -1 << 50
663+
f = float(i) - 0.5
664+
i = EvilInt(i)
665+
self.assertFalse(f == i)
666+
self.assertTrue(f != i)
667+
self.assertTrue(f < i)
668+
self.assertTrue(f <= i)
669+
self.assertFalse(f > i)
670+
self.assertFalse(f >= i)
671+
654672

655673
@unittest.skipUnless(hasattr(float, "__getformat__"), "requires __getformat__")
656674
class FormatFunctionsTestCase(unittest.TestCase):

Lib/test/test_functools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ def test_setstate_subclasses(self):
438438
self.assertIs(type(r[0]), tuple)
439439

440440
@support.skip_if_sanitizer("thread sanitizer crashes in __tsan::FuncEntry", thread=True)
441+
@support.skip_if_unlimited_stack_size
441442
@support.skip_emscripten_stack_overflow()
442443
def test_recursive_pickle(self):
443444
with replaced_module('functools', self.module):
@@ -2139,6 +2140,7 @@ def orig(a: int) -> nonexistent: ...
21392140
@support.skip_on_s390x
21402141
@unittest.skipIf(support.is_wasi, "WASI has limited C stack")
21412142
@support.skip_if_sanitizer("requires deep stack", ub=True, thread=True)
2143+
@support.skip_if_unlimited_stack_size
21422144
@support.skip_emscripten_stack_overflow()
21432145
def test_lru_recursion(self):
21442146

0 commit comments

Comments
 (0)