cdefs.h (4642B)
1 /* Common macro definitions for C include files. 2 Copyright (C) 2008-2023 Free Software Foundation, Inc. 3 4 This program is free software: you can redistribute it and/or 5 modify it under the terms of either: 6 7 * the GNU Lesser General Public License as published by the Free 8 Software Foundation; either version 3 of the License, or (at your 9 option) any later version. 10 11 or 12 13 * the GNU General Public License as published by the Free 14 Software Foundation; either version 2 of the License, or (at your 15 option) any later version. 16 17 or both in parallel, as here. 18 This program is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 GNU Lesser General Public License for more details. 22 23 You should have received a copy of the GNU Lesser General Public License 24 along with this program. If not, see <https://www.gnu.org/licenses/>. */ 25 26 #ifndef _UNISTRING_CDEFS_H 27 #define _UNISTRING_CDEFS_H 28 29 /* _GL_UNUSED_PARAMETER is a marker that can be prepended to function parameter 30 declarations for parameters that are not used. This helps to reduce 31 warnings, such as from GCC -Wunused-parameter. The syntax is as follows: 32 _GL_UNUSED_PARAMETER type param 33 or more generally 34 _GL_UNUSED_PARAMETER param_decl 35 For example: 36 _GL_UNUSED_PARAMETER int param 37 _GL_UNUSED_PARAMETER int *(*param) (void) 38 */ 39 #ifndef _GL_UNUSED_PARAMETER 40 # define _GL_UNUSED_PARAMETER _UC_ATTRIBUTE_MAYBE_UNUSED 41 #endif 42 /* _GL_ATTRIBUTE_MAYBE_UNUSED likewise. */ 43 #ifndef _GL_ATTRIBUTE_MAYBE_UNUSED 44 # define _GL_ATTRIBUTE_MAYBE_UNUSED _UC_ATTRIBUTE_MAYBE_UNUSED 45 #endif 46 47 #ifndef _GL_ATTRIBUTE_MALLOC 48 # define _GL_ATTRIBUTE_MALLOC _UC_ATTRIBUTE_MALLOC 49 #endif 50 51 /* _GL_ATTRIBUTE_DEALLOC (F, I) is for functions returning pointers 52 that can be freed by passing them as the Ith argument to the 53 function F. _UC_ATTRIBUTE_DEALLOC_FREE is for functions that 54 return pointers that can be freed via 'free'; it can be used 55 only after including stdlib.h. These macros cannot be used on 56 inline functions. */ 57 #ifndef _GL_ATTRIBUTE_DEALLOC 58 # define _GL_ATTRIBUTE_DEALLOC _UC_ATTRIBUTE_DEALLOC 59 #endif 60 #ifndef _GL_ATTRIBUTE_DEALLOC_FREE 61 # define _GL_ATTRIBUTE_DEALLOC_FREE _UC_ATTRIBUTE_DEALLOC_FREE 62 #endif 63 64 /* The definitions below are taken from gnulib/m4/gnulib-common.m4, 65 with prefix _UC instead of prefix _GL. */ 66 67 /* True if the compiler says it groks GNU C version MAJOR.MINOR. */ 68 #if defined __GNUC__ && defined __GNUC_MINOR__ 69 # define _UC_GNUC_PREREQ(major, minor) \ 70 ((major) < __GNUC__ + ((minor) <= __GNUC_MINOR__)) 71 #else 72 # define _UC_GNUC_PREREQ(major, minor) 0 73 #endif 74 75 #if (defined __has_attribute \ 76 && (!defined __clang_minor__ \ 77 || (defined __apple_build_version__ \ 78 ? 6000000 <= __apple_build_version__ \ 79 : 5 <= __clang_major__))) 80 # define _UC_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__) 81 #else 82 # define _UC_HAS_ATTRIBUTE(attr) _UC_ATTR_##attr 83 # define _UC_ATTR_malloc _UC_GNUC_PREREQ (3, 0) 84 # define _UC_ATTR_unused _UC_GNUC_PREREQ (2, 7) 85 #endif 86 87 #ifdef __cplusplus 88 # if defined __clang__ 89 # define _UC_BRACKET_BEFORE_ATTRIBUTE 1 90 # endif 91 #else 92 # if defined __GNUC__ && !defined __clang__ 93 # define _UC_BRACKET_BEFORE_ATTRIBUTE 1 94 # endif 95 #endif 96 97 #if _UC_GNUC_PREREQ (11, 0) 98 # define _UC_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i))) 99 #else 100 # define _UC_ATTRIBUTE_DEALLOC(f, i) 101 #endif 102 #if defined __cplusplus && defined __GNUC__ && !defined __clang__ 103 /* Work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231> */ 104 # define _UC_ATTRIBUTE_DEALLOC_FREE \ 105 _UC_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1) 106 #else 107 # define _UC_ATTRIBUTE_DEALLOC_FREE \ 108 _UC_ATTRIBUTE_DEALLOC (free, 1) 109 #endif 110 111 #if _UC_HAS_ATTRIBUTE (malloc) 112 # define _UC_ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) 113 #else 114 # define _UC_ATTRIBUTE_MALLOC 115 #endif 116 117 #ifndef _UC_BRACKET_BEFORE_ATTRIBUTE 118 # if defined __clang__ && defined __cplusplus 119 # if !defined __apple_build_version__ && __clang_major__ >= 10 120 # define _UC_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]] 121 # endif 122 # elif defined __has_c_attribute 123 # if __has_c_attribute (__maybe_unused__) 124 # define _UC_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]] 125 # endif 126 # endif 127 #endif 128 #ifndef _UC_ATTRIBUTE_MAYBE_UNUSED 129 # define _UC_ATTRIBUTE_MAYBE_UNUSED _UC_ATTRIBUTE_UNUSED 130 #endif 131 132 #if _UC_HAS_ATTRIBUTE (unused) 133 # define _UC_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 134 #else 135 # define _UC_ATTRIBUTE_UNUSED 136 #endif 137 138 #endif /* _UNISTRING_CDEFS_H */