Skip to content

Commit ab3a30b

Browse files
committed
Fix refleaks tests to account for quickened blocks
1 parent ec50298 commit ab3a30b

File tree

6 files changed

+50
-3
lines changed

6 files changed

+50
-3
lines changed

Include/internal/pycore_code.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ PyCodeObject_IsWarmedUp(PyCodeObject * co)
148148

149149
int _Py_Quicken(PyCodeObject *code);
150150

151+
extern Py_ssize_t _Py_QuickenedCount;
151152

152153
struct _PyCodeConstructor {
153154
/* metadata */

Lib/test/libregrtest/refleak.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ def get_pooled_int(value):
7373
alloc_deltas = [0] * repcount
7474
fd_deltas = [0] * repcount
7575
getallocatedblocks = sys.getallocatedblocks
76+
getallocatedblocks = sys.getallocatedblocks
7677
gettotalrefcount = sys.gettotalrefcount
78+
_getquickenedcount = sys._getquickenedcount
7779
fd_count = os_helper.fd_count
78-
7980
# initialize variables to make pyflakes quiet
8081
rc_before = alloc_before = fd_before = 0
8182

@@ -92,7 +93,7 @@ def get_pooled_int(value):
9293

9394
# dash_R_cleanup() ends with collecting cyclic trash:
9495
# read memory statistics immediately after.
95-
alloc_after = getallocatedblocks()
96+
alloc_after = getallocatedblocks() - _getquickenedcount()
9697
rc_after = gettotalrefcount()
9798
fd_after = fd_count()
9899

Objects/codeobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,7 @@ code_dealloc(PyCodeObject *co)
10451045
PyObject_ClearWeakRefs((PyObject*)co);
10461046
if (co->co_quickened) {
10471047
PyMem_Free(co->co_quickened);
1048+
_Py_QuickenedCount--;
10481049
}
10491050
PyObject_Free(co);
10501051
}

Python/clinic/sysmodule.c.h

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/specialize.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
<instr N-1>
2929
*/
3030

31+
Py_ssize_t _Py_QuickenedCount = 0;
32+
3133
static SpecializedCacheOrInstruction *
3234
allocate(int cache_count, int instruction_count)
3335
{
@@ -42,6 +44,7 @@ allocate(int cache_count, int instruction_count)
4244
PyErr_NoMemory();
4345
return NULL;
4446
}
47+
_Py_QuickenedCount++;
4548
array[0].entry.zero.cache_count = cache_count;
4649
return array;
4750
}

Python/sysmodule.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Data members:
1818
#include "pycore_ceval.h" // _Py_RecursionLimitLowerWaterMark()
1919
#include "pycore_initconfig.h" // _PyStatus_EXCEPTION()
2020
#include "pycore_object.h" // _PyObject_IS_GC()
21+
#include "pycore_code.h" // _Py_QuickenedCount
2122
#include "pycore_pathconfig.h" // _PyPathConfig_ComputeSysPath0()
2223
#include "pycore_pyerrors.h" // _PyErr_Fetch()
2324
#include "pycore_pylifecycle.h" // _PyErr_WriteUnraisableDefaultHook()
@@ -1763,8 +1764,20 @@ sys_gettotalrefcount_impl(PyObject *module)
17631764
{
17641765
return _Py_GetRefTotal();
17651766
}
1767+
17661768
#endif /* Py_REF_DEBUG */
17671769

1770+
/*[clinic input]
1771+
sys._getquickenedcount -> Py_ssize_t
1772+
[clinic start generated code]*/
1773+
1774+
static Py_ssize_t
1775+
sys__getquickenedcount_impl(PyObject *module)
1776+
/*[clinic end generated code: output=1ab259e7f91248a2 input=249d448159eca912]*/
1777+
{
1778+
return _Py_QuickenedCount;
1779+
}
1780+
17681781
/*[clinic input]
17691782
sys.getallocatedblocks -> Py_ssize_t
17701783
@@ -1995,6 +2008,7 @@ static PyMethodDef sys_methods[] = {
19952008
#endif
19962009
SYS_GETFILESYSTEMENCODING_METHODDEF
19972010
SYS_GETFILESYSTEMENCODEERRORS_METHODDEF
2011+
SYS__GETQUICKENEDCOUNT_METHODDEF
19982012
#ifdef Py_TRACE_REFS
19992013
{"getobjects", _Py_GetObjects, METH_VARARGS},
20002014
#endif

0 commit comments

Comments
 (0)