Proposal to add gc_list_for_each macro
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the repeated PyGC_Head traversal patterns in gc.c and the existing llist_for_each macro in pycore_llist.h. Add the proposed gc_list_for_each macro to the gc_list_xxx family, then verify that the reference-cycle garbage collector still builds and its existing behavior is unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100