Skip to content

Commit e4e6bbf

Browse files
Merge branch 'main' into call-len
2 parents 705bf8b + a5e628b commit e4e6bbf

16 files changed

+366
-382
lines changed

Doc/c-api/init_config.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ Configuration Options
320320
* - ``"cpu_count"``
321321
- :c:member:`cpu_count <PyConfig.cpu_count>`
322322
- ``int``
323-
- Read-only
323+
- Public
324324
* - ``"dev_mode"``
325325
- :c:member:`dev_mode <PyConfig.dev_mode>`
326326
- ``bool``
@@ -619,6 +619,8 @@ Some options are read from the :mod:`sys` attributes. For example, the option
619619
The caller must have an :term:`attached thread state`. The function cannot
620620
be called before Python initialization nor after Python finalization.
621621
622+
.. audit-event:: cpython.PyConfig_Set name,value c.PyConfig_Set
623+
622624
.. versionadded:: 3.14
623625
624626

Include/internal/pycore_interp_structs.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ extern "C" {
99

1010
#include "pycore_ast_state.h" // struct ast_state
1111
#include "pycore_llist.h" // struct llist_node
12-
#include "pycore_memoryobject.h" // struct _memoryobject_state
1312
#include "pycore_opcode_utils.h" // NUM_COMMON_CONSTANTS
1413
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
1514
#include "pycore_structs.h" // PyHamtObject
@@ -913,10 +912,9 @@ struct _is {
913912
struct _dtoa_state dtoa;
914913
struct _py_func_state func_state;
915914
struct _py_code_state code_state;
915+
916916
struct _Py_dict_state dict_state;
917917
struct _Py_exc_state exc_state;
918-
struct _memoryobject_state memobj_state;
919-
920918
struct _Py_mem_interp_free_queue mem_free_queue;
921919

922920
struct ast_state ast;

Include/internal/pycore_memoryobject.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
struct _memoryobject_state {
12-
PyTypeObject *XIBufferViewType;
13-
};
14-
15-
extern PyStatus _PyMemoryView_InitTypes(PyInterpreterState *);
16-
extern void _PyMemoryView_FiniTypes(PyInterpreterState *);
17-
18-
// exported for _interpreters module
19-
PyAPI_FUNC(PyTypeObject *) _PyMemoryView_GetXIBuffewViewType(void);
20-
21-
2211
extern PyTypeObject _PyManagedBuffer_Type;
2312

2413
PyObject *

Lib/test/test_capi/test_config.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Tests PyConfig_Get() and PyConfig_Set() C API (PEP 741).
33
"""
4+
import os
45
import sys
56
import sysconfig
67
import types
@@ -374,12 +375,23 @@ def expect_bool_not(value):
374375
finally:
375376
config_set(name, old_value)
376377

378+
def test_config_set_cpu_count(self):
379+
config_get = _testcapi.config_get
380+
config_set = _testcapi.config_set
381+
382+
old_value = config_get('cpu_count')
383+
try:
384+
config_set('cpu_count', 123)
385+
self.assertEqual(os.cpu_count(), 123)
386+
finally:
387+
config_set('cpu_count', old_value)
388+
377389
def test_config_set_read_only(self):
378390
# Test PyConfig_Set() on read-only options
379391
config_set = _testcapi.config_set
380392
for name, value in (
381393
("allocator", 0), # PyPreConfig member
382-
("cpu_count", 8),
394+
("perf_profiling", 8),
383395
("dev_mode", True),
384396
("filesystem_encoding", "utf-8"),
385397
):

Lib/test/test_remote_pdb.py

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@
1313
import unittest.mock
1414
from contextlib import contextmanager
1515
from pathlib import Path
16-
from test.support import is_wasi, os_helper
16+
from test.support import is_wasi, os_helper, SHORT_TIMEOUT
1717
from test.support.os_helper import temp_dir, TESTFN, unlink
1818
from typing import Dict, List, Optional, Tuple, Union, Any
1919

2020
import pdb
2121
from pdb import _PdbServer, _PdbClient
2222

2323

24+
if not sys.is_remote_debug_enabled():
25+
raise unittest.SkipTest('remote debugging is disabled')
26+
27+
2428
@contextmanager
2529
def kill_on_error(proc):
2630
"""Context manager killing the subprocess if a Python exception is raised."""
@@ -415,7 +419,7 @@ def test_connect_and_basic_commands(self):
415419
self._send_command(client_file, "c")
416420

417421
# Wait for process to finish
418-
stdout, _ = process.communicate(timeout=5)
422+
stdout, _ = process.communicate(timeout=SHORT_TIMEOUT)
419423

420424
# Check if we got the expected output
421425
self.assertIn("Function returned: 42", stdout)
@@ -458,19 +462,13 @@ def test_breakpoints(self):
458462

459463
# Continue to end
460464
self._send_command(client_file, "c")
461-
stdout, _ = process.communicate(timeout=5)
465+
stdout, _ = process.communicate(timeout=SHORT_TIMEOUT)
462466

463467
self.assertIn("Function returned: 42", stdout)
464468
self.assertEqual(process.returncode, 0)
465469

466470
def test_keyboard_interrupt(self):
467471
"""Test that sending keyboard interrupt breaks into pdb."""
468-
synchronizer_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
469-
synchronizer_sock.bind(('127.0.0.1', 0)) # Let OS assign port
470-
synchronizer_sock.settimeout(5)
471-
synchronizer_sock.listen(1)
472-
self.addCleanup(synchronizer_sock.close)
473-
sync_port = synchronizer_sock.getsockname()[1]
474472

475473
script = textwrap.dedent(f"""
476474
import time
@@ -487,11 +485,10 @@ def bar():
487485
version=pdb._PdbServer.protocol_version(),
488486
)
489487
print("Connected to debugger")
490-
iterations = 10
491-
socket.create_connection(('127.0.0.1', {sync_port})).close()
488+
iterations = 50
492489
while iterations > 0:
493-
print("Iteration", iterations)
494-
time.sleep(1)
490+
print("Iteration", iterations, flush=True)
491+
time.sleep(0.2)
495492
iterations -= 1
496493
return 42
497494
@@ -508,28 +505,26 @@ def bar():
508505
# Continue execution
509506
self._send_command(client_file, "c")
510507

511-
# Wait until execution has continued
512-
synchronizer_sock.accept()[0].close()
513-
514-
# Wait a bit so the remote leaves create_connection(). This is not
515-
# required but makes the rest of the test faster as we will exit the main
516-
# loop immediately by setting iterations to 0.
517-
time.sleep(0.1)
508+
# Confirm that the remote is already in the while loop. We know
509+
# it's in bar() and we can exit the loop immediately by setting
510+
# iterations to 0.
511+
while line := process.stdout.readline():
512+
if line.startswith("Iteration"):
513+
break
518514

519515
# Inject a script to interrupt the running process
520516
self._send_interrupt(process.pid)
521517
messages = self._read_until_prompt(client_file)
522518

523-
# Verify we got the keyboard interrupt message. Is possible that we get interrupted somewhere
524-
# in bar() or when leving create_connection()
519+
# Verify we got the keyboard interrupt message.
525520
interrupt_msgs = [msg['message'] for msg in messages if 'message' in msg]
526-
expected_msg = [msg for msg in interrupt_msgs if "bar()" in msg or "create_connection()" in msg]
521+
expected_msg = [msg for msg in interrupt_msgs if "bar()" in msg]
527522
self.assertGreater(len(expected_msg), 0)
528523

529524
# Continue to end as fast as we can
530525
self._send_command(client_file, "iterations = 0")
531526
self._send_command(client_file, "c")
532-
stdout, _ = process.communicate(timeout=5)
527+
stdout, _ = process.communicate(timeout=SHORT_TIMEOUT)
533528
self.assertIn("Function returned: 42", stdout)
534529
self.assertEqual(process.returncode, 0)
535530

@@ -547,7 +542,7 @@ def test_handle_eof(self):
547542
client_file.flush()
548543

549544
# The process should complete normally after receiving EOF
550-
stdout, stderr = process.communicate(timeout=5)
545+
stdout, stderr = process.communicate(timeout=SHORT_TIMEOUT)
551546

552547
# Verify process completed correctly
553548
self.assertIn("Function returned: 42", stdout)
@@ -597,7 +592,7 @@ def run_test():
597592
self.assertIn('protocol version', message['message'])
598593

599594
# The process should complete normally
600-
stdout, stderr = process.communicate(timeout=5)
595+
stdout, stderr = process.communicate(timeout=SHORT_TIMEOUT)
601596

602597
# Verify the process completed successfully
603598
self.assertIn("Test result: True", stdout)
@@ -639,7 +634,7 @@ def test_help_system(self):
639634
# Continue execution to finish the program
640635
self._send_command(client_file, "c")
641636

642-
stdout, stderr = process.communicate(timeout=5)
637+
stdout, stderr = process.communicate(timeout=SHORT_TIMEOUT)
643638
self.assertIn("Function returned: 42", stdout)
644639
self.assertEqual(process.returncode, 0)
645640

@@ -697,7 +692,7 @@ def test_multi_line_commands(self):
697692
# Continue execution to finish
698693
self._send_command(client_file, "c")
699694

700-
stdout, stderr = process.communicate(timeout=5)
695+
stdout, stderr = process.communicate(timeout=SHORT_TIMEOUT)
701696
self.assertIn("Function returned: 42", stdout)
702697
self.assertEqual(process.returncode, 0)
703698

Modules/_asynciomodule.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ typedef struct {
185185
/* Counter for autogenerated Task names */
186186
uint64_t task_name_counter;
187187

188+
/* Pointer to the asyncio debug offset to avoid it to be optimized away
189+
by the compiler */
190+
void *debug_offsets;
191+
188192
} asyncio_state;
189193

190194
static inline asyncio_state *
@@ -4320,6 +4324,8 @@ module_init(asyncio_state *state)
43204324
goto fail;
43214325
}
43224326

4327+
state->debug_offsets = &_AsyncioDebug;
4328+
43234329
Py_DECREF(module);
43244330
return 0;
43254331

Modules/_interpreters_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
_RESOLVE_MODINIT_FUNC_NAME(NAME)
66

77

8-
#ifdef REGISTERS_HEAP_TYPES
98
static int
109
ensure_xid_class(PyTypeObject *cls, xidatafunc getdata)
1110
{
@@ -17,6 +16,7 @@ ensure_xid_class(PyTypeObject *cls, xidatafunc getdata)
1716
return _PyXIData_RegisterClass(&ctx, cls, getdata);
1817
}
1918

19+
#ifdef REGISTERS_HEAP_TYPES
2020
static int
2121
clear_xid_class(PyTypeObject *cls)
2222
{

0 commit comments

Comments
 (0)