Skip to content

Commit 59a17a9

Browse files
committed
Update Python inlined files: 3.12.7 (2.4.2)
1 parent 0df1d11 commit 59a17a9

31 files changed

+250
-2076
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef Py_OSDEFS_H
2+
#define Py_OSDEFS_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
8+
/* Operating system dependencies */
9+
10+
#ifdef MS_WINDOWS
11+
#define SEP L'\\'
12+
#define ALTSEP L'/'
13+
#define MAXPATHLEN 256
14+
#define DELIM L';'
15+
#endif
16+
17+
#ifdef __VXWORKS__
18+
#define DELIM L';'
19+
#endif
20+
21+
/* Filename separator */
22+
#ifndef SEP
23+
#define SEP L'/'
24+
#endif
25+
26+
/* Max pathname length */
27+
#ifdef __hpux
28+
#include <sys/param.h>
29+
#include <limits.h>
30+
#ifndef PATH_MAX
31+
#define PATH_MAX MAXPATHLEN
32+
#endif
33+
#endif
34+
35+
#ifndef MAXPATHLEN
36+
#if defined(PATH_MAX) && PATH_MAX > 1024
37+
#define MAXPATHLEN PATH_MAX
38+
#else
39+
#define MAXPATHLEN 1024
40+
#endif
41+
#endif
42+
43+
/* Search path entry delimiter */
44+
#ifndef DELIM
45+
#define DELIM L':'
46+
#endif
47+
48+
#ifdef __cplusplus
49+
}
50+
#endif
51+
#endif /* !Py_OSDEFS_H */

graalpython/lib-python/3/test/support/__init__.py

Lines changed: 156 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
import warnings
1818

1919

20-
try:
21-
from _testcapi import unicode_legacy_string
22-
except ImportError:
23-
unicode_legacy_string = None
24-
2520
__all__ = [
2621
# globals
2722
"PIPE_MAX_SIZE", "verbose", "max_memuse", "use_resources", "failfast",
@@ -507,11 +502,18 @@ def has_no_debug_ranges():
507502
def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
508503
return unittest.skipIf(has_no_debug_ranges(), reason)
509504

510-
requires_legacy_unicode_capi = unittest.skipUnless(unicode_legacy_string,
511-
'requires legacy Unicode C API')
505+
def requires_legacy_unicode_capi():
506+
try:
507+
from _testcapi import unicode_legacy_string
508+
except ImportError:
509+
unicode_legacy_string = None
510+
511+
return unittest.skipUnless(unicode_legacy_string,
512+
'requires legacy Unicode C API')
512513

513514
MS_WINDOWS = (sys.platform == 'win32')
514515

516+
# Is not actually used in tests, but is kept for compatibility.
515517
is_jython = sys.platform.startswith('java')
516518

517519
is_android = hasattr(sys, 'getandroidapilevel')
@@ -587,7 +589,8 @@ def darwin_malloc_err_warning(test_name):
587589
msg = ' NOTICE '
588590
detail = (f'{test_name} may generate "malloc can\'t allocate region"\n'
589591
'warnings on macOS systems. This behavior is known. Do not\n'
590-
'report a bug unless tests are also failing. See bpo-40928.')
592+
'report a bug unless tests are also failing.\n'
593+
'See https://github.com/python/cpython/issues/85100')
591594

592595
padding, _ = shutil.get_terminal_size()
593596
print(msg.center(padding, '-'))
@@ -743,8 +746,6 @@ def gc_collect():
743746
"""
744747
import gc
745748
gc.collect()
746-
if is_jython:
747-
time.sleep(0.1)
748749
gc.collect()
749750
gc.collect()
750751

@@ -795,10 +796,20 @@ def check_cflags_pgo():
795796
_align = '0P'
796797
_vheader = _header + 'n'
797798

799+
def check_bolt_optimized():
800+
# Always return false, if the platform is WASI,
801+
# because BOLT optimization does not support WASM binary.
802+
if is_wasi:
803+
return False
804+
config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
805+
return '--enable-bolt' in config_args
806+
807+
798808
def calcobjsize(fmt):
799809
import struct
800810
return struct.calcsize(_header + fmt + _align)
801811

812+
802813
def calcvobjsize(fmt):
803814
import struct
804815
return struct.calcsize(_vheader + fmt + _align)
@@ -1099,6 +1110,19 @@ def refcount_test(test):
10991110
return no_tracing(cpython_only(test))
11001111

11011112

1113+
def requires_limited_api(test):
1114+
try:
1115+
import _testcapi
1116+
except ImportError:
1117+
return unittest.skip('needs _testcapi module')(test)
1118+
return unittest.skipUnless(
1119+
_testcapi.LIMITED_API_AVAILABLE, 'needs Limited API support')(test)
1120+
1121+
def requires_specialization(test):
1122+
return unittest.skipUnless(
1123+
opcode.ENABLE_SPECIALIZATION, "requires specialization")(test)
1124+
1125+
11021126
#=======================================================================
11031127
# Check for the presence of docstrings.
11041128

@@ -1722,6 +1746,18 @@ def setswitchinterval(interval):
17221746
return sys.setswitchinterval(interval)
17231747

17241748

1749+
def get_pagesize():
1750+
"""Get size of a page in bytes."""
1751+
try:
1752+
page_size = os.sysconf('SC_PAGESIZE')
1753+
except (ValueError, AttributeError):
1754+
try:
1755+
page_size = os.sysconf('SC_PAGE_SIZE')
1756+
except (ValueError, AttributeError):
1757+
page_size = 4096
1758+
return page_size
1759+
1760+
17251761
@contextlib.contextmanager
17261762
def disable_faulthandler():
17271763
import faulthandler
@@ -2041,16 +2077,7 @@ def get_recursion_available():
20412077
"""
20422078
limit = sys.getrecursionlimit()
20432079
depth = get_recursion_depth()
2044-
2045-
try:
2046-
from _testcapi import USE_STACKCHECK
2047-
except ImportError:
2048-
USE_STACKCHECK = False
2049-
2050-
if USE_STACKCHECK:
2051-
return max(limit - depth - 1, 0)
2052-
else:
2053-
return limit - depth
2080+
return limit - depth
20542081

20552082
@contextlib.contextmanager
20562083
def set_recursion_limit(limit):
@@ -2127,6 +2154,43 @@ def requires_venv_with_pip():
21272154
Py_DEBUG = hasattr(sys, 'gettotalrefcount')
21282155

21292156

2157+
def late_deletion(obj):
2158+
"""
2159+
Keep a Python alive as long as possible.
2160+
2161+
Create a reference cycle and store the cycle in an object deleted late in
2162+
Python finalization. Try to keep the object alive until the very last
2163+
garbage collection.
2164+
2165+
The function keeps a strong reference by design. It should be called in a
2166+
subprocess to not mark a test as "leaking a reference".
2167+
"""
2168+
2169+
# Late CPython finalization:
2170+
# - finalize_interp_clear()
2171+
# - _PyInterpreterState_Clear(): Clear PyInterpreterState members
2172+
# (ex: codec_search_path, before_forkers)
2173+
# - clear os.register_at_fork() callbacks
2174+
# - clear codecs.register() callbacks
2175+
2176+
ref_cycle = [obj]
2177+
ref_cycle.append(ref_cycle)
2178+
2179+
# Store a reference in PyInterpreterState.codec_search_path
2180+
import codecs
2181+
def search_func(encoding):
2182+
return None
2183+
search_func.reference = ref_cycle
2184+
codecs.register(search_func)
2185+
2186+
if hasattr(os, 'register_at_fork'):
2187+
# Store a reference in PyInterpreterState.before_forkers
2188+
def atfork_func():
2189+
pass
2190+
atfork_func.reference = ref_cycle
2191+
os.register_at_fork(before=atfork_func)
2192+
2193+
21302194
def busy_retry(timeout, err_msg=None, /, *, error=True):
21312195
"""
21322196
Run the loop body until "break" stops the loop.
@@ -2238,3 +2302,75 @@ def copy_python_src_ignore(path, names):
22382302
'build',
22392303
}
22402304
return ignored
2305+
2306+
2307+
def iter_builtin_types():
2308+
for obj in __builtins__.values():
2309+
if not isinstance(obj, type):
2310+
continue
2311+
cls = obj
2312+
if cls.__module__ != 'builtins':
2313+
continue
2314+
yield cls
2315+
2316+
2317+
def iter_slot_wrappers(cls):
2318+
assert cls.__module__ == 'builtins', cls
2319+
2320+
def is_slot_wrapper(name, value):
2321+
if not isinstance(value, types.WrapperDescriptorType):
2322+
assert not repr(value).startswith('<slot wrapper '), (cls, name, value)
2323+
return False
2324+
assert repr(value).startswith('<slot wrapper '), (cls, name, value)
2325+
assert callable(value), (cls, name, value)
2326+
assert name.startswith('__') and name.endswith('__'), (cls, name, value)
2327+
return True
2328+
2329+
ns = vars(cls)
2330+
unused = set(ns)
2331+
for name in dir(cls):
2332+
if name in ns:
2333+
unused.remove(name)
2334+
2335+
try:
2336+
value = getattr(cls, name)
2337+
except AttributeError:
2338+
# It's as though it weren't in __dir__.
2339+
assert name in ('__annotate__', '__annotations__', '__abstractmethods__'), (cls, name)
2340+
if name in ns and is_slot_wrapper(name, ns[name]):
2341+
unused.add(name)
2342+
continue
2343+
2344+
if not name.startswith('__') or not name.endswith('__'):
2345+
assert not is_slot_wrapper(name, value), (cls, name, value)
2346+
if not is_slot_wrapper(name, value):
2347+
if name in ns:
2348+
assert not is_slot_wrapper(name, ns[name]), (cls, name, value, ns[name])
2349+
else:
2350+
if name in ns:
2351+
assert ns[name] is value, (cls, name, value, ns[name])
2352+
yield name, True
2353+
else:
2354+
yield name, False
2355+
2356+
for name in unused:
2357+
value = ns[name]
2358+
if is_slot_wrapper(cls, name, value):
2359+
yield name, True
2360+
2361+
2362+
class BrokenIter:
2363+
def __init__(self, init_raises=False, next_raises=False, iter_raises=False):
2364+
if init_raises:
2365+
1/0
2366+
self.next_raises = next_raises
2367+
self.iter_raises = iter_raises
2368+
2369+
def __next__(self):
2370+
if self.next_raises:
2371+
1/0
2372+
2373+
def __iter__(self):
2374+
if self.iter_raises:
2375+
1/0
2376+
return self

graalpython/lib-python/3/test/test_capi/test_getargs.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
_testcapi = import_helper.import_module('_testcapi')
1111
from _testcapi import getargs_keywords, getargs_keyword_only
1212

13+
try:
14+
import _testinternalcapi
15+
except ImportError:
16+
_testinternalcapi = NULL
17+
1318
# > How about the following counterproposal. This also changes some of
1419
# > the other format codes to be a little more regular.
1520
# >
@@ -56,6 +61,8 @@
5661
LLONG_MIN = -2**63
5762
ULLONG_MAX = 2**64-1
5863

64+
NULL = None
65+
5966
class Index:
6067
def __index__(self):
6168
return 99
@@ -1041,7 +1048,7 @@ def test_et_hash(self):
10411048
buf = bytearray()
10421049
self.assertRaises(ValueError, getargs_et_hash, 'abc\xe9', 'latin1', buf)
10431050

1044-
@support.requires_legacy_unicode_capi
1051+
@support.requires_legacy_unicode_capi()
10451052
def test_u(self):
10461053
from _testcapi import getargs_u
10471054
with self.assertWarns(DeprecationWarning):
@@ -1056,11 +1063,8 @@ def test_u(self):
10561063
self.assertRaises(TypeError, getargs_u, memoryview(b'memoryview'))
10571064
with self.assertWarns(DeprecationWarning):
10581065
self.assertRaises(TypeError, getargs_u, None)
1059-
with warnings.catch_warnings():
1060-
warnings.simplefilter('error', DeprecationWarning)
1061-
self.assertRaises(DeprecationWarning, getargs_u, 'abc\xe9')
10621066

1063-
@support.requires_legacy_unicode_capi
1067+
@support.requires_legacy_unicode_capi()
10641068
def test_u_hash(self):
10651069
from _testcapi import getargs_u_hash
10661070
with self.assertWarns(DeprecationWarning):
@@ -1075,11 +1079,8 @@ def test_u_hash(self):
10751079
self.assertRaises(TypeError, getargs_u_hash, memoryview(b'memoryview'))
10761080
with self.assertWarns(DeprecationWarning):
10771081
self.assertRaises(TypeError, getargs_u_hash, None)
1078-
with warnings.catch_warnings():
1079-
warnings.simplefilter('error', DeprecationWarning)
1080-
self.assertRaises(DeprecationWarning, getargs_u_hash, 'abc\xe9')
10811082

1082-
@support.requires_legacy_unicode_capi
1083+
@support.requires_legacy_unicode_capi()
10831084
def test_Z(self):
10841085
from _testcapi import getargs_Z
10851086
with self.assertWarns(DeprecationWarning):
@@ -1094,11 +1095,8 @@ def test_Z(self):
10941095
self.assertRaises(TypeError, getargs_Z, memoryview(b'memoryview'))
10951096
with self.assertWarns(DeprecationWarning):
10961097
self.assertIsNone(getargs_Z(None))
1097-
with warnings.catch_warnings():
1098-
warnings.simplefilter('error', DeprecationWarning)
1099-
self.assertRaises(DeprecationWarning, getargs_Z, 'abc\xe9')
11001098

1101-
@support.requires_legacy_unicode_capi
1099+
@support.requires_legacy_unicode_capi()
11021100
def test_Z_hash(self):
11031101
from _testcapi import getargs_Z_hash
11041102
with self.assertWarns(DeprecationWarning):
@@ -1113,9 +1111,6 @@ def test_Z_hash(self):
11131111
self.assertRaises(TypeError, getargs_Z_hash, memoryview(b'memoryview'))
11141112
with self.assertWarns(DeprecationWarning):
11151113
self.assertIsNone(getargs_Z_hash(None))
1116-
with warnings.catch_warnings():
1117-
warnings.simplefilter('error', DeprecationWarning)
1118-
self.assertRaises(DeprecationWarning, getargs_Z_hash, 'abc\xe9')
11191114

11201115
def test_gh_99240_clear_args(self):
11211116
from _testcapi import gh_99240_clear_args
@@ -1235,7 +1230,7 @@ def test_skipitem_with_suffix(self):
12351230
dict_b = {'b':1}
12361231
keywords = ["a", "b"]
12371232

1238-
supported = ('s#', 's*', 'z#', 'z*', 'u#', 'Z#', 'y#', 'y*', 'w#', 'w*')
1233+
supported = ('s#', 's*', 'z#', 'z*', 'y#', 'y*', 'w#', 'w*')
12391234
for c in string.ascii_letters:
12401235
for c2 in '#*':
12411236
f = c + c2

graalpython/lib-python/3/test/test_csv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def test_writerows_errors(self):
278278
self.assertRaises(OSError, writer.writerows, BadIterable())
279279

280280
@support.cpython_only
281-
@support.requires_legacy_unicode_capi
281+
@support.requires_legacy_unicode_capi()
282282
@warnings_helper.ignore_warnings(category=DeprecationWarning)
283283
def test_writerows_legacy_strings(self):
284284
import _testcapi

0 commit comments

Comments
 (0)