Skip to content

Proposal to add gc_list_for_each macro #133058

@nybblista

Description

@nybblista

Feature or enhancement

Proposal:

In the implementation of the reference cycle garbage collector, gc.c file, I have noticed that we use the following for-loop pattern over and over to traverse a PyGC_Head list:

for (gc = GC_NEXT(list); gc != list; gc = GC_NEXT(gc)) {
  /* ... */
}

However, in pycore_llist.h we avoided that by using llist_for_each macro as:

// Iterate over a list.
#define llist_for_each(node, head) \
    for (node = (head)->next; node != (head); node = node->next)

I propose adding a new macro as gc_list_for_each to the gc_list_xxx family to serve the same purpose:

#define gc_list_for_each(gc, list) \
    for (gc = GC_NEXT((list)); gc != (list); gc = GC_NEXT(gc))

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions