Skip to content

Commit 2a25a71

Browse files
committed
Merge remote-tracking branch 'upstream/3.13' into backport-f04bea4-3.13
2 parents ba2968b + 7816ac3 commit 2a25a71

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+442
-254
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ jobs:
310310
# Keep 1.1.1w in our list despite it being upstream EOL and otherwise
311311
# unsupported as it most resembles other 1.1.1-work-a-like ssl APIs
312312
# supported by important vendors such as AWS-LC.
313-
openssl_ver: [1.1.1w, 3.0.15, 3.1.7, 3.2.3, 3.3.2]
313+
openssl_ver: [1.1.1w, 3.0.18, 3.1.7, 3.2.6, 3.3.5]
314314
env:
315315
OPENSSL_VER: ${{ matrix.openssl_ver }}
316316
MULTISSL_DIR: ${{ github.workspace }}/multissl
@@ -382,7 +382,7 @@ jobs:
382382
with:
383383
persist-credentials: false
384384
- name: Build and test
385-
run: ./Android/android.py ci ${{ matrix.arch }}-linux-android
385+
run: ./Android/android.py ci --fast-ci ${{ matrix.arch }}-linux-android
386386

387387
build-wasi:
388388
name: 'WASI'
@@ -399,7 +399,7 @@ jobs:
399399
needs: build-context
400400
if: needs.build-context.outputs.run-tests == 'true'
401401
env:
402-
OPENSSL_VER: 3.0.15
402+
OPENSSL_VER: 3.0.18
403403
PYTHONSTRICTEXTENSIONBUILD: 1
404404
steps:
405405
- uses: actions/checkout@v4
@@ -518,7 +518,7 @@ jobs:
518518
matrix:
519519
os: [ubuntu-24.04]
520520
env:
521-
OPENSSL_VER: 3.0.15
521+
OPENSSL_VER: 3.0.18
522522
PYTHONSTRICTEXTENSIONBUILD: 1
523523
ASAN_OPTIONS: detect_leaks=0:allocator_may_return_null=1:handle_segv=0
524524
steps:

.github/workflows/reusable-ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
matrix:
2626
os: [ubuntu-24.04, ubuntu-24.04-arm]
2727
env:
28-
OPENSSL_VER: 3.0.15
28+
OPENSSL_VER: 3.0.18
2929
PYTHONSTRICTEXTENSIONBUILD: 1
3030
TERM: linux
3131
steps:

Android/android.py

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import asyncio
44
import argparse
5+
import json
56
import os
67
import platform
78
import re
@@ -184,10 +185,16 @@ def make_build_python(context):
184185
run(["make", "-j", str(os.cpu_count())])
185186

186187

188+
# To create new builds of these dependencies, usually all that's necessary is to
189+
# push a tag to the cpython-android-source-deps repository, and GitHub Actions
190+
# will do the rest.
191+
#
192+
# If you're a member of the Python core team, and you'd like to be able to push
193+
# these tags yourself, please contact Malcolm Smith or Russell Keith-Magee.
187194
def unpack_deps(host, prefix_dir):
188195
os.chdir(prefix_dir)
189196
deps_url = "https://github.com/beeware/cpython-android-source-deps/releases/download"
190-
for name_ver in ["bzip2-1.0.8-3", "libffi-3.4.4-3", "openssl-3.0.15-4",
197+
for name_ver in ["bzip2-1.0.8-3", "libffi-3.4.4-3", "openssl-3.0.18-0",
191198
"sqlite-3.50.4-0", "xz-5.4.6-1"]:
192199
filename = f"{name_ver}-{host}.tar.gz"
193200
download(f"{deps_url}/{name_ver}/{filename}")
@@ -546,27 +553,33 @@ async def gradle_task(context):
546553
task_prefix = "connected"
547554
env["ANDROID_SERIAL"] = context.connected
548555

549-
if context.command:
550-
mode = "-c"
551-
module = context.command
552-
else:
553-
mode = "-m"
554-
module = context.module or "test"
556+
if context.ci_mode:
557+
context.args[0:0] = [
558+
# See _add_ci_python_opts in libregrtest/main.py.
559+
"-W", "error", "-bb", "-E",
560+
561+
# Randomization is disabled because order-dependent failures are
562+
# much less likely to pass on a rerun in single-process mode.
563+
"-m", "test",
564+
f"--{context.ci_mode}-ci", "--single-process", "--no-randomize"
565+
]
566+
567+
if not any(arg in context.args for arg in ["-c", "-m"]):
568+
context.args[0:0] = ["-m", "test"]
555569

556570
args = [
557571
gradlew, "--console", "plain", f"{task_prefix}DebugAndroidTest",
558572
] + [
559-
# Build-time properties
560-
f"-Ppython.{name}={value}"
561-
for name, value in [
562-
("sitePackages", context.site_packages), ("cwd", context.cwd)
563-
] if value
564-
] + [
565-
# Runtime properties
566-
f"-Pandroid.testInstrumentationRunnerArguments.python{name}={value}"
573+
f"-P{name}={value}"
567574
for name, value in [
568-
("Mode", mode), ("Module", module), ("Args", join_command(context.args))
569-
] if value
575+
("python.sitePackages", context.site_packages),
576+
("python.cwd", context.cwd),
577+
(
578+
"android.testInstrumentationRunnerArguments.pythonArgs",
579+
json.dumps(context.args),
580+
),
581+
]
582+
if value
570583
]
571584
if context.verbose >= 2:
572585
args.append("--info")
@@ -734,15 +747,14 @@ def ci(context):
734747
else:
735748
with TemporaryDirectory(prefix=SCRIPT_NAME) as temp_dir:
736749
print("::group::Tests")
750+
737751
# Prove the package is self-contained by using it to run the tests.
738752
shutil.unpack_archive(package_path, temp_dir)
739-
740-
# Randomization is disabled because order-dependent failures are
741-
# much less likely to pass on a rerun in single-process mode.
742-
launcher_args = ["--managed", "maxVersion", "-v"]
743-
test_args = ["--fast-ci", "--single-process", "--no-randomize"]
753+
launcher_args = [
754+
"--managed", "maxVersion", "-v", f"--{context.ci_mode}-ci"
755+
]
744756
run(
745-
["./android.py", "test", *launcher_args, "--", *test_args],
757+
["./android.py", "test", *launcher_args],
746758
cwd=temp_dir
747759
)
748760
print("::endgroup::")
@@ -825,25 +837,28 @@ def add_parser(*args, **kwargs):
825837
test.add_argument(
826838
"--cwd", metavar="DIR", type=abspath,
827839
help="Directory to copy as the app's working directory.")
828-
829-
mode_group = test.add_mutually_exclusive_group()
830-
mode_group.add_argument(
831-
"-c", dest="command", help="Execute the given Python code.")
832-
mode_group.add_argument(
833-
"-m", dest="module", help="Execute the module with the given name.")
834-
test.epilog = (
835-
"If neither -c nor -m are passed, the default is '-m test', which will "
836-
"run Python's own test suite.")
837840
test.add_argument(
838-
"args", nargs="*", help=f"Arguments to add to sys.argv. "
839-
f"Separate them from {SCRIPT_NAME}'s own arguments with `--`.")
841+
"args", nargs="*", help=f"Python command-line arguments. "
842+
f"Separate them from {SCRIPT_NAME}'s own arguments with `--`. "
843+
f"If neither -c nor -m are included, `-m test` will be prepended, "
844+
f"which will run Python's own test suite.")
840845

841846
# Package arguments.
842847
for subcommand in [package, ci]:
843848
subcommand.add_argument(
844849
"-g", action="store_true", default=False, dest="debug",
845850
help="Include debug information in package")
846851

852+
# CI arguments
853+
for subcommand in [test, ci]:
854+
group = subcommand.add_mutually_exclusive_group(required=subcommand is ci)
855+
group.add_argument(
856+
"--fast-ci", action="store_const", dest="ci_mode", const="fast",
857+
help="Add test arguments for GitHub Actions")
858+
group.add_argument(
859+
"--slow-ci", action="store_const", dest="ci_mode", const="slow",
860+
help="Add test arguments for buildbots")
861+
847862
return parser.parse_args()
848863

849864

Android/testbed/app/src/androidTest/java/org/python/testbed/PythonSuite.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class PythonSuite {
2020
val status = PythonTestRunner(
2121
InstrumentationRegistry.getInstrumentation().targetContext
2222
).run(
23-
InstrumentationRegistry.getArguments()
23+
InstrumentationRegistry.getArguments().getString("pythonArgs")!!,
2424
)
2525
assertEquals(0, status)
2626
} finally {

Android/testbed/app/src/main/c/main_activity.c

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <jni.h>
44
#include <pthread.h>
55
#include <Python.h>
6+
#include <signal.h>
67
#include <stdio.h>
78
#include <string.h>
89
#include <unistd.h>
@@ -15,6 +16,13 @@ static void throw_runtime_exception(JNIEnv *env, const char *message) {
1516
message);
1617
}
1718

19+
static void throw_errno(JNIEnv *env, const char *error_prefix) {
20+
char error_message[1024];
21+
snprintf(error_message, sizeof(error_message),
22+
"%s: %s", error_prefix, strerror(errno));
23+
throw_runtime_exception(env, error_message);
24+
}
25+
1826

1927
// --- Stdio redirection ------------------------------------------------------
2028

@@ -95,10 +103,7 @@ JNIEXPORT void JNICALL Java_org_python_testbed_PythonTestRunner_redirectStdioToL
95103
for (StreamInfo *si = STREAMS; si->file; si++) {
96104
char *error_prefix;
97105
if ((error_prefix = redirect_stream(si))) {
98-
char error_message[1024];
99-
snprintf(error_message, sizeof(error_message),
100-
"%s: %s", error_prefix, strerror(errno));
101-
throw_runtime_exception(env, error_message);
106+
throw_errno(env, error_prefix);
102107
return;
103108
}
104109
}
@@ -107,41 +112,86 @@ JNIEXPORT void JNICALL Java_org_python_testbed_PythonTestRunner_redirectStdioToL
107112

108113
// --- Python initialization ---------------------------------------------------
109114

110-
static PyStatus set_config_string(
111-
JNIEnv *env, PyConfig *config, wchar_t **config_str, jstring value
112-
) {
113-
const char *value_utf8 = (*env)->GetStringUTFChars(env, value, NULL);
114-
PyStatus status = PyConfig_SetBytesString(config, config_str, value_utf8);
115-
(*env)->ReleaseStringUTFChars(env, value, value_utf8);
116-
return status;
115+
static char *init_signals() {
116+
// Some tests use SIGUSR1, but that's blocked by default in an Android app in
117+
// order to make it available to `sigwait` in the Signal Catcher thread.
118+
// (https://cs.android.com/android/platform/superproject/+/android14-qpr3-release:art/runtime/signal_catcher.cc).
119+
// That thread's functionality is only useful for debugging the JVM, so disabling
120+
// it should not weaken the tests.
121+
//
122+
// There's no safe way of stopping the thread completely (#123982), but simply
123+
// unblocking SIGUSR1 is enough to fix most tests.
124+
//
125+
// However, in tests that generate multiple different signals in quick
126+
// succession, it's possible for SIGUSR1 to arrive while the main thread is busy
127+
// running the C-level handler for a different signal. In that case, the SIGUSR1
128+
// may be sent to the Signal Catcher thread instead, which will generate a log
129+
// message containing the text "reacting to signal".
130+
//
131+
// Such tests may need to be changed in one of the following ways:
132+
// * Use a signal other than SIGUSR1 (e.g. test_stress_delivery_simultaneous in
133+
// test_signal.py).
134+
// * Send the signal to a specific thread rather than the whole process (e.g.
135+
// test_signals in test_threadsignals.py.
136+
sigset_t set;
137+
if (sigemptyset(&set)) {
138+
return "sigemptyset";
139+
}
140+
if (sigaddset(&set, SIGUSR1)) {
141+
return "sigaddset";
142+
}
143+
if ((errno = pthread_sigmask(SIG_UNBLOCK, &set, NULL))) {
144+
return "pthread_sigmask";
145+
}
146+
return NULL;
117147
}
118148

119149
static void throw_status(JNIEnv *env, PyStatus status) {
120150
throw_runtime_exception(env, status.err_msg ? status.err_msg : "");
121151
}
122152

123153
JNIEXPORT int JNICALL Java_org_python_testbed_PythonTestRunner_runPython(
124-
JNIEnv *env, jobject obj, jstring home, jstring runModule
154+
JNIEnv *env, jobject obj, jstring home, jarray args
125155
) {
156+
const char *home_utf8 = (*env)->GetStringUTFChars(env, home, NULL);
157+
char cwd[PATH_MAX];
158+
snprintf(cwd, sizeof(cwd), "%s/%s", home_utf8, "cwd");
159+
if (chdir(cwd)) {
160+
throw_errno(env, "chdir");
161+
return 1;
162+
}
163+
164+
char *error_prefix;
165+
if ((error_prefix = init_signals())) {
166+
throw_errno(env, error_prefix);
167+
return 1;
168+
}
169+
126170
PyConfig config;
127171
PyStatus status;
128-
PyConfig_InitIsolatedConfig(&config);
172+
PyConfig_InitPythonConfig(&config);
129173

130-
status = set_config_string(env, &config, &config.home, home);
131-
if (PyStatus_Exception(status)) {
174+
jsize argc = (*env)->GetArrayLength(env, args);
175+
const char *argv[argc + 1];
176+
for (int i = 0; i < argc; i++) {
177+
jobject arg = (*env)->GetObjectArrayElement(env, args, i);
178+
argv[i] = (*env)->GetStringUTFChars(env, arg, NULL);
179+
}
180+
argv[argc] = NULL;
181+
182+
// PyConfig_SetBytesArgv "must be called before other methods, since the
183+
// preinitialization configuration depends on command line arguments"
184+
if (PyStatus_Exception(status = PyConfig_SetBytesArgv(&config, argc, (char**)argv))) {
132185
throw_status(env, status);
133186
return 1;
134187
}
135188

136-
status = set_config_string(env, &config, &config.run_module, runModule);
189+
status = PyConfig_SetBytesString(&config, &config.home, home_utf8);
137190
if (PyStatus_Exception(status)) {
138191
throw_status(env, status);
139192
return 1;
140193
}
141194

142-
// Some tests generate SIGPIPE and SIGXFSZ, which should be ignored.
143-
config.install_signal_handlers = 1;
144-
145195
status = Py_InitializeFromConfig(&config);
146196
if (PyStatus_Exception(status)) {
147197
throw_status(env, status);

0 commit comments

Comments
 (0)