Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add a public C-API function to iterate over GC’able objects #102013

Closed
Labels
@jbower-fb

Description

@jbower-fb

Feature or enhancement

An API similar to:

/* Visit all live GC-capable objects, similar to gc.get_objects(None).** Users should avoid allocating or deallocating objects on the Python heap in* the callback. */typedef void (*gcvisitobjects_t)(PyObject *, void *);PyAPI_FUNC(void) PyGC_VisitObjects(gcvisitobjects_t callback, void *arg);

Which could be used as:

void count_functions(PyObject *op, void *arg) {  if (PyFunction_Check(op)) {    (*(int*)arg)++;  }}int get_num_functions() {  int count;  PyGC_VisitObjects(count_functions, &count);  return count;}

Pitch

We have a version of this inCinder already and right now and use it toidentify all generator objects so they can be de-opted when our JIT is shutdown. In future we plan to use it for things like discovering existing PyFunction objects, and then usinggh-91049 to mark them as JIT’able. This could facilitate loading the JIT feature at a later time (e.g. as part of a module).

[Edited] In general, there already exists a Python API for iterating over GC’able objects viagc.get_objects(), however there is no good way of doing this from native extensions. While it is technically possible to import thegc module and extract thegc_objects function in C this is cumbersome, and more importantly might lead to unexpected behavior if Python code has replaced thegc_objects function.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp