https://github.com/python/cpython/commit/14b43d4d3c59b552b275dd4e85552ef005b5fddf
commit: 14b43d4d3c59b552b275dd4e85552ef005b5fddf
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-10-20T13:15:57-05:00
summary:
gh-159603: Call pthread_attr_init() in hardware_stack_limits() (#159857)
Always call pthread_attr_init() in hardware_stack_limits(), not only
on FreeBSD (if pthread_attr_get_np() is available).
Emscripten: add pthread_attr_init() workaround.
files:
M Python/ceval.c
diff --git a/Python/ceval.c b/Python/ceval.c
index d63dffdd789d56..2b8c425789c039 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -79,6 +79,7 @@ _Py_ReachedRecursionLimitWithMargin(PyThreadState *tstate,
int margin_count)
#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
@@ -91,6 +92,11 @@ typedef struct {
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) {
@@ -158,11 +164,12 @@ hardware_stack_limits(uintptr_t *base, uintptr_t *top,
uintptr_t sp)
size_t stack_size, guard_size;
void *stack_addr;
pthread_attr_t attr;
-#ifdef _Py_HAVE_PTHREAD_ATTR_GET_NP
+
int err = pthread_attr_init(&attr);
+#ifdef _Py_HAVE_PTHREAD_ATTR_GET_NP
err |= pthread_attr_get_np(pthread_self(), &attr);
#else
- int err = pthread_getattr_np(pthread_self(), &attr);
+ err |= pthread_getattr_np(pthread_self(), &attr);
#endif
if (err == 0) {
err = pthread_attr_getguardsize(&attr, &guard_size);
@@ -175,6 +182,7 @@ hardware_stack_limits(uintptr_t *base, uintptr_t *top,
uintptr_t sp)
return;
}
# endif
+
// Add some space for caller function then round to minimum page size
// This is a guess at the top of the stack, but should be a reasonably
// good guess if called from _PyThreadState_Attach when creating a thread.
_______________________________________________
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]