mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-08 19:38:02 +02:00
Add attribute(warn_unused_result)
This adds a compiler check that the function result is used by the caller and enables it by default for all cairo_private functions and for public API that returns a cairo_status_t. It has been discussed that to extend the warnings to all functions, a new function type could been introduced to cover static functions: cairo_static. This has not been done at the present time in order to minimise the churn and focus on the more common errors. In order to reduce the warning spew generated by gcc for invalid use of this attribute, -Wno-attributes is added to CFLAGS. This has the unfortunate side-effect of masking future warnings for all attributes - be warned!
This commit is contained in:
parent
9da86e4a38
commit
46eab95698
6 changed files with 41 additions and 27 deletions
13
configure.in
13
configure.in
|
|
@ -623,7 +623,8 @@ MAYBE_WARN="-Wall -Wextra \
|
|||
-Wpacked -Wswitch-enum -Wmissing-format-attribute \
|
||||
-Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations \
|
||||
-Wdeclaration-after-statement -Wold-style-definition \
|
||||
-Wno-missing-field-initializers -Wno-unused-parameter"
|
||||
-Wno-missing-field-initializers -Wno-unused-parameter \
|
||||
-Wno-attributes"
|
||||
|
||||
|
||||
# invalidate cached value if MAYBE_WARN has changed
|
||||
|
|
@ -844,9 +845,19 @@ AC_CONFIG_COMMANDS([src/cairo-features.h],
|
|||
# define CAIRO_END_DECLS
|
||||
#endif
|
||||
|
||||
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
|
||||
#define CAIRO_WARN_UNUSED_RESULT \
|
||||
__attribute__((__warn_unused_result__))
|
||||
#else
|
||||
#define CAIRO_WARN_UNUSED_RESULT
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
#ifndef cairo_public
|
||||
# define cairo_public
|
||||
#endif
|
||||
#ifndef cairo_public_warn
|
||||
# define cairo_public_warn CAIRO_WARN_UNUSED_RESULT
|
||||
#endif
|
||||
|
||||
#define CAIRO_VERSION_MAJOR $CAIRO_VERSION_MAJOR
|
||||
#define CAIRO_VERSION_MINOR $CAIRO_VERSION_MINOR
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ WARN_CFLAGS=""
|
|||
if test "x$GCC" = "xyes"; then
|
||||
WARN_CFLAGS="-Wall -Wpointer-arith -Wstrict-prototypes \
|
||||
-Wmissing-prototypes -Wmissing-declarations \
|
||||
-Wnested-externs -fno-strict-aliasing"
|
||||
-Wnested-externs -fno-strict-aliasing \
|
||||
-Wno-attributes"
|
||||
fi
|
||||
|
||||
AC_SUBST(WARN_CFLAGS)
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ SOFTWARE.
|
|||
#include "pixman-remap.h"
|
||||
|
||||
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun__)
|
||||
#define pixman_private __attribute__((__visibility__("hidden")))
|
||||
#define pixman_private __attribute__((__visibility__("hidden"),__warn_unused_result__))
|
||||
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
|
||||
#define pixman_private __hidden
|
||||
#else /* not gcc >= 3.3 and not Sun Studio >= 8 */
|
||||
|
|
|
|||
40
src/cairo.h
40
src/cairo.h
|
|
@ -313,7 +313,7 @@ cairo_public void *
|
|||
cairo_get_user_data (cairo_t *cr,
|
||||
const cairo_user_data_key_t *key);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_set_user_data (cairo_t *cr,
|
||||
const cairo_user_data_key_t *key,
|
||||
void *user_data,
|
||||
|
|
@ -972,7 +972,7 @@ cairo_font_options_copy (const cairo_font_options_t *original);
|
|||
cairo_public void
|
||||
cairo_font_options_destroy (cairo_font_options_t *options);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_font_options_status (cairo_font_options_t *options);
|
||||
|
||||
cairo_public void
|
||||
|
|
@ -1088,7 +1088,7 @@ cairo_font_face_destroy (cairo_font_face_t *font_face);
|
|||
cairo_public unsigned int
|
||||
cairo_font_face_get_reference_count (cairo_font_face_t *font_face);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_font_face_status (cairo_font_face_t *font_face);
|
||||
|
||||
/**
|
||||
|
|
@ -1141,7 +1141,7 @@ cairo_public void *
|
|||
cairo_font_face_get_user_data (cairo_font_face_t *font_face,
|
||||
const cairo_user_data_key_t *key);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_font_face_set_user_data (cairo_font_face_t *font_face,
|
||||
const cairo_user_data_key_t *key,
|
||||
void *user_data,
|
||||
|
|
@ -1164,7 +1164,7 @@ cairo_scaled_font_destroy (cairo_scaled_font_t *scaled_font);
|
|||
cairo_public unsigned int
|
||||
cairo_scaled_font_get_reference_count (cairo_scaled_font_t *scaled_font);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_scaled_font_status (cairo_scaled_font_t *scaled_font);
|
||||
|
||||
cairo_public cairo_font_type_t
|
||||
|
|
@ -1174,7 +1174,7 @@ cairo_public void *
|
|||
cairo_scaled_font_get_user_data (cairo_scaled_font_t *scaled_font,
|
||||
const cairo_user_data_key_t *key);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_scaled_font_set_user_data (cairo_scaled_font_t *scaled_font,
|
||||
const cairo_user_data_key_t *key,
|
||||
void *user_data,
|
||||
|
|
@ -1392,7 +1392,7 @@ cairo_path_destroy (cairo_path_t *path);
|
|||
|
||||
/* Error status queries */
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_status (cairo_t *cr);
|
||||
|
||||
cairo_public const char *
|
||||
|
|
@ -1418,7 +1418,7 @@ cairo_surface_destroy (cairo_surface_t *surface);
|
|||
cairo_public unsigned int
|
||||
cairo_surface_get_reference_count (cairo_surface_t *surface);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_surface_status (cairo_surface_t *surface);
|
||||
|
||||
/**
|
||||
|
|
@ -1482,11 +1482,11 @@ cairo_surface_get_content (cairo_surface_t *surface);
|
|||
|
||||
#if CAIRO_HAS_PNG_FUNCTIONS
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_surface_write_to_png (cairo_surface_t *surface,
|
||||
const char *filename);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_surface_write_to_png_stream (cairo_surface_t *surface,
|
||||
cairo_write_func_t write_func,
|
||||
void *closure);
|
||||
|
|
@ -1497,7 +1497,7 @@ cairo_public void *
|
|||
cairo_surface_get_user_data (cairo_surface_t *surface,
|
||||
const cairo_user_data_key_t *key);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_surface_set_user_data (cairo_surface_t *surface,
|
||||
const cairo_user_data_key_t *key,
|
||||
void *user_data,
|
||||
|
|
@ -1642,14 +1642,14 @@ cairo_pattern_destroy (cairo_pattern_t *pattern);
|
|||
cairo_public unsigned int
|
||||
cairo_pattern_get_reference_count (cairo_pattern_t *pattern);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_pattern_status (cairo_pattern_t *pattern);
|
||||
|
||||
cairo_public void *
|
||||
cairo_pattern_get_user_data (cairo_pattern_t *pattern,
|
||||
const cairo_user_data_key_t *key);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_pattern_set_user_data (cairo_pattern_t *pattern,
|
||||
const cairo_user_data_key_t *key,
|
||||
void *user_data,
|
||||
|
|
@ -1758,32 +1758,32 @@ cairo_pattern_set_filter (cairo_pattern_t *pattern, cairo_filter_t filter);
|
|||
cairo_public cairo_filter_t
|
||||
cairo_pattern_get_filter (cairo_pattern_t *pattern);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_pattern_get_rgba (cairo_pattern_t *pattern,
|
||||
double *red, double *green,
|
||||
double *blue, double *alpha);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_pattern_get_surface (cairo_pattern_t *pattern,
|
||||
cairo_surface_t **surface);
|
||||
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_pattern_get_color_stop_rgba (cairo_pattern_t *pattern,
|
||||
int index, double *offset,
|
||||
double *red, double *green,
|
||||
double *blue, double *alpha);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_pattern_get_color_stop_count (cairo_pattern_t *pattern,
|
||||
int *count);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_pattern_get_linear_points (cairo_pattern_t *pattern,
|
||||
double *x0, double *y0,
|
||||
double *x1, double *y1);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_pattern_get_radial_circles (cairo_pattern_t *pattern,
|
||||
double *x0, double *y0, double *r0,
|
||||
double *x1, double *y1, double *r1);
|
||||
|
|
@ -1820,7 +1820,7 @@ cairo_matrix_scale (cairo_matrix_t *matrix, double sx, double sy);
|
|||
cairo_public void
|
||||
cairo_matrix_rotate (cairo_matrix_t *matrix, double radians);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_public_warn cairo_status_t
|
||||
cairo_matrix_invert (cairo_matrix_t *matrix);
|
||||
|
||||
cairo_public void
|
||||
|
|
|
|||
|
|
@ -102,13 +102,15 @@ CAIRO_BEGIN_DECLS
|
|||
|
||||
/* slim_internal.h */
|
||||
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun)
|
||||
#define cairo_private __attribute__((__visibility__("hidden")))
|
||||
#define cairo_private __attribute__((__visibility__("hidden"),__warn_unused_result__))
|
||||
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
|
||||
#define cairo_private __hidden
|
||||
#define cairo_private __hidden CAIRO_WARN_UNUSED_RESULT
|
||||
#else /* not gcc >= 3.3 and not Sun Studio >= 8 */
|
||||
#define cairo_private
|
||||
#define cairo_private CAIRO_WARN_UNUSED_RESULT
|
||||
#endif
|
||||
|
||||
#define cairo_warn CAIRO_WARN_UNUSED_RESULT
|
||||
|
||||
/* This macro allow us to deprecate a function by providing an alias
|
||||
for the old function name to the new function name. With this
|
||||
macro, binary compatibility is preserved. The macro only works on
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ xargs grep -B 1 '^cairo_.*[ ]\+(' |
|
|||
awk '
|
||||
/^--$/ { context=""; public=0; next; }
|
||||
/:cairo_.*[ ]+\(/ { if (!public) {print context; print; print "--";} next; }
|
||||
/-cairo_public[ ]/ {public=1;}
|
||||
/-cairo_public.*[ ]/ {public=1;}
|
||||
{ context=$0; }
|
||||
' |
|
||||
sed 's/[.]h-/.h:/' |
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue