Skip to content
Merged
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
bpo-28254: Add documentation for the PyGC_*() functions.
  • Loading branch information
scoder committed Apr 28, 2021
commit 0f7e6088301597afccee6b5a1d61f04774c4ae11
40 changes: 40 additions & 0 deletions Doc/c-api/gcsupport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,43 @@ if the object is immutable.
this method (don't just call :c:func:`Py_DECREF` on a reference). The
collector will call this method if it detects that this object is involved
in a reference cycle.


Controlling the Garbage Collector State
---------------------------------------

The C-API provides the following functions for controlling
garbage collection runs.

Comment thread
scoder marked this conversation as resolved.
.. c:function:: Py_ssize_t PyGC_Collect(void)

Performs a garbage collection, if the garbage collector is enabled.
Comment thread
scoder marked this conversation as resolved.
Outdated
Returns the number of collected + uncollectable objects.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hum, uncollectable objects are stored in gc.garbage no? Shoud we document that?

The C code uses "unreachable objects that couldn't be collected" in a comment instead of "uncollectable objects". Maybe it's a more explicit definition.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think this C-API function is the right place to document these details. That's what the gc module is for.

If the garbage collector is disabled or already running,
returns ``0`` immediately.
Comment thread
scoder marked this conversation as resolved.
Outdated
Errors during garbage collection are ignored and printed.
Comment thread
scoder marked this conversation as resolved.
Outdated
This function does not raise exceptions.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@pablogsal: Do we want to document that it's safe to call this function with an exception raised, and that the exception is saved and then restored?



.. c:function:: int PyGC_Enable(void)

Enable the garbage collector.
Comment thread
scoder marked this conversation as resolved.
Outdated
Returns the previous state, 0 for disabled and 1 for enabled.

.. versionchanged:: 3.10
Comment thread
scoder marked this conversation as resolved.
Outdated


.. c:function:: int PyGC_Disable(void)

Disable the garbage collector.
Comment thread
scoder marked this conversation as resolved.
Outdated
Returns the previous state, 0 for disabled and 1 for enabled.

.. versionchanged:: 3.10


.. c:function:: int PyGC_IsEnabled(void)

Queries the state of the garbage collector.
Returns the current state, 0 for disabled and 1 for enabled.

.. versionchanged:: 3.10