Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ede0ce8

Browse filesBrowse files
authored
Merge branch 'main' into fix-issue-121284
2 parents 1da1d57 + fd545d7 commit ede0ce8
Copy full SHA for ede0ce8

File tree

Expand file treeCollapse file tree

7 files changed

+109
-65
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+109
-65
lines changed

‎Include/internal/pycore_object.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_object.h
+68Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,74 @@ _Py_DECREF_CODE(PyCodeObject *co)
430430
}
431431
#endif
432432

433+
#ifndef Py_GIL_DISABLED
434+
#ifdef Py_REF_DEBUG
435+
436+
static inline void Py_DECREF_MORTAL(const char *filename, int lineno, PyObject *op)
437+
{
438+
if (op->ob_refcnt <= 0) {
439+
_Py_NegativeRefcount(filename, lineno, op);
440+
}
441+
_Py_DECREF_STAT_INC();
442+
assert(!_Py_IsStaticImmortal(op));
443+
if (!_Py_IsImmortal(op)) {
444+
_Py_DECREF_DecRefTotal();
445+
}
446+
if (--op->ob_refcnt == 0) {
447+
#ifdef Py_TRACE_REFS
448+
_Py_ForgetReference(op);
449+
#endif
450+
_Py_Dealloc(op);
451+
}
452+
}
453+
#define Py_DECREF_MORTAL(op) Py_DECREF_MORTAL(__FILE__, __LINE__, _PyObject_CAST(op))
454+
455+
static inline void _Py_DECREF_MORTAL_SPECIALIZED(const char *filename, int lineno, PyObject *op, destructor destruct)
456+
{
457+
if (op->ob_refcnt <= 0) {
458+
_Py_NegativeRefcount(filename, lineno, op);
459+
}
460+
_Py_DECREF_STAT_INC();
461+
assert(!_Py_IsStaticImmortal(op));
462+
if (!_Py_IsImmortal(op)) {
463+
_Py_DECREF_DecRefTotal();
464+
}
465+
if (--op->ob_refcnt == 0) {
466+
#ifdef Py_TRACE_REFS
467+
_Py_ForgetReference(op);
468+
#endif
469+
_PyReftracerTrack(op, PyRefTracer_DESTROY);
470+
destruct(op);
471+
}
472+
}
473+
#define Py_DECREF_MORTAL_SPECIALIZED(op, destruct) _Py_DECREF_MORTAL_SPECIALIZED(__FILE__, __LINE__, op, destruct)
474+
475+
#else
476+
477+
static inline void Py_DECREF_MORTAL(PyObject *op)
478+
{
479+
assert(!_Py_IsStaticImmortal(op));
480+
_Py_DECREF_STAT_INC();
481+
if (--op->ob_refcnt == 0) {
482+
_Py_Dealloc(op);
483+
}
484+
}
485+
#define Py_DECREF_MORTAL(op) Py_DECREF_MORTAL(_PyObject_CAST(op))
486+
487+
static inline void Py_DECREF_MORTAL_SPECIALIZED(PyObject *op, destructor destruct)
488+
{
489+
assert(!_Py_IsStaticImmortal(op));
490+
_Py_DECREF_STAT_INC();
491+
if (--op->ob_refcnt == 0) {
492+
_PyReftracerTrack(op, PyRefTracer_DESTROY);
493+
destruct(op);
494+
}
495+
}
496+
#define Py_DECREF_MORTAL_SPECIALIZED(op, destruct) Py_DECREF_MORTAL_SPECIALIZED(_PyObject_CAST(op), destruct)
497+
498+
#endif
499+
#endif
500+
433501
/* Inline functions trading binary compatibility for speed:
434502
_PyObject_Init() is the fast version of PyObject_Init(), and
435503
_PyObject_InitVar() is the fast version of PyObject_InitVar().

‎Include/refcount.h

Copy file name to clipboardExpand all lines: Include/refcount.h
+9-60Lines changed: 9 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ having all the lower 32 bits set, which will avoid the reference count to go
4141
beyond the refcount limit. Immortality checks for reference count decreases will
4242
be done by checking the bit sign flag in the lower 32 bits.
4343
44+
To ensure that once an object becomes immortal, it remains immortal, the threshold
45+
for omitting increfs is much higher than for omitting decrefs. Consequently, once
46+
the refcount for an object exceeds _Py_IMMORTAL_MINIMUM_REFCNT it will gradually
47+
increase over time until it reaches _Py_IMMORTAL_INITIAL_REFCNT.
4448
*/
4549
#define _Py_IMMORTAL_INITIAL_REFCNT (3ULL << 30)
4650
#define _Py_IMMORTAL_MINIMUM_REFCNT (1ULL << 31)
@@ -288,7 +292,7 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
288292
}
289293
#elif SIZEOF_VOID_P > 4
290294
PY_UINT32_T cur_refcnt = op->ob_refcnt;
291-
if (((int32_t)cur_refcnt) < 0) {
295+
if (cur_refcnt >= _Py_IMMORTAL_INITIAL_REFCNT) {
292296
// the object is immortal
293297
_Py_INCREF_IMMORTAL_STAT_INC();
294298
return;
@@ -303,7 +307,10 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
303307
#endif
304308
_Py_INCREF_STAT_INC();
305309
#ifdef Py_REF_DEBUG
306-
_Py_INCREF_IncRefTotal();
310+
// Don't count the incref if the object is immortal.
311+
if (!_Py_IsImmortal(op)) {
312+
_Py_INCREF_IncRefTotal();
313+
}
307314
#endif
308315
#endif
309316
}
@@ -387,42 +394,6 @@ static inline void Py_DECREF(PyObject *op)
387394
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
388395

389396
#elif defined(Py_REF_DEBUG)
390-
static inline void Py_DECREF_MORTAL(const char *filename, int lineno, PyObject *op)
391-
{
392-
if (op->ob_refcnt <= 0) {
393-
_Py_NegativeRefcount(filename, lineno, op);
394-
}
395-
_Py_DECREF_STAT_INC();
396-
assert(!_Py_IsStaticImmortal(op));
397-
if (!_Py_IsImmortal(op)) {
398-
_Py_DECREF_DecRefTotal();
399-
}
400-
if (--op->ob_refcnt == 0) {
401-
_Py_Dealloc(op);
402-
}
403-
}
404-
#define Py_DECREF_MORTAL(op) Py_DECREF_MORTAL(__FILE__, __LINE__, _PyObject_CAST(op))
405-
406-
407-
408-
static inline void _Py_DECREF_MORTAL_SPECIALIZED(const char *filename, int lineno, PyObject *op, destructor destruct)
409-
{
410-
if (op->ob_refcnt <= 0) {
411-
_Py_NegativeRefcount(filename, lineno, op);
412-
}
413-
_Py_DECREF_STAT_INC();
414-
assert(!_Py_IsStaticImmortal(op));
415-
if (!_Py_IsImmortal(op)) {
416-
_Py_DECREF_DecRefTotal();
417-
}
418-
if (--op->ob_refcnt == 0) {
419-
#ifdef Py_TRACE_REFS
420-
_Py_ForgetReference(op);
421-
#endif
422-
destruct(op);
423-
}
424-
}
425-
#define Py_DECREF_MORTAL_SPECIALIZED(op, destruct) _Py_DECREF_MORTAL_SPECIALIZED(__FILE__, __LINE__, op, destruct)
426397

427398
static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
428399
{
@@ -448,28 +419,6 @@ static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
448419
#define Py_DECREF(op) Py_DECREF(__FILE__, __LINE__, _PyObject_CAST(op))
449420

450421
#else
451-
static inline void Py_DECREF_MORTAL(PyObject *op)
452-
{
453-
assert(!_Py_IsStaticImmortal(op));
454-
_Py_DECREF_STAT_INC();
455-
if (--op->ob_refcnt == 0) {
456-
_Py_Dealloc(op);
457-
}
458-
}
459-
#define Py_DECREF_MORTAL(op) Py_DECREF_MORTAL(_PyObject_CAST(op))
460-
461-
static inline void Py_DECREF_MORTAL_SPECIALIZED(PyObject *op, destructor destruct)
462-
{
463-
assert(!_Py_IsStaticImmortal(op));
464-
_Py_DECREF_STAT_INC();
465-
if (--op->ob_refcnt == 0) {
466-
#ifdef Py_TRACE_REFS
467-
_Py_ForgetReference(op);
468-
#endif
469-
destruct(op);
470-
}
471-
}
472-
#define Py_DECREF_MORTAL_SPECIALIZED(op, destruct) Py_DECREF_MORTAL_SPECIALIZED(_PyObject_CAST(op), destruct)
473422

474423
static inline Py_ALWAYS_INLINE void Py_DECREF(PyObject *op)
475424
{

‎Lib/test/test_bigmem.py

Copy file name to clipboardExpand all lines: Lib/test/test_bigmem.py
+23-1Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"""
1010

1111
from test import support
12-
from test.support import bigmemtest, _1G, _2G, _4G
12+
from test.support import bigmemtest, _1G, _2G, _4G, import_helper
13+
_testcapi = import_helper.import_module('_testcapi')
1314

1415
import unittest
1516
import operator
@@ -1257,6 +1258,27 @@ def test_dict(self, size):
12571258
d[size] = 1
12581259

12591260

1261+
class ImmortalityTest(unittest.TestCase):
1262+
1263+
@bigmemtest(size=_2G, memuse=pointer_size * 9/8)
1264+
def test_stickiness(self, size):
1265+
"""Check that immortality is "sticky", so that
1266+
once an object is immortal it remains so."""
1267+
if size < _2G:
1268+
# Not enough memory to cause immortality on overflow
1269+
return
1270+
o1 = o2 = o3 = o4 = o5 = o6 = o7 = o8 = object()
1271+
l = [o1] * (size-20)
1272+
self.assertFalse(_testcapi.is_immortal(o1))
1273+
for _ in range(30):
1274+
l.append(l[0])
1275+
self.assertTrue(_testcapi.is_immortal(o1))
1276+
del o2, o3, o4, o5, o6, o7, o8
1277+
self.assertTrue(_testcapi.is_immortal(o1))
1278+
del l
1279+
self.assertTrue(_testcapi.is_immortal(o1))
1280+
1281+
12601282
if __name__ == '__main__':
12611283
if len(sys.argv) > 1:
12621284
support.set_memlimit(sys.argv[1])

‎PC/python_uwp.cpp

Copy file name to clipboardExpand all lines: PC/python_uwp.cpp
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
#include <string>
1212

13+
#if defined(__clang__)
14+
#define _SILENCE_CLANG_COROUTINE_MESSAGE
15+
#endif
16+
1317
#include <appmodel.h>
1418
#include <winrt\Windows.ApplicationModel.h>
1519
#include <winrt\Windows.Storage.h>

‎Python/specialize.c

Copy file name to clipboardExpand all lines: Python/specialize.c
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "pycore_opcode_utils.h" // RESUME_AT_FUNC_START
1919
#include "pycore_pylifecycle.h" // _PyOS_URandomNonblock()
2020
#include "pycore_runtime.h" // _Py_ID()
21+
#include "pycore_unicodeobject.h" // _PyUnicodeASCIIIter_Type
2122

2223
#include <stdlib.h> // rand()
2324

‎configure

Copy file name to clipboardExpand all lines: configure
+2-2Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎configure.ac

Copy file name to clipboardExpand all lines: configure.ac
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7559,10 +7559,10 @@ _RESTORE_VAR([CPPFLAGS])
75597559
case "$ac_sys_system" in
75607560
Linux*) _PYTHREAD_NAME_MAXLEN=15;; # Linux and Android
75617561
SunOS*) _PYTHREAD_NAME_MAXLEN=31;;
7562-
NetBSD*) _PYTHREAD_NAME_MAXLEN=31;;
7562+
NetBSD*) _PYTHREAD_NAME_MAXLEN=15;; # gh-131268
75637563
Darwin) _PYTHREAD_NAME_MAXLEN=63;;
75647564
iOS) _PYTHREAD_NAME_MAXLEN=63;;
7565-
FreeBSD*) _PYTHREAD_NAME_MAXLEN=98;;
7565+
FreeBSD*) _PYTHREAD_NAME_MAXLEN=19;; # gh-131268
75667566
*) _PYTHREAD_NAME_MAXLEN=;;
75677567
esac
75687568
if test -n "$_PYTHREAD_NAME_MAXLEN"; then

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.