[PATCH] screenshooter: Properly handle multiple outputs.

Andreas Ericsson ae at op5.se
Thu Apr 5 08:01:46 PDT 2012


On 04/05/2012 12:08 PM, Jonas Ådahl wrote:
> On Thu, Apr 5, 2012 at 11:42 AM, Andreas Ericsson<ae at op5.se>  wrote:
>> On 04/04/2012 02:37 PM, Kristian Hoegsberg wrote:
>>> On Wed, Apr 04, 2012 at 01:51:08AM -0600, Scott Moreau wrote:
>>>> ---
>>>
>>>>
>>>> -    write_png(output_width, output_height, data);
>>>> +    write_png(ss_area_width, ss_area_height, data);
>>>> +
>>>> +    wl_list_for_each(ss_output,&output_list, link) {
>>>> +            free(ss_output);
>>>
>>> You need wl_list_for_each_safe here since you're freeing the structs
>>> that holds the prev/next pointers.
>>>
>>
>> Is there a point to having two different ones? The compiler still
>> generates code to stash the next and prev pointers, so any difference
>> in execution time should be microscopic, if it exists at all, and the
>> possibility of using the wrong one is obviously very real.
> 
> With wl_list_for_each, iterating over a list of 'struct foo' you need
> only declare one such struct. With wl_list_for_each_safe you also need
> to declare a "tmp" one.
> 

Yes, but the compiler knows how to optimize it away, so the generated
assembly shouldn't differ much (if at all) either way.

> As a side-effect it can be easier to read since one can assume that
> when using the _safe version the item may be destroyed, while using
> the plain version, it's means that the item will not be destroyed.
> Except if someone uses it incorrectly of course.
> 

So what's worse? Someone having to look an extra time to be sure that
an object is destroyed, or having to figure out the difference between
the two when writing a patch, and then having all reviewers eyeballing
said patch to make sure noone forgot to use _safe() when they should
have.

That's a rhetorical question, btw. I'll investigate the difference in
the generated code when I get home.

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.


More information about the wayland-devel mailing list