aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@evo.osdl.org>2005-08-11 15:12:04 -0700
committerLinus Torvalds <torvalds@evo.osdl.org>2005-08-11 15:12:04 -0700
commitf39e2bb1cd833b37a6ac98d2521e92b87e1c315c (patch)
tree46aa3388694b42d476f979d5832262e83e6627b3 /ptrlist.c
parentHave more bits for "stream number" in "struct pos" (diff)
downloadsparse-f39e2bb1cd833b37a6ac98d2521e92b87e1c315c.tar.gz
sparse-f39e2bb1cd833b37a6ac98d2521e92b87e1c315c.tar.bz2
sparse-f39e2bb1cd833b37a6ac98d2521e92b87e1c315c.zip
Add 'undo_ptr_list_last()' helper function
It's like 'delete_ptr_list_last()', except it doesn't de-allocate the ptrlist block that it removes the last entry from. Useful when you know you're going to add things back (ie basic block tail rewriting), and when you can't afford to de-allocate the ptrlist because you're in a loop.
Diffstat (limited to 'ptrlist.c')
-rw-r--r--ptrlist.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/ptrlist.c b/ptrlist.c
index 065891c..14d8416 100644
--- a/ptrlist.c
+++ b/ptrlist.c
@@ -177,6 +177,27 @@ out:
return count;
}
+/* This removes the last entry, but doesn't pack the ptr list */
+void * undo_ptr_list_last(struct ptr_list **head)
+{
+ struct ptr_list *last, *first = *head;
+
+ if (!first)
+ return NULL;
+ last = first;
+ do {
+ last = last->prev;
+ if (last->nr) {
+ void *ptr;
+ int nr = --last->nr;
+ ptr = last->list[nr];
+ last->list[nr] = (void *)0xf1f1f1f1;
+ return ptr;
+ }
+ } while (last != first);
+ return NULL;
+}
+
void * delete_ptr_list_last(struct ptr_list **head)
{
void *ptr = NULL;