patch for VxWorks / Wind River Diab Compiler support

Manfred Kogler <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CAMfrEkiRa1+cTZQcWuiN0HF-bM9Q8Dj0MGjwDW3guJn02wnUng@mail.gmail.com>
Hi all,

I am using cairo in a VxWorks project using Wind River Diab Compiler on a
PPC405 (no HW-floating point support). To get it cleanly compiled, I had to
fix a few warnings and errors:


(1) warning: last enum literal of several enumerations is frequently
suffixed with a comma
    e.g.
        typedef enum _cairo_backend_type {
            CAIRO_TYPE_DEFAULT,
            CAIRO_TYPE_SKIA,
        } cairo_backend_type_t;

            => removed comma after last enum literal

        typedef enum _cairo_backend_type {
            CAIRO_TYPE_DEFAULT,
            CAIRO_TYPE_SKIA
        } cairo_backend_type_t;


(2) error: structure initializations using braced lists must only use
non-const initializers

    => introduced define CAIRO_ONLY_CONST_INITIALIZERS_IN_BRACED_LIST:
        - if not defined (default), compiled code is like in cairo 1.12.16
        - if defined (explicitly define for Diab compiler), structure
initializations
          using braced lists that use non-const initialializers are
replaced by equivalent
          initialization statements


(3) no-floating-point-optimization / consistency: every call of
_cairo_round() is replaced
    with _cairo_lround()

    This is because to support no-floating-point-optimization, in header
file cairoint.h function
    _cairo_lround() is either inlined to _cairo_round() or implemented on
its own, depending
    on define DISABLE_SOME_FLOATING_POINT.

    Actually a proposal at this point: shouldn't _cairo_round() be removed
completely and
    instead only _cairo_lround() be used? (This proposal is not considered
in my patch!)


(4) error: array declarations of len 0 are not allowed -> replaced with
pointer to array-elem
    see file cairo-image-compositor.c:
        uint8_t _buf[0];
            ->
        uint8_t *_buf;


The patch I attached is based on cairo 1.12.16 release. I propose to take
it into the next release.

Many thanks and best regards,
Fred

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
cairo-1.12.16__diab-compiler_support.patch (application/octet-stream, 13.7 KB)
diff -r -u cairo-1.12.16/src/cairo-backend-private.h cairo-1.12.16__MODIFIED/src/cairo-backend-private.h
--- cairo-1.12.16/src/cairo-backend-private.h	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-backend-private.h	2014-02-18 14:32:46.526434900 +0100
@@ -41,7 +41,7 @@
 
 typedef enum _cairo_backend_type {
     CAIRO_TYPE_DEFAULT,
-    CAIRO_TYPE_SKIA,
+    CAIRO_TYPE_SKIA
 } cairo_backend_type_t;
 
 struct _cairo_backend {
diff -r -u cairo-1.12.16/src/cairo-bentley-ottmann-rectangular.c cairo-1.12.16__MODIFIED/src/cairo-bentley-ottmann-rectangular.c
--- cairo-1.12.16/src/cairo-bentley-ottmann-rectangular.c	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-bentley-ottmann-rectangular.c	2014-02-18 14:38:18.523631300 +0100
@@ -249,6 +249,7 @@
     /* Only emit (trivial) non-degenerate trapezoids with positive height. */
     if (likely (left->top < bot)) {
 	if (sweep_line->do_traps) {
+#ifndef CAIRO_ONLY_CONST_INITIALIZERS_IN_BRACED_LIST
 	    cairo_line_t _left = {
 		{ left->x, left->top },
 		{ left->x, bot },
@@ -256,6 +257,19 @@
 		{ left->right->x, left->top },
 		{ left->right->x, bot },
 	    };
+#else
+	    cairo_line_t _left, _right;
+
+	    _left.p1.x = left->x;
+	    _left.p1.y = left->top;
+	    _left.p2.x = left->x;
+	    _left.p2.y = bot;
+
+	    _right.p1.x = left->right->x;
+	    _right.p1.y = left->top;
+	    _right.p2.x = left->right->x;
+	    _right.p2.y = bot;
+#endif
 	    _cairo_traps_add_trap (sweep_line->container, left->top, bot, &_left, &_right);
 	    status = _cairo_traps_status ((cairo_traps_t *) sweep_line->container);
 	} else {
diff -r -u cairo-1.12.16/src/cairo-botor-scan-converter.c cairo-1.12.16__MODIFIED/src/cairo-botor-scan-converter.c
--- cairo-1.12.16/src/cairo-botor-scan-converter.c	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-botor-scan-converter.c	2014-02-18 14:39:15.785356900 +0100
@@ -101,7 +101,7 @@
 
 enum {
     START = 0x1,
-    STOP = 0x2,
+    STOP = 0x2
 };
 
 /* the parent is always given by index/2 */
diff -r -u cairo-1.12.16/src/cairo-cff-subset.c cairo-1.12.16__MODIFIED/src/cairo-cff-subset.c
--- cairo-1.12.16/src/cairo-cff-subset.c	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-cff-subset.c	2014-02-18 14:40:36.497427300 +0100
@@ -1164,7 +1164,7 @@
             p = decode_number (p, &yy);
     }
     /* Freetype uses 1/yy to get units per EM */
-    font->units_per_em = _cairo_round(1.0/yy);
+    font->units_per_em = _cairo_lround(1.0/yy);
 }
 
 static cairo_int_status_t
diff -r -u cairo-1.12.16/src/cairo-error-private.h cairo-1.12.16__MODIFIED/src/cairo-error-private.h
--- cairo-1.12.16/src/cairo-error-private.h	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-error-private.h	2014-02-18 14:41:47.358512700 +0100
@@ -98,7 +98,7 @@
     CAIRO_INT_STATUS_NOTHING_TO_DO,
     CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY,
     CAIRO_INT_STATUS_IMAGE_FALLBACK,
-    CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN,
+    CAIRO_INT_STATUS_ANALYZE_RECORDING_SURFACE_PATTERN
 };
 
 typedef enum _cairo_int_status cairo_int_status_t;
diff -r -u cairo-1.12.16/src/cairo-font-face-twin.c cairo-1.12.16__MODIFIED/src/cairo-font-face-twin.c
--- cairo-1.12.16/src/cairo-font-face-twin.c	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-font-face-twin.c	2014-02-18 14:42:03.907167400 +0100
@@ -367,8 +367,8 @@
     compute_hinting_scale (cr, x, y, y_scale, y_scale_inv);
 }
 
-#define SNAPXI(p)	(_cairo_round ((p) * x_scale) * x_scale_inv)
-#define SNAPYI(p)	(_cairo_round ((p) * y_scale) * y_scale_inv)
+#define SNAPXI(p)	(_cairo_lround ((p) * x_scale) * x_scale_inv)
+#define SNAPYI(p)	(_cairo_lround ((p) * y_scale) * y_scale_inv)
 
 /* This controls the global font size */
 #define F(g)		((g) / 72.)
diff -r -u cairo-1.12.16/src/cairo-image-compositor.c cairo-1.12.16__MODIFIED/src/cairo-image-compositor.c
--- cairo-1.12.16/src/cairo-image-compositor.c	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-image-compositor.c	2014-02-18 14:47:30.887013100 +0100
@@ -698,8 +698,17 @@
 			    cairo_tristrip_t *strip)
 {
     pixman_triangle_t tri;
+#ifndef CAIRO_ONLY_CONST_INITIALIZERS_IN_BRACED_LIST
     pixman_point_fixed_t *p[3] = {&tri.p1, &tri.p2, &tri.p3 };
     int n;
+#else
+    int n;
+    pixman_point_fixed_t *p[3];
+
+    p[0] = &tri.p1;
+    p[1] = &tri.p2;
+    p[2] = &tri.p3;
+#endif
 
     set_point (p[0], &strip->points[0]);
     set_point (p[1], &strip->points[1]);
@@ -1561,7 +1570,7 @@
 	    uint8_t *data;
 	} mask;
     } u;
-    uint8_t _buf[0];
+    uint8_t *_buf;
 #define SZ_BUF (int)(sizeof (cairo_abstract_span_renderer_t) - sizeof (cairo_image_span_renderer_t))
 } cairo_image_span_renderer_t;
 COMPILE_TIME_ASSERT (sizeof (cairo_image_span_renderer_t) <= sizeof (cairo_abstract_span_renderer_t));
diff -r -u cairo-1.12.16/src/cairo-mask-compositor.c cairo-1.12.16__MODIFIED/src/cairo-mask-compositor.c
--- cairo-1.12.16/src/cairo-mask-compositor.c	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-mask-compositor.c	2014-02-18 14:48:04.496013100 +0100
@@ -710,7 +710,7 @@
 enum {
     NEED_CLIP_REGION = 0x1,
     NEED_CLIP_SURFACE = 0x2,
-    FORCE_CLIP_REGION = 0x4,
+    FORCE_CLIP_REGION = 0x4
 };
 
 static cairo_bool_t
diff -r -u cairo-1.12.16/src/cairo-pattern-private.h cairo-1.12.16__MODIFIED/src/cairo-pattern-private.h
--- cairo-1.12.16/src/cairo-pattern-private.h	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-pattern-private.h	2014-02-18 14:49:06.587013100 +0100
@@ -51,7 +51,7 @@
     CAIRO_PATTERN_NOTIFY_MATRIX = 0x1,
     CAIRO_PATTERN_NOTIFY_FILTER = 0x2,
     CAIRO_PATTERN_NOTIFY_EXTEND = 0x4,
-    CAIRO_PATTERN_NOTIFY_OPACITY = 0x9,
+    CAIRO_PATTERN_NOTIFY_OPACITY = 0x9
 };
 
 struct _cairo_pattern_observer {
diff -r -u cairo-1.12.16/src/cairo-recording-surface-private.h cairo-1.12.16__MODIFIED/src/cairo-recording-surface-private.h
--- cairo-1.12.16/src/cairo-recording-surface-private.h	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-recording-surface-private.h	2014-02-18 14:49:32.136013100 +0100
@@ -48,7 +48,7 @@
     CAIRO_COMMAND_MASK,
     CAIRO_COMMAND_STROKE,
     CAIRO_COMMAND_FILL,
-    CAIRO_COMMAND_SHOW_TEXT_GLYPHS,
+    CAIRO_COMMAND_SHOW_TEXT_GLYPHS
 } cairo_command_type_t;
 
 typedef enum {
diff -r -u cairo-1.12.16/src/cairo-rtree-private.h cairo-1.12.16__MODIFIED/src/cairo-rtree-private.h
--- cairo-1.12.16/src/cairo-rtree-private.h	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-rtree-private.h	2014-02-18 14:49:39.447013100 +0100
@@ -47,7 +47,7 @@
 enum {
     CAIRO_RTREE_NODE_AVAILABLE,
     CAIRO_RTREE_NODE_DIVIDED,
-    CAIRO_RTREE_NODE_OCCUPIED,
+    CAIRO_RTREE_NODE_OCCUPIED
 };
 
 typedef struct _cairo_rtree_node {
diff -r -u cairo-1.12.16/src/cairo-surface-observer.c cairo-1.12.16__MODIFIED/src/cairo-surface-observer.c
--- cairo-1.12.16/src/cairo-surface-observer.c	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-surface-observer.c	2014-02-18 14:49:49.763013100 +0100
@@ -1770,7 +1770,7 @@
 static double percent (cairo_time_t a, cairo_time_t b)
 {
     /* Fake %.1f */
-    return _cairo_round (_cairo_time_to_s (a) * 1000 /
+    return _cairo_lround (_cairo_time_to_s (a) * 1000 /
 			 _cairo_time_to_s (b)) / 10;
 }
 
diff -r -u cairo-1.12.16/src/cairo-surface-subsurface.c cairo-1.12.16__MODIFIED/src/cairo-surface-subsurface.c
--- cairo-1.12.16/src/cairo-surface-subsurface.c	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-surface-subsurface.c	2014-02-18 14:51:08.778013100 +0100
@@ -114,9 +114,20 @@
 				 const cairo_clip_t *clip)
 {
     cairo_surface_subsurface_t *surface = abstract_surface;
+#ifndef CAIRO_ONLY_CONST_INITIALIZERS_IN_BRACED_LIST
     cairo_rectangle_int_t rect = { 0, 0, surface->extents.width, surface->extents.height };
     cairo_status_t status;
     cairo_clip_t *target_clip;
+#else
+    cairo_status_t status;
+    cairo_clip_t *target_clip;
+    cairo_rectangle_int_t rect;
+
+    rect.x = 0;
+    rect.y = 0;
+    rect.width = surface->extents.width;
+    rect.height = surface->extents.height;
+#endif
 
     target_clip = _cairo_clip_copy_intersect_rectangle (clip, &rect);
     status = _cairo_surface_offset_paint (surface->target,
@@ -134,9 +145,20 @@
 				const cairo_clip_t *clip)
 {
     cairo_surface_subsurface_t *surface = abstract_surface;
+#ifndef CAIRO_ONLY_CONST_INITIALIZERS_IN_BRACED_LIST
     cairo_rectangle_int_t rect = { 0, 0, surface->extents.width, surface->extents.height };
     cairo_status_t status;
     cairo_clip_t *target_clip;
+#else
+    cairo_status_t status;
+    cairo_clip_t *target_clip;
+    cairo_rectangle_int_t rect;
+
+    rect.x = 0;
+    rect.y = 0;
+    rect.width = surface->extents.width;
+    rect.height = surface->extents.height;
+#endif
 
     target_clip = _cairo_clip_copy_intersect_rectangle (clip, &rect);
     status = _cairo_surface_offset_mask (surface->target,
@@ -157,9 +179,20 @@
 				const cairo_clip_t		*clip)
 {
     cairo_surface_subsurface_t *surface = abstract_surface;
+#ifndef CAIRO_ONLY_CONST_INITIALIZERS_IN_BRACED_LIST
     cairo_rectangle_int_t rect = { 0, 0, surface->extents.width, surface->extents.height };
     cairo_status_t status;
     cairo_clip_t *target_clip;
+#else
+    cairo_status_t status;
+    cairo_clip_t *target_clip;
+    cairo_rectangle_int_t rect;
+
+    rect.x = 0;
+    rect.y = 0;
+    rect.width = surface->extents.width;
+    rect.height = surface->extents.height;
+#endif
 
     target_clip = _cairo_clip_copy_intersect_rectangle (clip, &rect);
     status = _cairo_surface_offset_fill (surface->target,
@@ -183,9 +216,20 @@
 				  const cairo_clip_t			*clip)
 {
     cairo_surface_subsurface_t *surface = abstract_surface;
+#ifndef CAIRO_ONLY_CONST_INITIALIZERS_IN_BRACED_LIST
     cairo_rectangle_int_t rect = { 0, 0, surface->extents.width, surface->extents.height };
     cairo_status_t status;
     cairo_clip_t *target_clip;
+#else
+    cairo_status_t status;
+    cairo_clip_t *target_clip;
+    cairo_rectangle_int_t rect;
+
+    rect.x = 0;
+    rect.y = 0;
+    rect.width = surface->extents.width;
+    rect.height = surface->extents.height;
+#endif
 
     target_clip = _cairo_clip_copy_intersect_rectangle (clip, &rect);
     status = _cairo_surface_offset_stroke (surface->target,
@@ -207,9 +251,20 @@
 				  const cairo_clip_t	*clip)
 {
     cairo_surface_subsurface_t *surface = abstract_surface;
+#ifndef CAIRO_ONLY_CONST_INITIALIZERS_IN_BRACED_LIST
     cairo_rectangle_int_t rect = { 0, 0, surface->extents.width, surface->extents.height };
     cairo_status_t status;
     cairo_clip_t *target_clip;
+#else
+    cairo_status_t status;
+    cairo_clip_t *target_clip;
+    cairo_rectangle_int_t rect;
+
+    rect.x = 0;
+    rect.y = 0;
+    rect.width = surface->extents.width;
+    rect.height = surface->extents.height;
+#endif
 
     target_clip = _cairo_clip_copy_intersect_rectangle (clip, &rect);
     status = _cairo_surface_offset_glyphs (surface->target,
diff -r -u cairo-1.12.16/src/cairo-traps-compositor.c cairo-1.12.16__MODIFIED/src/cairo-traps-compositor.c
--- cairo-1.12.16/src/cairo-traps-compositor.c	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-traps-compositor.c	2014-02-18 14:51:55.892013100 +0100
@@ -920,7 +920,7 @@
 enum {
     NEED_CLIP_REGION = 0x1,
     NEED_CLIP_SURFACE = 0x2,
-    FORCE_CLIP_REGION = 0x4,
+    FORCE_CLIP_REGION = 0x4
 };
 
 static cairo_bool_t
diff -r -u cairo-1.12.16/src/cairo-traps.c cairo-1.12.16__MODIFIED/src/cairo-traps.c
--- cairo-1.12.16/src/cairo-traps.c	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-traps.c	2014-02-18 15:08:39.958013100 +0100
@@ -1025,8 +1025,22 @@
 	if (spans[0].coverage) {
 	    cairo_fixed_t x0 = _cairo_fixed_from_int(spans[0].x);
 	    cairo_fixed_t x1 = _cairo_fixed_from_int(spans[1].x);
+#ifndef CAIRO_ONLY_CONST_INITIALIZERS_IN_BRACED_LIST
 	    cairo_line_t left = { { x0, top }, { x0, bot } },
 			 right = { { x1, top }, { x1, bot } };
+#else
+	    cairo_line_t left, right;
+
+	    left.p1.x = x0;
+	    left.p1.y = top;
+	    left.p2.x = x0;
+	    left.p2.y = bot;
+
+	    right.p1.x = x1;
+	    right.p1.y = top;
+	    right.p2.x = x1;
+	    right.p2.y = bot;
+#endif
 	    _cairo_traps_add_trap (r->traps, top, bot, &left, &right);
 	}
 	spans++;
diff -r -u cairo-1.12.16/src/cairo-types-private.h cairo-1.12.16__MODIFIED/src/cairo-types-private.h
--- cairo-1.12.16/src/cairo-types-private.h	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairo-types-private.h	2014-02-18 14:52:08.275013100 +0100
@@ -257,7 +257,7 @@
 } cairo_internal_surface_type_t;
 
 typedef enum _cairo_internal_device_type {
-    CAIRO_INTERNAL_DEVICE_TYPE_OBSERVER = 0x1000,
+    CAIRO_INTERNAL_DEVICE_TYPE_OBSERVER = 0x1000
 } cairo_device_surface_type_t;
 
 #define CAIRO_HAS_TEST_PAGINATED_SURFACE 1
@@ -389,7 +389,7 @@
     CAIRO_STOCK_WHITE,
     CAIRO_STOCK_BLACK,
     CAIRO_STOCK_TRANSPARENT,
-    CAIRO_STOCK_NUM_COLORS,
+    CAIRO_STOCK_NUM_COLORS
 } cairo_stock_t;
 
 typedef enum _cairo_image_transparency {
diff -r -u cairo-1.12.16/src/cairoint.h cairo-1.12.16__MODIFIED/src/cairoint.h
--- cairo-1.12.16/src/cairoint.h	2013-08-26 17:07:21.000000000 +0200
+++ cairo-1.12.16__MODIFIED/src/cairoint.h	2014-02-18 14:47:51.430013100 +0100
@@ -735,7 +735,7 @@
 
 enum {
     CAIRO_OPERATOR_BOUND_BY_MASK = 1 << 1,
-    CAIRO_OPERATOR_BOUND_BY_SOURCE = 1 << 2,
+    CAIRO_OPERATOR_BOUND_BY_SOURCE = 1 << 2
 };
 
 cairo_private uint32_t
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.