[cairo] [cairo-commit] Branch 1.10 - src/cairo-image-surface.c

Chris Wilson chris at chris-wilson.co.uk
Tue Nov 2 07:10:52 PDT 2010


On Tue, 02 Nov 2010 10:03:32 -0400, Behdad Esfahbod <behdad at behdad.org> wrote:
> In fact, most of these can also be macroized.  Something like:
> 
> #define CAIRO_STACK_ARRAY_DEFINE(Type, Name) \
> 	Type stack_##Name[CAIRO_STACK_ARRAY_LENGTH (Type)]; \
> 	Type *Name = stack_##Name;
> 
> #define CAIRO_STACK_ARRAY_ENSURE(Name, Size) \
>         (likely ((Size) <= ARRAY_LENGTH (stack_##Name)) ? \
> 	  CAIRO_STATUS_SUCCESS : \
> 	  (Name = _cairo_malloc_ab ((Size), sizeof (*Name)), \
> 	   (unlikely (Name == NULL) ? \
> 	     _cairo_error (CAIRO_STATUS_NO_MEMORY) : \
> 	     CAIRO_STATUS_SUCCESS)))
> 
> #define CAIRO_STACK_ARRAY_FREE(Name) \
> 	do { if (Name != stack_##Name) free (Name); } while (0)
> 
> ENSURE can be rewritten to do realloc if necessary.

Nice. We have liberally used stack allocation and those macros should
remove a lot of the repetition. The type-checking define alone would make
the code much simpler.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the cairo mailing list