Skip to content
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
encukou and vstinner authored Mar 19, 2026
commit 30a602fed19bf733e0f5700aa808f674c3e429c0
9 changes: 6 additions & 3 deletions Doc/c-api/gcsupport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ The :c:member:`~PyTypeObject.tp_traverse` handler must have the following type:
:c:member:`~PyTypeObject.tp_flags` field, the traverse function must call
:c:func:`PyObject_VisitManagedDict` like this::

PyObject_VisitManagedDict((PyObject*)self, visit, arg);
int err = PyObject_VisitManagedDict((PyObject*)self, visit, arg);
if (err) {
return err;
}

Only the members that the instance *owns* (by having
:term:`strong references <strong reference>` to them) must be
Expand Down Expand Up @@ -382,14 +385,14 @@ The following functions and macros are safe to use in a
"DuringGC" functions
^^^^^^^^^^^^^^^^^^^^

The following functions should *only* used in a
The following functions should *only* be used in a
:c:member:`~PyTypeObject.tp_traverse` handler; calling them in other
contexts may have unintended consequences.

These functions act like their counterparts without the ``_DuringGC`` suffix,
but they are guaranteed to not have side effects, they do not set an exception
on failure, and they return/set :term:`borrowed references <borrowed reference>`
as detailed in the individual documentation..
as detailed in the individual documentation.

Note that these functions may fail (return ``NULL`` or ``-1``),
but as they do not set an exception, no error information is available.
Expand Down
2 changes: 1 addition & 1 deletion Modules/_testcapi/heaptype.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@
pytype_getmodulebydef(PyObject *self, PyObject *type)
{
PyObject *mod = PyType_GetModuleByDef((PyTypeObject *)type, _testcapimodule);
assert(mod == PyType_GetModuleByDef((PyTypeObject *)type, _testcapimodule));
assert(mod == PyType_GetModuleByDef_DuringGC((PyTypeObject *)type, _testcapimodule));

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (x64)

'==': 'PyObject *' differs in levels of indirection from 'int' [D:\a\cpython\cpython\PCbuild\_testcapi.vcxproj]

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (x64)

'PyType_GetModuleByDef_DuringGC' undefined; assuming extern returning int [D:\a\cpython\cpython\PCbuild\_testcapi.vcxproj]

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

comparison between pointer and integer

Check failure on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

implicit declaration of function ‘PyType_GetModuleByDef_DuringGC’; did you mean ‘PyType_GetModuleByToken_DuringGC’? [-Werror=implicit-function-declaration]

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'==': 'PyObject *' differs in levels of indirection from 'int' [D:\a\cpython\cpython\PCbuild\_testcapi.vcxproj]

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'PyType_GetModuleByDef_DuringGC' undefined; assuming extern returning int [D:\a\cpython\cpython\PCbuild\_testcapi.vcxproj]

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04)

comparison between pointer and integer

Check failure on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04)

implicit declaration of function ‘PyType_GetModuleByDef_DuringGC’; did you mean ‘PyType_GetModuleByToken_DuringGC’? [-Werror=implicit-function-declaration]

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

comparison between pointer and integer

Check failure on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

implicit declaration of function ‘PyType_GetModuleByDef_DuringGC’; did you mean ‘PyType_GetModuleByToken_DuringGC’? [-Werror=implicit-function-declaration]

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04-arm)

comparison between pointer and integer

Check failure on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04-arm)

implicit declaration of function ‘PyType_GetModuleByDef_DuringGC’; did you mean ‘PyType_GetModuleByToken_DuringGC’? [-Werror=implicit-function-declaration]

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04-arm)

comparison between pointer and integer

Check failure on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04-arm)

implicit declaration of function ‘PyType_GetModuleByDef_DuringGC’; did you mean ‘PyType_GetModuleByToken_DuringGC’? [-Werror=implicit-function-declaration]

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Ubuntu (bolt) / build and test (ubuntu-24.04)

comparison between pointer and integer

Check failure on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Ubuntu (bolt) / build and test (ubuntu-24.04)

implicit declaration of function ‘PyType_GetModuleByDef_DuringGC’; did you mean ‘PyType_GetModuleByToken_DuringGC’? [-Werror=implicit-function-declaration]

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Cross build Linux

comparison between pointer and integer

Check failure on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Cross build Linux

implicit declaration of function ‘PyType_GetModuleByDef_DuringGC’; did you mean ‘PyType_GetModuleByToken_DuringGC’? [-Werror=implicit-function-declaration]

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'==': 'PyObject *' differs in levels of indirection from 'int' [C:\a\cpython\cpython\PCbuild\_testcapi.vcxproj]

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'PyType_GetModuleByDef_DuringGC' undefined; assuming extern returning int [C:\a\cpython\cpython\PCbuild\_testcapi.vcxproj]

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

comparison between pointer and integer

Check failure on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

implicit declaration of function ‘PyType_GetModuleByDef_DuringGC’; did you mean ‘PyType_GetModuleByToken_DuringGC’? [-Werror=implicit-function-declaration]

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (arm64)

'==': 'PyObject *' differs in levels of indirection from 'int' [C:\a\cpython\cpython\PCbuild\_testcapi.vcxproj]

Check warning on line 540 in Modules/_testcapi/heaptype.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (arm64)

'PyType_GetModuleByDef_DuringGC' undefined; assuming extern returning int [C:\a\cpython\cpython\PCbuild\_testcapi.vcxproj]
return Py_XNewRef(mod);
}

Expand Down
3 changes: 0 additions & 3 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5745,9 +5745,6 @@ PyType_GetModule_DuringGC(PyTypeObject *type)
return NULL;
}
PyHeapTypeObject* et = (PyHeapTypeObject*)type;
if (!et->ht_module) {
return NULL;
}
return et->ht_module;
}

Expand Down
Loading