Make safe double remove?

Jonathan Howard jonathan at unbiased.name
Tue Jan 28 09:16:20 PST 2014


Code is already using wl_list_init to have the construction of unlinked 
items in a stable state so that they can be destroyed with wl_list_remove.

A problem is it is easy to write code that calls wl_list_remove during 
the structures life and miss that you need to reset with wl_list_init 
for when it is later destroyed.

Having wl_list_remove place items in this unlinked state makes the 
destruction safe (and makes quite a few lines of code redundant.)

--- wayland-util.c	2014-01-28 16:09:13.179052955 +0000
+++ wayland-util.c.init	2014-01-28 16:13:32.225704904 +0000
@@ -52,8 +52,8 @@
  {
  	elm->prev->next = elm->next;
  	elm->next->prev = elm->prev;
-	elm->next = NULL;
-	elm->prev = NULL;
+	elm->next = elm;
+	elm->prev = elm;
  }

  WL_EXPORT int



More information about the wayland-devel mailing list