Skip to content

gh-155358: Convert sys structseq types to heap types - #155368

Closed
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:sys_types
Closed

gh-155358: Convert sys structseq types to heap types#155368
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:sys_types

Conversation

@vstinner

@vstinner vstinner commented Aug 7, 2026

Copy link
Copy Markdown
Member

Convert the following structseq types from static (built-in) types to heap types:

  • AsyncGenHooksType
  • Hash_InfoType
  • WindowsVersionType
  • FlagsType
  • VersionInfoType

So these types are no longer shared between sub-interpreters.

Cleanup also the EmscriptenInfoType type.

Changes:

  • Replace _PyStructSequence_InitBuiltin() with PyStructSequence_NewType() or _PyStructSequence_NewType().
  • Add PyInterpreterState.sys_state structure.
  • Rename sys.get_asyncgen_hooks() type from "asyncgen_hooks" to "sys.asyncgen_hooks".
  • Add test.support.check_immutable_type().

Convert the following structseq types from static (built-in) types to
heap types:

* AsyncGenHooksType
* Hash_InfoType
* WindowsVersionType
* FlagsType
* VersionInfoType

So these types are no longer shared between sub-interpreters.

Cleanup also the EmscriptenInfoType type.

Changes:

* Replace _PyStructSequence_InitBuiltin() with
  PyStructSequence_NewType() or _PyStructSequence_NewType().
* Add PyInterpreterState.sys_state structure.
* Rename sys.get_asyncgen_hooks() type from "asyncgen_hooks" to
  "sys.asyncgen_hooks".
* Add test.support.check_immutable_type().
@vstinner

vstinner commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

If this change is merged, it would be interesting to convert the following 4 static types to heap types as well:

Objects/floatobject.c:    if (_PyStructSequence_InitBuiltin(interp, &FloatInfoType,
Objects/longobject.c:    if (_PyStructSequence_InitBuiltin(interp, &Int_InfoType,
Python/errors.c:    if (_PyStructSequence_InitBuiltin(interp, &UnraisableHookArgsType,
Python/thread.c:    if (_PyStructSequence_InitBuiltin(interp, &ThreadInfoType, &threadinfo_desc) < 0) {

@vstinner

Copy link
Copy Markdown
Member Author

So these types are no longer shared between sub-interpreters.

I discovered later that these types are immutable, so I'm not sure that it's a big deal to share these static types between sub-interpreters.

This change is mostly needed if issue gh-155358 is accepted. For now, I prefer to close the PR, since it doesn't need to be strictly needed (if the issue is not accepted).

I already pushed the uncontroversial part of this change as a separated PR: PR gh-155510 checks that 5 sys types, such as type(sys.flags), are immutable (and add test.support.check_immutable_type() helper function).

@vstinner vstinner closed this Aug 13, 2026
@vstinner
vstinner deleted the sys_types branch August 13, 2026 10:51
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.

1 participant