From 35b61a7512dc1b8b1d8bc562aad2a72d254b8a69 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sun, 1 Sep 2013 15:01:15 +0000 Subject: Move GCC attributes into a centraized defines Instead of having ifdef __GNUC__ all over the headers to use special compiler's hints use a special file where all things like this are concentrated. Makes code easier to follow and allows to manage special attributes in more efficient way. Thanks Campbell for review! --- source/blender/blenlib/BLI_compiler_attrs.h | 88 ++++++++++++++++ source/blender/blenlib/BLI_dynstr.h | 14 +-- source/blender/blenlib/BLI_endian_switch.h | 41 +++----- source/blender/blenlib/BLI_math_geom.h | 7 +- source/blender/blenlib/BLI_math_vector.h | 99 +++++++++--------- source/blender/blenlib/BLI_memarena.h | 50 ++------- source/blender/blenlib/BLI_mempool.h | 105 +++---------------- source/blender/blenlib/BLI_path_util.h | 26 ++--- source/blender/blenlib/BLI_smallhash.h | 32 ++---- source/blender/blenlib/BLI_string.h | 157 +++++----------------------- source/blender/blenlib/BLI_string_utf8.h | 60 +++++------ source/blender/blenlib/BLI_utildefines.h | 6 -- 12 files changed, 248 insertions(+), 437 deletions(-) create mode 100644 source/blender/blenlib/BLI_compiler_attrs.h (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/BLI_compiler_attrs.h b/source/blender/blenlib/BLI_compiler_attrs.h new file mode 100644 index 00000000000..fc16e7dbba6 --- /dev/null +++ b/source/blender/blenlib/BLI_compiler_attrs.h @@ -0,0 +1,88 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2013 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Campbell Barton + * Sergey Sharybin + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BLI_COMPILER_ATTRS_H__ +#define __BLI_COMPILER_ATTRS_H__ + +/** \file BLI_compiler_attrs.h + * \ingroup bli + */ + +/* hint to make sure function result is actually used */ +#ifdef __GNUC__ +# define ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#else +# define ATTR_WARN_UNUSED_RESULT +#endif + +/* hint to mark function arguments expected to be non-null + * if no arguments are given to the macro, all of pointer + * arguments owuld be expected to be non-null + */ +#ifdef __GNUC__ +# define ATTR_NONNULL(args ...) __attribute__((nonnull(args))) +#else +# define ATTR_NONNULL(...) +#endif + +/* hint to mark function as it wouldn't return */ +#if defined(__GNUC__) || defined(__clang__) +# define ATTR_NORETURN __attribute__((noreturn)) +#else +# define ATTR_NORETURN +#endif + +/* hint to treat any non-null function return value cannot alias any other pointer */ +#if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 403)) +# define ATTR_MALLOC __attribute__((malloc)) +#else +# define ATTR_MALLOC +#endif + +/* the function return value points to memory (2 args for 'size * tot') */ +#if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 403)) +# define ATTR_ALLOC_SIZE(args ...) __attribute__((alloc_size(args))) +#else +# define ATTR_ALLOC_SIZE(...) +#endif + +/* ensures a NULL terminating argument as the n'th last argument of a variadic function */ +#ifdef __GNUC__ +# define ATTR_SENTINEL(arg_pos) __attribute__((sentinel(arg_pos))) +#else +# define ATTR_SENTINEL(arg_pos) +#endif + +/* hint to compiler that function uses printf-style format string */ +#ifdef __GNUC__ +# define ATTR_PRINTF_FORMAT(format_param, dots_param) __attribute__((format(printf, format_param, dots_param))) +#else +# define ATTR_PRINTF_FORMAT(format_param, dots_param) +#endif + +#endif /* __BLI_COMPILER_ATTRS_H__ */ diff --git a/source/blender/blenlib/BLI_dynstr.h b/source/blender/blenlib/BLI_dynstr.h index 833c416c1c1..61bdf23cec1 100644 --- a/source/blender/blenlib/BLI_dynstr.h +++ b/source/blender/blenlib/BLI_dynstr.h @@ -40,6 +40,8 @@ #include +#include "BLI_compiler_attrs.h" + struct DynStr; /** The abstract DynStr type */ @@ -75,16 +77,8 @@ void BLI_dynstr_nappend(DynStr *ds, const char *cstr, int len); * \param ds The DynStr to append to. * \param format The printf format string to use. */ -void BLI_dynstr_appendf(DynStr *ds, const char *format, ...) -#ifdef __GNUC__ -__attribute__ ((format(printf, 2, 3))) -#endif -; -void BLI_dynstr_vappendf(DynStr *ds, const char *format, va_list args) -#ifdef __GNUC__ -__attribute__ ((format(printf, 2, 0))) -#endif -; +void BLI_dynstr_appendf(DynStr *ds, const char *format, ...) ATTR_PRINTF_FORMAT(2, 3); +void BLI_dynstr_vappendf(DynStr *ds, const char *format, va_list args) ATTR_PRINTF_FORMAT(2, 0); /** * Find the length of a DynStr. diff --git a/source/blender/blenlib/BLI_endian_switch.h b/source/blender/blenlib/BLI_endian_switch.h index f48b1b072c3..35242fecf4a 100644 --- a/source/blender/blenlib/BLI_endian_switch.h +++ b/source/blender/blenlib/BLI_endian_switch.h @@ -27,35 +27,28 @@ * \ingroup bli */ -#ifdef __GNUC__ -# define ATTR_ENDIAN_SWITCH \ - __attribute__((nonnull(1))) -#else -# define ATTR_ENDIAN_SWITCH -#endif +#include "BLI_compiler_attrs.h" /* BLI_endian_switch_inline.h */ -BLI_INLINE void BLI_endian_switch_int16(short *val) ATTR_ENDIAN_SWITCH; -BLI_INLINE void BLI_endian_switch_uint16(unsigned short *val) ATTR_ENDIAN_SWITCH; -BLI_INLINE void BLI_endian_switch_int32(int *val) ATTR_ENDIAN_SWITCH; -BLI_INLINE void BLI_endian_switch_uint32(unsigned int *val) ATTR_ENDIAN_SWITCH; -BLI_INLINE void BLI_endian_switch_float(float *val) ATTR_ENDIAN_SWITCH; -BLI_INLINE void BLI_endian_switch_int64(int64_t *val) ATTR_ENDIAN_SWITCH; -BLI_INLINE void BLI_endian_switch_uint64(uint64_t *val) ATTR_ENDIAN_SWITCH; -BLI_INLINE void BLI_endian_switch_double(double *val) ATTR_ENDIAN_SWITCH; +BLI_INLINE void BLI_endian_switch_int16(short *val) ATTR_NONNULL(1); +BLI_INLINE void BLI_endian_switch_uint16(unsigned short *val) ATTR_NONNULL(1); +BLI_INLINE void BLI_endian_switch_int32(int *val) ATTR_NONNULL(1); +BLI_INLINE void BLI_endian_switch_uint32(unsigned int *val) ATTR_NONNULL(1); +BLI_INLINE void BLI_endian_switch_float(float *val) ATTR_NONNULL(1); +BLI_INLINE void BLI_endian_switch_int64(int64_t *val) ATTR_NONNULL(1); +BLI_INLINE void BLI_endian_switch_uint64(uint64_t *val) ATTR_NONNULL(1); +BLI_INLINE void BLI_endian_switch_double(double *val) ATTR_NONNULL(1); /* endian_switch.c */ -void BLI_endian_switch_int16_array(short *val, const int size) ATTR_ENDIAN_SWITCH; -void BLI_endian_switch_uint16_array(unsigned short *val, const int size) ATTR_ENDIAN_SWITCH; -void BLI_endian_switch_int32_array(int *val, const int size) ATTR_ENDIAN_SWITCH; -void BLI_endian_switch_uint32_array(unsigned int *val, const int size) ATTR_ENDIAN_SWITCH; -void BLI_endian_switch_float_array(float *val, const int size) ATTR_ENDIAN_SWITCH; -void BLI_endian_switch_int64_array(int64_t *val, const int size) ATTR_ENDIAN_SWITCH; -void BLI_endian_switch_uint64_array(uint64_t *val, const int size) ATTR_ENDIAN_SWITCH; -void BLI_endian_switch_double_array(double *val, const int size) ATTR_ENDIAN_SWITCH; +void BLI_endian_switch_int16_array(short *val, const int size) ATTR_NONNULL(1); +void BLI_endian_switch_uint16_array(unsigned short *val, const int size) ATTR_NONNULL(1); +void BLI_endian_switch_int32_array(int *val, const int size) ATTR_NONNULL(1); +void BLI_endian_switch_uint32_array(unsigned int *val, const int size) ATTR_NONNULL(1); +void BLI_endian_switch_float_array(float *val, const int size) ATTR_NONNULL(1); +void BLI_endian_switch_int64_array(int64_t *val, const int size) ATTR_NONNULL(1); +void BLI_endian_switch_uint64_array(uint64_t *val, const int size) ATTR_NONNULL(1); +void BLI_endian_switch_double_array(double *val, const int size) ATTR_NONNULL(1); #include "BLI_endian_switch_inline.h" -#undef ATTR_ENDIAN_SWITCH - #endif /* __BLI_ENDIAN_SWITCH_H__ */ diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 559157370ca..d3f6c7ef14b 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -34,6 +34,7 @@ extern "C" { #endif +#include "BLI_compiler_attrs.h" #include "BLI_math_inline.h" #if BLI_MATH_DO_INLINE @@ -293,11 +294,7 @@ float form_factor_hemi_poly(float p[3], float n[3], bool axis_dominant_v3_to_m3(float r_mat[3][3], const float normal[3]); void axis_dominant_v3(int *r_axis_a, int *r_axis_b, const float axis[3]); -float axis_dominant_v3_max(int *r_axis_a, int *r_axis_b, const float axis[3]) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -#endif -; +float axis_dominant_v3_max(int *r_axis_a, int *r_axis_b, const float axis[3]) ATTR_WARN_UNUSED_RESULT; MINLINE int max_axis_v3(const float vec[3]); MINLINE int min_axis_v3(const float vec[3]); diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index 0a819ce062e..675ba88fc72 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -34,6 +34,7 @@ extern "C" { #endif +#include "BLI_compiler_attrs.h" #include "BLI_math_inline.h" /************************************* Init ***********************************/ @@ -43,11 +44,6 @@ extern "C" { # pragma GCC diagnostic ignored "-Wredundant-decls" #endif -#ifdef __GNUC__ -# define UNUSED_RESULT_ATTR __attribute__((warn_unused_result)) -#else -# define UNUSED_RESULT_ATTR -#endif MINLINE void zero_v2(float r[2]); MINLINE void zero_v3(float r[3]); @@ -117,10 +113,10 @@ MINLINE void mul_v3_v3(float r[3], const float a[3]); MINLINE void mul_v3_v3v3(float r[3], const float a[3], const float b[3]); MINLINE void mul_v4_fl(float r[4], float f); MINLINE void mul_v4_v4fl(float r[3], const float a[3], float f); -MINLINE float mul_project_m4_v3_zfac(float mat[4][4], const float co[3]) UNUSED_RESULT_ATTR; -MINLINE float dot_m3_v3_row_x(float M[3][3], const float a[3]) UNUSED_RESULT_ATTR; -MINLINE float dot_m3_v3_row_y(float M[3][3], const float a[3]) UNUSED_RESULT_ATTR; -MINLINE float dot_m3_v3_row_z(float M[3][3], const float a[3]) UNUSED_RESULT_ATTR; +MINLINE float mul_project_m4_v3_zfac(float mat[4][4], const float co[3]) ATTR_WARN_UNUSED_RESULT; +MINLINE float dot_m3_v3_row_x(float M[3][3], const float a[3]) ATTR_WARN_UNUSED_RESULT; +MINLINE float dot_m3_v3_row_y(float M[3][3], const float a[3]) ATTR_WARN_UNUSED_RESULT; +MINLINE float dot_m3_v3_row_z(float M[3][3], const float a[3]) ATTR_WARN_UNUSED_RESULT; MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f); MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3]); @@ -139,10 +135,10 @@ MINLINE void negate_v4_v4(float r[4], const float a[3]); MINLINE void negate_v3_short(short r[3]); -MINLINE float dot_v2v2(const float a[2], const float b[2]) UNUSED_RESULT_ATTR; -MINLINE float dot_v3v3(const float a[3], const float b[3]) UNUSED_RESULT_ATTR; +MINLINE float dot_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT; +MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT; -MINLINE float cross_v2v2(const float a[2], const float b[2]) UNUSED_RESULT_ATTR; +MINLINE float cross_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT; MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3]); MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3]); @@ -151,20 +147,20 @@ MINLINE void star_m3_v3(float rmat[3][3], float a[3]); /*********************************** Length **********************************/ -MINLINE float len_squared_v2(const float v[2]) UNUSED_RESULT_ATTR; -MINLINE float len_squared_v3(const float v[3]) UNUSED_RESULT_ATTR; -MINLINE float len_manhattan_v2(const float v[2]) UNUSED_RESULT_ATTR; -MINLINE int len_manhattan_v2_int(const int v[2]) UNUSED_RESULT_ATTR; -MINLINE float len_manhattan_v3(const float v[3]) UNUSED_RESULT_ATTR; -MINLINE float len_v2(const float a[2]) UNUSED_RESULT_ATTR; -MINLINE float len_v2v2(const float a[2], const float b[2]) UNUSED_RESULT_ATTR; -MINLINE float len_squared_v2v2(const float a[2], const float b[2]) UNUSED_RESULT_ATTR; -MINLINE float len_squared_v3v3(const float a[3], const float b[3]) UNUSED_RESULT_ATTR; -MINLINE float len_manhattan_v2v2(const float a[2], const float b[2]) UNUSED_RESULT_ATTR; -MINLINE int len_manhattan_v2v2_int(const int a[2], const int b[2]) UNUSED_RESULT_ATTR; -MINLINE float len_manhattan_v3v3(const float a[3], const float b[3]) UNUSED_RESULT_ATTR; -MINLINE float len_v3(const float a[3]) UNUSED_RESULT_ATTR; -MINLINE float len_v3v3(const float a[3], const float b[3]) UNUSED_RESULT_ATTR; +MINLINE float len_squared_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT; +MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT; +MINLINE float len_manhattan_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT; +MINLINE int len_manhattan_v2_int(const int v[2]) ATTR_WARN_UNUSED_RESULT; +MINLINE float len_manhattan_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT; +MINLINE float len_v2(const float a[2]) ATTR_WARN_UNUSED_RESULT; +MINLINE float len_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT; +MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT; +MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT; +MINLINE float len_manhattan_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT; +MINLINE int len_manhattan_v2v2_int(const int a[2], const int b[2]) ATTR_WARN_UNUSED_RESULT; +MINLINE float len_manhattan_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT; +MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT; +MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT; MINLINE float normalize_v2(float r[2]); MINLINE float normalize_v2_v2(float r[2], const float a[2]); @@ -196,41 +192,41 @@ void flip_v2_v2v2(float v[2], const float v1[2], const float v2[2]); /********************************* Comparison ********************************/ -MINLINE bool is_zero_v2(const float a[3]) UNUSED_RESULT_ATTR; -MINLINE bool is_zero_v3(const float a[3]) UNUSED_RESULT_ATTR; -MINLINE bool is_zero_v4(const float a[4]) UNUSED_RESULT_ATTR; +MINLINE bool is_zero_v2(const float a[3]) ATTR_WARN_UNUSED_RESULT; +MINLINE bool is_zero_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT; +MINLINE bool is_zero_v4(const float a[4]) ATTR_WARN_UNUSED_RESULT; -MINLINE bool is_finite_v2(const float a[3]) UNUSED_RESULT_ATTR; -MINLINE bool is_finite_v3(const float a[3]) UNUSED_RESULT_ATTR; -MINLINE bool is_finite_v4(const float a[4]) UNUSED_RESULT_ATTR; +MINLINE bool is_finite_v2(const float a[3]) ATTR_WARN_UNUSED_RESULT; +MINLINE bool is_finite_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT; +MINLINE bool is_finite_v4(const float a[4]) ATTR_WARN_UNUSED_RESULT; -MINLINE bool is_one_v3(const float a[3]) UNUSED_RESULT_ATTR; +MINLINE bool is_one_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT; -MINLINE bool equals_v2v2(const float v1[2], const float v2[2]) UNUSED_RESULT_ATTR; -MINLINE bool equals_v3v3(const float a[3], const float b[3]) UNUSED_RESULT_ATTR; -MINLINE bool compare_v2v2(const float a[2], const float b[2], const float limit) UNUSED_RESULT_ATTR; -MINLINE bool compare_v3v3(const float a[3], const float b[3], const float limit) UNUSED_RESULT_ATTR; -MINLINE bool compare_len_v3v3(const float a[3], const float b[3], const float limit) UNUSED_RESULT_ATTR; +MINLINE bool equals_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT; +MINLINE bool equals_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT; +MINLINE bool compare_v2v2(const float a[2], const float b[2], const float limit) ATTR_WARN_UNUSED_RESULT; +MINLINE bool compare_v3v3(const float a[3], const float b[3], const float limit) ATTR_WARN_UNUSED_RESULT; +MINLINE bool compare_len_v3v3(const float a[3], const float b[3], const float limit) ATTR_WARN_UNUSED_RESULT; -MINLINE bool compare_v4v4(const float a[4], const float b[4], const float limit) UNUSED_RESULT_ATTR; -MINLINE bool equals_v4v4(const float a[4], const float b[4]) UNUSED_RESULT_ATTR; +MINLINE bool compare_v4v4(const float a[4], const float b[4], const float limit) ATTR_WARN_UNUSED_RESULT; +MINLINE bool equals_v4v4(const float a[4], const float b[4]) ATTR_WARN_UNUSED_RESULT; -MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2]) UNUSED_RESULT_ATTR; +MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2]) ATTR_WARN_UNUSED_RESULT; /********************************** Angles ***********************************/ /* - angle with 2 arguments is angle between vector */ /* - angle with 3 arguments is angle between 3 points at the middle point */ /* - angle_normalized_* is faster equivalent if vectors are normalized */ -float angle_v2v2(const float a[2], const float b[2]) UNUSED_RESULT_ATTR; -float angle_signed_v2v2(const float v1[2], const float v2[2]) UNUSED_RESULT_ATTR; -float angle_v2v2v2(const float a[2], const float b[2], const float c[2]) UNUSED_RESULT_ATTR; -float angle_normalized_v2v2(const float a[2], const float b[2]) UNUSED_RESULT_ATTR; -float angle_v3v3(const float a[3], const float b[3]) UNUSED_RESULT_ATTR; -float angle_v3v3v3(const float a[3], const float b[3], const float c[3]) UNUSED_RESULT_ATTR; -float cos_v3v3v3(const float p1[3], const float p2[3], const float p3[3]) UNUSED_RESULT_ATTR; -float angle_normalized_v3v3(const float v1[3], const float v2[3]) UNUSED_RESULT_ATTR; -float angle_on_axis_v3v3v3_v3(const float v1[3], const float v2[3], const float v3[3], const float axis[3]) UNUSED_RESULT_ATTR; +float angle_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT; +float angle_signed_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT; +float angle_v2v2v2(const float a[2], const float b[2], const float c[2]) ATTR_WARN_UNUSED_RESULT; +float angle_normalized_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT; +float angle_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT; +float angle_v3v3v3(const float a[3], const float b[3], const float c[3]) ATTR_WARN_UNUSED_RESULT; +float cos_v3v3v3(const float p1[3], const float p2[3], const float p3[3]) ATTR_WARN_UNUSED_RESULT; +float angle_normalized_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT; +float angle_on_axis_v3v3v3_v3(const float v1[3], const float v2[3], const float v3[3], const float axis[3]) ATTR_WARN_UNUSED_RESULT; void angle_tri_v3(float angles[3], const float v1[3], const float v2[3], const float v3[3]); void angle_quad_v3(float angles[4], const float v1[3], const float v2[3], const float v3[3], const float v4[3]); void angle_poly_v3(float *angles, const float *verts[3], int len); @@ -266,7 +262,7 @@ void axis_sort_v3(const float axis_values[3], int r_axis_order[3]); /***************************** Array Functions *******************************/ /* attempted to follow fixed length vertex functions. names could be improved*/ -double dot_vn_vn(const float *array_src_a, const float *array_src_b, const int size) UNUSED_RESULT_ATTR; +double dot_vn_vn(const float *array_src_a, const float *array_src_b, const int size) ATTR_WARN_UNUSED_RESULT; float normalize_vn_vn(float *array_tar, const float *array_src, const int size); float normalize_vn(float *array_tar, const int size); void range_vn_i(int *array_tar, const int size, const int start); @@ -297,7 +293,6 @@ void fill_vn_fl(float *array_tar, const int size, const float val); #ifdef BLI_MATH_GCC_WARN_PRAGMA # pragma GCC diagnostic pop #endif -#undef UNUSED_RESULT_ATTR #ifdef __cplusplus } diff --git a/source/blender/blenlib/BLI_memarena.h b/source/blender/blenlib/BLI_memarena.h index fbcacf515b5..f8df8b0d63d 100644 --- a/source/blender/blenlib/BLI_memarena.h +++ b/source/blender/blenlib/BLI_memarena.h @@ -41,57 +41,23 @@ extern "C" { #endif +#include "BLI_compiler_attrs.h" + /* A reasonable standard buffer size, big * enough to not cause much internal fragmentation, * small enough not to waste resources */ #define BLI_MEMARENA_STD_BUFSIZE (1 << 14) -/* some GNU attributes are only available from GCC 4.3 */ -#define MEM_GNU_ATTRIBUTES (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 403)) - struct MemArena; typedef struct MemArena MemArena; -struct MemArena *BLI_memarena_new(const int bufsize, const char *name) -#if MEM_GNU_ATTRIBUTES -__attribute__((malloc)) -__attribute__((warn_unused_result)) -__attribute__((nonnull(2))) -#endif -; - -void BLI_memarena_free(struct MemArena *ma) -#if MEM_GNU_ATTRIBUTES -__attribute__((nonnull(1))) -#endif -; - -void BLI_memarena_use_malloc(struct MemArena *ma) -#if MEM_GNU_ATTRIBUTES -__attribute__((nonnull(1))) -#endif -; -void BLI_memarena_use_calloc(struct MemArena *ma) -#if MEM_GNU_ATTRIBUTES -__attribute__((nonnull(1))) -#endif -; - -void BLI_memarena_use_align(struct MemArena *ma, const int align) -#if MEM_GNU_ATTRIBUTES -__attribute__((nonnull(1))) -#endif -; - -void *BLI_memarena_alloc(struct MemArena *ma, int size) -#if MEM_GNU_ATTRIBUTES -__attribute__((malloc)) -__attribute__((warn_unused_result)) -__attribute__((nonnull(1))) -__attribute__((alloc_size(2))) -#endif -; +struct MemArena *BLI_memarena_new(const int bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2) ATTR_MALLOC; +void BLI_memarena_free(struct MemArena *ma) ATTR_NONNULL(1); +void BLI_memarena_use_malloc(struct MemArena *ma) ATTR_NONNULL(1); +void BLI_memarena_use_calloc(struct MemArena *ma) ATTR_NONNULL(1); +void BLI_memarena_use_align(struct MemArena *ma, const int align) ATTR_NONNULL(1); +void *BLI_memarena_alloc(struct MemArena *ma, int size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2); void BLI_memarena_clear(MemArena *ma) #if MEM_GNU_ATTRIBUTES diff --git a/source/blender/blenlib/BLI_mempool.h b/source/blender/blenlib/BLI_mempool.h index 153a3735182..88650719712 100644 --- a/source/blender/blenlib/BLI_mempool.h +++ b/source/blender/blenlib/BLI_mempool.h @@ -39,6 +39,8 @@ extern "C" { #endif +#include "BLI_compiler_attrs.h" + struct BLI_mempool; struct BLI_mempool_chunk; @@ -49,85 +51,21 @@ typedef struct BLI_mempool BLI_mempool; * 'free'. use with care.*/ BLI_mempool *BLI_mempool_create(unsigned int esize, unsigned int totelem, - unsigned int pchunk, unsigned int flag) -#ifdef __GNUC__ -__attribute__((malloc)) -__attribute__((warn_unused_result)) -#endif -; -void *BLI_mempool_alloc(BLI_mempool *pool) -#ifdef __GNUC__ -__attribute__((malloc)) -__attribute__((warn_unused_result)) -__attribute__((nonnull(1))) -#endif -; -void *BLI_mempool_calloc(BLI_mempool *pool) -#ifdef __GNUC__ -__attribute__((malloc)) -__attribute__((warn_unused_result)) -__attribute__((nonnull(1))) -#endif -; -void BLI_mempool_free(BLI_mempool *pool, void *addr) -#ifdef __GNUC__ -__attribute__((nonnull(1, 2))) -#endif -; + unsigned int pchunk, unsigned int flag) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT; +void *BLI_mempool_alloc(BLI_mempool *pool) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); +void *BLI_mempool_calloc(BLI_mempool *pool) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); +void BLI_mempool_free(BLI_mempool *pool, void *addr) ATTR_NONNULL(1, 2); void BLI_mempool_clear_ex(BLI_mempool *pool, - const int totelem_reserve) -#ifdef __GNUC__ -__attribute__((nonnull(1))) -#endif -; -void BLI_mempool_clear(BLI_mempool *pool) -#ifdef __GNUC__ -__attribute__((nonnull(1))) -#endif -; -void BLI_mempool_destroy(BLI_mempool *pool) -#ifdef __GNUC__ -__attribute__((nonnull(1))) -#endif -; -int BLI_mempool_count(BLI_mempool *pool) -#ifdef __GNUC__ -__attribute__((nonnull(1))) -#endif -; -void *BLI_mempool_findelem(BLI_mempool *pool, unsigned int index) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull(1))) -#endif -; -void BLI_mempool_as_table(BLI_mempool *pool, void **data) -#ifdef __GNUC__ -__attribute__((nonnull(1, 2))) -#endif -; + const int totelem_reserve) ATTR_NONNULL(1); +void BLI_mempool_clear(BLI_mempool *pool) ATTR_NONNULL(1); +void BLI_mempool_destroy(BLI_mempool *pool) ATTR_NONNULL(1); +int BLI_mempool_count(BLI_mempool *pool) ATTR_NONNULL(1); +void *BLI_mempool_findelem(BLI_mempool *pool, unsigned int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); -void **BLI_mempool_as_tableN(BLI_mempool *pool, const char *allocstr) -#ifdef __GNUC__ -__attribute__((malloc)) -__attribute__((warn_unused_result)) -__attribute__((nonnull(1, 2))) -#endif -; - -void BLI_mempool_as_array(BLI_mempool *pool, void *data) -#ifdef __GNUC__ -__attribute__((nonnull(1, 2))) -#endif -; - -void *BLI_mempool_as_arrayN(BLI_mempool *pool, const char *allocstr) -#ifdef __GNUC__ -__attribute__((malloc)) -__attribute__((warn_unused_result)) -__attribute__((nonnull(1, 2))) -#endif -; +void BLI_mempool_as_table(BLI_mempool *pool, void **data) ATTR_NONNULL(1, 2); +void **BLI_mempool_as_tableN(BLI_mempool *pool, const char *allocstr) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); +void BLI_mempool_as_array(BLI_mempool *pool, void *data) ATTR_NONNULL(1, 2); +void *BLI_mempool_as_arrayN(BLI_mempool *pool, const char *allocstr) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); /** iteration stuff. note: this may easy to produce bugs with **/ /* private structure */ @@ -143,17 +81,8 @@ enum { BLI_MEMPOOL_ALLOW_ITER = (1 << 1) }; -void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter) -#ifdef __GNUC__ -__attribute__((nonnull(1, 2))) -#endif -; -void *BLI_mempool_iterstep(BLI_mempool_iter *iter) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull(1))) -#endif -; +void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter) ATTR_NONNULL(); +void *BLI_mempool_iterstep(BLI_mempool_iter *iter) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); #ifdef __cplusplus } diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 113c511a4f7..d4c5d5fed9f 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -35,6 +35,8 @@ extern "C" { #endif +#include "BLI_compiler_attrs.h" + struct ListBase; struct direntry; @@ -90,17 +92,9 @@ void BLI_split_dirfile(const char *string, char *dir, char *file, const size_t d void BLI_split_dir_part(const char *string, char *dir, const size_t dirlen); void BLI_split_file_part(const char *string, char *file, const size_t filelen); void BLI_path_append(char *__restrict dst, const size_t maxlen, - const char *__restrict file) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; + const char *__restrict file) ATTR_NONNULL(); void BLI_join_dirfile(char *__restrict string, const size_t maxlen, - const char *__restrict dir, const char *__restrict file) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; + const char *__restrict dir, const char *__restrict file) ATTR_NONNULL(); const char *BLI_path_basename(const char *path); typedef enum bli_rebase_state { @@ -132,11 +126,7 @@ void BLI_stringenc(char *string, const char *head, const char *tail, unsigned sh int BLI_split_name_num(char *left, int *nr, const char *name, const char delim); /* make sure path separators conform to system one */ -void BLI_clean(char *path) -#ifdef __GNUC__ -__attribute__((nonnull(1))) -#endif -; +void BLI_clean(char *path) ATTR_NONNULL(); /** * dir can be any input, like from buttons, and this function @@ -182,11 +172,7 @@ bool BLI_path_is_rel(const char *path); # define BLI_path_ncmp strncmp #endif -void BLI_char_switch(char *string, char from, char to) -#ifdef __GNUC__ -__attribute__((nonnull(1))) -#endif -; +void BLI_char_switch(char *string, char from, char to) ATTR_NONNULL(); /* Initialize path to program executable */ void BLI_init_program_path(const char *argv0); diff --git a/source/blender/blenlib/BLI_smallhash.h b/source/blender/blenlib/BLI_smallhash.h index 275599a612c..4f5446043da 100644 --- a/source/blender/blenlib/BLI_smallhash.h +++ b/source/blender/blenlib/BLI_smallhash.h @@ -37,6 +37,8 @@ /* based on a doubling non-chaining approach */ +#include "BLI_compiler_attrs.h" + typedef struct { uintptr_t key; void *val; @@ -59,27 +61,15 @@ typedef struct { unsigned int i; } SmallHashIter; -#ifdef __GNUC__ -# define ATTR_NONULL_FIRST __attribute__((nonnull(1))) -# define ATTR_UNUSED_RESULT __attribute__((warn_unused_result)) -#else -# define ATTR_NONULL_FIRST -# define ATTR_UNUSED_RESULT -#endif - - -void BLI_smallhash_init(SmallHash *hash) ATTR_NONULL_FIRST; -void BLI_smallhash_release(SmallHash *hash) ATTR_NONULL_FIRST; -void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item) ATTR_NONULL_FIRST; -void BLI_smallhash_remove(SmallHash *hash, uintptr_t key) ATTR_NONULL_FIRST; -void *BLI_smallhash_lookup(SmallHash *hash, uintptr_t key) ATTR_NONULL_FIRST ATTR_UNUSED_RESULT; -int BLI_smallhash_haskey(SmallHash *hash, uintptr_t key) ATTR_NONULL_FIRST; -int BLI_smallhash_count(SmallHash *hash) ATTR_NONULL_FIRST; -void *BLI_smallhash_iternext(SmallHashIter *iter, uintptr_t *key) ATTR_NONULL_FIRST ATTR_UNUSED_RESULT; -void *BLI_smallhash_iternew(SmallHash *hash, SmallHashIter *iter, uintptr_t *key) ATTR_NONULL_FIRST ATTR_UNUSED_RESULT; +void BLI_smallhash_init(SmallHash *hash) ATTR_NONNULL(1); +void BLI_smallhash_release(SmallHash *hash) ATTR_NONNULL(1); +void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item) ATTR_NONNULL(1); +void BLI_smallhash_remove(SmallHash *hash, uintptr_t key) ATTR_NONNULL(1); +void *BLI_smallhash_lookup(SmallHash *hash, uintptr_t key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; +int BLI_smallhash_haskey(SmallHash *hash, uintptr_t key) ATTR_NONNULL(1); +int BLI_smallhash_count(SmallHash *hash) ATTR_NONNULL(1); +void *BLI_smallhash_iternext(SmallHashIter *iter, uintptr_t *key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; +void *BLI_smallhash_iternew(SmallHash *hash, SmallHashIter *iter, uintptr_t *key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; /* void BLI_smallhash_print(SmallHash *hash); */ /* UNUSED */ -#undef ATTR_NONULL_FIRST -#undef ATTR_UNUSED_RESULT - #endif /* __BLI_SMALLHASH_H__ */ diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index 6c66d2f4e18..b995f2565e1 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -38,152 +38,43 @@ extern "C" { #endif -char *BLI_strdupn(const char *str, const size_t len) -#ifdef __GNUC__ -__attribute__((malloc)) -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; +#include "BLI_compiler_attrs.h" -char *BLI_strdup(const char *str) -#ifdef __GNUC__ -__attribute__((malloc)) -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; +char *BLI_strdupn(const char *str, const size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -char *BLI_strdupcat(const char *__restrict str1, const char *__restrict str2) -#ifdef __GNUC__ -__attribute__((malloc)) -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; +char *BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC; -char *BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; +char *BLI_strdupcat(const char *__restrict str1, const char *__restrict str2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC; -size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, const size_t maxncpy) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; +char *BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL(); -size_t BLI_strcpy_rlen(char *__restrict dst, const char *__restrict src) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; +size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict prefix) -#ifdef __GNUC__ -__attribute__((malloc)) -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; +size_t BLI_strcpy_rlen(char *__restrict dst, const char *__restrict src) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -char *BLI_replacestrN(const char *__restrict str, const char *__restrict substr_old, const char *__restrict substr_new) -#ifdef __GNUC__ -__attribute__((malloc)) -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; +char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict prefix) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC; -size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format, ...) -#ifdef __GNUC__ -__attribute__ ((format(printf, 3, 4))) -__attribute__((nonnull)) -#endif -; +char *BLI_replacestrN(const char *__restrict str, const char *__restrict substr_old, const char *__restrict substr_new) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC; -size_t BLI_vsnprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format, va_list arg) -#ifdef __GNUC__ -__attribute__ ((format(printf, 3, 0))) -#endif -; - -char *BLI_sprintfN(const char *__restrict format, ...) -#ifdef __GNUC__ -__attribute__((malloc)) -__attribute__ ((format(printf, 1, 2))) -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; +size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format, ...) ATTR_NONNULL() ATTR_PRINTF_FORMAT(3, 4); -size_t BLI_strescape(char *__restrict dst, const char *__restrict src, const size_t maxncpy) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; +size_t BLI_vsnprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format, va_list arg) ATTR_PRINTF_FORMAT(3, 0); -int BLI_strcaseeq(const char *a, const char *b) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; +char *BLI_sprintfN(const char *__restrict format, ...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC ATTR_PRINTF_FORMAT(1, 2); -char *BLI_strcasestr(const char *s, const char *find) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; -int BLI_strcasecmp(const char *s1, const char *s2) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; -int BLI_strncasecmp(const char *s1, const char *s2, size_t len) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; -int BLI_natstrcmp(const char *s1, const char *s2) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; -size_t BLI_strnlen(const char *str, const size_t maxlen) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; -void BLI_timestr(double _time, char *str, size_t maxlen) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; +size_t BLI_strescape(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL(); -void BLI_ascii_strtolower(char *str, const size_t len) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; -void BLI_ascii_strtoupper(char *str, const size_t len) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; -int BLI_str_rstrip_float_zero(char *str, const char pad) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; +int BLI_strcaseeq(const char *a, const char *b) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +char *BLI_strcasestr(const char *s, const char *find) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +int BLI_strcasecmp(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +int BLI_strncasecmp(const char *s1, const char *s2, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +int BLI_natstrcmp(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +size_t BLI_strnlen(const char *str, const size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +void BLI_timestr(double _time, char *str, size_t maxlen) ATTR_NONNULL(); + +void BLI_ascii_strtolower(char *str, const size_t len) ATTR_NONNULL(); +void BLI_ascii_strtoupper(char *str, const size_t len) ATTR_NONNULL(); +int BLI_str_rstrip_float_zero(char *str, const char pad) ATTR_NONNULL(); #ifdef __cplusplus } diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h index db32190494a..4aef2318683 100644 --- a/source/blender/blenlib/BLI_string_utf8.h +++ b/source/blender/blenlib/BLI_string_utf8.h @@ -31,57 +31,45 @@ extern "C" { #endif -#ifdef __GNUC__ -# define ATTR_NONULL __attribute__((nonnull)) -# define ATTR_NONULL_FIRST __attribute__((nonnull(1))) -# define ATTR_UNUSED_RESULT __attribute__((warn_unused_result)) -#else -# define ATTR_NONULL -# define ATTR_NONULL_FIRST -# define ATTR_UNUSED_RESULT -#endif +#include "BLI_compiler_attrs.h" -char *BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONULL; -char *BLI_strncat_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONULL; -int BLI_utf8_invalid_byte(const char *str, int length) ATTR_NONULL; -int BLI_utf8_invalid_strip(char *str, int length) ATTR_NONULL; +char *BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL(); +char *BLI_strncat_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL(); +int BLI_utf8_invalid_byte(const char *str, int length) ATTR_NONNULL(); +int BLI_utf8_invalid_strip(char *str, int length) ATTR_NONNULL(); -int BLI_str_utf8_size(const char *p) ATTR_NONULL; /* warning, can return -1 on bad chars */ -int BLI_str_utf8_size_safe(const char *p) ATTR_NONULL; +int BLI_str_utf8_size(const char *p) ATTR_NONNULL(); /* warning, can return -1 on bad chars */ +int BLI_str_utf8_size_safe(const char *p) ATTR_NONNULL(); /* copied from glib */ -unsigned int BLI_str_utf8_as_unicode(const char *p) ATTR_NONULL; -unsigned int BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *__restrict index) ATTR_NONULL; -unsigned int BLI_str_utf8_as_unicode_and_size_safe(const char *__restrict p, size_t *__restrict index) ATTR_NONULL; -unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t *__restrict index) ATTR_NONULL; +unsigned int BLI_str_utf8_as_unicode(const char *p) ATTR_NONNULL(); +unsigned int BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *__restrict index) ATTR_NONNULL(); +unsigned int BLI_str_utf8_as_unicode_and_size_safe(const char *__restrict p, size_t *__restrict index) ATTR_NONNULL(); +unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t *__restrict index) ATTR_NONNULL(); size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf); -char *BLI_str_find_prev_char_utf8(const char *str, const char *p) ATTR_NONULL; -char *BLI_str_find_next_char_utf8(const char *p, const char *end) ATTR_NONULL_FIRST; -char *BLI_str_prev_char_utf8(const char *p) ATTR_NONULL; +char *BLI_str_find_prev_char_utf8(const char *str, const char *p) ATTR_NONNULL(); +char *BLI_str_find_next_char_utf8(const char *p, const char *end) ATTR_NONNULL(1); +char *BLI_str_prev_char_utf8(const char *p) ATTR_NONNULL(); /* wchar_t functions, copied from blenders own font.c originally */ -size_t BLI_wstrlen_utf8(const wchar_t *src) ATTR_NONULL; -size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes) ATTR_NONULL; -size_t BLI_strlen_utf8(const char *strc) ATTR_NONULL; -size_t BLI_strnlen_utf8_ex(const char *strc, const size_t maxlen, size_t *r_len_bytes) ATTR_NONULL; -size_t BLI_strnlen_utf8(const char *strc, const size_t maxlen) ATTR_NONULL; -size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, const size_t maxcpy) ATTR_NONULL; -size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst, const char *__restrict src, const size_t maxcpy) ATTR_NONULL; +size_t BLI_wstrlen_utf8(const wchar_t *src) ATTR_NONNULL(); +size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes) ATTR_NONNULL(); +size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(); +size_t BLI_strnlen_utf8_ex(const char *strc, const size_t maxlen, size_t *r_len_bytes) ATTR_NONNULL(); +size_t BLI_strnlen_utf8(const char *strc, const size_t maxlen) ATTR_NONNULL(); +size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, const size_t maxcpy) ATTR_NONNULL(); +size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst, const char *__restrict src, const size_t maxcpy) ATTR_NONNULL(); /* count columns that character/string occupies, based on wcwidth.c */ int BLI_wcwidth(wchar_t ucs); -int BLI_wcswidth(const wchar_t *pwcs, size_t n) ATTR_NONULL; -int BLI_str_utf8_char_width(const char *p) ATTR_NONULL; /* warning, can return -1 on bad chars */ -int BLI_str_utf8_char_width_safe(const char *p) ATTR_NONULL; +int BLI_wcswidth(const wchar_t *pwcs, size_t n) ATTR_NONNULL(); +int BLI_str_utf8_char_width(const char *p) ATTR_NONNULL(); /* warning, can return -1 on bad chars */ +int BLI_str_utf8_char_width_safe(const char *p) ATTR_NONNULL(); #define BLI_UTF8_MAX 6 /* mem */ #define BLI_UTF8_WIDTH_MAX 2 /* columns */ #define BLI_UTF8_ERR ((unsigned int)-1) -#undef ATTR_NONULL -#undef ATTR_NONULL_FIRST -#undef ATTR_UNUSED_RESULT - #ifdef __cplusplus } #endif diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 327a997bf39..c3a3c035ed3 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -337,12 +337,6 @@ # define UNUSED_FUNCTION(x) UNUSED_ ## x #endif -#ifdef __GNUC__ -# define WARN_UNUSED __attribute__((warn_unused_result)) -#else -# define WARN_UNUSED -#endif - /*little macro so inline keyword works*/ #if defined(_MSC_VER) # define BLI_INLINE static __forceinline -- cgit v1.2.3