svn commit: trunk/busybox: include libbb procps util-linux

landley at busybox.net landley at busybox.net
Mon May 8 19:03:10 UTC 2006


Author: landley
Date: 2006-05-08 12:03:07 -0700 (Mon, 08 May 2006)
New Revision: 15037

Log:
Fiddling with llist to make memory management easier.  Specifically, the
option to delete the contents of the list when we delete the list is a
good thing.


Modified:
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/Makefile.in
   trunk/busybox/libbb/llist.c
   trunk/busybox/procps/pidof.c
   trunk/busybox/util-linux/mount.c


Changeset:
Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2006-05-08 18:30:33 UTC (rev 15036)
+++ trunk/busybox/include/libbb.h	2006-05-08 19:03:07 UTC (rev 15037)
@@ -477,8 +477,8 @@
 } llist_t;
 extern llist_t *llist_add_to(llist_t *old_head, char *new_item);
 extern llist_t *llist_add_to_end(llist_t *list_head, char *data);
-extern llist_t *llist_free_one(llist_t *elm);
-extern void llist_free(llist_t *elm);
+extern void *llist_pop(llist_t **elm);
+extern void llist_free(llist_t *elm, void (*freeit)(void *data));
 
 extern void print_login_issue(const char *issue_file, const char *tty);
 extern void print_login_prompt(void);

Modified: trunk/busybox/libbb/Makefile.in
===================================================================
--- trunk/busybox/libbb/Makefile.in	2006-05-08 18:30:33 UTC (rev 15036)
+++ trunk/busybox/libbb/Makefile.in	2006-05-08 19:03:07 UTC (rev 15037)
@@ -101,7 +101,7 @@
 	$(compile.c) -DL_$(notdir $*)
 
 LIBBB_MSRC6:=$(srcdir)/llist.c
-LIBBB_MOBJ6:=llist_add_to.o llist_add_to_end.o llist_free_one.o llist_free.o
+LIBBB_MOBJ6:=llist_add_to.o llist_add_to_end.o llist_pop.o llist_free.o
 LIBBB_MOBJ6:=$(patsubst %,$(LIBBB_DIR)/%, $(LIBBB_MOBJ6))
 $(LIBBB_MOBJ6):$(LIBBB_MSRC6)
 	$(compile.c) -DL_$(notdir $*)

Modified: trunk/busybox/libbb/llist.c
===================================================================
--- trunk/busybox/libbb/llist.c	2006-05-08 18:30:33 UTC (rev 15036)
+++ trunk/busybox/libbb/llist.c	2006-05-08 19:03:07 UTC (rev 15037)
@@ -47,21 +47,32 @@
 }
 #endif
 
-#ifdef L_llist_free_one
-/* Free the current list element and advance to the next entry in the list.
- * Returns a pointer to the next element.  */
-llist_t *llist_free_one(llist_t *elm)
+#ifdef L_llist_pop
+/* Remove first element from the list and return it */
+void *llist_pop(llist_t **head)
 {
-	llist_t *next = elm ? elm->link : NULL;
-	free(elm);
-	return next;
+	void *data;
+
+	if(!*head) data = *head;
+	else {
+		void *next = (*head)->link;
+		data = (*head)->data;
+		*head = (*head)->link;
+		free(next);
+	}
+
+	return data;
 }
 #endif
 
 #ifdef L_llist_free
-/* Recursively free all elements in the linked list.  */
-void llist_free(llist_t *elm)
+/* Recursively free all elements in the linked list.  If freeit != NULL
+ * call it on each datum in the list */
+void llist_free(llist_t *elm, void (*freeit)(void *data))
 {
-	while ((elm = llist_free_one(elm)));
+	while (elm) {
+		void *data = llist_pop(&elm);
+		if (freeit) freeit(data);
+	}
 }
 #endif

Modified: trunk/busybox/procps/pidof.c
===================================================================
--- trunk/busybox/procps/pidof.c	2006-05-08 18:30:33 UTC (rev 15036)
+++ trunk/busybox/procps/pidof.c	2006-05-08 19:03:07 UTC (rev 15037)
@@ -65,7 +65,7 @@
 		while (omits_p) {
 			/* are we asked to exclude the parent's process ID?  */
 			if (!strncmp(omits_p->data, "%PPID", 5)) {
-				omits_p = llist_free_one(omits_p);
+				llist_pop(&omits_p);
 				snprintf(getppid_str, sizeof(getppid_str), "%d", getppid());
 				omits_p = llist_add_to(omits_p, getppid_str);
 #if 0
@@ -117,7 +117,7 @@
 
 #if ENABLE_FEATURE_PIDOF_OMIT
 	if (ENABLE_FEATURE_CLEAN_UP)
-		llist_free(omits);
+		llist_free(omits, NULL);
 #endif
 	return fail ? EXIT_FAILURE : EXIT_SUCCESS;
 }

Modified: trunk/busybox/util-linux/mount.c
===================================================================
--- trunk/busybox/util-linux/mount.c	2006-05-08 18:30:33 UTC (rev 15036)
+++ trunk/busybox/util-linux/mount.c	2006-05-08 19:03:07 UTC (rev 15037)
@@ -182,7 +182,7 @@
 #if ENABLE_FEATURE_CLEAN_UP
 static void delete_block_backed_filesystems(void)
 {
-	llist_free(fslist);
+	llist_free(fslist, free);
 }
 #else
 void delete_block_backed_filesystems(void);




More information about the busybox-cvs mailing list