<p dir="ltr">Jonathan,<br>
I have thought on multiple occations about doing this exact thing.  If we do, we should probably also make wl_list_insert_list safe.</p>
<p dir="ltr">The counter-argument for all this is that you have to keep track of whether or not your elements are in a list anyway to avoid corruption.  For instance, you still have to watch for double wl_list_insert which will also break things badly.  You could say, "We'll modify wl_list_insert so it's safe too" but then you inserting an element that is already in a list becomes "safe" from a segfault perspective and you make it easy to have program logic errors that don't result in a crash, just things being subtly wrong and impossible to track down.</p>

<p dir="ltr">All said, I think I'd be in favor of making double-remove safe.  However, it's not a silver bullet.<br>
--Jason Ekstrand</p>
<div class="gmail_quote">On Jan 28, 2014 11:22 AM, "Jonathan Howard" <<a href="mailto:jonathan@unbiased.name">jonathan@unbiased.name</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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.<br>
<br>
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.<br>
<br>
Having wl_list_remove place items in this unlinked state makes the destruction safe (and makes quite a few lines of code redundant.)<br>
<br>
--- wayland-util.c      2014-01-28 16:09:<a href="tel:13.179052955" value="+13179052955" target="_blank">13.179052955</a> +0000<br>
+++ wayland-util.c.init 2014-01-28 16:13:32.225704904 +0000<br>
@@ -52,8 +52,8 @@<br>
 {<br>
        elm->prev->next = elm->next;<br>
        elm->next->prev = elm->prev;<br>
-       elm->next = NULL;<br>
-       elm->prev = NULL;<br>
+       elm->next = elm;<br>
+       elm->prev = elm;<br>
 }<br>
<br>
 WL_EXPORT int<br>
<br>
______________________________<u></u>_________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org" target="_blank">wayland-devel@lists.<u></u>freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/<u></u>mailman/listinfo/wayland-devel</a><br>
</blockquote></div>