mirror of
https://github.com/Ryujinx/libsoundio.git
synced 2024-12-22 17:55:37 +00:00
Fix compiler attributes for MSVC
This commit is contained in:
parent
d1eb1d8042
commit
8587a22b21
40
src/list.h
40
src/list.h
|
@ -25,28 +25,28 @@
|
|||
|
||||
#define SOUNDIO_MAKE_LIST_PROTO(Type, Name, static_kw) \
|
||||
static_kw void Name##_deinit(struct Name *s); \
|
||||
static_kw int __attribute__((warn_unused_result)) Name##_append(struct Name *s, Type item); \
|
||||
static_kw int SOUNDIO_ATTR_WARN_UNUSED_RESULT Name##_append(struct Name *s, Type item); \
|
||||
static_kw Type Name##_val_at(struct Name *s, int index); \
|
||||
static_kw Type * Name##_ptr_at(struct Name *s, int index); \
|
||||
static_kw Type Name##_pop(struct Name *s); \
|
||||
static_kw int __attribute__((warn_unused_result)) Name##_add_one(struct Name *s); \
|
||||
static_kw int SOUNDIO_ATTR_WARN_UNUSED_RESULT Name##_add_one(struct Name *s); \
|
||||
static_kw Type Name##_last_val(struct Name *s); \
|
||||
static_kw Type *Name##_last_ptr(struct Name *s); \
|
||||
static_kw int __attribute__((warn_unused_result)) Name##_resize(struct Name *s, int new_length); \
|
||||
static_kw int SOUNDIO_ATTR_WARN_UNUSED_RESULT Name##_resize(struct Name *s, int new_length); \
|
||||
static_kw void Name##_clear(struct Name *s); \
|
||||
static_kw int __attribute__((warn_unused_result)) \
|
||||
static_kw int SOUNDIO_ATTR_WARN_UNUSED_RESULT \
|
||||
Name##_ensure_capacity(struct Name *s, int new_capacity); \
|
||||
static_kw Type Name##_swap_remove(struct Name *s, int index);
|
||||
|
||||
|
||||
#define SOUNDIO_MAKE_LIST_DEF(Type, Name, static_kw) \
|
||||
__attribute__ ((unused)) \
|
||||
SOUNDIO_ATTR_UNUSED \
|
||||
static_kw void Name##_deinit(struct Name *s) { \
|
||||
free(s->items); \
|
||||
} \
|
||||
\
|
||||
__attribute__ ((unused)) \
|
||||
__attribute__ ((warn_unused_result)) \
|
||||
SOUNDIO_ATTR_UNUSED \
|
||||
SOUNDIO_ATTR_WARN_UNUSED_RESULT \
|
||||
static_kw int Name##_ensure_capacity(struct Name *s, int new_capacity) { \
|
||||
int better_capacity = soundio_int_max(s->capacity, 16); \
|
||||
while (better_capacity < new_capacity) \
|
||||
|
@ -61,8 +61,8 @@
|
|||
return 0; \
|
||||
} \
|
||||
\
|
||||
__attribute__ ((unused)) \
|
||||
__attribute__ ((warn_unused_result)) \
|
||||
SOUNDIO_ATTR_UNUSED \
|
||||
SOUNDIO_ATTR_WARN_UNUSED_RESULT \
|
||||
static_kw int Name##_append(struct Name *s, Type item) { \
|
||||
int err = Name##_ensure_capacity(s, s->length + 1); \
|
||||
if (err) \
|
||||
|
@ -72,7 +72,7 @@
|
|||
return 0; \
|
||||
} \
|
||||
\
|
||||
__attribute__ ((unused)) \
|
||||
SOUNDIO_ATTR_UNUSED \
|
||||
static_kw Type Name##_val_at(struct Name *s, int index) { \
|
||||
assert(index >= 0); \
|
||||
assert(index < s->length); \
|
||||
|
@ -82,22 +82,22 @@
|
|||
/* remember that the pointer to this item is invalid after you \
|
||||
* modify the length of the list \
|
||||
*/ \
|
||||
__attribute__ ((unused)) \
|
||||
SOUNDIO_ATTR_UNUSED \
|
||||
static_kw Type * Name##_ptr_at(struct Name *s, int index) { \
|
||||
assert(index >= 0); \
|
||||
assert(index < s->length); \
|
||||
return &s->items[index]; \
|
||||
} \
|
||||
\
|
||||
__attribute__ ((unused)) \
|
||||
SOUNDIO_ATTR_UNUSED \
|
||||
static_kw Type Name##_pop(struct Name *s) { \
|
||||
assert(s->length >= 1); \
|
||||
s->length -= 1; \
|
||||
return s->items[s->length]; \
|
||||
} \
|
||||
\
|
||||
__attribute__ ((unused)) \
|
||||
__attribute__ ((warn_unused_result)) \
|
||||
SOUNDIO_ATTR_UNUSED \
|
||||
SOUNDIO_ATTR_WARN_UNUSED_RESULT \
|
||||
static_kw int Name##_resize(struct Name *s, int new_length) { \
|
||||
assert(new_length >= 0); \
|
||||
int err = Name##_ensure_capacity(s, new_length); \
|
||||
|
@ -107,30 +107,30 @@
|
|||
return 0; \
|
||||
} \
|
||||
\
|
||||
__attribute__ ((unused)) \
|
||||
__attribute__ ((warn_unused_result)) \
|
||||
SOUNDIO_ATTR_UNUSED \
|
||||
SOUNDIO_ATTR_WARN_UNUSED_RESULT \
|
||||
static_kw int Name##_add_one(struct Name *s) { \
|
||||
return Name##_resize(s, s->length + 1); \
|
||||
} \
|
||||
\
|
||||
__attribute__ ((unused)) \
|
||||
SOUNDIO_ATTR_UNUSED \
|
||||
static_kw Type Name##_last_val(struct Name *s) { \
|
||||
assert(s->length >= 1); \
|
||||
return s->items[s->length - 1]; \
|
||||
} \
|
||||
\
|
||||
__attribute__ ((unused)) \
|
||||
SOUNDIO_ATTR_UNUSED \
|
||||
static_kw Type *Name##_last_ptr(struct Name *s) { \
|
||||
assert(s->length >= 1); \
|
||||
return &s->items[s->length - 1]; \
|
||||
} \
|
||||
\
|
||||
__attribute__ ((unused)) \
|
||||
SOUNDIO_ATTR_UNUSED \
|
||||
static_kw void Name##_clear(struct Name *s) { \
|
||||
s->length = 0; \
|
||||
} \
|
||||
\
|
||||
__attribute__ ((unused)) \
|
||||
SOUNDIO_ATTR_UNUSED \
|
||||
static_kw Type Name##_swap_remove(struct Name *s, int index) { \
|
||||
assert(index >= 0); \
|
||||
assert(index < s->length); \
|
||||
|
|
24
src/util.h
24
src/util.h
|
@ -21,6 +21,21 @@
|
|||
|
||||
#define ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0]))
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define SOUNDIO_ATTR_COLD
|
||||
#define SOUNDIO_ATTR_NORETURN __declspec(noreturn)
|
||||
#define SOUNDIO_ATTR_FORMAT(...)
|
||||
#define SOUNDIO_ATTR_UNUSED __pragma(warning(suppress:4100))
|
||||
#define SOUNDIO_ATTR_WARN_UNUSED_RESULT _Check_return_
|
||||
#else
|
||||
#define SOUNDIO_ATTR_COLD __attribute__((cold))
|
||||
#define SOUNDIO_ATTR_NORETURN __attribute__((noreturn))
|
||||
#define SOUNDIO_ATTR_FORMAT(...) __attribute__((format(__VA_ARGS__)))
|
||||
#define SOUNDIO_ATTR_UNUSED __attribute__((unused))
|
||||
#define SOUNDIO_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
||||
#endif
|
||||
|
||||
|
||||
static inline int soundio_int_min(int a, int b) {
|
||||
return (a <= b) ? a : b;
|
||||
}
|
||||
|
@ -45,13 +60,14 @@ static inline double soundio_double_clamp(double min_value, double value, double
|
|||
return soundio_double_max(soundio_double_min(value, max_value), min_value);
|
||||
}
|
||||
|
||||
SOUNDIO_ATTR_NORETURN
|
||||
void soundio_panic(const char *format, ...)
|
||||
__attribute__((cold))
|
||||
__attribute__ ((noreturn))
|
||||
__attribute__ ((format (printf, 1, 2)));
|
||||
SOUNDIO_ATTR_COLD
|
||||
SOUNDIO_ATTR_FORMAT(printf, 1, 2)
|
||||
;
|
||||
|
||||
char *soundio_alloc_sprintf(int *len, const char *format, ...)
|
||||
__attribute__ ((format (printf, 2, 3)));
|
||||
SOUNDIO_ATTR_FORMAT(printf, 2, 3);
|
||||
|
||||
static inline char *soundio_str_dupe(const char *str, int str_len) {
|
||||
char *out = ALLOCATE_NONZERO(char, str_len + 1);
|
||||
|
|
Loading…
Reference in a new issue