compat: add a few more attribute macros

This commit is contained in:
Andrei Alexeyev 2023-01-08 23:54:01 +01:00
parent a025ea5251
commit 11c9bf6681
No known key found for this signature in database
GPG key ID: 72D26128040B9690
3 changed files with 32 additions and 10 deletions

View file

@ -297,6 +297,18 @@ endif
config.set('TAISEI_BUILDCONF_HAVE_ZIP_COMPRESSION_METHOD_SUPPORTED', have_zip_compression_method_supported)
config.set('TAISEI_BUILDCONF_HAVE_ATTR_DESIGNATED_INIT', cc.compiles(
'struct { int dummy; } __attribute__((designated_init)) x;',
name : '__attribute__((designated_init))',
args : ['-Wattributes', '-Werror']
))
config.set('TAISEI_BUILDCONF_HAVE_ATTR_MALLOC_WITH_ARGS', cc.compiles(
'void myfree(void *p); void *myalloc() __attribute__((malloc(myfree, 1)));',
name : '__attribute__((malloc(deallocator, index)))',
args : ['-Wattributes', '-Werror']
))
prefer_relpath_systems = [
'windows',
]

View file

@ -272,7 +272,7 @@ typedef _Complex double cmplx;
attr_returns_nonnull attr_returns_max_aligned attr_nodiscard
// Structure must not be initialized with an implicit (non-designated) initializer.
#if __has_attribute(designated_init) && defined(TAISEI_BUILDCONF_USE_DESIGNATED_INIT)
#if __has_attribute(designated_init) && defined(TAISEI_BUILDCONF_HAVE_ATTR_DESIGNATED_INIT)
#define attr_designated_init \
__attribute__ ((designated_init))
#else
@ -284,9 +284,25 @@ typedef _Complex double cmplx;
#define attr_malloc \
__attribute__ ((malloc))
// Function returns a pointer to object whose size is specified by the 'size_arg_index'th function argument.
#define attr_alloc_size(size_arg_index) \
__attribute__ ((alloc_size(size_arg_index)))
// Function returns a pointer that must be 'freed' with the specified deallocator function
#ifdef TAISEI_BUILDCONF_HAVE_ATTR_MALLOC_WITH_ARGS
#define attr_dealloc(deallocator, arg_index) \
__attribute__ ((malloc(deallocator, arg_index)))
#else
#define attr_dealloc(deallocator, arg_index)
#endif
// With one argument n: function returns a pointer to object whose size is specified by the
// nth argument.
// With two arguments n, m: function returns a pointer to object whose size is specified by the
// product of nth and mth arguments.
#define attr_alloc_size(...) \
__attribute__ ((alloc_size(__VA_ARGS__)))
// Function returns a pointer aligned to a byte boundary specified by nth argument
#define attr_alloc_align(arg_index) \
__attribute__ ((alloc_align(arg_index)))
#define INLINE static inline attr_must_inline __attribute__((gnu_inline))

View file

@ -23,12 +23,6 @@ if is_developer_build
util_src += files('debug.c')
endif
config.set('TAISEI_BUILDCONF_USE_DESIGNATED_INIT', cc.compiles(
'struct { int dummy; } __attribute__((designated_init)) x;',
name : '__attribute__((designated_init)) with -Werror',
args : ['-Wattributes', '-Werror']
))
if dep_crypto.found()
util_src += files('sha256_openssl.c')
else