Skip to content

Thread ID assertion in pystate.c failing under WASI #110455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brettcannon opened this issue Oct 6, 2023 · 1 comment
Closed

Thread ID assertion in pystate.c failing under WASI #110455

brettcannon opened this issue Oct 6, 2023 · 1 comment
Assignees
Labels
3.12 only security fixes 3.13 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) OS-wasi type-bug An unexpected behavior, bug, or error

Comments

@brettcannon
Copy link
Member

brettcannon commented Oct 6, 2023

Bug report

Bug description:

The following assert fails under a debug build with WASI:

assert(tstate->thread_id > 0);

It's probably due to the pthread stubs always returning 0 as the thread ID:

PyAPI_FUNC(pthread_t) pthread_self(void)
{
return 0;
}

It can probably be solved by making the assertion conditional on `HAVE_PTHREAD_STUBS not being defined:

#if !defined(HAVE_PTHREAD_STUBS)

CPython versions tested on:

CPython main branch

Operating systems tested on:

Other

Linked PRs

@brettcannon brettcannon added type-bug An unexpected behavior, bug, or error 3.12 only security fixes OS-wasi 3.13 bugs and security fixes labels Oct 6, 2023
@brettcannon
Copy link
Member Author

This fixes it:

diff --git a/Python/pystate.c b/Python/pystate.c
index dcc6c11221..f7042d0e21 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -270,7 +270,9 @@ unbind_tstate(PyThreadState *tstate)
     // XXX assert(tstate_is_alive(tstate));
     assert(tstate_is_bound(tstate));
     // XXX assert(!tstate->_status.active);
+#ifndef HAVE_PTHREAD_STUBS
     assert(tstate->thread_id > 0);
+#endif
 #ifdef PY_HAVE_THREAD_NATIVE_ID
     assert(tstate->native_thread_id > 0);
 #endif

@brettcannon brettcannon added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Oct 6, 2023
@brettcannon brettcannon self-assigned this Oct 6, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 6, 2023
…f HAVE_PTHREAD_STUBS` (pythonGH-110487)

(cherry picked from commit 5fd8821)

Co-authored-by: Brett Cannon <[email protected]>
brettcannon added a commit that referenced this issue Oct 6, 2023
…ef HAVE_PTHREAD_STUBS` (GH-110487) (GH-110491)

GH-110455: Guard `assert(tstate->thread_id > 0)` with `GH-ifndef HAVE_PTHREAD_STUBS` (GH-110487)
(cherry picked from commit 5fd8821)

Co-authored-by: Brett Cannon <[email protected]>
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 only security fixes 3.13 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) OS-wasi type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant