diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-05-12 21:43:44 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-05-12 21:43:44 (GMT) |
commit | 2d169b268bc760eb6d052d8e11d66fe7b1113ee9 (patch) | |
tree | b9d56dab1e240b37cae76c07b8ddbf9e787a565a /Objects | |
parent | 36c4e38f73b6fcb26359ec12338e34d9cc1b75b9 (diff) | |
download | cpython-2d169b268bc760eb6d052d8e11d66fe7b1113ee9.zip cpython-2d169b268bc760eb6d052d8e11d66fe7b1113ee9.tar.gz cpython-2d169b268bc760eb6d052d8e11d66fe7b1113ee9.tar.bz2 |
Make the reference counting of dictkeys objects participate in refleak hunting
(issue #13903).
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/dictobject.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 7b5b0f4..077f3cd 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -261,8 +261,11 @@ PyDict_Fini(void) PyDict_ClearFreeList(); } -#define DK_INCREF(dk) (++(dk)->dk_refcnt) -#define DK_DECREF(dk) if ((--(dk)->dk_refcnt) == 0) free_keys_object(dk) +#define DK_DEBUG_INCREF _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA +#define DK_DEBUG_DECREF _Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA + +#define DK_INCREF(dk) (DK_DEBUG_INCREF ++(dk)->dk_refcnt) +#define DK_DECREF(dk) if (DK_DEBUG_DECREF (--(dk)->dk_refcnt) == 0) free_keys_object(dk) #define DK_SIZE(dk) ((dk)->dk_size) #define DK_MASK(dk) (((dk)->dk_size)-1) #define IS_POWER_OF_2(x) (((x) & (x-1)) == 0) @@ -324,7 +327,7 @@ static PyDictKeysObject *new_keys_object(Py_ssize_t size) PyErr_NoMemory(); return NULL; } - dk->dk_refcnt = 1; + DK_DEBUG_INCREF dk->dk_refcnt = 1; dk->dk_size = size; dk->dk_usable = USABLE_FRACTION(size); ep0 = &dk->dk_entries[0]; @@ -959,7 +962,7 @@ dictresize(PyDictObject *mp, Py_ssize_t minused) } } assert(oldkeys->dk_refcnt == 1); - PyMem_FREE(oldkeys); + DK_DEBUG_DECREF PyMem_FREE(oldkeys); } return 0; } @@ -1259,7 +1262,7 @@ PyDict_Clear(PyObject *op) } else { assert(oldkeys->dk_refcnt == 1); - free_keys_object(oldkeys); + DK_DECREF(oldkeys); } } @@ -1367,7 +1370,8 @@ dict_dealloc(PyDictObject *mp) DK_DECREF(keys); } else { - free_keys_object(keys); + assert(keys->dk_refcnt == 1); + DK_DECREF(keys); } if (numfree < PyDict_MAXFREELIST && Py_TYPE(mp) == &PyDict_Type) free_list[numfree++] = mp; |