Re: [PATCH][2.5] Single linked lists for Linux, overly complicated but working

Nikita Danilov (Nikita@Namesys.COM)
Thu, 26 Sep 2002 20:13:16 +0400


Lightweight Patch Manager writes:
> This is an overly complicated version, I guess I'll have a better one
> once I've got my noodles in. Wait an hour, I'll be back.
>
> And BTW, I got the luckynet address fixed, you can send me again...
>
> --- /dev/null Wed Dec 31 17:00:00 1969
> +++ slist-2.5/include/linux/slist.h Thu Sep 26 09:57:25 2002
> @@ -0,0 +1,139 @@
> +#ifdef __KERNEL__
> +#ifndef _LINUX_SLIST_H
> +#define _LINUX_SLIST_H
> +
> +#include <asm/processor.h>
> +
> +/*
> + * Type-safe single linked list helper-functions.
> + * (originally taken from list.h)
> + *
> + * Thomas 'Dent' Mirlacher, Daniel Phillips,
> + * Andreas Bogk, Thunder from the hill
> + */
> +
> +#define INIT_SLIST_HEAD(name) \
> + (name->next = name)
> +
> +#define SLIST_HEAD_INIT(name) \
> + name
> +
> +#define SLIST_HEAD(type,name) \
> + typeof(type) name = INIT_SLIST_HEAD(name)
> +
> +/**
> + * slist_add_front - add a new entry at the first slot, moving the old head
> + * to the second slot
> + * @new: new entry to be added
> + * @head: head of the single linked list
> + *
> + * Insert a new entry before the specified head.
> + * This is good for implementing stacks.
> + */
> +
> +#define slist_add_front(_new, _head) \
> +do { \
> + (_new)->next = (_head); \
> + (_head) = (_new); \
> +} while (0)

Can these macros be updated to only evaluate their arguments once? By
use of "typeof" maybe? Otherwise, slist_add_front(foo++, bar()) is going
to lead to strange things.

> +
> +/**
> + * slist_add - add a new entry

[...]

Nikita.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/