Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Consolidate stateful C globals under a single struct (bpo-30860) #152

Closed
akruis opened this issue Mar 25, 2018 · 2 comments
Closed

Consolidate stateful C globals under a single struct (bpo-30860) #152

akruis opened this issue Mar 25, 2018 · 2 comments

Comments

@akruis
Copy link

akruis commented Mar 25, 2018

bpo-30860 consolidates global variables unter the _PyRuntime struct. We should do the same for Stackless globals. See https://bugs.python.org/issue30860 for details.

@akruis akruis added this to the v3.7.x-slp milestone Mar 25, 2018
akruis pushed a commit that referenced this issue Oct 14, 2018
Preparations:
- use meaningful variable names
- remove dead code
- move the stackless addition to PyThreadState to the end of the struct
- remove redundant declarations from stackless_structs.h
akruis pushed a commit that referenced this issue Oct 14, 2018
Add legitimate globals to ignored-globals.txt. All other Stackless
globals should be moved to runtime or interpreter state.
akruis pushed a commit that referenced this issue Oct 14, 2018
It was only used during module initialization.
akruis pushed a commit that referenced this issue Oct 14, 2018
…nd interpreter state

Add struct _stackless_runtime_state to _PyRuntimeState and
PyStacklessInterpreterState to PyInterpreterState. For now both structs
are empty. I'll move Stackless globals into them.
akruis pushed a commit that referenced this issue Oct 14, 2018
Add sub-struct transfer to _PyRuntime.st.
akruis pushed a commit that referenced this issue Oct 14, 2018
…erpreterState

The variable holds a complex callable object, which must not be
shared between different interpreters.
@akruis
Copy link
Author

akruis commented Oct 14, 2018

I just merged pull request #153, but the task is not yet completed.
$ ./python Tools/c-globals/check-c-globals.py still emits a few lines related to Stackless:

  # filename: Stackless/module/channelobject.c
                        NAME                          EXTERNAL   CAPI    SCOPE  
---------------------------------------------------- ---------- ------ ---------
 channel_hook                                                                   
---------------------------------------------------- ---------- ------ ---------

  # filename: Stackless/module/stacklessmodule.c
                        NAME                          EXTERNAL   CAPI    SCOPE  
---------------------------------------------------- ---------- ------ ---------
 slp_error_handler                                                              
---------------------------------------------------- ---------- ------ ---------

  # filename: ~???~
                        NAME                          EXTERNAL   CAPI    SCOPE  
---------------------------------------------------- ---------- ------ ---------
 _Py_CheckRecursionLimit                                 X        X             
 _Py_RefTotal                                            X        X             
 slp_cstack_chain                                        X                      
 slp_enable_softswitch                                   X                      
 slp_initial_tstate                                      X                      
 _slp_schedule_fasthook                                  X                      
 _slp_schedule_hook                                      X                      
 slp_try_stackless                                       X                      
---------------------------------------------------- ---------- ------ ---------

akruis pushed a commit that referenced this issue Oct 17, 2018
Removed globals:
- slp_initial_tstate
- channel_hook
- slp_error_handler
- _slp_schedule_fasthook
- _slp_schedule_hook
- slp_cstack_chain
- mem_bomb

Additionally I optimized the ordering of the fields of PyStacklessState
and PyStacklessInterpreterState to avoid padding.
akruis pushed a commit that referenced this issue Oct 17, 2018
Move slp_enable_softswitch to PyStacklessInterpreterState.
Move slp_try_stackless, cstack_cache and cstack_cachecount to
struct _stackless_runtime_state.
@akruis
Copy link
Author

akruis commented Oct 17, 2018

Finally I consolidated all stateful C globals of Stackless into runtime- or interpreter state.

Moved to _PyRuntimeState.st (st is a struct _stackless_runtime_state):

  • Globals used during hard C-stack switching in slp_transfer() to _PyRuntimeState.st.transfer
  • Global slp_try_stackless to _PyRuntimeState.st.try_stackless
  • Static global cstack_cache to _PyRuntimeState.st.cstack_cache
  • Static global cstack_cachecount to _PyRuntimeState.st.cstack_cachecount

Moved to struct PyStacklessInterpreterState:

  • Global slp_enable_softswitch to field .enable_softswitch.
  • Global slp_initial_tstate to field .initial_tstate.
  • Static global channel_hook to field .channel_hook.
  • Static global slp_error_handler to field .error_handler.
  • Global _slp_schedule_fasthook to field .schedule_fasthook.
  • Global _slp_schedule_hook to field .schedule_hook.
  • Global slp_cstack_chain to field .cstack_chain.
  • Static global mem_bomb to field .mem_bomb.
  • Static global reduce_frame_func to field .reduce_frame_func.

As a consequence I had to change internal API: the STACKLESS_PROPOSE*-macros to require the thread state as first parameter. (The STACKLESS_PROMOTE*-macros, which are more likely to be used by extension modules, did not change.)

@akruis akruis closed this as completed Oct 17, 2018
akruis pushed a commit that referenced this issue Nov 1, 2018
Introduced by commit 6e1250a / issue #152.
akruis pushed a commit that referenced this issue Nov 11, 2018
The commit used a C11 feature. Unfortunately only clang emits a warning.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant