On Fri, Jul 11, 2014 at 12:58:31AM +0100, Ramsay Jones wrote:

>  #define DEFINE_ALLOCATOR(name, type)                         \
> -static unsigned int name##_allocs;                           \
> +static struct alloc_state name##_state;                              \
>  void *alloc_##name##_node(void)                                      \
>  {                                                            \
> -     static int nr;                                          \
> -     static type *block;                                     \
> -     void *ret;                                              \
> -                                                             \
> -     if (!nr) {                                              \
> -             nr = BLOCKING;                                  \
> -             block = xmalloc(BLOCKING * sizeof(type));       \
> -     }                                                       \
> -     nr--;                                                   \
> -     name##_allocs++;                                        \
> -     ret = block++;                                          \
> -     memset(ret, 0, sizeof(type));                           \
> -     return ret;                                             \
> +     return alloc_node(&name##_state, sizeof(type));         \
>  }

Yay. Not only does this solve the problem, but it gets rid of nasty
multi-line macro. In fact, I kind of wonder if we should just do away
with the macro entirely, and write out:

  static struct alloc_state blob_state;
  void alloc_blob_node(void)
  {
        return alloc_node(&blob_state, sizeof(struct blob));
  }

It's more lines, but it is probably less obfuscated to a reader.

-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to