https://github.com/python/cpython/commit/67683da0ec8368c302569ff87af30fa1da2f873b
commit: 67683da0ec8368c302569ff87af30fa1da2f873b
branch: main
author: Pengyu Lee <[email protected]>
committer: freakboy3742 <[email protected]>
date: 2026-11-02T13:50:10+08:00
summary:

gh-160873: Remove obsolete pthread_getattr_np workaround (#160902)

Removes a workaround that was needed for older versions of Emscripten, 
but is no longer required. Also adapts to new command line arguments for
enabling threading.

files:
M Platforms/emscripten/README.md
M Python/ceval.c
M configure
M configure.ac

diff --git a/Platforms/emscripten/README.md b/Platforms/emscripten/README.md
index ce230c4b74a2738..b1fccea0af9f87b 100644
--- a/Platforms/emscripten/README.md
+++ b/Platforms/emscripten/README.md
@@ -138,7 +138,7 @@ await createEmscriptenModule({
 
 - Threading is disabled by default. The ``configure`` option
   ``--enable-wasm-pthreads`` adds compiler flag ``-pthread`` and
-  linker flags ``-sUSE_PTHREADS -sPROXY_TO_PTHREAD``.
+  linker flags ``-pthread -sPROXY_TO_PTHREAD``.
 - pthread support requires WASM threads and SharedArrayBuffer (bulk memory).
   The Node.JS runtime keeps a pool of web workers around. Each web worker
   uses several file descriptors (eventfd, epoll, pipe).
diff --git a/Python/ceval.c b/Python/ceval.c
index aba8d2c0c762edf..0d053cdc7a63e34 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -70,70 +70,6 @@ _Py_ReachedRecursionLimitWithMargin(PyThreadState *tstate, 
int margin_count)
 #  define Py_C_STACK_SIZE 4000000
 #endif
 
-#if defined(__EMSCRIPTEN__)
-
-// Temporary workaround to make `pthread_getattr_np` work on Emscripten.
-// Emscripten 4.0.6 will contain a fix:
-// https://github.com/emscripten-core/emscripten/pull/23887
-
-#include "emscripten/stack.h"
-
-#define pthread_attr_t workaround_pthread_attr_t
-#define pthread_attr_init workaround_pthread_attr_init
-#define pthread_getattr_np workaround_pthread_getattr_np
-#define pthread_attr_getguardsize workaround_pthread_attr_getguardsize
-#define pthread_attr_getstack workaround_pthread_attr_getstack
-#define pthread_attr_destroy workaround_pthread_attr_destroy
-
-typedef struct {
-    void *_a_stackaddr;
-    size_t _a_stacksize, _a_guardsize;
-} pthread_attr_t;
-
-extern __attribute__((__visibility__("hidden"))) unsigned __default_guardsize;
-
-int pthread_attr_init(pthread_attr_t *a)
-{
-       return 0;
-}
-
-// Modified version of pthread_getattr_np from the upstream PR.
-
-int pthread_getattr_np(pthread_t thread, pthread_attr_t *attr) {
-  attr->_a_stackaddr = (void*)emscripten_stack_get_base();
-  attr->_a_stacksize = emscripten_stack_get_base() - 
emscripten_stack_get_end();
-  attr->_a_guardsize = __default_guardsize;
-  return 0;
-}
-
-// These three functions copied without any changes from Emscripten libc.
-
-int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t 
*restrict size)
-{
-       *size = a->_a_guardsize;
-       return 0;
-}
-
-int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict 
addr, size_t *restrict size)
-{
-/// XXX musl is not standard-conforming? It should not report EINVAL if 
_a_stackaddr is zero, and it should
-///     report EINVAL if a is null: 
http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_attr_getstack.html
-       if (!a) return EINVAL;
-//     if (!a->_a_stackaddr)
-//             return EINVAL;
-
-       *size = a->_a_stacksize;
-       *addr = (void *)(a->_a_stackaddr - *size);
-       return 0;
-}
-
-int pthread_attr_destroy(pthread_attr_t *a)
-{
-       return 0;
-}
-
-#endif
-
 static void
 hardware_stack_limits(uintptr_t *base, uintptr_t *top, uintptr_t sp)
 {
diff --git a/configure b/configure
index 1b81c6022bfbfdb..f85f487e0249d67 100755
--- a/configure
+++ b/configure
@@ -5055,8 +5055,8 @@ fi
 case $host in #(
   wasm64-*-emscripten) :
 
-    as_fn_append CFLAGS " -sMEMORY64=1"
-    as_fn_append LDFLAGS " -sMEMORY64=1"
+    as_fn_append CFLAGS " -m64"
+    as_fn_append LDFLAGS " -m64"
    ;; #(
   *) :
      ;;
@@ -10229,7 +10229,7 @@ fi
 then :
 
       as_fn_append CFLAGS_NODIST " -pthread"
-      as_fn_append LDFLAGS_NODIST " -sUSE_PTHREADS"
+      as_fn_append LDFLAGS_NODIST " -pthread"
       as_fn_append LINKFORSHARED " -sPROXY_TO_PTHREAD"
 
 fi
diff --git a/configure.ac b/configure.ac
index fa076d486c29607..4b8e6d59a5cf46d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1153,12 +1153,12 @@ if test -z "$CFLAGS"; then
 fi
 
 dnl Emscripten SDK and WASI SDK default to wasm32.
-dnl On Emscripten use MEMORY64 setting to build target wasm64-emscripten.
+dnl On Emscripten use -m64 to build target wasm64-emscripten.
 dnl for wasm64.
 AS_CASE([$host],
   [wasm64-*-emscripten], [
-    AS_VAR_APPEND([CFLAGS], [" -sMEMORY64=1"])
-    AS_VAR_APPEND([LDFLAGS], [" -sMEMORY64=1"])
+    AS_VAR_APPEND([CFLAGS], [" -m64"])
+    AS_VAR_APPEND([LDFLAGS], [" -m64"])
   ],
 )
 
@@ -2659,7 +2659,7 @@ AS_CASE([$ac_sys_system],
 
     AS_VAR_IF([enable_wasm_pthreads], [yes], [
       AS_VAR_APPEND([CFLAGS_NODIST], [" -pthread"])
-      AS_VAR_APPEND([LDFLAGS_NODIST], [" -sUSE_PTHREADS"])
+      AS_VAR_APPEND([LDFLAGS_NODIST], [" -pthread"])
       AS_VAR_APPEND([LINKFORSHARED], [" -sPROXY_TO_PTHREAD"])
     ])
     dnl not completely sure whether or not we want -sEXIT_RUNTIME, keeping it 
for now.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to