From edee8a34465ba299fcfa29415586158de0513205 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 18 Dec 2017 23:00:13 +0100 Subject: [PATCH] Compiler.h: add gcc_returns_nonnull, gcc_returns_twice --- src/Compiler.h | 4 ++++ src/db/plugins/simple/Directory.hxx | 2 +- src/db/plugins/simple/Song.hxx | 4 ++-- src/output/OutputPlugin.hxx | 2 +- src/pcm/PcmBuffer.hxx | 4 ++-- src/pcm/SampleFormat.hxx | 2 +- src/tag/Tag.hxx | 6 +++--- src/util/Alloc.hxx | 14 +++++++------- src/util/ReusableArray.hxx | 2 +- src/util/StringAPI.hxx | 4 ++-- src/util/VarSize.hxx | 2 +- src/util/WStringAPI.hxx | 4 ++-- 12 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/Compiler.h b/src/Compiler.h index 54c16c5e9..08c93a142 100644 --- a/src/Compiler.h +++ b/src/Compiler.h @@ -93,6 +93,8 @@ #define gcc_nonnull(...) __attribute__((nonnull(__VA_ARGS__))) #define gcc_nonnull_all __attribute__((nonnull)) +#define gcc_returns_nonnull __attribute__((returns_nonnull)) +#define gcc_returns_twice __attribute__((returns_twice)) #define gcc_likely(x) __builtin_expect (!!(x), 1) #define gcc_unlikely(x) __builtin_expect (!!(x), 0) @@ -121,6 +123,8 @@ #define gcc_nonnull(...) #define gcc_nonnull_all +#define gcc_returns_nonnull +#define gcc_returns_twice #define gcc_likely(x) (x) #define gcc_unlikely(x) (x) diff --git a/src/db/plugins/simple/Directory.hxx b/src/db/plugins/simple/Directory.hxx index 7370aea9b..4a6fcd0a9 100644 --- a/src/db/plugins/simple/Directory.hxx +++ b/src/db/plugins/simple/Directory.hxx @@ -106,7 +106,7 @@ public: /** * Create a new root #Directory object. */ - gcc_malloc + gcc_malloc gcc_returns_nonnull static Directory *NewRoot() { return new Directory(std::string(), nullptr); } diff --git a/src/db/plugins/simple/Song.hxx b/src/db/plugins/simple/Song.hxx index 9831d638b..13c8bd6be 100644 --- a/src/db/plugins/simple/Song.hxx +++ b/src/db/plugins/simple/Song.hxx @@ -95,11 +95,11 @@ struct Song { Song(const char *_uri, size_t uri_length, Directory &parent); ~Song(); - gcc_malloc + gcc_malloc gcc_returns_nonnull static Song *NewFrom(DetachedSong &&other, Directory &parent); /** allocate a new song with a local file name */ - gcc_malloc + gcc_malloc gcc_returns_nonnull static Song *NewFile(const char *path_utf8, Directory &parent); /** diff --git a/src/output/OutputPlugin.hxx b/src/output/OutputPlugin.hxx index 8738131d0..f55aebc78 100644 --- a/src/output/OutputPlugin.hxx +++ b/src/output/OutputPlugin.hxx @@ -76,7 +76,7 @@ ao_plugin_test_default_device(const AudioOutputPlugin *plugin) : false; } -gcc_malloc +gcc_malloc gcc_returns_nonnull AudioOutput * ao_plugin_init(EventLoop &event_loop, const AudioOutputPlugin &plugin, diff --git a/src/pcm/PcmBuffer.hxx b/src/pcm/PcmBuffer.hxx index 0c4b62431..68b169eb3 100644 --- a/src/pcm/PcmBuffer.hxx +++ b/src/pcm/PcmBuffer.hxx @@ -47,11 +47,11 @@ public: * to signal "error". An empty destination buffer is not * always an error. */ - gcc_malloc + gcc_malloc gcc_returns_nonnull void *Get(size_t size); template - gcc_malloc + gcc_malloc gcc_returns_nonnull T *GetT(size_t n) { return (T *)Get(n * sizeof(T)); } diff --git a/src/pcm/SampleFormat.hxx b/src/pcm/SampleFormat.hxx index 9d956b7f9..badfe1781 100644 --- a/src/pcm/SampleFormat.hxx +++ b/src/pcm/SampleFormat.hxx @@ -122,7 +122,7 @@ sample_format_size(SampleFormat format) * @param format a #SampleFormat enum value * @return the string */ -gcc_pure gcc_malloc +gcc_pure gcc_malloc gcc_returns_nonnull const char * sample_format_to_string(SampleFormat format) noexcept; diff --git a/src/tag/Tag.hxx b/src/tag/Tag.hxx index 64b79e969..0696cbab9 100644 --- a/src/tag/Tag.hxx +++ b/src/tag/Tag.hxx @@ -116,7 +116,7 @@ struct Tag { * * @return a newly allocated tag */ - gcc_malloc + gcc_malloc gcc_returns_nonnull static Tag *Merge(const Tag &base, const Tag &add); /** @@ -125,7 +125,7 @@ struct Tag { * * @return a newly allocated tag */ - gcc_malloc + gcc_malloc gcc_returns_nonnull static Tag *MergeReplace(Tag *base, Tag *add); /** @@ -148,7 +148,7 @@ struct Tag { * (e.g. #TAG_ALBUM_ARTIST falls back to #TAG_ARTIST). If * there is no such value, returns an empty string. */ - gcc_pure + gcc_pure gcc_returns_nonnull const char *GetSortValue(TagType type) const noexcept; class const_iterator { diff --git a/src/util/Alloc.hxx b/src/util/Alloc.hxx index 0fbe4d6b4..2a933fcd4 100644 --- a/src/util/Alloc.hxx +++ b/src/util/Alloc.hxx @@ -30,7 +30,7 @@ * This function never fails; in out-of-memory situations, it aborts * the process. */ -gcc_malloc +gcc_malloc gcc_returns_nonnull void * xalloc(size_t size); @@ -40,7 +40,7 @@ xalloc(size_t size); * This function never fails; in out-of-memory situations, it aborts * the process. */ -gcc_malloc gcc_nonnull_all +gcc_malloc gcc_returns_nonnull gcc_nonnull_all void * xmemdup(const void *s, size_t size); @@ -50,7 +50,7 @@ xmemdup(const void *s, size_t size); * This function never fails; in out-of-memory situations, it aborts * the process. */ -gcc_malloc gcc_nonnull_all +gcc_malloc gcc_returns_nonnull gcc_nonnull_all char * xstrdup(const char *s); @@ -60,7 +60,7 @@ xstrdup(const char *s); * This function never fails; in out-of-memory situations, it aborts * the process. */ -gcc_malloc gcc_nonnull_all +gcc_malloc gcc_returns_nonnull gcc_nonnull_all char * xstrndup(const char *s, size_t n); @@ -71,15 +71,15 @@ xstrndup(const char *s, size_t n); * This function never fails; in out-of-memory situations, it aborts * the process. */ -gcc_malloc gcc_nonnull_all +gcc_malloc gcc_returns_nonnull gcc_nonnull_all char * xstrcatdup(const char *a, const char *b); -gcc_malloc gcc_nonnull_all +gcc_malloc gcc_returns_nonnull gcc_nonnull_all char * xstrcatdup(const char *a, const char *b, const char *c); -gcc_malloc gcc_nonnull_all +gcc_malloc gcc_returns_nonnull gcc_nonnull_all char * xstrcatdup(const char *a, const char *b, const char *c, const char *d); diff --git a/src/util/ReusableArray.hxx b/src/util/ReusableArray.hxx index cb40e610a..706291382 100644 --- a/src/util/ReusableArray.hxx +++ b/src/util/ReusableArray.hxx @@ -84,7 +84,7 @@ public: * Get the buffer, and guarantee a minimum size. This buffer * becomes invalid with the next Get() call. */ - gcc_malloc + gcc_malloc gcc_returns_nonnull T *Get(size_t size) { if (gcc_unlikely(size > capacity)) { /* too small: grow */ diff --git a/src/util/StringAPI.hxx b/src/util/StringAPI.hxx index 1d6a7dea9..b94a4566f 100644 --- a/src/util/StringAPI.hxx +++ b/src/util/StringAPI.hxx @@ -107,7 +107,7 @@ UnsafeCopyString(char *dest, const char *src) noexcept strcpy(dest, src); } -gcc_nonnull_all +gcc_returns_nonnull gcc_nonnull_all static inline char * UnsafeCopyStringP(char *dest, const char *src) noexcept { @@ -165,7 +165,7 @@ StringCollate(const char *a, const char *b) noexcept * Copy the string to a new allocation. The return value must be * freed with free(). */ -gcc_malloc gcc_nonnull_all +gcc_malloc gcc_returns_nonnull gcc_nonnull_all static inline char * DuplicateString(const char *p) noexcept { diff --git a/src/util/VarSize.hxx b/src/util/VarSize.hxx index 5f383bc4b..000be6bc8 100644 --- a/src/util/VarSize.hxx +++ b/src/util/VarSize.hxx @@ -50,7 +50,7 @@ * #T */ template -gcc_malloc +gcc_malloc gcc_returns_nonnull T * NewVarSize(size_t declared_tail_size, size_t real_tail_size, Args&&... args) { diff --git a/src/util/WStringAPI.hxx b/src/util/WStringAPI.hxx index 4d000dab1..e27f76bb8 100644 --- a/src/util/WStringAPI.hxx +++ b/src/util/WStringAPI.hxx @@ -97,7 +97,7 @@ UnsafeCopyString(wchar_t *dest, const wchar_t *src) noexcept wcscpy(dest, src); } -gcc_nonnull_all +gcc_returns_nonnull gcc_nonnull_all static inline wchar_t * UnsafeCopyStringP(wchar_t *dest, const wchar_t *src) noexcept { @@ -155,7 +155,7 @@ StringIsEqualIgnoreCase(const wchar_t *a, const wchar_t *b, #ifndef __BIONIC__ -gcc_malloc gcc_nonnull_all +gcc_malloc gcc_returns_nonnull gcc_nonnull_all static inline wchar_t * DuplicateString(const wchar_t *p) {