Skip to content

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Oct 6, 2025

Add PyUnstable_ThreadState_SetStack() and
PyUnstable_ThreadState_ResetStack() functions to set the stack base address and stack size of a Python thread state.


📚 Documentation preview 📚: https://cpython-previews--139668.org.readthedocs.build/

Add PyUnstable_ThreadState_SetStack() and
PyUnstable_ThreadState_ResetStack() functions to set the stack base
address and stack size of a Python thread state.
@encukou
Copy link
Member

encukou commented Oct 6, 2025

This generally matches what I came up with :)

The start argument might be confusing, as the place usage grows towards.
Why not use bottom & top as in the internals?

@vstinner
Copy link
Member Author

vstinner commented Oct 6, 2025

This generally matches what I came up with :)

Good!

The start argument might be confusing, as the place usage grows towards. Why not use bottom & top as in the internals?

APIs like make_fcontext() or sigaltstack() use void *stack_start_address and size_t stack_size.

pthread_attr_setstack() and pthread_attr_getstack() also use void *stack_start_address and size_t stack_size.

.. versionadded:: next
.. c:function:: void PyUnstable_ThreadState_ResetStack(PyThreadState *tstate)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure of this name. Maybe PyUnstable_ThreadState_InitStack() would be more explicit?

assert(ts->c_stack_soft_limit < ts->c_stack_top);

// Test the stack pointer
#if !defined(NDEBUG) && !defined(__wasi__)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertions fail on WASI but I don't have time right now to investigate why.

@vstinner
Copy link
Member Author

vstinner commented Oct 6, 2025

cc @markshannon @zooba

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants