Skip to content
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

Multiphase module initialization #393

Merged
merged 3 commits into from
Jan 31, 2023

Commits on Jan 31, 2023

  1. Multiphase module initialization

    Make the multiphase module initialization the only way to initialize HPy
    modules, abandons the previous single phase initialization.
    
    HPy_MODINIT takes name of the extesion, so that it can generate
    PyInit_XXX for CPython, and HPyModuleDef. There is no user provided init
    function anymore. The runtime initializes the module and if the user wants
    to populate the module, or do any other initialization, they can define one
    or more HPy_mod_exec slots that are called by the runtime right after
    the module is created. The slots are defined in the same way as slots
    for types: by using HPyDef_SLOT macro.
    
    As a consequence, `HPy_MODINIT(myextension, hpydef)` is all that is necessary
    if the module only exposes module functions.
    
    Users can also define `HPy_mod_create` slot, similar to CPython's
    `Py_mod_create`, but in HPy this slot can return only objects that are not
    of the builtin module type.
    
    The reasoning is that builtin module objects can be created by the runtime
    from `HPyModuleDef` and, for the time being, there is no use-case for
    manually creating builtin module objects in the `HPy_mod_create` slot or
    anywhere else. If such a use-case emerges, support for it can be easily
    added to HPy.
    
    If user specifies the `HPy_mod_create slot`, specifying anything else
    (setting it to a non-default value) in `HPyModuleDef` is an error.
    
    Removes `HPyModule_Create` API/ABI function. The CPython equivalent
    `PyModule_Create` works only for single phase module initialization.
    We may add equivalents of `PyModule_FromDefAndSpec` to allow manual
    module creation if there is a use-case.
    
    Additionally, removes the CPython semantics of negative `m_size`. HPy
    will add other more explicit means to communicate subinterpreters
    support.
    steve-s committed Jan 31, 2023
    Configuration menu
    Copy the full SHA
    c1464c1 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    4d9ca6b View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    d7daa8f View commit details
    Browse the repository at this point in the history