gh-110481: Fix Py_SET_REFCNT() integer overflow (#112174)

If Py_NOGIL is defined and Py_SET_REFCNT() is called with a reference
count larger than UINT32_MAX, make the object immortal.

Set _Py_IMMORTAL_REFCNT constant type to Py_ssize_t to fix the
following compiler warning:

Include/internal/pycore_global_objects_fini_generated.h:14:24:
warning: comparison of integers of different signs: 'Py_ssize_t'
(aka 'long') and 'unsigned int' [-Wsign-compare]

    if (Py_REFCNT(obj) < _Py_IMMORTAL_REFCNT) {
        ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~
This commit is contained in:
Victor Stinner 2023-12-01 15:50:16 +01:00 committed by GitHub
parent c2982380f8
commit 5f6ac2d88a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 10 deletions

View file

@ -287,6 +287,8 @@ General Options
.. versionadded:: 3.11
.. _free-threading-build:
.. option:: --disable-gil
Enables **experimental** support for running Python without the