8000 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
Apply suggestions from code review
Co-authored-by: Victor Stinner <vstinner@python.org>
  • Loading branch information
pablogsal and vstinner authored May 1, 2024
commit 4a96b8b855368dc9ec3ddaf5c476f0522d32d658
2 changes: 1 addition & 1 deletion Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ Python-level trace functions in previous versions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to add a new section and just put the "versionadded:: 3.13" just after.

Example: "Reference Tracing".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

.. c:type:: int (*PyRefTracer)(PyObject *, int event, void* data)

The type of the trace function registered using :c:func:`PyRefTracer_SetTracer`
The type of the trace function registered using :c:func:`PyRefTracer_SetTracer`.
The first parameter is a Python object that has been just created (when **event**
is set to :c:data:`PyRefTracer_CREATE`) or about to be destroyed (when **event**
is set to :c:data:`PyRefTracer_DESTROY`). The **data** argument is the opaque pointer
Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ typedef struct _Py_DebugOffsets {
/* Reference tracer state */
struct _reftracer_runtime_state {
PyRefTracer tracer_func;
void* data;
void* tracer_data;
};

/* Full Python runtime state */
Expand Down Expand Up @@ -235,7 +235,7 @@ typedef struct pyruntimestate {
struct _fileutils_state fileutils;
struct _faulthandler_runtime_state faulthandler;
struct _tracemalloc_runtime_state tracemalloc;
struct _reftracer_runtime_state reftracer;
struct _reftracer_runtime_state ref_tracer;

// The rwmutex is used to prevent overlapping global and per-interpreter
// stop-the-world events. Global stop-the-world events lock the mutex
Expand Down
4 changes: 2 additions & 2 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3292,7 +3292,7 @@ struct simpletracer_data {

static int _simpletracer(PyObject *obj, PyRefTracerEvent event, void* data) {
struct simpletracer_data* the_data = (struct simpletracer_data*)data;
assert(the_data->create_count + the_data->destroy_count < 10);
assert(the_data->create_count + the_data->destroy_count < Py_ARRAY_LENGTH(the_data->addresses));
the_data->addresses[the_data->create_count + the_data->destroy_count] = obj;
if (event == PyRefTracer_CREATE) {
the_data->create_count++;
Expand All @@ -3306,7 +3306,7 @@ static PyObject *
test_reftracer(PyObject *ob, PyObject *Py_UNUSED(ignored))
{
struct simpletracer_data tracer_data = {0};
void* the_data = (void*)&tracer_data;
void* the_data = &tracer_data;
// Install a simple tracer function
PyRefTracer_SetTracer(_simpletracer, the_data);

Expand Down
0