[Mesa-dev] [RFC] Moving from macro to inline for list manipulation

Jerome Glisse j.glisse at gmail.com
Mon Mar 28 14:54:35 PDT 2011


Hi,

One short coming of macro has keep entertaining me until i figure out
what was wrong, here is
a simple scenario :

Macro can lead to hard to debug list bugs. For instance consider
the following :
LIST_ADD(item, list->prev)
3 instruction of the macro became :
(list->prev)->next->prev = item
which is equivalent to :
list->prev = item
Thus list prev field changes and next instruction in the macro
(list->prev)->next = item
became :
item->next = item
And you endup with list corruption, other case lead to similar
list corruption. Inline function are not affected by this short
coming

Thus i propose to switch list manipulation from macro to inline
function, attached patch does exactly that. If there is no objection
in next couple of week i will merge it. (to avoid mass renaming it
keeps the macro that just wrap the functions it also add a bunch of
new list walking helper)

Cheers,
Jerome
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-gallium-list-use-inline-function-to-avoid-macro-shot.patch
Type: application/octet-stream
Size: 4924 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110328/f03f3051/attachment.obj>


More information about the mesa-dev mailing list