Skip to content

Commit 40c9ea5

Browse files
committed
Handle variable-held complete programs in link_check transpiler.
1 parent 9d36838 commit 40c9ea5

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

Tools/configure/configure.awk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8325,7 +8325,7 @@ function u_setup_pthreads( ac_cv_cxx_thread, ac_cv_kpthread, ac_cv_kthread, a
83258325
pyconf_result(unistd_defines_pthreads)
83268326
prog = "#include <stdio.h>\n#include <stdlib.h>\n#include <pthread.h>\nvoid *start_routine(void *arg) { exit(0); }\nint main(void) { pthread_create(NULL, NULL, start_routine, NULL); return 0; }\n"
83278327
pyconf_checking("for pthread_create in -lpthread")
8328-
if (pyconf_link_check("", prog "\nint main(void) { return 0; }", "-lpthread")) {
8328+
if (pyconf_link_check("", (index(prog, "int main") ? prog : prog "\nint main(void) { return 0; }"), "-lpthread")) {
83298329
pyconf_result("yes")
83308330
V["LIBS"] = V["LIBS"] " -lpthread"
83318331
V["posix_threads"] = "yes"

Tools/configure/transpiler/pysh_to_awk.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2760,10 +2760,21 @@ def _build_link_check_call(self, method: str, call: Call) -> A.FuncCall:
27602760
elif len(positional) == 1:
27612761
if _is_complete_program(positional[0]):
27622762
source = self._expr(positional[0])
2763-
else:
2763+
elif isinstance(positional[0], Const):
27642764
source = self._build_check_source(
27652765
inc_lines, self._expr(positional[0]), None
27662766
)
2767+
else:
2768+
# Variable — might be a complete program at runtime.
2769+
# Emit a runtime check mirroring Python link_check's
2770+
# prologue_is_source detection.
2771+
var_expr = self._expr(positional[0])
2772+
wrapped = self._build_check_source(inc_lines, var_expr, None)
2773+
source = A.Ternary(
2774+
A.FuncCall("index", [var_expr, A.StringLit("int main")]),
2775+
var_expr,
2776+
wrapped,
2777+
)
27672778

27682779
# If includes was a variable, prepend runtime-generated #include lines
27692780
if includes_expr is not None:

0 commit comments

Comments
 (0)