diff options
author | Tim Peters <tim.peters@gmail.com> | 2004-11-01 16:39:57 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2004-11-01 16:39:57 (GMT) |
commit | bc1d1b80d1abfd7f95cb02e7f09be18b94504559 (patch) | |
tree | 04de032a82c04d8545f7e9a9002ed4218fd23389 | |
parent | 099ecfbec9a2a8bdca0ce9afdad4e1158b8e2169 (diff) | |
download | cpython-bc1d1b80d1abfd7f95cb02e7f09be18b94504559.zip cpython-bc1d1b80d1abfd7f95cb02e7f09be18b94504559.tar.gz cpython-bc1d1b80d1abfd7f95cb02e7f09be18b94504559.tar.bz2 |
gc_list_move(): Make this truly equivalent to remove+append. While
nothing in gc currently cares, the original coding could screw up if,
e.g., you tried to move a node to the list it's already in, and the node
was already the last in its list.
-rw-r--r-- | Modules/gcmodule.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 4bfdea6..c563ed8 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -168,14 +168,16 @@ gc_list_remove(PyGC_Head *node) static void gc_list_move(PyGC_Head *node, PyGC_Head *list) { + PyGC_Head *new_prev; PyGC_Head *current_prev = node->gc.gc_prev; PyGC_Head *current_next = node->gc.gc_next; - PyGC_Head *new_prev = list->gc.gc_prev; + /* Unlink from current list. */ current_prev->gc.gc_next = current_next; current_next->gc.gc_prev = current_prev; - node->gc.gc_next = list; - node->gc.gc_prev = new_prev; + /* Relink at end of new list. */ + new_prev = node->gc.gc_prev = list->gc.gc_prev; new_prev->gc.gc_next = list->gc.gc_prev = node; + node->gc.gc_next = list; } /* append list `from` onto list `to`; `from` becomes an empty list */ |