diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2024-04-28 15:23:48 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2024-05-06 17:47:11 -0700 |
commit | b880645f6e517a707e2bcc747c5385a786ff06b0 (patch) | |
tree | b067eec70fc8a6f0ffc9375e53c63ceeb33305c1 /include | |
parent | 73696aa2fdd35f4f7c0f822cb3e75efb4f7fcde5 (diff) |
Add alloc_size & malloc attributes to allocation functions
All functions get alloc_size, but only fresh allocators get the
malloc attribute - it doesn't support realloc style functions.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/app/xfs/-/merge_requests/7>
Diffstat (limited to 'include')
-rw-r--r-- | include/os.h | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/include/os.h b/include/os.h index ad159a9..9906275 100644 --- a/include/os.h +++ b/include/os.h @@ -57,6 +57,26 @@ typedef struct _auth *AuthPtr; #include "client.h" #include "misc.h" +#if __has_attribute(alloc_size) +#define XFS_ATTRIBUTE_ALLOC_SIZE(ARGS) __attribute__ ((alloc_size ARGS)) +#else +#define XFS_ATTRIBUTE_ALLOC_SIZE(ARGS) +#endif + +#if __has_attribute(malloc) +# if defined(__clang__) || (defined(__GNUC__) && __GNUC__ < 11) +/* Clang or older gcc do not support the optional deallocator argument */ +# define XFS_ATTRIBUTE_MALLOC(ARGS) __attribute__((malloc)) +# else +# define XFS_ATTRIBUTE_MALLOC(ARGS) __attribute__((malloc ARGS)) +# endif +#else +# define XFS_ATTRIBUTE_MALLOC(ARGS) +#endif + +#define XFS_ALLOCATOR(DEALLOC, SIZE) \ + XFS_ATTRIBUTE_MALLOC(DEALLOC) XFS_ATTRIBUTE_ALLOC_SIZE(SIZE) + typedef pointer FID; #define ALLOCATE_LOCAL_FALLBACK(_size) FSalloc((unsigned long)_size) @@ -128,12 +148,17 @@ extern void GiveUp (int n); extern void ServerCacheFlush (int n); extern void ServerReconfig (int n); extern unsigned int GetTimeInMillis (void); -extern pointer FSalloc(unsigned long); -extern pointer FSallocarray(unsigned long, unsigned long); -extern pointer FScalloc (unsigned long, unsigned long); -extern pointer FSrealloc(pointer, unsigned long); -extern pointer FSreallocarray (pointer, unsigned long, unsigned long); extern void FSfree(pointer); +extern pointer FSalloc(unsigned long) + XFS_ATTRIBUTE_ALLOC_SIZE((1)) XFS_ATTRIBUTE_MALLOC((FSfree)); +extern pointer FSallocarray(unsigned long, unsigned long) + XFS_ATTRIBUTE_ALLOC_SIZE((1,2)) XFS_ATTRIBUTE_MALLOC((FSfree)); +extern pointer FScalloc (unsigned long, unsigned long) + XFS_ATTRIBUTE_ALLOC_SIZE((1,2)) XFS_ATTRIBUTE_MALLOC((FSfree)); +extern pointer FSrealloc(pointer, unsigned long) + XFS_ATTRIBUTE_ALLOC_SIZE((2)); +extern pointer FSreallocarray (pointer, unsigned long, unsigned long) + XFS_ATTRIBUTE_ALLOC_SIZE((2,3)); extern void ProcessCmdLine (int argc, char **argv); extern void ProcessLSoption (char *str); extern void SetUserId(void); |