[Spice-devel] [PATCH spice-server v2] Remove iterator from list iteration macros
Uri Lublin
uril at redhat.com
Mon Aug 21 11:46:02 UTC 2017
On 08/21/2017 01:35 PM, Frediano Ziglio wrote:
> Avoid to have to declare iterator and pass as an argument.
>
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Ack.
> ---
> server/display-channel.c | 32 +++++++++++---------------------
> server/display-channel.h | 4 ++--
> server/main-channel.c | 18 ++++++------------
> server/red-channel.c | 24 ++++++++----------------
> server/red-channel.h | 4 ++--
> server/red-client.c | 19 +++++++------------
> server/red-common.h | 10 +++++-----
> server/red-worker.c | 6 ++----
> server/reds-private.h | 4 ++--
> server/reds.c | 45 +++++++++++++++------------------------------
> server/stream.c | 15 +++++----------
> 11 files changed, 65 insertions(+), 116 deletions(-)
>
> Changes since v1:
> - fix macro concatenation and expansion of __LINE__.
Yes, using another macro (G_PASTE) as an indirection macro works.
Uri.
[keeping only the v2 lines below]
> diff --git a/server/red-common.h b/server/red-common.h
> index cb459b05..9ff1fd9b 100644
> --- a/server/red-common.h
> +++ b/server/red-common.h
> @@ -81,16 +81,16 @@ typedef struct GListIter {
> } GListIter;
>
> #define GLIST_FOREACH_GENERIC(_list, _iter, _type, _data, _dir) \
> - for (_iter.link = _list; \
> + for (GListIter _iter = { .link = _list }; \
> (_data = (_type *) (_iter.link ? _iter.link->data : NULL), \
> _iter.next = (_iter.link ? _iter.link->_dir : NULL), \
> _iter.link) != NULL; \
> _iter.link = _iter.next)
>
> -#define GLIST_FOREACH(_list, _iter, _type, _data) \
> - GLIST_FOREACH_GENERIC(_list, _iter, _type, _data, next)
> +#define GLIST_FOREACH(_list, _type, _data) \
> + GLIST_FOREACH_GENERIC(_list, G_PASTE(_iter_, __LINE__), _type, _data, next)
>
> -#define GLIST_FOREACH_REVERSED(_list, _iter, _type, _data) \
> - GLIST_FOREACH_GENERIC(_list, _iter, _type, _data, prev)
> +#define GLIST_FOREACH_REVERSED(_list, _type, _data) \
> + GLIST_FOREACH_GENERIC(_list, G_PASTE(_iter_, __LINE__), _type, _data, prev)
>
> #endif /* RED_COMMON_H_ */
More information about the Spice-devel
mailing list