Skip to content

Commit df1c5d4

Browse files
committed
Merge 'origin/main' into gh-131253-pystats-ft
2 parents 60454a2 + 98d462c commit df1c5d4

File tree

7 files changed

+53
-6
lines changed

7 files changed

+53
-6
lines changed

Doc/library/array.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defined:
2424
+-----------+--------------------+-------------------+-----------------------+-------+
2525
| ``'u'`` | wchar_t | Unicode character | 2 | \(1) |
2626
+-----------+--------------------+-------------------+-----------------------+-------+
27-
| ``'w'`` | Py_UCS4 | Unicode character | 4 | |
27+
| ``'w'`` | Py_UCS4 | Unicode character | 4 | \(2) |
2828
+-----------+--------------------+-------------------+-----------------------+-------+
2929
| ``'h'`` | signed short | int | 2 | |
3030
+-----------+--------------------+-------------------+-----------------------+-------+
@@ -60,6 +60,9 @@ Notes:
6060
.. deprecated-removed:: 3.3 3.16
6161
Please migrate to ``'w'`` typecode.
6262

63+
(2)
64+
.. versionadded:: 3.13
65+
6366

6467
The actual representation of values is determined by the machine architecture
6568
(strictly speaking, by the C implementation). The actual size can be accessed

Doc/whatsnew/3.14.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,18 @@ The behavior of :func:`!gc.collect` changes slightly:
10811081

10821082
(Contributed by Mark Shannon in :gh:`108362`.)
10831083

1084+
Platform support
1085+
================
1086+
1087+
* :pep:`776`: Emscripten is now an officially supported platform at
1088+
:pep:`tier 3 <11#tier-3>`. As a part of this effort, more than 25 bugs in
1089+
`Emscripten libc`__ were fixed. Emscripten now includes support
1090+
for :mod:`ctypes`, :mod:`termios`, and :mod:`fcntl`, as well as
1091+
experimental support for :ref:`PyREPL <tut-interactive>`.
1092+
1093+
(Contributed by R. Hood Chatham in :gh:`127146`, :gh:`127683`, and :gh:`136931`.)
1094+
1095+
__ https://emscripten.org/docs/porting/emscripten-runtime-environment.html
10841096

10851097
Other language changes
10861098
======================

Include/internal/pycore_traceback.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ extern int _Py_WriteIndentedMargin(int, const char*, PyObject *);
100100
extern int _Py_WriteIndent(int, PyObject *);
101101

102102
// Export for the faulthandler module
103+
PyAPI_FUNC(void) _Py_InitDumpStack(void);
103104
PyAPI_FUNC(void) _Py_DumpStack(int fd);
104105

105106
#ifdef __cplusplus

Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def run_repl(
5151
cwd: str | None = None,
5252
skip: bool = False,
5353
timeout: float = SHORT_TIMEOUT,
54+
exit_on_output: str | None = None,
5455
) -> tuple[str, int]:
5556
temp_dir = None
5657
if cwd is None:
@@ -64,6 +65,7 @@ def run_repl(
6465
cwd=cwd,
6566
skip=skip,
6667
timeout=timeout,
68+
exit_on_output=exit_on_output,
6769
)
6870
finally:
6971
if temp_dir is not None:
@@ -78,6 +80,7 @@ def _run_repl(
7880
cwd: str,
7981
skip: bool,
8082
timeout: float,
83+
exit_on_output: str | None,
8184
) -> tuple[str, int]:
8285
assert pty
8386
master_fd, slave_fd = pty.openpty()
@@ -123,6 +126,11 @@ def _run_repl(
123126
except OSError:
124127
break
125128
output.append(data)
129+
if exit_on_output is not None:
130+
output = ["".join(output)]
131+
if exit_on_output in output[0]:
132+
process.kill()
133+
break
126134
else:
127135
os.close(master_fd)
128136
process.kill()
@@ -1718,18 +1726,24 @@ def test_history_survive_crash(self):
17181726

17191727
commands = "1\n2\n3\nexit()\n"
17201728
output, exit_code = self.run_repl(commands, env=env, skip=True)
1729+
self.assertEqual(exit_code, 0)
17211730

1722-
commands = "spam\nimport time\ntime.sleep(1000)\nquit\n"
1723-
try:
1724-
self.run_repl(commands, env=env, timeout=3)
1725-
except AssertionError:
1726-
pass
1731+
# Run until "0xcafe" is printed (as "51966") and then kill the
1732+
# process to simulate a crash. Note that the output also includes
1733+
# the echoed input commands.
1734+
commands = "spam\nimport time\n0xcafe\ntime.sleep(1000)\nquit\n"
1735+
output, exit_code = self.run_repl(commands, env=env,
1736+
exit_on_output="51966")
1737+
self.assertNotEqual(exit_code, 0)
17271738

17281739
history = pathlib.Path(hfile.name).read_text()
17291740
self.assertIn("2", history)
17301741
self.assertIn("exit()", history)
17311742
self.assertIn("spam", history)
17321743
self.assertIn("import time", history)
1744+
# History is written after each command's output is printed to the
1745+
# console, so depending on how quickly the process is killed,
1746+
# the last command may or may not be written to the history file.
17331747
self.assertNotIn("sleep", history)
17341748
self.assertNotIn("quit", history)
17351749

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a potential async-signal-safety issue in :mod:`faulthandler` when
2+
printing C stack traces.

Modules/faulthandler.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ faulthandler_enable(void)
524524
}
525525
#endif
526526

527+
// gh-137185: Initialize C stack trace dumping outside of the signal
528+
// handler. Specifically, we call backtrace() to ensure that libgcc is
529+
// dynamically loaded outside of the signal handler.
530+
_Py_InitDumpStack();
531+
527532
for (size_t i=0; i < faulthandler_nsignals; i++) {
528533
fault_handler_t *handler;
529534
int err;

Python/traceback.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,3 +1326,13 @@ _Py_DumpStack(int fd)
13261326
PUTS(fd, " <cannot get C stack on this system>\n");
13271327
}
13281328
#endif
1329+
1330+
void
1331+
_Py_InitDumpStack(void)
1332+
{
1333+
#ifdef CAN_C_BACKTRACE
1334+
// gh-137185: Call backtrace() once to force libgcc to be loaded early.
1335+
void *callstack[1];
1336+
(void)backtrace(callstack, 1);
1337+
#endif
1338+
}

0 commit comments

Comments
 (0)