<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 9, 2015 at 7:58 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"><div class="HOEnZb"><div class="h5">On Mon, Mar 9, 2015 at 7:32 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
><br>
><br>
> On Mon, Mar 9, 2015 at 7:24 PM, Matt Turner <<a href="mailto:mattst88@gmail.com">mattst88@gmail.com</a>> wrote:<br>
>><br>
>> On Mon, Mar 9, 2015 at 6:36 PM, Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
>> wrote:<br>
>> > 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<br>
>> > *before)<br>
>> > exec_node_data(__type, (__list)->head, __field),<br>
>> > \<br>
>> > * __next =<br>
>> > \<br>
>> > exec_node_data(__type, (__node)->__field.next, __field);<br>
>> > \<br>
>> > - __next != NULL;<br>
>> > \<br>
>> > + &__next->__field != NULL;<br>
>> > \<br>
>><br>
>> 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>
><br>
><br>
> No, "__field" is the name of the exec_node field embedded in the __type<br>
> struct. So if I have<br>
><br>
> struct foo {<br>
> /* stuff */<br>
> struct exec_node bar;<br>
> }<br>
><br>
> as my type, __type is "struct foo", __next and __node are both of type<br>
> "__type *", and __field is "bar". So, in order to get form __next to an<br>
> exec_node, you have to do &__next->__field because we need the actual<br>
> exec_node back.<br>
<br>
</div></div>More concretely, for something like:<br>
<br>
foreach_list_typed_safe (bblock_link, successor, link,<br>
&predecessor->block->children)<br>
<br>
I think this macro expands to (after this patch)<br>
<br>
for (bblock_link * successor =<br>
exec_node_data(bblock_link,<br>
(&predecessor->block->children)->head, link),<br>
* __next =<br>
exec_node_data(bblock_link, (successor)->link.next, link);<br>
&__next->link != NULL;<br>
successor = __next, __next =<br>
exec_node_data(bblock_link, (__next)->link.next, link))<br>
<br>
How can the address of a field in a struct (e.g., __next->link) be NULL?<br>
</blockquote></div><br></div><div class="gmail_extra">If the address of the struct is (void *)-8 and the link field is 8 bytes into the struct. In this case, assuming unsigned overflow (I think that's reasonably safe), the address of the link will be (void *)0<br></div><div class="gmail_extra">--Jason<br></div></div>