Skip to content

Commit 716f4dc

Browse files
authored
Merge branch 'main' into test_embed
2 parents ad09d0b + a679366 commit 716f4dc

16 files changed

Lines changed: 98 additions & 97 deletions

File tree

Include/internal/pycore_ceval.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,16 @@ extern void _PyEval_DeactivateOpCache(void);
208208

209209
/* --- _Py_EnterRecursiveCall() ----------------------------------------- */
210210

211-
static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
211+
static inline int _Py_ReachedRecursionLimit(PyThreadState *tstate) {
212212
uintptr_t here_addr = _Py_get_machine_stack_pointer();
213213
_PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate;
214-
// Overflow if stack pointer is between soft limit and the base of the hardware stack.
215-
// If it is below the hardware stack base, assume that we have the wrong stack limits, and do nothing.
216-
// We could have the wrong stack limits because of limited platform support, or user-space threads.
214+
// Possible overflow if stack pointer is beyond the soft limit.
215+
// _Py_CheckRecursiveCall will check for corner cases and
216+
// report an error if there is an overflow.
217217
#if _Py_STACK_GROWS_DOWN
218-
return here_addr < _tstate->c_stack_soft_limit && here_addr >= _tstate->c_stack_soft_limit - 2 * _PyOS_STACK_MARGIN_BYTES;
218+
return here_addr < _tstate->c_stack_soft_limit;
219219
#else
220-
return here_addr > _tstate->c_stack_soft_limit && here_addr <= _tstate->c_stack_soft_limit + 2 * _PyOS_STACK_MARGIN_BYTES;
220+
return here_addr > _tstate->c_stack_soft_limit;
221221
#endif
222222
}
223223

@@ -232,7 +232,7 @@ PyAPI_FUNC(int) _Py_CheckRecursiveCallPy(
232232

233233
static inline int _Py_EnterRecursiveCallTstate(PyThreadState *tstate,
234234
const char *where) {
235-
return (_Py_MakeRecCheck(tstate) && _Py_CheckRecursiveCall(tstate, where));
235+
return (_Py_ReachedRecursionLimit(tstate) && _Py_CheckRecursiveCall(tstate, where));
236236
}
237237

238238
static inline int _Py_EnterRecursiveCall(const char *where) {
@@ -246,8 +246,6 @@ static inline void _Py_LeaveRecursiveCallTstate(PyThreadState *tstate) {
246246

247247
PyAPI_FUNC(void) _Py_InitializeRecursionLimits(PyThreadState *tstate);
248248

249-
PyAPI_FUNC(int) _Py_ReachedRecursionLimit(PyThreadState *tstate);
250-
251249
// Export for test_peg_generator
252250
PyAPI_FUNC(int) _Py_ReachedRecursionLimitWithMargin(
253251
PyThreadState *tstate,

Include/internal/pycore_pystate.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,20 @@ static uintptr_t return_pointer_as_int(char* p) {
316316

317317
static inline uintptr_t
318318
_Py_get_machine_stack_pointer(void) {
319-
#if _Py__has_builtin(__builtin_frame_address) || defined(__GNUC__)
320-
return (uintptr_t)__builtin_frame_address(0);
321-
#elif defined(_MSC_VER)
322-
return (uintptr_t)_AddressOfReturnAddress();
319+
uintptr_t result;
320+
#if defined(_M_ARM64)
321+
result = __getReg(31);
322+
#elif defined(_M_X64) || defined(_M_IX86)
323+
result = (uintptr_t)_AddressOfReturnAddress();
324+
#elif defined(__aarch64__)
325+
__asm__ ("mov %0, sp" : "=r" (result));
326+
#elif defined(__x86_64__)
327+
__asm__("{movq %%rsp, %0" : "=r" (result));
323328
#else
324329
char here;
325-
/* Avoid compiler warning about returning stack address */
326-
return return_pointer_as_int(&here);
330+
result = (uintptr_t)&here;
327331
#endif
332+
return result;
328333
}
329334

330335
static inline intptr_t

Include/internal/pycore_pythonrun.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ extern PyObject * _Py_CompileStringObjectWithModule(
4646
* stack consumption of PyEval_EvalDefault */
4747
#if (defined(Py_DEBUG) \
4848
|| defined(_Py_ADDRESS_SANITIZER) \
49-
|| defined(_Py_THREAD_SANITIZER))
49+
|| defined(_Py_THREAD_SANITIZER)) \
50+
|| defined(_Py_UNDEFINED_BEHAVIOR_SANITIZER)
5051
# define _PyOS_LOG2_STACK_MARGIN 12
5152
#else
5253
# define _PyOS_LOG2_STACK_MARGIN 11

Lib/test/_test_multiprocessing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6310,6 +6310,8 @@ def test_resource_tracker_sigint(self):
63106310
# Catchable signal (ignored by semaphore tracker)
63116311
self.check_resource_tracker_death(signal.SIGINT, False)
63126312

6313+
@unittest.skipUnless(hasattr(signal, 'pthread_sigmask'),
6314+
'need signal.pthread_sigmask')
63136315
def test_resource_tracker_sigterm(self):
63146316
# Catchable signal (ignored by semaphore tracker)
63156317
self.check_resource_tracker_death(signal.SIGTERM, False)

Lib/test/support/__init__.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,6 @@ def requires(resource, msg=None):
324324
if resource == 'gui' and not _is_gui_available():
325325
raise ResourceDenied(_is_gui_available.reason)
326326

327-
def _get_kernel_version(sysname="Linux"):
328-
import platform
329-
if platform.system() != sysname:
330-
return None
331-
version_txt = platform.release().split('-', 1)[0]
332-
try:
333-
return tuple(map(int, version_txt.split('.')))
334-
except ValueError:
335-
return None
336-
337327
def _requires_unix_version(sysname, min_version):
338328
"""Decorator raising SkipTest if the OS is `sysname` and the version is less
339329
than `min_version`.
@@ -2806,6 +2796,10 @@ def exceeds_recursion_limit():
28062796
is_s390x = hasattr(os, 'uname') and os.uname().machine == 's390x'
28072797
skip_on_s390x = unittest.skipIf(is_s390x, 'skipped on s390x')
28082798

2799+
# Cygwin uses the newlib C library
2800+
skip_on_newlib = unittest.skipIf(sys.platform == 'cygwin',
2801+
'the test fails on newlib C library')
2802+
28092803
Py_TRACE_REFS = hasattr(sys, 'getobjects')
28102804

28112805
_JIT_ENABLED = sys._jit.is_enabled()

Lib/test/test_math.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ def testHypot(self):
922922
@requires_IEEE_754
923923
@unittest.skipIf(HAVE_DOUBLE_ROUNDING,
924924
"hypot() loses accuracy on machines with double rounding")
925+
@support.skip_on_newlib
925926
def testHypotAccuracy(self):
926927
# Verify improved accuracy in cases that were known to be inaccurate.
927928
#
@@ -1253,12 +1254,6 @@ def testLog2(self):
12531254
self.assertEqual(math.log2(4), 2.0)
12541255
self.assertEqual(math.log2(MyIndexable(4)), 2.0)
12551256

1256-
# Large integer values
1257-
self.assertEqual(math.log2(2**1023), 1023.0)
1258-
self.assertEqual(math.log2(2**1024), 1024.0)
1259-
self.assertEqual(math.log2(2**2000), 2000.0)
1260-
self.assertEqual(math.log2(MyIndexable(2**2000)), 2000.0)
1261-
12621257
self.assertRaises(ValueError, math.log2, 0.0)
12631258
self.assertRaises(ValueError, math.log2, 0)
12641259
self.assertRaises(ValueError, math.log2, MyIndexable(0))
@@ -1276,12 +1271,19 @@ def testLog2(self):
12761271
@requires_IEEE_754
12771272
# log2() is not accurate enough on Mac OS X Tiger (10.4)
12781273
@support.requires_mac_ver(10, 5)
1274+
@support.skip_on_newlib
12791275
def testLog2Exact(self):
12801276
# Check that we get exact equality for log2 of powers of 2.
12811277
actual = [math.log2(math.ldexp(1.0, n)) for n in range(-1074, 1024)]
12821278
expected = [float(n) for n in range(-1074, 1024)]
12831279
self.assertEqual(actual, expected)
12841280

1281+
# Large integer values
1282+
self.assertEqual(math.log2(2**1023), 1023.0)
1283+
self.assertEqual(math.log2(2**1024), 1024.0)
1284+
self.assertEqual(math.log2(2**2000), 2000.0)
1285+
self.assertEqual(math.log2(MyIndexable(2**2000)), 2000.0)
1286+
12851287
def testLog10(self):
12861288
self.assertRaises(TypeError, math.log10)
12871289
self.ftest('log10(0.1)', math.log10(0.1), -1)
@@ -2615,6 +2617,7 @@ def test_fma_nan_results(self):
26152617
self.assertIsNaN(math.fma(a, math.nan, b))
26162618
self.assertIsNaN(math.fma(a, b, math.nan))
26172619

2620+
@support.skip_on_newlib
26182621
def test_fma_infinities(self):
26192622
# Cases involving infinite inputs or results.
26202623
positives = [1e-300, 2.3, 1e300, math.inf]
@@ -2685,7 +2688,7 @@ def test_fma_infinities(self):
26852688
# gh-73468: On some platforms, libc fma() doesn't implement IEE 754-2008
26862689
# properly: it doesn't use the right sign when the result is zero.
26872690
@unittest.skipIf(
2688-
sys.platform.startswith(("freebsd", "wasi", "netbsd", "emscripten"))
2691+
sys.platform.startswith(("freebsd", "wasi", "netbsd", "emscripten", "cygwin"))
26892692
or (sys.platform == "android" and platform.machine() == "x86_64")
26902693
or support.linked_to_musl(), # gh-131032
26912694
f"this platform doesn't implement IEE 754-2008 properly")
@@ -2743,6 +2746,7 @@ def test_fma_zero_result(self):
27432746
self.assertIsNegativeZero(math.fma(y-x, -(x+y), -z))
27442747
self.assertIsPositiveZero(math.fma(x-y, -(x+y), z))
27452748

2749+
@support.skip_on_newlib
27462750
def test_fma_overflow(self):
27472751
a = b = float.fromhex('0x1p512')
27482752
c = float.fromhex('0x1p1023')
@@ -2776,11 +2780,13 @@ def test_fma_overflow(self):
27762780
c = float.fromhex('0x1.fffffffffffffp+1023')
27772781
self.assertEqual(math.fma(a, b, -c), c)
27782782

2783+
@support.skip_on_newlib
27792784
def test_fma_single_round(self):
27802785
a = float.fromhex('0x1p-50')
27812786
self.assertEqual(math.fma(a - 1.0, a + 1.0, 1.0), a*a)
27822787

2783-
def test_random(self):
2788+
@support.skip_on_newlib
2789+
def test_fma_random(self):
27842790
# A collection of randomly generated inputs for which the naive FMA
27852791
# (with two rounds) gives a different result from a singly-rounded FMA.
27862792

Lib/test/test_pyexpat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ def test_trigger_leak(self):
861861
def test_deeply_nested_content_model(self):
862862
# This should raise a RecursionError and not crash.
863863
# See https://github.com/python/cpython/issues/145986.
864-
N = 500_000
864+
N = 800_000
865865
data = (
866866
b'<!DOCTYPE root [\n<!ELEMENT root '
867867
+ b'(a, ' * N + b'a' + b')' * N

Lib/test/test_socket.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7191,12 +7191,6 @@ def test_aes_cbc(self):
71917191

71927192
@support.requires_linux_version(4, 9) # see gh-73510
71937193
def test_aead_aes_gcm(self):
7194-
kernel_version = support._get_kernel_version("Linux")
7195-
if kernel_version is not None:
7196-
if kernel_version >= (6, 16) and kernel_version < (6, 18):
7197-
# See https://github.com/python/cpython/issues/139310.
7198-
self.skipTest("upstream Linux kernel issue")
7199-
72007194
key = bytes.fromhex('c939cc13397c1d37de6ae0e1cb7c423c')
72017195
iv = bytes.fromhex('b3d8cc017cbb89b39e0f67e2')
72027196
plain = bytes.fromhex('c3b3c41f113a31b73d9a5cd432103069')

Lib/test/test_statistics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import sys
1717
import unittest
1818
from test import support
19-
from test.support import import_helper, requires_IEEE_754
19+
from test.support import import_helper, requires_IEEE_754, skip_on_newlib
2020

2121
from decimal import Decimal
2222
from fractions import Fraction
@@ -2799,6 +2799,7 @@ def test_sqrtprod_helper_function_fundamentals(self):
27992799
@unittest.skipIf(HAVE_DOUBLE_ROUNDING,
28002800
"accuracy not guaranteed on machines with double rounding")
28012801
@support.cpython_only # Allow for a weaker sumprod() implementation
2802+
@skip_on_newlib
28022803
def test_sqrtprod_helper_function_improved_accuracy(self):
28032804
# Test a known example where accuracy is improved
28042805
x, y, target = 0.8035720646477457, 0.7957468097636939, 0.7996498651651661

Lib/test/test_strptime.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
else:
2020
glibc_ver = None
2121

22+
def skip_cygwin_locale():
23+
if sys.platform != 'cygwin':
24+
return
25+
loc = locale.getlocale(locale.LC_TIME)[0]
26+
if loc in ('my_MM', 'or_IN'):
27+
raise unittest.SkipTest('test fails on Cygwin')
28+
2229

2330
class getlang_Tests(unittest.TestCase):
2431
"""Test _getlang"""
@@ -509,6 +516,8 @@ def test_bad_timezone(self):
509516
'my_MM', 'or_IN', 'shn_MM', 'az_IR',
510517
'byn_ER', 'wal_ET', 'lzh_TW')
511518
def test_date_time_locale(self):
519+
skip_cygwin_locale()
520+
512521
# Test %c directive
513522
loc = locale.getlocale(locale.LC_TIME)[0]
514523
if glibc_ver and glibc_ver < (2, 31) and loc == 'br_FR':
@@ -536,6 +545,8 @@ def test_date_time_locale(self):
536545
'csb_PL', 'br_FR', 'gez_ET', 'brx_IN',
537546
'my_MM', 'shn_MM')
538547
def test_date_time_locale2(self):
548+
skip_cygwin_locale()
549+
539550
# Test %c directive
540551
loc = locale.getlocale(locale.LC_TIME)[0]
541552
if sys.platform.startswith('sunos'):
@@ -550,6 +561,8 @@ def test_date_time_locale2(self):
550561
'he_IL', 'eu_ES', 'ar_AE',
551562
'az_IR', 'my_MM', 'or_IN', 'shn_MM', 'lzh_TW')
552563
def test_date_locale(self):
564+
skip_cygwin_locale()
565+
553566
# Test %x directive
554567
now = time.time()
555568
self.roundtrip('%x', slice(0, 3), time.localtime(now))
@@ -567,6 +580,8 @@ def test_date_locale(self):
567580
@run_with_locales('LC_TIME', 'en_US', 'fr_FR', 'de_DE', 'ja_JP',
568581
'eu_ES', 'ar_AE', 'my_MM', 'shn_MM', 'lzh_TW')
569582
def test_date_locale2(self):
583+
skip_cygwin_locale()
584+
570585
# Test %x directive
571586
loc = locale.getlocale(locale.LC_TIME)[0]
572587
if sys.platform.startswith(('sunos', 'aix')):
@@ -587,6 +602,8 @@ def test_date_locale2(self):
587602
'ti_ET', 'tig_ER', 'wal_ET', 'lzh_TW',
588603
'ar_SA', 'bg_BG')
589604
def test_time_locale(self):
605+
skip_cygwin_locale()
606+
590607
# Test %X directive
591608
loc = locale.getlocale(locale.LC_TIME)[0]
592609
pos = slice(3, 6)

0 commit comments

Comments
 (0)