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/blenkernel/BKE_DerivedMesh.h | 8 +- source/blender/blenkernel/BKE_idprop.h | 171 +++++--------------------- source/blender/blenkernel/BKE_lamp.h | 8 +- source/blender/blenkernel/BKE_library.h | 30 +---- source/blender/blenkernel/BKE_modifier.h | 7 +- source/blender/blenkernel/BKE_report.h | 13 +- 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 - source/blender/bmesh/intern/bmesh_iterators.h | 13 +- source/blender/bmesh/intern/bmesh_polygon.h | 9 +- source/blender/editors/include/UI_interface.h | 31 +---- source/blender/imbuf/intern/jpeg.c | 6 +- source/blender/makesdna/DNA_ipo_types.h | 2 + source/blender/makesdna/intern/SConscript | 3 +- source/blender/makesrna/RNA_access.h | 20 +-- source/blender/windowmanager/WM_api.h | 19 +-- source/blender/windowmanager/WM_types.h | 33 ++--- 27 files changed, 328 insertions(+), 730 deletions(-) create mode 100644 source/blender/blenlib/BLI_compiler_attrs.h (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 8396380fd06..ebfc3f473d5 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -72,6 +72,8 @@ #include "DNA_customdata_types.h" #include "DNA_meshdata_types.h" +#include "BLI_compiler_attrs.h" + #include "BKE_customdata.h" #include "BKE_bvhutils.h" @@ -735,11 +737,7 @@ void DM_debug_print(DerivedMesh *dm); void DM_debug_print_cdlayers(CustomData *cdata); #endif -#ifdef __GNUC__ -BLI_INLINE int DM_origindex_mface_mpoly(const int *index_mf_to_mpoly, const int *index_mp_to_orig, const int i) - __attribute__((nonnull(1))) -; -#endif +BLI_INLINE int DM_origindex_mface_mpoly(const int *index_mf_to_mpoly, const int *index_mp_to_orig, const int i) ATTR_NONNULL(1); BLI_INLINE int DM_origindex_mface_mpoly(const int *index_mf_to_mpoly, const int *index_mp_to_orig, const int i) { diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h index 133a0690dc6..71fd163a8ee 100644 --- a/source/blender/blenkernel/BKE_idprop.h +++ b/source/blender/blenkernel/BKE_idprop.h @@ -30,6 +30,8 @@ #include "DNA_ID.h" +#include "BLI_compiler_attrs.h" + struct IDProperty; struct ID; @@ -55,32 +57,14 @@ typedef union IDPropertyTemplate { /* ----------- Property Array Type ---------- */ -IDProperty *IDP_NewIDPArray(const char *name) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; -IDProperty *IDP_CopyIDPArray(IDProperty *array) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; +IDProperty *IDP_NewIDPArray(const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +IDProperty *IDP_CopyIDPArray(IDProperty *array) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); void IDP_FreeIDPArray(IDProperty *prop); /* shallow copies item */ -void IDP_SetIndexArray(struct IDProperty *prop, int index, struct IDProperty *item); -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -struct IDProperty *IDP_GetIndexArray(struct IDProperty *prop, int index) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; +void IDP_SetIndexArray(struct IDProperty *prop, int index, struct IDProperty *item) ATTR_NONNULL(); +struct IDProperty *IDP_GetIndexArray(struct IDProperty *prop, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); void IDP_AppendArray(struct IDProperty *prop, struct IDProperty *item); void IDP_ResizeIDPArray(struct IDProperty *prop, int len); @@ -90,33 +74,11 @@ void IDP_ResizeArray(struct IDProperty *prop, int newlen); void IDP_FreeArray(struct IDProperty *prop); /* ---------- String Type ------------ */ -IDProperty *IDP_NewString(const char *st, const char *name, int maxlen) /* maxlen excludes '\0' */ -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull (2))) /* 'name' arg */ -#endif -; - -void IDP_AssignString(struct IDProperty *prop, const char *st, int maxlen) /* maxlen excludes '\0' */ -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; -void IDP_ConcatStringC(struct IDProperty *prop, const char *st) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; -void IDP_ConcatString(struct IDProperty *str1, struct IDProperty *append) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; -void IDP_FreeString(struct IDProperty *prop) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; +IDProperty *IDP_NewString(const char *st, const char *name, int maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2 /* 'name 'arg */); /* maxlen excludes '\0' */ +void IDP_AssignString(struct IDProperty *prop, const char *st, int maxlen) ATTR_NONNULL(); /* maxlen excludes '\0' */ +void IDP_ConcatStringC(struct IDProperty *prop, const char *st) ATTR_NONNULL(); +void IDP_ConcatString(struct IDProperty *str1, struct IDProperty *append) ATTR_NONNULL(); +void IDP_FreeString(struct IDProperty *prop) ATTR_NONNULL(); /*-------- ID Type -------*/ void IDP_LinkID(struct IDProperty *prop, ID *id); @@ -125,107 +87,30 @@ void IDP_UnlinkID(struct IDProperty *prop); /*-------- Group Functions -------*/ /** Sync values from one group to another, only where they match */ -void IDP_SyncGroupValues(struct IDProperty *dest, struct IDProperty *src) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; - -void IDP_ReplaceGroupInGroup(struct IDProperty *dest, struct IDProperty *src) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; -void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; - -void IDP_MergeGroup(IDProperty *dest, IDProperty *src, const int do_overwrite) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; - -int IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; +void IDP_SyncGroupValues(struct IDProperty *dest, struct IDProperty *src) ATTR_NONNULL(); +void IDP_ReplaceGroupInGroup(struct IDProperty *dest, struct IDProperty *src) ATTR_NONNULL(); +void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL(); +void IDP_MergeGroup(IDProperty *dest, IDProperty *src, const int do_overwrite) ATTR_NONNULL(); +int IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL(); int IDP_InsertToGroup(struct IDProperty *group, struct IDProperty *previous, - struct IDProperty *pnew) -#ifdef __GNUC__ -__attribute__((nonnull (1, 3))) /* 'group', 'pnew' */ -#endif -; -void IDP_RemFromGroup(struct IDProperty *group, struct IDProperty *prop) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; + struct IDProperty *pnew) ATTR_NONNULL(1 /* group */, 3 /* pnew */); +void IDP_RemFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL(); -IDProperty *IDP_GetPropertyFromGroup(struct IDProperty *prop, const char *name) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; -IDProperty *IDP_GetPropertyTypeFromGroup(struct IDProperty *prop, const char *name, const char type) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; -void *IDP_GetGroupIterator(struct IDProperty *prop) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -#endif -; -IDProperty *IDP_GroupIterNext(void *vself) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; -void IDP_FreeIterBeforeEnd(void *vself) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; +IDProperty *IDP_GetPropertyFromGroup(struct IDProperty *prop, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +IDProperty *IDP_GetPropertyTypeFromGroup(struct IDProperty *prop, const char *name, const char type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +void *IDP_GetGroupIterator(struct IDProperty *prop) ATTR_WARN_UNUSED_RESULT; +IDProperty *IDP_GroupIterNext(void *vself) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +void IDP_FreeIterBeforeEnd(void *vself) ATTR_NONNULL(); /*-------- Main Functions --------*/ -struct IDProperty *IDP_GetProperties(struct ID *id, int create_if_needed) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; -struct IDProperty *IDP_CopyProperty(struct IDProperty *prop) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; +struct IDProperty *IDP_GetProperties(struct ID *id, int create_if_needed) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +struct IDProperty *IDP_CopyProperty(struct IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -int IDP_EqualsProperties_ex(IDProperty *prop1, IDProperty *prop2, const int is_strict) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -#endif -; +int IDP_EqualsProperties_ex(IDProperty *prop1, IDProperty *prop2, const int is_strict) ATTR_WARN_UNUSED_RESULT; -int IDP_EqualsProperties(struct IDProperty *prop1, struct IDProperty *prop2) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -#endif -; +int IDP_EqualsProperties(struct IDProperty *prop1, struct IDProperty *prop2) ATTR_WARN_UNUSED_RESULT; -struct IDProperty *IDP_New(const int type, const IDPropertyTemplate *val, const char *name) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; +struct IDProperty *IDP_New(const int type, const IDPropertyTemplate *val, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); void IDP_FreeProperty(struct IDProperty *prop); diff --git a/source/blender/blenkernel/BKE_lamp.h b/source/blender/blenkernel/BKE_lamp.h index 205c7c7d1e6..fb2c4da91ea 100644 --- a/source/blender/blenkernel/BKE_lamp.h +++ b/source/blender/blenkernel/BKE_lamp.h @@ -36,13 +36,15 @@ extern "C" { #endif +#include "BLI_compiler_attrs.h" + struct Lamp; struct Main; struct Scene; -struct Lamp *BKE_lamp_add(struct Main *bmain, const char *name) WARN_UNUSED; -struct Lamp *BKE_lamp_copy(struct Lamp *la) WARN_UNUSED; -struct Lamp *localize_lamp(struct Lamp *la) WARN_UNUSED; +struct Lamp *BKE_lamp_add(struct Main *bmain, const char *name) ATTR_WARN_UNUSED_RESULT; +struct Lamp *BKE_lamp_copy(struct Lamp *la) ATTR_WARN_UNUSED_RESULT; +struct Lamp *localize_lamp(struct Lamp *la) ATTR_WARN_UNUSED_RESULT; void BKE_lamp_make_local(struct Lamp *la); void BKE_lamp_free(struct Lamp *la); diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index 3c5406c4a77..b8da5002d84 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -36,6 +36,8 @@ extern "C" { #endif +#include "BLI_compiler_attrs.h" + struct ListBase; struct ID; struct Main; @@ -45,24 +47,9 @@ struct bContext; struct PointerRNA; struct PropertyRNA; -void *BKE_libblock_alloc(struct ListBase *lb, short type, const char *name) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; -void *BKE_libblock_copy_ex(struct Main *bmain, struct ID *id) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; -void *BKE_libblock_copy(struct ID *id) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; +void *BKE_libblock_alloc(struct ListBase *lb, short type, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +void *BKE_libblock_copy_ex(struct Main *bmain, struct ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +void *BKE_libblock_copy(struct ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); void BKE_libblock_copy_data(struct ID *id, const struct ID *id_from, const bool do_action); void BKE_id_lib_local_paths(struct Main *bmain, struct Library *lib, struct ID *id); @@ -99,12 +86,7 @@ void rename_id(struct ID *id, const char *name); void name_uiprefix_id(char *name, const struct ID *id); void test_idbutton(char *name); void BKE_library_make_local(struct Main *bmain, struct Library *lib, bool untagged_only); -struct ID *BKE_libblock_find_name(const short type, const char *name) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -__attribute__((nonnull)) -#endif -; +struct ID *BKE_libblock_find_name(const short type, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); void clear_id_newpoins(void); #if 0 diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index 8f0d612d473..f42e131394b 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -29,6 +29,7 @@ */ #include "DNA_modifier_types.h" /* needed for all enum typdefs */ +#include "BLI_compiler_attrs.h" #include "BKE_customdata.h" struct ID; @@ -325,11 +326,7 @@ bool modifier_isCorrectableDeformed(struct ModifierData *md); bool modifier_isSameTopology(ModifierData *md); bool modifier_isNonGeometrical(ModifierData *md); bool modifier_isEnabled(struct Scene *scene, struct ModifierData *md, int required_mode); -void modifier_setError(struct ModifierData *md, const char *format, ...) -#ifdef __GNUC__ -__attribute__ ((format(printf, 2, 3))) -#endif -; +void modifier_setError(struct ModifierData *md, const char *format, ...) ATTR_PRINTF_FORMAT(2, 3); bool modifier_isPreview(struct ModifierData *md); void modifiers_foreachObjectLink(struct Object *ob, diff --git a/source/blender/blenkernel/BKE_report.h b/source/blender/blenkernel/BKE_report.h index ae457cf4f47..101fc463375 100644 --- a/source/blender/blenkernel/BKE_report.h +++ b/source/blender/blenkernel/BKE_report.h @@ -34,6 +34,7 @@ extern "C" { #include #include "DNA_windowmanager_types.h" +#include "BLI_compiler_attrs.h" #include "BLI_utildefines.h" /* Reporting Information and Errors @@ -47,18 +48,10 @@ void BKE_reports_init(ReportList *reports, int flag); void BKE_reports_clear(ReportList *reports); void BKE_report(ReportList *reports, ReportType type, const char *message); -void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...) -#ifdef __GNUC__ -__attribute__ ((format(printf, 3, 4))) -#endif -; +void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...) ATTR_PRINTF_FORMAT(3, 4); void BKE_reports_prepend(ReportList *reports, const char *prepend); -void BKE_reports_prependf(ReportList *reports, const char *prepend, ...) -#ifdef __GNUC__ -__attribute__ ((format(printf, 2, 3))) -#endif -; +void BKE_reports_prependf(ReportList *reports, const char *prepend, ...) ATTR_PRINTF_FORMAT(2, 3); ReportType BKE_report_print_level(ReportList *reports); void BKE_report_print_level_set(ReportList *reports, ReportType level); 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 diff --git a/source/blender/bmesh/intern/bmesh_iterators.h b/source/blender/bmesh/intern/bmesh_iterators.h index b5535b59321..bb25d3fabd1 100644 --- a/source/blender/bmesh/intern/bmesh_iterators.h +++ b/source/blender/bmesh/intern/bmesh_iterators.h @@ -39,6 +39,7 @@ * */ +#include "BLI_compiler_attrs.h" #include "BLI_mempool.h" /* Defines for passing to BM_iter_new. @@ -181,18 +182,10 @@ typedef struct BMIter { char itype; } BMIter; -void *BM_iter_at_index(BMesh *bm, const char itype, void *data, int index) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -#endif -; +void *BM_iter_at_index(BMesh *bm, const char itype, void *data, int index) ATTR_WARN_UNUSED_RESULT; int BM_iter_as_array(BMesh *bm, const char itype, void *data, void **array, const int len); void *BM_iter_as_arrayN(BMesh *bm, const char itype, void *data, int *r_len, - void **stack_array, int stack_array_size) -#ifdef __GNUC__ -__attribute__((warn_unused_result)) -#endif -; + void **stack_array, int stack_array_size) ATTR_WARN_UNUSED_RESULT; int BMO_iter_as_array(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, const char restrictmask, void **array, const int len); void *BMO_iter_as_arrayN(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, const char restrictmask, diff --git a/source/blender/bmesh/intern/bmesh_polygon.h b/source/blender/bmesh/intern/bmesh_polygon.h index e5dc5c081c3..90f0075da26 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.h +++ b/source/blender/bmesh/intern/bmesh_polygon.h @@ -27,12 +27,9 @@ * \ingroup bmesh */ -int BM_face_calc_tessellation(const BMFace *f, BMLoop **r_loops, int (*r_index)[3]) -#ifdef __GNUC__ - __attribute__((warn_unused_result)) - __attribute__((nonnull)) -#endif -; +#include "BLI_compiler_attrs.h" + +int BM_face_calc_tessellation(const BMFace *f, BMLoop **r_loops, int (*r_index)[3]) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); void BM_face_calc_normal(const BMFace *f, float r_no[3]); void BM_face_calc_normal_vcos(BMesh *bm, BMFace *f, float r_no[3], float const (*vertexCos)[3]); diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 5712b64ae8f..8b395505623 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -32,6 +32,7 @@ #ifndef __UI_INTERFACE_H__ #define __UI_INTERFACE_H__ +#include "BLI_compiler_attrs.h" #include "BLI_sys_types.h" /* size_t */ #include "RNA_types.h" #include "DNA_userdef_types.h" @@ -327,30 +328,14 @@ typedef void (*uiMenuHandleFunc)(struct bContext *C, void *arg, int event); typedef struct uiPopupMenu uiPopupMenu; -struct uiPopupMenu *uiPupMenuBegin(struct bContext *C, const char *title, int icon) -#ifdef __GNUC__ -__attribute__((nonnull)) -#endif -; +struct uiPopupMenu *uiPupMenuBegin(struct bContext *C, const char *title, int icon) ATTR_NONNULL(); void uiPupMenuEnd(struct bContext *C, struct uiPopupMenu *head); struct uiLayout *uiPupMenuLayout(uiPopupMenu *head); -void uiPupMenuOkee(struct bContext *C, const char *opname, const char *str, ...) -#ifdef __GNUC__ -__attribute__ ((format(printf, 3, 4))) -#endif -; +void uiPupMenuOkee(struct bContext *C, const char *opname, const char *str, ...) ATTR_PRINTF_FORMAT(3, 4); void uiPupMenuSaveOver(struct bContext *C, struct wmOperator *op, const char *filename); -void uiPupMenuNotice(struct bContext *C, const char *str, ...) -#ifdef __GNUC__ -__attribute__ ((format(printf, 2, 3))) -#endif -; -void uiPupMenuError(struct bContext *C, const char *str, ...) -#ifdef __GNUC__ -__attribute__ ((format(printf, 2, 3))) -#endif -; +void uiPupMenuNotice(struct bContext *C, const char *str, ...) ATTR_PRINTF_FORMAT(2, 3); +void uiPupMenuError(struct bContext *C, const char *str, ...) ATTR_PRINTF_FORMAT(2, 3); void uiPupMenuReports(struct bContext *C, struct ReportList *reports); void uiPupMenuInvoke(struct bContext *C, const char *idname); /* popup registered menu */ @@ -550,11 +535,7 @@ typedef struct uiStringInfo { /* Note: Expects pointers to uiStringInfo structs as parameters. * Will fill them with translated strings, when possible. * Strings in uiStringInfo must be MEM_freeN'ed by caller. */ -void uiButGetStrInfo(struct bContext *C, uiBut *but, ...) -#ifdef __GNUC__ -__attribute__((sentinel)) -#endif -; +void uiButGetStrInfo(struct bContext *C, uiBut *but, ...) ATTR_SENTINEL(0); /* Edit i18n stuff. */ /* Name of the main py op from i18n addon. */ diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c index 38caf224c42..a31ed5e7420 100644 --- a/source/blender/imbuf/intern/jpeg.c +++ b/source/blender/imbuf/intern/jpeg.c @@ -59,11 +59,7 @@ #define IS_maxjpg(x) ((x->ftype & JPG_MSK) == JPG_MAX) /* the types are from the jpeg lib */ -static void jpeg_error(j_common_ptr cinfo) -#ifdef __GNUC__ -__attribute__((noreturn)) -#endif -; +static void jpeg_error(j_common_ptr cinfo) ATTR_NORETURN; static void init_source(j_decompress_ptr cinfo); static boolean fill_input_buffer(j_decompress_ptr cinfo); static void skip_input_data(j_decompress_ptr cinfo, long num_bytes); diff --git a/source/blender/makesdna/DNA_ipo_types.h b/source/blender/makesdna/DNA_ipo_types.h index 3e641fba1ac..2699c6e576e 100644 --- a/source/blender/makesdna/DNA_ipo_types.h +++ b/source/blender/makesdna/DNA_ipo_types.h @@ -42,6 +42,8 @@ #include "DNA_ID.h" +#include "BLI_compiler_attrs.h" + /* -------------------------- Type Defines --------------------------- */ /* sometimes used - mainly for GE/Ketsji */ diff --git a/source/blender/makesdna/intern/SConscript b/source/blender/makesdna/intern/SConscript index 2ae9b22e61c..7c3af30ee83 100644 --- a/source/blender/makesdna/intern/SConscript +++ b/source/blender/makesdna/intern/SConscript @@ -47,7 +47,8 @@ makesdna_tool.Append(CCFLAGS = '-DBASE_HEADER="\\"source/blender/makesdna/\\"" ' makesdna_tool.Append (CPPPATH = ['#/intern/guardedalloc', '#/intern/atomic', - '../../makesdna', '../../bmesh']) + '../../makesdna', '../../bmesh', + '../../blenlib']) if env['OURPLATFORM'] == 'linuxcross': USE_WINE = True # when cross compiling on linux 64bit this is useful diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 0725cea3291..9ba30ec0350 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -31,6 +31,8 @@ #include "RNA_types.h" +#include "BLI_compiler_attrs.h" + #ifdef __cplusplus extern "C" { #endif @@ -1085,17 +1087,9 @@ int RNA_function_call_lookup(struct bContext *C, struct ReportList *reports, Poi const char *identifier, ParameterList *parms); int RNA_function_call_direct(struct bContext *C, struct ReportList *reports, PointerRNA *ptr, - FunctionRNA *func, const char *format, ...) -#ifdef __GNUC__ -__attribute__ ((format(printf, 5, 6))) -#endif -; + FunctionRNA *func, const char *format, ...) ATTR_PRINTF_FORMAT(5, 6); int RNA_function_call_direct_lookup(struct bContext *C, struct ReportList *reports, PointerRNA *ptr, - const char *identifier, const char *format, ...) -#ifdef __GNUC__ -__attribute__ ((format(printf, 5, 6))) -#endif -; + const char *identifier, const char *format, ...) ATTR_PRINTF_FORMAT(5, 6); int RNA_function_call_direct_va(struct bContext *C, struct ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format, va_list args); int RNA_function_call_direct_va_lookup(struct bContext *C, struct ReportList *reports, PointerRNA *ptr, @@ -1121,11 +1115,7 @@ StructRNA *ID_code_to_RNA_type(short idcode); # define RNA_warning(format, ...) _RNA_warning("%s: " format "\n", __FUNCTION__, __VA_ARGS__) #endif -void _RNA_warning(const char *format, ...) -#ifdef __GNUC__ -__attribute__ ((format(printf, 1, 2))) -#endif -; +void _RNA_warning(const char *format, ...) ATTR_PRINTF_FORMAT(1, 2); /* Equals test (skips pointers and collections) * is_strict false assumes uninitialized properties are equal */ diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 2a8358f832a..455fbf4e50a 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -40,6 +40,7 @@ /* dna-savable wmStructs here */ #include "DNA_windowmanager_types.h" #include "WM_keymap.h" +#include "BLI_compiler_attrs.h" #ifdef __cplusplus extern "C" { @@ -76,17 +77,9 @@ void WM_init_native_pixels(bool do_it); void WM_init (struct bContext *C, int argc, const char **argv); void WM_exit_ext (struct bContext *C, const short do_python); -void WM_exit (struct bContext *C) -#if defined(__GNUC__) || defined(__clang__) -__attribute__((noreturn)) -#endif -; +void WM_exit (struct bContext *C) ATTR_NORETURN; -void WM_main (struct bContext *C) -#if defined(__GNUC__) || defined(__clang__) -__attribute__((noreturn)) -#endif -; +void WM_main (struct bContext *C) ATTR_NORETURN; bool WM_init_game (struct bContext *C); void WM_init_splash (struct bContext *C); @@ -180,11 +173,7 @@ void WM_main_remove_notifier_reference(const void *reference); /* reports */ void WM_report(const struct bContext *C, ReportType type, const char *message); -void WM_reportf(const struct bContext *C, ReportType type, const char *format, ...) -#ifdef __GNUC__ -__attribute__ ((format(printf, 3, 4))) -#endif -; +void WM_reportf(const struct bContext *C, ReportType type, const char *format, ...) ATTR_PRINTF_FORMAT(3, 4); void wm_event_add(struct wmWindow *win, const struct wmEvent *event_to_add); void wm_event_init_from_window(struct wmWindow *win, struct wmEvent *event); diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index f1932c8aa97..e6b6df11d7d 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -115,6 +115,7 @@ struct ImBuf; #include "RNA_types.h" #include "DNA_listBase.h" +#include "BLI_compiler_attrs.h" /* exported types for WM */ #include "wm_cursors.h" @@ -522,12 +523,8 @@ typedef struct wmOperatorType { * parameters may be provided through operator properties. cannot use * any interface code or input device state. * - see defines below for return values */ - int (*exec)(struct bContext *, struct wmOperator *) -#ifdef __GNUC__ - __attribute__((warn_unused_result)) -#endif - ; - + int (*exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT; + /* this callback executes on a running operator whenever as property * is changed. It can correct its own properties or report errors for * invalid settings in exceptional cases. @@ -538,25 +535,13 @@ typedef struct wmOperatorType { * any further events are handled in modal. if the operation is * canceled due to some external reason, cancel is called * - see defines below for return values */ - int (*invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) -#ifdef __GNUC__ - __attribute__((warn_unused_result)) -#endif - ; + int (*invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT; int (*cancel)(struct bContext *, struct wmOperator *); - int (*modal)(struct bContext *, struct wmOperator *, const struct wmEvent *) -#ifdef __GNUC__ - __attribute__((warn_unused_result)) -#endif - ; + int (*modal)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT; /* verify if the operator can be executed in the current context, note * that the operator might still fail to execute even if this return true */ - int (*poll)(struct bContext *) -#ifdef __GNUC__ - __attribute__((warn_unused_result)) -#endif - ; + int (*poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT; /* optional panel for redo and repeat, autogenerated if not set */ void (*ui)(struct bContext *, struct wmOperator *); @@ -580,11 +565,7 @@ typedef struct wmOperatorType { /* only used for operators defined with python * use to store pointers to python functions */ void *pyop_data; - int (*pyop_poll)(struct bContext *, struct wmOperatorType *ot) -#ifdef __GNUC__ - __attribute__((warn_unused_result)) -#endif - ; + int (*pyop_poll)(struct bContext *, struct wmOperatorType *ot) ATTR_WARN_UNUSED_RESULT; /* RNA integration */ ExtensionRNA ext; -- cgit v1.2.3