Visitar URL original
Add API to allow extensions to set callback function on creation and destruction of PyCodeObject · Issue #91054 · python/cpython · GitHub
Skip to content

Add API to allow extensions to set callback function on creation and destruction of PyCodeObject #91054

Description

@mpage
mannequin
BPO 46898
Nosy @carljm, @DinoV, @itamaro, @mpage

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2022-03-01.22:20:58.520>
labels = ['expert-C-API', 'type-feature', '3.11']
title = 'Add API to allow extensions to set callback function on creation and destruction of PyCodeObject'
updated_at = <Date 2022-03-01.22:20:58.520>
user = 'https://github.com/mpage'

bugs.python.org fields:

activity = <Date 2022-03-01.22:20:58.520>
actor = 'mpage'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['C API']
creation = <Date 2022-03-01.22:20:58.520>
creator = 'mpage'
dependencies = []
files = []
hgrepos = []
issue_num = 46898
keywords = []
message_count = 1.0
messages = ['414309']
nosy_count = 4.0
nosy_names = ['carljm', 'dino.viehland', 'itamaro', 'mpage']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue46898'
versions = ['Python 3.11']

Linked PRs

Activity

  1. mpage commented on Mar 1, 2022

    mpagemannequin
    MannequinAuthor

    CPython extensions providing optimized execution of Python bytecode (e.g. the Cinder JIT) may need to hook into the lifecycle of code objects to determine what to optimize or to free resources allocated for code objects that no longer exist. We propose adding an API to allow extensions to set callbacks that will be invoked whenever code objects are created or destroyed.

    Proposed API:

    typedef enum {
      PYCODE_LCEVT_CREATED,
      PYCODE_LCEVT_DESTROYED
    } PyCode_LifecycleEvent;
    
    // A callback to be called when a code object is created or about to be destroyed.
    typedef void(*PyCode_LifecycleCallback)(
      PyCode_LifecycleEvent event,
      PyCodeObject* code);
    
    void PyCode_SetLifecycleCallback(PyCode_LifecycleCallback callback);
    PyCode_LifecycleCallback PyCode_GetLifecycleCallback();
    
    
  2. transferred this issue fromon Apr 10, 2022
  3. gvanrossum commented on Sep 15, 2022

    @gvanrossum
    Member

    In which header file would you put that? Maybe this is simple enough that you should just submit a PR?

  4. itamaro commented on Sep 15, 2022

    @itamaro
    Contributor

    In which header file would you put that?

    would Include/cpython/code.h make sense for this API?

    Maybe this is simple enough that you should just submit a PR?

    hopefully yes, we intend to do that for 3.12.
    does the proposed API look reasonable?

  5. added
    3.12only security fixes
    and removed
    3.11only security fixes
    on Sep 24, 2022
  6. gvanrossum commented on Sep 24, 2022

    @gvanrossum
    Member

    The API looks reasonable -- I'd spell LifeCycle with two capital letters (though Wikipedia seems divided on this), and I'd start the enum values with PY_CODE, similar to _PyCodeLocationInfoKind in the same file. The implementation would seem straightforward, and code objects aren't created or destroyed at a monstrous rate (it might be worth seeing if this slows down unmarshalling noticeably, but I doubt it). The callback should probably be stored in the per-interpreter state.

  7. added 4 commits that reference this issue on Nov 23, 2022
  8. added a commit that references this issue on Dec 2, 2022
  9. added a commit that references this issue on Dec 3, 2022
  10. pablogsal commented on Dec 3, 2022

    @pablogsal
    Member

    Unfotunately, there are many buildbots failing to build this PR. Check buildbot.python.org/all/#/release_status for reference

    As per our buildbot policy, this PR will be reverted if the buildbot fleet is not fixed in the next 24h. @markshannon @itamaro can you please take a look?

    I have opened #99976. I will close it if the issue is fixed before the deadline.

  11. added a commit that references this issue on Dec 3, 2022
  12. added a commit that references this issue on Dec 4, 2022
  13. itamaro commented on Dec 4, 2022

    @itamaro
    Contributor

    this issue can be closed now!

  14. added 3 commits that reference this issue on Aug 9, 2023
  15. added a commit that references this issue on Aug 10, 2023
  16. added a commit that references this issue on Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions