Skip to content

Commit 6efb4c0

Browse files
committed
Rename stuff
1 parent 4c1a6bc commit 6efb4c0

File tree

9 files changed

+71
-64
lines changed

9 files changed

+71
-64
lines changed

Include/internal/pycore_frame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, _PyStackRef func,
410410
_PyInterpreterFrame *previous);
411411

412412
void
413-
_PyFrame_MoveToReachable(_PyInterpreterFrame *frame, PyGC_Head *reachable, int visited_space);
413+
_PyFrame_MoveUnvisited(_PyInterpreterFrame *frame, PyGC_Head *to, int visited_space);
414414

415415
#ifdef __cplusplus
416416
}

Include/internal/pycore_gc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ extern void _PyGC_VisitObjectsWorldStopped(PyInterpreterState *interp,
401401
gcvisitobjects_t callback, void *arg);
402402
#endif
403403

404-
void _PyGC_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space);
404+
void _PyGC_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space);
405405

406406
#ifdef __cplusplus
407407
}

Objects/dictobject.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4476,7 +4476,7 @@ dict_popitem_impl(PyDictObject *self)
44764476
}
44774477

44784478
void
4479-
_PyDict_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space)
4479+
_PyDict_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space)
44804480
{
44814481
PyDictObject *mp = (PyDictObject *)op;
44824482
PyDictKeysObject *keys = mp->ma_keys;
@@ -4486,15 +4486,15 @@ _PyDict_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space)
44864486
if (!mp->ma_values->embedded) {
44874487
for (i = 0; i < n; i++) {
44884488
PyObject *value = mp->ma_values->values[i];
4489-
_PyGC_MoveToReachable(value, reachable, visited_space);
4489+
_PyGC_MoveUnvisited(value, to, visited_space);
44904490
}
44914491
}
44924492
}
44934493
else {
44944494
PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(keys);
44954495
for (i = 0; i < n; i++) {
44964496
PyObject *value = entries[i].me_value;
4497-
_PyGC_MoveToReachable(value, reachable, visited_space);
4497+
_PyGC_MoveUnvisited(value, to, visited_space);
44984498
}
44994499
}
45004500
}
@@ -4503,9 +4503,9 @@ _PyDict_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space)
45034503
for (i = 0; i < n; i++) {
45044504
if (entries[i].me_value != NULL) {
45054505
PyObject *key = entries[i].me_key;
4506-
_PyGC_MoveToReachable(key, reachable, visited_space);
4506+
_PyGC_MoveUnvisited(key, to, visited_space);
45074507
PyObject *value = entries[i].me_value;
4508-
_PyGC_MoveToReachable(value, reachable, visited_space);
4508+
_PyGC_MoveUnvisited(value, to, visited_space);
45094509
}
45104510
}
45114511
}

Objects/genobject.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ gen_traverse(PyObject *self, visitproc visit, void *arg)
7979
}
8080

8181
void
82-
_PyGen_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space)
82+
_PyGen_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space)
8383
{
8484
PyGenObject *gen = (PyGenObject *)op;
8585
if (gen->gi_frame_state == FRAME_CLEARED) {
8686
return;
8787
}
88-
_PyGC_MoveToReachable(gen->gi_exc_state.exc_value, reachable, visited_space);
88+
_PyGC_MoveUnvisited(gen->gi_exc_state.exc_value, to, visited_space);
8989
if (gen->gi_frame_state == FRAME_EXECUTING) {
9090
/* if executing we already traversed it on the stack */
9191
return;
9292
}
9393
_PyInterpreterFrame *frame = &gen->gi_iframe;
94-
_PyFrame_MoveToReachable(frame, reachable, visited_space);
94+
_PyFrame_MoveUnvisited(frame, to, visited_space);
9595
}
9696

9797
void
@@ -1443,11 +1443,11 @@ typedef struct _PyAsyncGenWrappedValue {
14431443

14441444

14451445
void
1446-
_PyAsyncGen_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space)
1446+
_PyAsyncGen_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space)
14471447
{
14481448
PyAsyncGenObject *ag = _PyAsyncGenObject_CAST(op);
1449-
_PyGC_MoveToReachable(ag->ag_origin_or_finalizer, reachable, visited_space);
1450-
_PyGen_MoveToReachable(op, reachable, visited_space);
1449+
_PyGC_MoveUnvisited(ag->ag_origin_or_finalizer, to, visited_space);
1450+
_PyGen_MoveUnvisited(op, to, visited_space);
14511451
}
14521452

14531453
static int
@@ -1733,11 +1733,11 @@ async_gen_asend_dealloc(PyObject *self)
17331733
}
17341734

17351735
void
1736-
_PyAsyncAsend_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space)
1736+
_PyAsyncAsend_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space)
17371737
{
17381738
PyAsyncGenASend *ags = _PyAsyncGenASend_CAST(op);
1739-
_PyGC_MoveToReachable((PyObject *)ags->ags_sendval, reachable, visited_space);
1740-
_PyAsyncGen_MoveToReachable((PyObject *)ags->ags_gen, reachable, visited_space);
1739+
_PyGC_MoveUnvisited((PyObject *)ags->ags_sendval, to, visited_space);
1740+
_PyAsyncGen_MoveUnvisited((PyObject *)ags->ags_gen, to, visited_space);
17411741
}
17421742

17431743
static int

Objects/listobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3277,13 +3277,13 @@ list_remove_impl(PyListObject *self, PyObject *value)
32773277
}
32783278

32793279
void
3280-
_PyList_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space)
3280+
_PyList_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space)
32813281
{
32823282
PyListObject *o = (PyListObject *)op;
32833283
Py_ssize_t i;
32843284
for (i = Py_SIZE(o); --i >= 0; ) {
32853285
PyObject *item = o->ob_item[i];
3286-
_PyGC_MoveToReachable(item, reachable, visited_space);
3286+
_PyGC_MoveUnvisited(item, to, visited_space);
32873287
}
32883288
}
32893289

Objects/setobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,13 +701,13 @@ set_traverse(PyObject *self, visitproc visit, void *arg)
701701
}
702702

703703
void
704-
_PySet_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space)
704+
_PySet_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space)
705705
{
706706
PySetObject *so = (PySetObject *)op;
707707
Py_ssize_t pos = 0;
708708
setentry *entry;
709709
while (set_next(so, &pos, &entry)) {
710-
_PyGC_MoveToReachable(entry->key, reachable, visited_space);
710+
_PyGC_MoveUnvisited(entry->key, to, visited_space);
711711
}
712712
}
713713

Objects/tupleobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,12 +624,12 @@ tuple_count(PyTupleObject *self, PyObject *value)
624624
}
625625

626626
void
627-
_PyTuple_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space)
627+
_PyTuple_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space)
628628
{
629629
PyTupleObject *o = (PyTupleObject *)op;
630630
for (Py_ssize_t i = Py_SIZE(o); --i >= 0; ) {
631631
PyObject *item = o->ob_item[i];
632-
_PyGC_MoveToReachable(item, reachable, visited_space);
632+
_PyGC_MoveUnvisited(item, to, visited_space);
633633
}
634634
}
635635

Objects/typeobject.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6216,15 +6216,15 @@ PyDoc_STRVAR(type_doc,
62166216

62176217

62186218
void
6219-
_PyType_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space)
6219+
_PyType_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space)
62206220
{
62216221
PyTypeObject *type = (PyTypeObject *)op;
6222-
_PyGC_MoveToReachable(type->tp_dict, reachable, visited_space);
6223-
_PyGC_MoveToReachable(type->tp_cache, reachable, visited_space);
6224-
_PyGC_MoveToReachable(type->tp_mro, reachable, visited_space);
6225-
_PyGC_MoveToReachable(type->tp_bases, reachable, visited_space);
6226-
_PyGC_MoveToReachable((PyObject *)type->tp_base, reachable, visited_space);
6227-
_PyGC_MoveToReachable(((PyHeapTypeObject *)type)->ht_module, reachable, visited_space);
6222+
_PyGC_MoveUnvisited(type->tp_dict, to, visited_space);
6223+
_PyGC_MoveUnvisited(type->tp_cache, to, visited_space);
6224+
_PyGC_MoveUnvisited(type->tp_mro, to, visited_space);
6225+
_PyGC_MoveUnvisited(type->tp_bases, to, visited_space);
6226+
_PyGC_MoveUnvisited((PyObject *)type->tp_base, to, visited_space);
6227+
_PyGC_MoveUnvisited(((PyHeapTypeObject *)type)->ht_module, to, visited_space);
62286228
}
62296229

62306230
static int

Python/gc.c

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,28 +1419,28 @@ completed_cycle(GCState *gcstate)
14191419
}
14201420

14211421
void
1422-
_PyGC_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space)
1422+
_PyGC_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space)
14231423
{
14241424
if (op != NULL && !_Py_IsImmortal(op) && _PyObject_IS_GC(op)) {
14251425
PyGC_Head *gc = AS_GC(op);
14261426
if (_PyObject_GC_IS_TRACKED(op) &&
14271427
gc_old_space(gc) != visited_space) {
14281428
gc_flip_old_space(gc);
1429-
gc_list_move(gc, reachable);
1429+
gc_list_move(gc, to);
14301430
}
14311431
}
14321432
}
14331433

14341434
/* TO DO -- Move this into pycore_stackref.h */
14351435

14361436
void
1437-
_PyFrame_MoveToReachable(_PyInterpreterFrame *frame, PyGC_Head *reachable, int visited_space)
1437+
_PyFrame_MoveUnvisited(_PyInterpreterFrame *frame, PyGC_Head *to, int visited_space)
14381438
{
14391439
_PyStackRef *locals = frame->localsplus;
14401440
_PyStackRef *sp = frame->stackpointer;
1441-
_PyGC_MoveToReachable(frame->f_locals, reachable, visited_space);
1441+
_PyGC_MoveUnvisited(frame->f_locals, to, visited_space);
14421442
PyObject *func = PyStackRef_AsPyObjectBorrow(frame->f_funcobj);
1443-
_PyGC_MoveToReachable(func, reachable, visited_space);
1443+
_PyGC_MoveUnvisited(func, to, visited_space);
14441444
while (sp > locals) {
14451445
sp--;
14461446
_PyStackRef ref = *sp;
@@ -1451,25 +1451,25 @@ _PyFrame_MoveToReachable(_PyInterpreterFrame *frame, PyGC_Head *reachable, int v
14511451
if (_PyObject_GC_IS_TRACKED(op) &&
14521452
gc_old_space(gc) != visited_space) {
14531453
gc_flip_old_space(gc);
1454-
gc_list_move(gc, reachable);
1454+
gc_list_move(gc, to);
14551455
}
14561456
}
14571457
}
14581458
}
14591459
}
14601460

1461-
extern void _PySet_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space);
1462-
extern void _PyDict_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space);
1463-
extern void _PyGen_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space);
1464-
extern void _PyAsyncGen_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space);
1465-
extern void _PyAsyncAsend_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space);
1466-
extern void _PyList_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space);
1467-
extern void _PyTuple_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space);
1468-
extern void _PyType_MoveToReachable(PyObject *op, PyGC_Head *reachable, int visited_space);
1461+
extern void _PySet_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space);
1462+
extern void _PyDict_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space);
1463+
extern void _PyGen_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space);
1464+
extern void _PyAsyncGen_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space);
1465+
extern void _PyAsyncAsend_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space);
1466+
extern void _PyList_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space);
1467+
extern void _PyTuple_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space);
1468+
extern void _PyType_MoveUnvisited(PyObject *op, PyGC_Head *to, int visited_space);
14691469

14701470

14711471
static Py_ssize_t
1472-
mark_all_reachable(PyGC_Head *reachable, PyGC_Head *visited, int visited_space)
1472+
move_all_transitively_reachable(PyGC_Head *reachable, PyGC_Head *visited, int visited_space)
14731473
{
14741474
// Transitively traverse all objects from reachable, until empty
14751475
struct container_and_flag arg = {
@@ -1486,12 +1486,19 @@ mark_all_reachable(PyGC_Head *reachable, PyGC_Head *visited, int visited_space)
14861486
objects_marked++;
14871487
PyObject *op = FROM_GC(gc);
14881488
assert(PyObject_IS_GC(op));
1489+
assert(_PyObject_GC_IS_TRACKED(op));
1490+
if (_Py_IsImmortal(op)) {
1491+
PyGC_Head *prev = _PyGCHead_PREV(gc);
1492+
gc_list_move(gc, &get_gc_state()->permanent_generation.head);
1493+
gc = prev;
1494+
continue;
1495+
}
14891496
switch(Py_TYPE(op)->tp_version_tag) {
14901497
case _Py_TYPE_VERSION_LIST:
1491-
_PyList_MoveToReachable(op, reachable, visited_space);
1498+
_PyList_MoveUnvisited(op, reachable, visited_space);
14921499
break;
14931500
case _Py_TYPE_VERSION_TUPLE:
1494-
_PyTuple_MoveToReachable(op, reachable, visited_space);
1501+
_PyTuple_MoveUnvisited(op, reachable, visited_space);
14951502
break;
14961503
case _Py_TYPE_VERSION_MODULE:
14971504
{
@@ -1507,24 +1514,24 @@ mark_all_reachable(PyGC_Head *reachable, PyGC_Head *visited, int visited_space)
15071514
}
15081515
/* fall through */
15091516
case _Py_TYPE_VERSION_DICT:
1510-
_PyDict_MoveToReachable(op, reachable, visited_space);
1517+
_PyDict_MoveUnvisited(op, reachable, visited_space);
15111518
break;
15121519
case _Py_TYPE_VERSION_SET:
15131520
case _Py_TYPE_VERSION_FROZEN_SET:
1514-
_PySet_MoveToReachable(op, reachable, visited_space);
1521+
_PySet_MoveUnvisited(op, reachable, visited_space);
15151522
break;
15161523
case _Py_TYPE_VERSION_ASYNC_GENERATOR:
1517-
_PyAsyncGen_MoveToReachable(op, reachable, visited_space);
1524+
_PyAsyncGen_MoveUnvisited(op, reachable, visited_space);
15181525
break;
15191526
case _Py_TYPE_VERSION_ASYNC_ASEND:
1520-
_PyAsyncAsend_MoveToReachable(op, reachable, visited_space);
1527+
_PyAsyncAsend_MoveUnvisited(op, reachable, visited_space);
15211528
break;
15221529
case _Py_TYPE_VERSION_COROUTINE:
15231530
case _Py_TYPE_VERSION_GENERATOR:
1524-
_PyGen_MoveToReachable(op, reachable, visited_space);
1531+
_PyGen_MoveUnvisited(op, reachable, visited_space);
15251532
break;
15261533
case _Py_TYPE_VERSION_TYPE:
1527-
_PyType_MoveToReachable(op, reachable, visited_space);
1534+
_PyType_MoveUnvisited(op, reachable, visited_space);
15281535
break;
15291536
default:
15301537
{
@@ -1543,19 +1550,19 @@ mark_global_roots(PyInterpreterState *interp, PyGC_Head *visited, int visited_sp
15431550
PyGC_Head reachable;
15441551
gc_list_init(&reachable);
15451552
Py_ssize_t objects_marked = 0;
1546-
_PyGC_MoveToReachable(interp->sysdict, &reachable, visited_space);
1547-
_PyGC_MoveToReachable(interp->builtins, &reachable, visited_space);
1548-
_PyGC_MoveToReachable(interp->dict, &reachable, visited_space);
1553+
_PyGC_MoveUnvisited(interp->sysdict, &reachable, visited_space);
1554+
_PyGC_MoveUnvisited(interp->builtins, &reachable, visited_space);
1555+
_PyGC_MoveUnvisited(interp->dict, &reachable, visited_space);
15491556
struct types_state *types = &interp->types;
15501557
for (int i = 0; i < _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES; i++) {
1551-
_PyGC_MoveToReachable(types->builtins.initialized[i].tp_dict, &reachable, visited_space);
1552-
_PyGC_MoveToReachable(types->builtins.initialized[i].tp_subclasses, &reachable, visited_space);
1558+
_PyGC_MoveUnvisited(types->builtins.initialized[i].tp_dict, &reachable, visited_space);
1559+
_PyGC_MoveUnvisited(types->builtins.initialized[i].tp_subclasses, &reachable, visited_space);
15531560
}
15541561
for (int i = 0; i < _Py_MAX_MANAGED_STATIC_EXT_TYPES; i++) {
1555-
_PyGC_MoveToReachable(types->for_extensions.initialized[i].tp_dict, &reachable, visited_space);
1556-
_PyGC_MoveToReachable(types->for_extensions.initialized[i].tp_subclasses, &reachable, visited_space);
1562+
_PyGC_MoveUnvisited(types->for_extensions.initialized[i].tp_dict, &reachable, visited_space);
1563+
_PyGC_MoveUnvisited(types->for_extensions.initialized[i].tp_subclasses, &reachable, visited_space);
15571564
}
1558-
objects_marked += mark_all_reachable(&reachable, visited, visited_space);
1565+
objects_marked += move_all_transitively_reachable(&reachable, visited, visited_space);
15591566
assert(gc_list_is_empty(&reachable));
15601567
return objects_marked + 20;
15611568
}
@@ -1577,7 +1584,7 @@ mark_stacks(PyInterpreterState *interp, PyGC_Head *visited, int visited_space, b
15771584
frame = frame->previous;
15781585
continue;
15791586
}
1580-
_PyFrame_MoveToReachable(frame, &reachable, visited_space);
1587+
_PyFrame_MoveUnvisited(frame, &reachable, visited_space);
15811588
if (!start && frame->visited) {
15821589
// If this frame has already been visited, then the lower frames
15831590
// will have already been visited and will not have changed
@@ -1590,7 +1597,7 @@ mark_stacks(PyInterpreterState *interp, PyGC_Head *visited, int visited_space, b
15901597
ts = PyThreadState_Next(ts);
15911598
HEAD_UNLOCK(runtime);
15921599
}
1593-
Py_ssize_t objects_marked = mark_all_reachable(&reachable, visited, visited_space);
1600+
Py_ssize_t objects_marked = move_all_transitively_reachable(&reachable, visited, visited_space);
15941601
assert(gc_list_is_empty(&reachable));
15951602
return objects_marked;
15961603
}
@@ -1662,12 +1669,12 @@ gc_collect_increment(PyThreadState *tstate, struct gc_collection_stats *stats)
16621669
}
16631670
PyGC_Head *not_visited = &gcstate->old[gcstate->visited_space^1].head;
16641671
PyGC_Head *visited = &gcstate->old[gcstate->visited_space].head;
1665-
PyGC_Head increment;
1666-
gc_list_init(&increment);
16671672
Py_ssize_t objects_marked = mark_stacks(tstate->interp, visited, gcstate->visited_space, false);
16681673
GC_STAT_ADD(1, objects_transitively_reachable, objects_marked);
16691674
gcstate->work_to_do -= objects_marked;
16701675
gc_list_set_space(&gcstate->young.head, gcstate->visited_space);
1676+
PyGC_Head increment;
1677+
gc_list_init(&increment);
16711678
gc_list_merge(&gcstate->young.head, &increment);
16721679
gc_list_validate_space(&increment, gcstate->visited_space);
16731680
Py_ssize_t increment_size = 0;

0 commit comments

Comments
 (0)