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(...) __attribute__((nonnull(__VA_ARGS__)))
|
||||||
#define gcc_nonnull_all __attribute__((nonnull))
|
#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_likely(x) __builtin_expect (!!(x), 1)
|
||||||
#define gcc_unlikely(x) __builtin_expect (!!(x), 0)
|
#define gcc_unlikely(x) __builtin_expect (!!(x), 0)
|
||||||
@ -121,6 +123,8 @@
|
|||||||
|
|
||||||
#define gcc_nonnull(...)
|
#define gcc_nonnull(...)
|
||||||
#define gcc_nonnull_all
|
#define gcc_nonnull_all
|
||||||
|
#define gcc_returns_nonnull
|
||||||
|
#define gcc_returns_twice
|
||||||
|
|
||||||
#define gcc_likely(x) (x)
|
#define gcc_likely(x) (x)
|
||||||
#define gcc_unlikely(x) (x)
|
#define gcc_unlikely(x) (x)
|
||||||
|
@ -106,7 +106,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Create a new root #Directory object.
|
* Create a new root #Directory object.
|
||||||
*/
|
*/
|
||||||
gcc_malloc
|
gcc_malloc gcc_returns_nonnull
|
||||||
static Directory *NewRoot() {
|
static Directory *NewRoot() {
|
||||||
return new Directory(std::string(), nullptr);
|
return new Directory(std::string(), nullptr);
|
||||||
}
|
}
|
||||||
|
@ -95,11 +95,11 @@ struct Song {
|
|||||||
Song(const char *_uri, size_t uri_length, Directory &parent);
|
Song(const char *_uri, size_t uri_length, Directory &parent);
|
||||||
~Song();
|
~Song();
|
||||||
|
|
||||||
gcc_malloc
|
gcc_malloc gcc_returns_nonnull
|
||||||
static Song *NewFrom(DetachedSong &&other, Directory &parent);
|
static Song *NewFrom(DetachedSong &&other, Directory &parent);
|
||||||
|
|
||||||
/** allocate a new song with a local file name */
|
/** 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);
|
static Song *NewFile(const char *path_utf8, Directory &parent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,7 +76,7 @@ ao_plugin_test_default_device(const AudioOutputPlugin *plugin)
|
|||||||
: false;
|
: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
gcc_malloc
|
gcc_malloc gcc_returns_nonnull
|
||||||
AudioOutput *
|
AudioOutput *
|
||||||
ao_plugin_init(EventLoop &event_loop,
|
ao_plugin_init(EventLoop &event_loop,
|
||||||
const AudioOutputPlugin &plugin,
|
const AudioOutputPlugin &plugin,
|
||||||
|
@ -47,11 +47,11 @@ public:
|
|||||||
* to signal "error". An empty destination buffer is not
|
* to signal "error". An empty destination buffer is not
|
||||||
* always an error.
|
* always an error.
|
||||||
*/
|
*/
|
||||||
gcc_malloc
|
gcc_malloc gcc_returns_nonnull
|
||||||
void *Get(size_t size);
|
void *Get(size_t size);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
gcc_malloc
|
gcc_malloc gcc_returns_nonnull
|
||||||
T *GetT(size_t n) {
|
T *GetT(size_t n) {
|
||||||
return (T *)Get(n * sizeof(T));
|
return (T *)Get(n * sizeof(T));
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ sample_format_size(SampleFormat format)
|
|||||||
* @param format a #SampleFormat enum value
|
* @param format a #SampleFormat enum value
|
||||||
* @return the string
|
* @return the string
|
||||||
*/
|
*/
|
||||||
gcc_pure gcc_malloc
|
gcc_pure gcc_malloc gcc_returns_nonnull
|
||||||
const char *
|
const char *
|
||||||
sample_format_to_string(SampleFormat format) noexcept;
|
sample_format_to_string(SampleFormat format) noexcept;
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ struct Tag {
|
|||||||
*
|
*
|
||||||
* @return a newly allocated tag
|
* @return a newly allocated tag
|
||||||
*/
|
*/
|
||||||
gcc_malloc
|
gcc_malloc gcc_returns_nonnull
|
||||||
static Tag *Merge(const Tag &base, const Tag &add);
|
static Tag *Merge(const Tag &base, const Tag &add);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,7 +125,7 @@ struct Tag {
|
|||||||
*
|
*
|
||||||
* @return a newly allocated tag
|
* @return a newly allocated tag
|
||||||
*/
|
*/
|
||||||
gcc_malloc
|
gcc_malloc gcc_returns_nonnull
|
||||||
static Tag *MergeReplace(Tag *base, Tag *add);
|
static Tag *MergeReplace(Tag *base, Tag *add);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,7 +148,7 @@ struct Tag {
|
|||||||
* (e.g. #TAG_ALBUM_ARTIST falls back to #TAG_ARTIST). If
|
* (e.g. #TAG_ALBUM_ARTIST falls back to #TAG_ARTIST). If
|
||||||
* there is no such value, returns an empty string.
|
* there is no such value, returns an empty string.
|
||||||
*/
|
*/
|
||||||
gcc_pure
|
gcc_pure gcc_returns_nonnull
|
||||||
const char *GetSortValue(TagType type) const noexcept;
|
const char *GetSortValue(TagType type) const noexcept;
|
||||||
|
|
||||||
class const_iterator {
|
class const_iterator {
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
* This function never fails; in out-of-memory situations, it aborts
|
* This function never fails; in out-of-memory situations, it aborts
|
||||||
* the process.
|
* the process.
|
||||||
*/
|
*/
|
||||||
gcc_malloc
|
gcc_malloc gcc_returns_nonnull
|
||||||
void *
|
void *
|
||||||
xalloc(size_t size);
|
xalloc(size_t size);
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ xalloc(size_t size);
|
|||||||
* This function never fails; in out-of-memory situations, it aborts
|
* This function never fails; in out-of-memory situations, it aborts
|
||||||
* the process.
|
* the process.
|
||||||
*/
|
*/
|
||||||
gcc_malloc gcc_nonnull_all
|
gcc_malloc gcc_returns_nonnull gcc_nonnull_all
|
||||||
void *
|
void *
|
||||||
xmemdup(const void *s, size_t size);
|
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
|
* This function never fails; in out-of-memory situations, it aborts
|
||||||
* the process.
|
* the process.
|
||||||
*/
|
*/
|
||||||
gcc_malloc gcc_nonnull_all
|
gcc_malloc gcc_returns_nonnull gcc_nonnull_all
|
||||||
char *
|
char *
|
||||||
xstrdup(const char *s);
|
xstrdup(const char *s);
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ xstrdup(const char *s);
|
|||||||
* This function never fails; in out-of-memory situations, it aborts
|
* This function never fails; in out-of-memory situations, it aborts
|
||||||
* the process.
|
* the process.
|
||||||
*/
|
*/
|
||||||
gcc_malloc gcc_nonnull_all
|
gcc_malloc gcc_returns_nonnull gcc_nonnull_all
|
||||||
char *
|
char *
|
||||||
xstrndup(const char *s, size_t n);
|
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
|
* This function never fails; in out-of-memory situations, it aborts
|
||||||
* the process.
|
* the process.
|
||||||
*/
|
*/
|
||||||
gcc_malloc gcc_nonnull_all
|
gcc_malloc gcc_returns_nonnull gcc_nonnull_all
|
||||||
char *
|
char *
|
||||||
xstrcatdup(const char *a, const char *b);
|
xstrcatdup(const char *a, const char *b);
|
||||||
|
|
||||||
gcc_malloc gcc_nonnull_all
|
gcc_malloc gcc_returns_nonnull gcc_nonnull_all
|
||||||
char *
|
char *
|
||||||
xstrcatdup(const char *a, const char *b, const char *c);
|
xstrcatdup(const char *a, const char *b, const char *c);
|
||||||
|
|
||||||
gcc_malloc gcc_nonnull_all
|
gcc_malloc gcc_returns_nonnull gcc_nonnull_all
|
||||||
char *
|
char *
|
||||||
xstrcatdup(const char *a, const char *b, const char *c, const char *d);
|
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
|
* Get the buffer, and guarantee a minimum size. This buffer
|
||||||
* becomes invalid with the next Get() call.
|
* becomes invalid with the next Get() call.
|
||||||
*/
|
*/
|
||||||
gcc_malloc
|
gcc_malloc gcc_returns_nonnull
|
||||||
T *Get(size_t size) {
|
T *Get(size_t size) {
|
||||||
if (gcc_unlikely(size > capacity)) {
|
if (gcc_unlikely(size > capacity)) {
|
||||||
/* too small: grow */
|
/* too small: grow */
|
||||||
|
@ -107,7 +107,7 @@ UnsafeCopyString(char *dest, const char *src) noexcept
|
|||||||
strcpy(dest, src);
|
strcpy(dest, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
gcc_nonnull_all
|
gcc_returns_nonnull gcc_nonnull_all
|
||||||
static inline char *
|
static inline char *
|
||||||
UnsafeCopyStringP(char *dest, const char *src) noexcept
|
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
|
* Copy the string to a new allocation. The return value must be
|
||||||
* freed with free().
|
* freed with free().
|
||||||
*/
|
*/
|
||||||
gcc_malloc gcc_nonnull_all
|
gcc_malloc gcc_returns_nonnull gcc_nonnull_all
|
||||||
static inline char *
|
static inline char *
|
||||||
DuplicateString(const char *p) noexcept
|
DuplicateString(const char *p) noexcept
|
||||||
{
|
{
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
* #T
|
* #T
|
||||||
*/
|
*/
|
||||||
template<class T, typename... Args>
|
template<class T, typename... Args>
|
||||||
gcc_malloc
|
gcc_malloc gcc_returns_nonnull
|
||||||
T *
|
T *
|
||||||
NewVarSize(size_t declared_tail_size, size_t real_tail_size, Args&&... args)
|
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);
|
wcscpy(dest, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
gcc_nonnull_all
|
gcc_returns_nonnull gcc_nonnull_all
|
||||||
static inline wchar_t *
|
static inline wchar_t *
|
||||||
UnsafeCopyStringP(wchar_t *dest, const wchar_t *src) noexcept
|
UnsafeCopyStringP(wchar_t *dest, const wchar_t *src) noexcept
|
||||||
{
|
{
|
||||||
@ -155,7 +155,7 @@ StringIsEqualIgnoreCase(const wchar_t *a, const wchar_t *b,
|
|||||||
|
|
||||||
#ifndef __BIONIC__
|
#ifndef __BIONIC__
|
||||||
|
|
||||||
gcc_malloc gcc_nonnull_all
|
gcc_malloc gcc_returns_nonnull gcc_nonnull_all
|
||||||
static inline wchar_t *
|
static inline wchar_t *
|
||||||
DuplicateString(const wchar_t *p)
|
DuplicateString(const wchar_t *p)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user