Skip to content

Commit 40327d5

Browse files
Merge branch 'main' into gh-161968-inplace-mul-sq-repeat
2 parents d13d63d + 1d64195 commit 40327d5

14 files changed

Lines changed: 128 additions & 32 deletions

File tree

‎Doc/c-api/dict.rst‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,14 @@ Dictionary objects
472472
473473
.. c:function:: int PyDict_Update(PyObject *a, PyObject *b)
474474
475-
This is the same as ``PyDict_Merge(a, b, 1)`` in C, and is similar to
476-
``a.update(b)`` in Python except that :c:func:`PyDict_Update` doesn't fall
477-
back to the iterating over a sequence of key value pairs if the second
478-
argument has no "keys" attribute. Return ``0`` on success or ``-1`` if an
479-
exception was raised.
475+
This is the same as ``PyDict_Merge(a, b, 1)`` in C.
476+
477+
Similar to ``a.update(b)`` in Python, except that this function
478+
does not fall back to the iterating over a sequence of key-value pairs
479+
if *b* is not a mapping.
480+
Use :c:func:`PyDict_MergeFromSeq2` for this case.
481+
482+
Return ``0`` on success or ``-1`` if an exception was raised.
480483
481484
.. note::
482485

‎Include/internal/pycore_instruction_sequence.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ typedef struct instruction_sequence {
4040
/* Map of a label id to instruction offset (index into s_instrs).
4141
* If s_labelmap is NULL, then each label id is the offset itself.
4242
*/
43-
int *s_labelmap;
4443
int s_labelmap_size;
44+
int *s_labelmap;
4545

4646
/* PyList of instruction sequences of nested functions */
4747
PyObject *s_nested;

‎Lib/test/libregrtest/utils.py‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,32 @@ def display_header(use_resources: dict[str, str | None],
665665
if process_cpu_count and process_cpu_count != cpu_count:
666666
cpu_count = f"{process_cpu_count} (process) / {cpu_count} (system)"
667667
print("== CPU count:", cpu_count)
668-
print("== encodings: locale=%s FS=%s"
669-
% (locale.getencoding(), sys.getfilesystemencoding()))
668+
669+
encodings = []
670+
if _winapi is not None:
671+
# Log ANSI and OEM code pages
672+
ansi = f'cp{_winapi.GetACP()}'
673+
oem = f'cp{_winapi.GetOEMCP()}'
674+
if ansi == oem:
675+
encodings.append(f'ansi=oem={ansi}')
676+
else:
677+
encodings.append(f'ansi={ansi}')
678+
encodings.append(f'oem={oem}')
679+
encodings.append(f'FS={sys.getfilesystemencoding()}')
680+
else:
681+
locale_encoding = locale.getencoding() # nl_langinfo(CODESET)
682+
fs_encoding = sys.getfilesystemencoding() # normalized name
683+
if locale_encoding.lower() == fs_encoding.lower():
684+
encodings.append(f'locale=FS={fs_encoding}')
685+
else:
686+
encodings.append(f'locale={locale_encoding}')
687+
encodings.append(f'FS={fs_encoding}')
688+
if not sys.flags.utf8_mode:
689+
encodings.append('utf8=0')
690+
if (not sys.flags.ignore_environment
691+
and os.environ.get('PYTHONCOERCECLOCALE') == '0'):
692+
encodings.append('coerce=0')
693+
print(f"== encodings: {' '.join(encodings)}")
670694

671695
if use_resources:
672696
text = format_resources(use_resources)

‎Lib/test/test_cext/extension.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,18 @@ module_exec(PyObject *module)
483483
return -1;
484484
}
485485
#endif
486+
487+
#ifdef Py_LIMITED_API
488+
if (PyModule_AddIntMacro(module, Py_LIMITED_API) < 0) {
489+
return -1;
490+
}
491+
#endif
492+
#ifdef Py_TARGET_ABI3T
493+
if (PyModule_AddIntMacro(module, Py_TARGET_ABI3T) < 0) {
494+
return -1;
495+
}
496+
#endif
497+
486498
// Ignore "unused argument" warning when none of these macros is defined
487499
(void)module;
488500
return 0;

‎Lib/test/test_cext/runtests.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,19 @@ def main():
6363
'__STRICT_ANSI__',
6464
'__cplusplus',
6565
'_MSVC_LANG',
66+
'Py_LIMITED_API',
67+
'Py_TARGET_ABI3T',
6668
):
6769
try:
6870
value = getattr(testmod, name)
6971
except AttributeError:
70-
pass
71-
else:
72-
print(f'{name}: {value}')
73-
newline = True
72+
continue
73+
74+
if name in ('Py_LIMITED_API', 'Py_TARGET_ABI3T'):
75+
value = f'0x{value:08x}'
76+
77+
print(f'{name}: {value}')
78+
newline = True
7479
if newline:
7580
print()
7681

‎Lib/test/test_ctypes/test_callbacks.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from ctypes.util import find_library, struct, wrap_dll_function
1616
from test import support
1717
from test.support import import_helper
18+
from test.support import script_helper
1819
_ctypes_test = import_helper.import_module("_ctypes_test")
1920

2021

@@ -559,6 +560,19 @@ def cb():
559560

560561
self.assertEqual(_testfunc_callback_int_to_longlong(cb), -1)
561562

563+
def test_import_does_not_open_fds(self):
564+
# gh-135893: Importing ctypes must not allocate a libffi closure,
565+
# which can leave a file descriptor open for the rest of the
566+
# process' lifetime.
567+
code = """if 1:
568+
from test.support import os_helper
569+
before = os_helper.fd_count()
570+
import ctypes
571+
after = os_helper.fd_count()
572+
assert before == after
573+
"""
574+
script_helper.assert_python_ok("-c", code)
575+
562576

563577
if __name__ == '__main__':
564578
unittest.main()

‎Lib/test/test_ssl.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
import ctypes
4141
except ImportError:
4242
ctypes = None
43+
try:
44+
from _hashlib import get_fips_mode
45+
except ImportError:
46+
def get_fips_mode(): return False
4347

4448

4549
ssl = import_helper.import_module("ssl")
@@ -2478,6 +2482,9 @@ def test_outer_alpn_does_not_replace_inner(self):
24782482
self.assertEqual(server.selected_alpn_protocol(), 'h2')
24792483

24802484
@unittest.skipUnless(ssl.HAS_ECH, 'requires ECH')
2485+
# At 2026-11-13 (OpenSSL 4.0.3 on Fedora 45), the test is incompatible
2486+
# with FIPS mode: https://github.com/openssl/openssl/issues/33724
2487+
@unittest.skipIf(get_fips_mode(), 'gh-161932: test incompatible with FIPS')
24812488
def test_outer_alpn_without_ech_config(self):
24822489
for options in (0, ssl.OP_ECH_GREASE):
24832490
client_ctx, server_ctx, hostname = testing_context()
@@ -2491,6 +2498,9 @@ def test_outer_alpn_without_ech_config(self):
24912498
self.assertEqual(server.selected_alpn_protocol(), 'h2')
24922499

24932500
@unittest.skipUnless(ssl.HAS_ECH, 'requires ECH')
2501+
# At 2026-11-13 (OpenSSL 4.0.3 on Fedora 45), the test is incompatible
2502+
# with FIPS mode: https://github.com/openssl/openssl/issues/33724
2503+
@unittest.skipIf(get_fips_mode(), 'gh-161932: test incompatible with FIPS')
24942504
def test_grease(self):
24952505
client_ctx, server_ctx, hostname = testing_context()
24962506
client_ctx.options |= ssl.OP_ECH_GREASE
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Reduce padding in the internal instruction sequence structure, saving 8 bytes
2+
per instance on 64-bit platforms. Patch by Shamil Abdulaev.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a regression where importing :mod:`ctypes` could leave an extra file
2+
descriptor open on some Linux systems, or hang in x86-64 macOS applications
3+
signed with the hardened runtime.

‎Modules/_ctypes/_ctypes.c‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6553,18 +6553,6 @@ _ctypes_add_version_constants(PyObject *mod)
65536553
static int
65546554
_ctypes_mod_exec(PyObject *mod)
65556555
{
6556-
// See https://github.com/python/cpython/issues/128485
6557-
// This allocates some memory and then frees it to ensure that the
6558-
// the dlmalloc allocator initializes itself to avoid data races
6559-
// in free-threading.
6560-
void *codeloc = NULL;
6561-
void *ptr = Py_ffi_closure_alloc(sizeof(void *), &codeloc);
6562-
if (ptr == NULL) {
6563-
PyErr_NoMemory();
6564-
return -1;
6565-
}
6566-
Py_ffi_closure_free(ptr);
6567-
65686556
_ctypes_init_fielddesc();
65696557

65706558
ctypes_state *st = get_module_state(mod);

0 commit comments

Comments
 (0)