8000 gh-108634: Py_TRACE_REFS uses a hash table by vstinner · Pull Request #108663 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-108634: Py_TRACE_REFS uses a hash table #108663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
_Py_AddToAllObjects(): remove force parameter
  • Loading branch information
vstinner committed Aug 30, 2023
commit 68e398d4d19e4430df9fedc3c251f402f288cf9f
2 changes: 1 addition & 1 deletion Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ extern void _PyDebug_PrintTotalRefs(void);
#endif

#ifdef Py_TRACE_REFS
extern void _Py_AddToAllObjects(PyObject *op, int force);
extern void _Py_AddToAllObjects(PyObject *op);
extern void _Py_PrintReferences(PyInterpreterState *, FILE *);
extern void _Py_PrintReferenceAddresses(PyInterpreterState *, FILE *);
#endif
Expand Down
24 changes: 9 additions & 15 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,17 @@ _PyRefchain_Remove(PyInterpreterState *interp, PyObject *obj)
}


/* Insert op at the front of the list of all objects. If force is true,
* op is added even if _ob_prev and _ob_next are non-NULL already. If
* force is false amd _ob_prev or _ob_next are non-NULL, do nothing.
* force should be true if and only if op points to freshly allocated,
* uninitialized memory, or you've unlinked op from the list and are
* relinking it into the front.
* Note that objects are normally added to the list via _Py_NewReference,
* which is called by PyObject_Init. Not all objects are initialized that
* way, though; exceptions include statically allocated type objects, and
* statically allocated singletons (like Py_True and Py_None).
*/
/* Add an object to the refchain hash table.
*
* Note that objects are normally added to the list by PyObject_Init()
* indirectly. Not all objects are initialized that way, though; exceptions
* include statically allocated type objects, and statically allocated
* singletons (like Py_True and Py_None). */
void
_Py_AddToAllObjects(PyObject *op, int force)
_Py_AddToAllObjects(PyObject *op)
{
PyInterpreterState *interp = _PyInterpreterState_GET();
bool traced = _PyRefchain_IsTraced(interp, op);
if (force || !traced) {
if (!_PyRefchain_IsTraced(interp, op)) {
_PyRefchain_Trace(interp, op);
}
}
Expand Down Expand Up @@ -2250,7 +2244,7 @@ new_reference(PyObject *op)
// Skip the immortal object check in Py_SET_REFCNT; always set refcnt to 1
op->ob_refcnt = 1;
#ifdef Py_TRACE_REFS
_Py_AddToAllObjects(op, 1);
_Py_AddToAllObjects(op);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -7508,7 +7508,7 @@ type_ready(PyTypeObject *type, int rerunbuiltin)
* to get type objects into the doubly-linked list of all objects.
* Still, not all type objects go through PyType_Ready.
*/
_Py_AddToAllObjects((PyObject *)type, 0);
_Py_AddToAllObjects((PyObject *)type);
#endif

/* Initialize tp_dict: _PyType_IsReady() tests if tp_dict != NULL */
Expand Down
2 changes: 1 addition & 1 deletion Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3110,7 +3110,7 @@ _PyBuiltin_Init(PyInterpreterState *interp)
* result, programs leaking references to None and False (etc)
* couldn't be diagnosed by examining sys.getobjects(0).
*/
#define ADD_TO_ALL(OBJECT) _Py_AddToAllObjects((PyObject *)(OBJECT), 0)
#define ADD_TO_ALL(OBJECT) _Py_AddToAllObjects((PyObject *)(OBJECT))
#else
#define ADD_TO_ALL(OBJECT) (void)0
#endif
Expand Down
1 change: 0 additions & 1 deletion Python/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ _Py_hashtable_set(_Py_hashtable_t *ht, const void *key, void *value)
assert(entry == NULL);
#endif


entry = ht->alloc.malloc(sizeof(_Py_hashtable_entry_t));
if (entry == NULL) {
/* memory allocation failed */
Expand Down
0