10000 gh-93502: Add new C-API functions to trace object creation and destruction by pablogsal · Pull Request #115945 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-93502: Add new C-API functions to trace object creation and destruction #115945

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

Merged
merged 10 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improve docs
  • Loading branch information
pablogsal committed May 1, 2024
commit a326f3f087c4e7b52e2dbee57d56e49e76ce30cf
26 changes: 15 additions & 11 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1925,23 +1925,27 @@ Python-level trace functions in previous versions.
object has been destroyed.

.. c:function:: int PyRefTracer_SetTracer(PyRefTracer tracer, void *data)

Register a reference tracer function. The function will be called when a new Python
has been created or when an object is going to be destroyed. If **data** is provided
it must be an opaque pointer that will be provided when the tracer function is called.

Not that tracer functions **must not** create Python objects inside or otherwise the
call will be re-entrant.


Register a reference tracer function. The function will be called when a new
Python has been created or when an object is going to be destroyed. If
**data** is provided it must be an opaque pointer that will be provided when
the tracer function is called.

Not that tracer functions **must not** create Python objects inside or
otherwise the call will be re-entrant. The tracer also **must not** clear
any existing exception or set an exception. The GIL will be held every time
the tracer function is called.

The GIL must be held when calling this function.

.. versionadded:: 3.13

.. c:function:: PyRefTracer PyRefTracer_GetTracer(void** data)

Get the registered reference tracer function and the value of the opaque data pointer that
was registered when :c:func:`PyRefTracer_SetTracer` was called. If no tracer was registered
this function will return NULL and will set the **data** pointer to NULL.
Get the registered reference tracer function and the value of the opaque data
pointer that was registered when :c:func:`PyRefTracer_SetTracer` was called.
If no tracer was registered this function will return NULL and will set the
**data** pointer to NULL.

The GIL must be held when calling this function.

Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,11 @@ New Features
* Add :c:func:`PyType_GetModuleByDef` to the limited C API
(Contributed by Victor Stinner in :gh:`116936`.)

* Add two new functions to the C-API, :c:func:`PyRefTracer_SetTracer` and
:c:func:`PyRefTracer_GetTracer`, that allows to track object creation and
destruction the same way the :mod:`tracemalloc` module does. (Contributed
by Pablo Galindo in :gh:`93502`.)


Porting to Python 3.13
----------------------
Expand Down
0