Compiler.h: add gcc_returns_nonnull, gcc_returns_twice
This commit is contained in:
parent
5582367d68
commit
edee8a3446
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
/**
|
||||
|
@ -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,
|
||||
|
@ -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<typename T>
|
||||
gcc_malloc
|
||||
gcc_malloc gcc_returns_nonnull
|
||||
T *GetT(size_t n) {
|
||||
return (T *)Get(n * sizeof(T));
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -50,7 +50,7 @@
|
||||
* #T
|
||||
*/
|
||||
template<class T, typename... Args>
|
||||
gcc_malloc
|
||||
gcc_malloc gcc_returns_nonnull
|
||||
T *
|
||||
NewVarSize(size_t declared_tail_size, size_t real_tail_size, Args&&... args)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user