8000 Fixes for refcount tests · python/cpython@e530f0b · GitHub
[go: up one dir, main page]

Skip to content

Commit e530f0b

Browse files
Fixes for refcount tests
1 parent 65c7e30 commit e530f0b

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

Include/object.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,12 +512,12 @@ static inline void _Py_INCREF(PyObject *op)
512512
#else
513513
// Non-limited C API and limited C API for Python 3.9 and older access
514514
// directly PyObject.ob_refcnt.
515-
#ifdef Py_REF_DEBUG
516-
_Py_RefTotal++;
517-
#endif
518515
if (_Py_IsImmortal(op)) {
519516
return;
520517
}
518+
#ifdef Py_REF_DEBUG
519+
_Py_RefTotal++;
520+
#endif
521521
op->ob_refcnt++;
522522
#endif
523523
}
@@ -535,12 +535,12 @@ static inline void _Py_DECREF(
535535
#else
536536
// Non-limited C API and limited C API for Python 3.9 and older access
537537
// directly PyObject.ob_refcnt.
538-
#ifdef Py_REF_DEBUG
539-
_Py_RefTotal--;
540-
#endif
541538
if (_Py_IsImmortal(op)) {
542539
return;
543540
}
541+
#ifdef Py_REF_DEBUG
542+
_Py_RefTotal--;
543+
#endif
544544
if (--op->ob_refcnt != 0) {
545545
#ifdef Py_REF_DEBUG
546546
if (op->ob_refcnt < 0) {

Lib/test/t.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import unittest
2+
3+
GLOBAL_LIST = []
4+
5+
class RefLeakTest(unittest.TestCase):
6+
def test_leak(self):
7+
GLOBAL_LIST.append(object())
8+
9+
if __name__ == '__main__':
10+
unittest.main()

Lib/test/test_regrtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ class RefLeakTest(unittest.TestCase):
913913
def test_leak(self):
914914
GLOBAL_LIST.append(object())
915915
""")
916-
self.check_leak(code, 'references')
916+
self.check_leak(code, 'memory blocks')
917917

918918
@unittest.skipUnless(Py_DEBUG, 'need a debug build')
919919
def test_huntrleaks_fd_leak(self):

t.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import unittest
2+
3+
GLOBAL_LIST = []
4+
5+
class RefLeakTest(unittest.TestCase):
6+
def test_leak(self):
7+
GLOBAL_LIST.append(object())
8+
9+
if __name__ == '__main__':
10+
unittest.main()

0 commit comments

Comments
 (0)
0