<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 9, 2015 at 7:24 PM, Matt Turner <span dir="ltr"><<a href="mailto:mattst88@gmail.com" target="_blank">mattst88@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Mon, Mar 9, 2015 at 6:36 PM, Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>> wrote:<br>
</span><span class="">> From: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>><br>
><br>
> __next and __prev are pointers to the structure containing the exec_node<br>
> link, not the embedded exec_node. NULL checks would fail unless the<br>
> embedded exec_node happened to be at offset 0 in the parent struct.<br>
><br>
> Signed-off-by: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>><br>
> Reviewed-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
> ---<br>
> src/glsl/list.h | 4 ++--<br>
> 1 file changed, 2 insertions(+), 2 deletions(-)<br>
><br>
> diff --git a/src/glsl/list.h b/src/glsl/list.h<br>
> index ddb98f7..680e963 100644<br>
> --- a/src/glsl/list.h<br>
> +++ b/src/glsl/list.h<br>
> @@ -684,7 +684,7 @@ inline void exec_node::insert_before(exec_list *before)<br>
> exec_node_data(__type, (__list)->head, __field), \<br>
> * __next = \<br>
> exec_node_data(__type, (__node)->__field.next, __field); \<br>
> - __next != NULL; \<br>
> + &__next->__field != NULL; \<br>
<br>
</span>I'm not understanding now the address of __next->__field can ever be NULL.<br>
<br>
__next is something with an embedded struct exec_node, so don't we<br>
want "__next->__field != NULL" without the address-of operator?<br></blockquote><div><br></div><div>No, "__field" is the name of the exec_node field embedded in the __type struct. So if I have<br><br></div><div>struct foo {<br></div><div> /* stuff */<br></div><div> struct exec_node bar;<br>}<br><br></div><div>as my type, __type is "struct foo", __next and __node are both of type "__type *", and __field is "bar". So, in order to get form __next to an exec_node, you have to do &__next->__field because we need the actual exec_node back.<br><br></div><div>Put differently, &__next->field undoes the pointer arithmatic that exec_node_data(__type, ptr, __field) does. Ideallly, we would like __next to be a pointer of type "struct exec_node" and do the conversion to "__type *" later. Unfortunately, C doesn't let us do that inside the for loop. So we settle for extra pointer arithmetic.<br><br></div><div>The other option, of course, would be to use a struct but then we couldn't make a variable named __node on behalf of the caller.<br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
> __node = __next, __next = \<br>
> exec_node_data(__type, (__next)->__field.next, __field))<br>
><br>
> @@ -693,7 +693,7 @@ inline void exec_node::insert_before(exec_list *before)<br>
> exec_node_data(__type, (__list)->tail_pred, __field), \<br>
> * __prev = \<br>
> exec_node_data(__type, (__node)->__field.prev, __field); \<br>
> - __prev != NULL; \<br>
> + &__prev->__field != NULL; \<br>
> __node = __prev, __prev = \<br>
> exec_node_data(__type, (__prev)->__field.prev, __field))<br>
><br>
> --<br>
> 2.2.2<br>
><br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div></div>