[cairo] [PATCH] make sure compilers don't optimize cairo_status_t to unsigned char

Liu Yubao yubao.liu at gmail.com
Mon Jun 23 23:01:04 PDT 2008


Hi,

I use a GCC 4.2.1 cross compiling toolchain to build cairo-1.6.4 and find a problem. 
In cairo-clip.c:557:_cairo_clip_clip() function:

    status = _cairo_clip_intersect_path (clip,
                                         path, fill_rule, tolerance,
                                         antialias);
    if (status == CAIRO_STATUS_SUCCESS)
        clip->serial = _cairo_surface_allocate_clip_serial (target);

    if (status != CAIRO_INT_STATUS_UNSUPPORTED)
        return status;

The _cairo_clip_intersect_path() function returns CAIRO_INT_STATUS_UNSUPPORTED for a
cairo_image_surface_t, I guess the -O2 option make cairo_status_t be optimized to unsigned
char by GCC 4.2.1, so the "status" variable becomes 233 and the 
"status != CAIRO_INT_STATUS_UNSUPPORTED" condition becomes true wrongly.

I googled the web and find some GCC options related to that optimization:

    -fenum-int-equiv
    -fshort-enums
    -enum int

Somebody says these options can lead to binary incompatibility problem and my project
doesn't specify these explicitly, so I think it's better to modify cairo's code to prevent
that optimization. 

Best regards,
Liu Yubao

diff --git a/src/cairo.h b/src/cairo.h
index 4a3a773..8b791cd 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -237,8 +237,10 @@ typedef enum _cairo_status {
     CAIRO_STATUS_INVALID_INDEX,
     CAIRO_STATUS_CLIP_NOT_REPRESENTABLE,
     CAIRO_STATUS_TEMP_FILE_ERROR,
-    CAIRO_STATUS_INVALID_STRIDE
+    CAIRO_STATUS_INVALID_STRIDE,
     /* after adding a new error: update CAIRO_STATUS_LAST_STATUS in cairoint.h */
+
+    CAIRO_STATUS_DONT_OPTIMIZE_ENUM_TO_UNSIGNED_CHAR = 0x00FFFFFF
 } cairo_status_t;

 /**





More information about the cairo mailing list