Skip to content

[pycore] internal macros for accessing empty string/bytes and other singletons #123660

Closed as not planned
@picnixz

Description

@picnixz

Feature or enhancement

Proposal:

This is an issue to track the progress of using macros (for now internally) instead of using &_Py_STR(empty), &_Py_SINGLETON(bytes_empty) and &_Py_SINGLETON(tuple_empty).

Note that we already have a public API for 0/1 so I won't touch them. However, for strings and bytes, it could be better to use the global singletons instead. Note that using the public Py_GetConstant or Py_GetConstantBorrowed (it's the same anyway since those constants are immortal) is not possible because the constants being returned are first constructed using other public functions (e.g., PyUnicode_New(0, 0) which itself returns the immortal empty string singleton; in particular, you cannot make Py_GetConstantBorrow(Py_CONSTANT_EMPTY_STR) a macro and use it inside PyUnicode_New(0, 0) due to recursion issues and other compilation issues).

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions