[cairo-commit] src/cairo-bentley-ottmann.c src/cairo-gstate.c src/cairo-image-surface.c src/cairoint.h src/cairo-region.c src/cairo-surface.c src/cairo-traps.c src/cairo-xlib-surface.c

Chris Wilson ickle at kemper.freedesktop.org
Mon Dec 17 05:48:10 PST 2007


 src/cairo-bentley-ottmann.c |    2 +-
 src/cairo-gstate.c          |   10 ++++------
 src/cairo-image-surface.c   |   12 ++----------
 src/cairo-region.c          |    4 +---
 src/cairo-surface.c         |    2 +-
 src/cairo-traps.c           |    4 +---
 src/cairo-xlib-surface.c    |    7 ++-----
 src/cairoint.h              |    2 ++
 8 files changed, 14 insertions(+), 29 deletions(-)

New commits:
commit 8343d6cc2a5e9198e1205e431de018f74107d9d8
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Dec 17 13:42:07 2007 +0000

    Replace various uses of CAIRO_STACK_BUF_SIZE with a single macro.
    
    In http://bugs.freedesktop.org/show_bug.cgi?id=13699, Pavel Vozenilek
    reports a duplicate define for computing the appropriate length for an
    on-stack array. The macro in question, and a few other places, was
    performing CAIRO_STACK_BUF_SIZE/sizeof(stack[0]) so we can simplify
    them slightly by using a common macro.

diff --git a/src/cairo-bentley-ottmann.c b/src/cairo-bentley-ottmann.c
index b8a5f81..3ef7858 100644
--- a/src/cairo-bentley-ottmann.c
+++ b/src/cairo-bentley-ottmann.c
@@ -1421,7 +1421,7 @@ _cairo_bentley_ottmann_tessellate_polygon (cairo_traps_t	*traps,
 {
     int intersections;
     cairo_status_t status;
-    cairo_bo_edge_t stack_edges[CAIRO_STACK_BUFFER_SIZE / sizeof (cairo_bo_edge_t)];
+    cairo_bo_edge_t stack_edges[CAIRO_STACK_ARRAY_LENGTH (cairo_bo_edge_t)];
     cairo_bo_edge_t *edges;
     cairo_fixed_t xmin = 0x7FFFFFFF;
     cairo_fixed_t ymin = 0x7FFFFFFF;
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index c2ab8a2..99ce1d9 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -1575,7 +1575,6 @@ _cairo_gstate_glyph_extents (cairo_gstate_t *gstate,
     return cairo_scaled_font_status (gstate->scaled_font);
 }
 
-#define STACK_GLYPHS_LEN ((int) (CAIRO_STACK_BUFFER_SIZE / sizeof (cairo_glyph_t)))
 cairo_status_t
 _cairo_gstate_show_glyphs (cairo_gstate_t *gstate,
 			   const cairo_glyph_t *glyphs,
@@ -1584,7 +1583,7 @@ _cairo_gstate_show_glyphs (cairo_gstate_t *gstate,
     cairo_status_t status;
     cairo_pattern_union_t source_pattern;
     cairo_glyph_t *transformed_glyphs;
-    cairo_glyph_t stack_transformed_glyphs[STACK_GLYPHS_LEN];
+    cairo_glyph_t stack_transformed_glyphs[CAIRO_STACK_ARRAY_LENGTH (cairo_glyph_t)];
 
     if (gstate->source->status)
 	return gstate->source->status;
@@ -1597,7 +1596,7 @@ _cairo_gstate_show_glyphs (cairo_gstate_t *gstate,
     if (status)
 	return status;
 
-    if (num_glyphs <= STACK_GLYPHS_LEN) {
+    if (num_glyphs <= ARRAY_LENGTH (stack_transformed_glyphs)) {
 	transformed_glyphs = stack_transformed_glyphs;
     } else {
 	transformed_glyphs = _cairo_malloc_ab (num_glyphs, sizeof(cairo_glyph_t));
@@ -1636,13 +1635,13 @@ _cairo_gstate_glyph_path (cairo_gstate_t      *gstate,
 {
     cairo_status_t status;
     cairo_glyph_t *transformed_glyphs;
-    cairo_glyph_t stack_transformed_glyphs[STACK_GLYPHS_LEN];
+    cairo_glyph_t stack_transformed_glyphs[CAIRO_STACK_ARRAY_LENGTH (cairo_glyph_t)];
 
     status = _cairo_gstate_ensure_scaled_font (gstate);
     if (status)
 	return status;
 
-    if (num_glyphs < STACK_GLYPHS_LEN)
+    if (num_glyphs < ARRAY_LENGTH (stack_transformed_glyphs))
       transformed_glyphs = stack_transformed_glyphs;
     else
       transformed_glyphs = _cairo_malloc_ab (num_glyphs, sizeof(cairo_glyph_t));
@@ -1663,7 +1662,6 @@ _cairo_gstate_glyph_path (cairo_gstate_t      *gstate,
 
     return status;
 }
-#undef STACK_GLYPHS_LEN
 
 cairo_status_t
 _cairo_gstate_set_antialias (cairo_gstate_t *gstate,
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index ec3477b..e3de7a4 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -1034,8 +1034,6 @@ _cairo_image_surface_composite (cairo_operator_t	op,
     return status;
 }
 
-#define STACK_RECTS_LEN (CAIRO_STACK_BUFFER_SIZE / sizeof(pixman_rectangle16_t))
-
 static cairo_int_status_t
 _cairo_image_surface_fill_rectangles (void		      *abstract_surface,
 				      cairo_operator_t	       op,
@@ -1046,7 +1044,7 @@ _cairo_image_surface_fill_rectangles (void		      *abstract_surface,
     cairo_image_surface_t *surface = abstract_surface;
 
     pixman_color_t pixman_color;
-    pixman_rectangle16_t stack_rects[STACK_RECTS_LEN];
+    pixman_rectangle16_t stack_rects[CAIRO_STACK_ARRAY_LENGTH (pixman_rectangle16_t)];
     pixman_rectangle16_t *pixman_rects = stack_rects;
     int i;
 
@@ -1085,10 +1083,6 @@ _cairo_image_surface_fill_rectangles (void		      *abstract_surface,
     return status;
 }
 
-#undef STACK_RECTS_LEN
-
-#define STACK_TRAPS_LEN ((int) (CAIRO_STACK_BUFFER_SIZE / sizeof(pixman_trapezoid_t)))
-
 static cairo_int_status_t
 _cairo_image_surface_composite_trapezoids (cairo_operator_t	op,
 					   cairo_pattern_t	*pattern,
@@ -1110,7 +1104,7 @@ _cairo_image_surface_composite_trapezoids (cairo_operator_t	op,
     pixman_image_t		*mask;
     pixman_format_code_t	 format;
     uint32_t			*mask_data;
-    pixman_trapezoid_t		 stack_traps[STACK_TRAPS_LEN];
+    pixman_trapezoid_t		 stack_traps[CAIRO_STACK_ARRAY_LENGTH (pixman_trapezoid_t)];
     pixman_trapezoid_t		*pixman_traps = stack_traps;
     int				 mask_stride;
     int				 mask_bpp;
@@ -1244,8 +1238,6 @@ _cairo_image_surface_composite_trapezoids (cairo_operator_t	op,
     return status;
 }
 
-#undef STACK_TRAPS_LEN
-
 cairo_int_status_t
 _cairo_image_surface_set_clip_region (void *abstract_surface,
 				      cairo_region_t *region)
diff --git a/src/cairo-region.c b/src/cairo-region.c
index b4b9117..7bf4982 100644
--- a/src/cairo-region.c
+++ b/src/cairo-region.c
@@ -52,14 +52,12 @@ _cairo_region_init_rect (cairo_region_t *region,
 			     rect->width, rect->height);
 }
 
-#define STACK_BOXES_LEN ((int) (CAIRO_STACK_BUFFER_SIZE / sizeof(pixman_box16_t)))
-
 cairo_int_status_t
 _cairo_region_init_boxes (cairo_region_t *region,
 			  cairo_box_int_t *boxes,
 			  int count)
 {
-    pixman_box16_t stack_pboxes[STACK_BOXES_LEN];
+    pixman_box16_t stack_pboxes[CAIRO_STACK_ARRAY_LENGTH (pixman_box16_t)];
     pixman_box16_t *pboxes = stack_pboxes;
     cairo_int_status_t status = CAIRO_STATUS_SUCCESS;
     int i;
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index ed332f5..fe03b8c 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -1286,7 +1286,7 @@ _cairo_surface_fill_region (cairo_surface_t	   *surface,
 {
     int num_boxes;
     cairo_box_int_t *boxes = NULL;
-    cairo_rectangle_int_t stack_rects[CAIRO_STACK_BUFFER_SIZE / sizeof (cairo_rectangle_int_t)];
+    cairo_rectangle_int_t stack_rects[CAIRO_STACK_ARRAY_LENGTH (cairo_rectangle_int_t)];
     cairo_rectangle_int_t *rects = stack_rects;
     cairo_status_t status;
     int i;
diff --git a/src/cairo-traps.c b/src/cairo-traps.c
index 099b09e..d5e7532 100644
--- a/src/cairo-traps.c
+++ b/src/cairo-traps.c
@@ -571,8 +571,6 @@ _cairo_traps_extents (cairo_traps_t *traps, cairo_box_t *extents)
     *extents = traps->extents;
 }
 
-#define STACK_BOXES_LEN ((int) (CAIRO_STACK_BUFFER_SIZE / sizeof(cairo_box_int_t)))
-
 /**
  * _cairo_traps_extract_region:
  * @traps: a #cairo_traps_t
@@ -591,7 +589,7 @@ cairo_int_status_t
 _cairo_traps_extract_region (cairo_traps_t  *traps,
 			     cairo_region_t *region)
 {
-    cairo_box_int_t stack_boxes[STACK_BOXES_LEN];
+    cairo_box_int_t stack_boxes[CAIRO_STACK_ARRAY_LENGTH (cairo_box_int_t)];
     cairo_box_int_t *boxes = stack_boxes;
     int i, box_count;
     cairo_int_status_t status;
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 93a19fc..129277c 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -2857,7 +2857,6 @@ typedef struct {
 typedef int cairo_xlib_glyph_t_size_assertion [sizeof (cairo_xlib_glyph_t) == sizeof (cairo_glyph_t) ? 1 : -1];
 
 #define GLYPH_INDEX_SKIP ((unsigned long) -1)
-#define STACK_ELTS_LEN ((int) (CAIRO_STACK_BUFFER_SIZE / sizeof (XGlyphElt8)))
 
 static cairo_status_t
 _cairo_xlib_surface_emit_glyphs_chunk (cairo_xlib_surface_t *dst,
@@ -2878,7 +2877,7 @@ _cairo_xlib_surface_emit_glyphs_chunk (cairo_xlib_surface_t *dst,
 
     /* Element buffer stuff */
     XGlyphElt8 *elts;
-    XGlyphElt8 stack_elts[STACK_ELTS_LEN];
+    XGlyphElt8 stack_elts[CAIRO_STACK_ARRAY_LENGTH (XGlyphElt8)];
 
     /* Reuse the input glyph array for output char generation */
     char *char8 = (char *) glyphs;
@@ -2907,7 +2906,7 @@ _cairo_xlib_surface_emit_glyphs_chunk (cairo_xlib_surface_t *dst,
     }
 
     /* Allocate element array */
-    if (num_elts <= STACK_ELTS_LEN) {
+    if (num_elts <= ARRAY_LENGTH (stack_elts)) {
       elts = stack_elts;
     } else {
       elts = _cairo_malloc_ab (num_elts, sizeof (XGlyphElt8));
@@ -2972,8 +2971,6 @@ _cairo_xlib_surface_emit_glyphs_chunk (cairo_xlib_surface_t *dst,
     return CAIRO_STATUS_SUCCESS;
 }
 
-#undef STACK_ELTS_LEN
-
 static cairo_status_t
 _cairo_xlib_surface_emit_glyphs (cairo_xlib_surface_t *dst,
 				 cairo_xlib_glyph_t *glyphs,
diff --git a/src/cairoint.h b/src/cairoint.h
index bde8f6b..5924ab3 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -109,6 +109,8 @@ CAIRO_BEGIN_DECLS
 #define CAIRO_STACK_BUFFER_SIZE (512 * sizeof (int))
 #endif
 
+#define CAIRO_STACK_ARRAY_LENGTH(T) (CAIRO_STACK_BUFFER_SIZE / sizeof(T))
+
 #define ASSERT_NOT_REACHED		\
 do {					\
     static const int NOT_REACHED = 0;	\


More information about the cairo-commit mailing list