mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 22:48:34 +00:00
Add REAL_FATTR_ macros to func_attr.h, use them in lib/k*
Otherwise FUNC_ATTR_* macros may appear empty
This commit is contained in:
@@ -16,6 +16,11 @@
|
|||||||
// Defined DEFINE_FUNC_ATTRIBUTES and defined DO_NOT_DEFINE_EMPTY_ATTRIBUTES is
|
// Defined DEFINE_FUNC_ATTRIBUTES and defined DO_NOT_DEFINE_EMPTY_ATTRIBUTES is
|
||||||
// not used by anything.
|
// not used by anything.
|
||||||
|
|
||||||
|
// FUNC_ATTR_* macros should be in *.c files for declarations generator. If you
|
||||||
|
// define a function for which declaration is not generated by
|
||||||
|
// gendeclarations.lua (e.g. template hash implementation) then you should use
|
||||||
|
// REAL_FATTR_* macros.
|
||||||
|
|
||||||
// gcc and clang expose their version as follows:
|
// gcc and clang expose their version as follows:
|
||||||
//
|
//
|
||||||
// gcc 4.7.2:
|
// gcc 4.7.2:
|
||||||
@@ -84,21 +89,22 @@
|
|||||||
#undef FUNC_ATTR_NONNULL_RET
|
#undef FUNC_ATTR_NONNULL_RET
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEFINE_FUNC_ATTRIBUTES
|
#ifndef DID_REAL_ATTR
|
||||||
|
#define DID_REAL_ATTR
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
// place defines for all gnulikes here, for now that's gcc, clang and
|
// place defines for all gnulikes here, for now that's gcc, clang and
|
||||||
// intel.
|
// intel.
|
||||||
|
|
||||||
// place these after the argument list of the function declaration
|
// place these after the argument list of the function declaration
|
||||||
// (not definition), like so:
|
// (not definition), like so:
|
||||||
// void myfunc(void) FUNC_ATTR_ALWAYS_INLINE;
|
// void myfunc(void) REAL_FATTR_ALWAYS_INLINE;
|
||||||
#define FUNC_ATTR_MALLOC __attribute__((malloc))
|
#define REAL_FATTR_MALLOC __attribute__((malloc))
|
||||||
#define FUNC_ATTR_ALLOC_ALIGN(x) __attribute__((alloc_align(x)))
|
#define REAL_FATTR_ALLOC_ALIGN(x) __attribute__((alloc_align(x)))
|
||||||
#define FUNC_ATTR_PURE __attribute__ ((pure))
|
#define REAL_FATTR_PURE __attribute__ ((pure))
|
||||||
#define FUNC_ATTR_CONST __attribute__((const))
|
#define REAL_FATTR_CONST __attribute__((const))
|
||||||
#define FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
#define REAL_FATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
||||||
#define FUNC_ATTR_ALWAYS_INLINE __attribute__((always_inline))
|
#define REAL_FATTR_ALWAYS_INLINE __attribute__((always_inline))
|
||||||
#define FUNC_ATTR_UNUSED __attribute__((unused))
|
#define REAL_FATTR_UNUSED __attribute__((unused))
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
// clang only
|
// clang only
|
||||||
@@ -110,66 +116,92 @@
|
|||||||
__GNUC_MINOR__ * 100 + \
|
__GNUC_MINOR__ * 100 + \
|
||||||
__GNUC_PATCHLEVEL__)
|
__GNUC_PATCHLEVEL__)
|
||||||
// gcc only
|
// gcc only
|
||||||
#define FUNC_ATTR_ALLOC_SIZE(x) __attribute__((alloc_size(x)))
|
#define REAL_FATTR_ALLOC_SIZE(x) __attribute__((alloc_size(x)))
|
||||||
#define FUNC_ATTR_ALLOC_SIZE_PROD(x,y) __attribute__((alloc_size(x,y)))
|
#define REAL_FATTR_ALLOC_SIZE_PROD(x,y) __attribute__((alloc_size(x,y)))
|
||||||
#define FUNC_ATTR_NONNULL_ALL __attribute__((nonnull))
|
#define REAL_FATTR_NONNULL_ALL __attribute__((nonnull))
|
||||||
#define FUNC_ATTR_NONNULL_ARG(...) __attribute__((nonnull(__VA_ARGS__)))
|
#define REAL_FATTR_NONNULL_ARG(...) __attribute__((nonnull(__VA_ARGS__)))
|
||||||
#if GCC_VERSION >= 40900
|
#if GCC_VERSION >= 40900
|
||||||
#define FUNC_ATTR_NONNULL_RET __attribute__((returns_nonnull))
|
#define REAL_FATTR_NONNULL_RET __attribute__((returns_nonnull))
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DO_NOT_DEFINE_EMPTY_ATTRIBUTES
|
|
||||||
// define function attributes that haven't been defined for this specific
|
// define function attributes that haven't been defined for this specific
|
||||||
// compiler.
|
// compiler.
|
||||||
|
|
||||||
#ifndef FUNC_ATTR_MALLOC
|
#ifndef REAL_FATTR_MALLOC
|
||||||
#define FUNC_ATTR_MALLOC
|
#define REAL_FATTR_MALLOC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FUNC_ATTR_ALLOC_SIZE
|
#ifndef REAL_FATTR_ALLOC_SIZE
|
||||||
#define FUNC_ATTR_ALLOC_SIZE(x)
|
#define REAL_FATTR_ALLOC_SIZE(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FUNC_ATTR_ALLOC_SIZE_PROD
|
#ifndef REAL_FATTR_ALLOC_SIZE_PROD
|
||||||
#define FUNC_ATTR_ALLOC_SIZE_PROD(x,y)
|
#define REAL_FATTR_ALLOC_SIZE_PROD(x,y)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FUNC_ATTR_ALLOC_ALIGN
|
#ifndef REAL_FATTR_ALLOC_ALIGN
|
||||||
#define FUNC_ATTR_ALLOC_ALIGN(x)
|
#define REAL_FATTR_ALLOC_ALIGN(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FUNC_ATTR_PURE
|
#ifndef REAL_FATTR_PURE
|
||||||
#define FUNC_ATTR_PURE
|
#define REAL_FATTR_PURE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FUNC_ATTR_CONST
|
#ifndef REAL_FATTR_CONST
|
||||||
#define FUNC_ATTR_CONST
|
#define REAL_FATTR_CONST
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FUNC_ATTR_WARN_UNUSED_RESULT
|
#ifndef REAL_FATTR_WARN_UNUSED_RESULT
|
||||||
#define FUNC_ATTR_WARN_UNUSED_RESULT
|
#define REAL_FATTR_WARN_UNUSED_RESULT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FUNC_ATTR_ALWAYS_INLINE
|
#ifndef REAL_FATTR_ALWAYS_INLINE
|
||||||
#define FUNC_ATTR_ALWAYS_INLINE
|
#define REAL_FATTR_ALWAYS_INLINE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FUNC_ATTR_UNUSED
|
#ifndef REAL_FATTR_UNUSED
|
||||||
#define FUNC_ATTR_UNUSED
|
#define REAL_FATTR_UNUSED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FUNC_ATTR_NONNULL_ALL
|
#ifndef REAL_FATTR_NONNULL_ALL
|
||||||
#define FUNC_ATTR_NONNULL_ALL
|
#define REAL_FATTR_NONNULL_ALL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FUNC_ATTR_NONNULL_ARG
|
#ifndef REAL_FATTR_NONNULL_ARG
|
||||||
#define FUNC_ATTR_NONNULL_ARG(...)
|
#define REAL_FATTR_NONNULL_ARG(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FUNC_ATTR_NONNULL_RET
|
#ifndef REAL_FATTR_NONNULL_RET
|
||||||
#define FUNC_ATTR_NONNULL_RET
|
#define REAL_FATTR_NONNULL_RET
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEFINE_FUNC_ATTRIBUTES
|
||||||
|
#define FUNC_ATTR_MALLOC REAL_FATTR_MALLOC
|
||||||
|
#define FUNC_ATTR_ALLOC_SIZE(x) REAL_FATTR_ALLOC_SIZE(x)
|
||||||
|
#define FUNC_ATTR_ALLOC_SIZE_PROD(x,y) REAL_FATTR_ALLOC_SIZE_PROD(x,y)
|
||||||
|
#define FUNC_ATTR_ALLOC_ALIGN(x) REAL_FATTR_ALLOC_ALIGN(x)
|
||||||
|
#define FUNC_ATTR_PURE REAL_FATTR_PURE
|
||||||
|
#define FUNC_ATTR_CONST REAL_FATTR_CONST
|
||||||
|
#define FUNC_ATTR_WARN_UNUSED_RESULT REAL_FATTR_WARN_UNUSED_RESULT
|
||||||
|
#define FUNC_ATTR_ALWAYS_INLINE REAL_FATTR_ALWAYS_INLINE
|
||||||
|
#define FUNC_ATTR_UNUSED REAL_FATTR_UNUSED
|
||||||
|
#define FUNC_ATTR_NONNULL_ALL REAL_FATTR_NONNULL_ALL
|
||||||
|
#define FUNC_ATTR_NONNULL_ARG(...) REAL_FATTR_NONNULL_ARG(__VA_ARGS__)
|
||||||
|
#define FUNC_ATTR_NONNULL_RET REAL_FATTR_NONNULL_RET
|
||||||
|
#elif !defined(DO_NOT_DEFINE_EMPTY_ATTRIBUTES)
|
||||||
|
#define FUNC_ATTR_MALLOC
|
||||||
|
#define FUNC_ATTR_ALLOC_SIZE(x)
|
||||||
|
#define FUNC_ATTR_ALLOC_SIZE_PROD(x,y)
|
||||||
|
#define FUNC_ATTR_ALLOC_ALIGN(x)
|
||||||
|
#define FUNC_ATTR_PURE
|
||||||
|
#define FUNC_ATTR_CONST
|
||||||
|
#define FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
|
#define FUNC_ATTR_ALWAYS_INLINE
|
||||||
|
#define FUNC_ATTR_UNUSED
|
||||||
|
#define FUNC_ATTR_NONNULL_ALL
|
||||||
|
#define FUNC_ATTR_NONNULL_ARG(...)
|
||||||
|
#define FUNC_ATTR_NONNULL_RET
|
||||||
|
#endif
|
||||||
|
@@ -131,9 +131,7 @@ int main() {
|
|||||||
|
|
||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
|
|
||||||
#define DEFINE_FUNC_ATTRIBUTES
|
|
||||||
#include "nvim/func_attr.h"
|
#include "nvim/func_attr.h"
|
||||||
#undef DEFINE_FUNC_ATTRIBUTES
|
|
||||||
|
|
||||||
/* compiler specific configuration */
|
/* compiler specific configuration */
|
||||||
|
|
||||||
@@ -209,7 +207,7 @@ static const double __ac_HASH_UPPER = 0.77;
|
|||||||
return (kh_##name##_t*)kcalloc(1, sizeof(kh_##name##_t)); \
|
return (kh_##name##_t*)kcalloc(1, sizeof(kh_##name##_t)); \
|
||||||
} \
|
} \
|
||||||
SCOPE void kh_destroy_##name(kh_##name##_t *h) \
|
SCOPE void kh_destroy_##name(kh_##name##_t *h) \
|
||||||
FUNC_ATTR_UNUSED; \
|
REAL_FATTR_UNUSED; \
|
||||||
SCOPE void kh_destroy_##name(kh_##name##_t *h) \
|
SCOPE void kh_destroy_##name(kh_##name##_t *h) \
|
||||||
{ \
|
{ \
|
||||||
if (h) { \
|
if (h) { \
|
||||||
@@ -219,7 +217,7 @@ static const double __ac_HASH_UPPER = 0.77;
|
|||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
SCOPE void kh_clear_##name(kh_##name##_t *h) \
|
SCOPE void kh_clear_##name(kh_##name##_t *h) \
|
||||||
FUNC_ATTR_UNUSED; \
|
REAL_FATTR_UNUSED; \
|
||||||
SCOPE void kh_clear_##name(kh_##name##_t *h) \
|
SCOPE void kh_clear_##name(kh_##name##_t *h) \
|
||||||
{ \
|
{ \
|
||||||
if (h && h->flags) { \
|
if (h && h->flags) { \
|
||||||
@@ -228,7 +226,7 @@ static const double __ac_HASH_UPPER = 0.77;
|
|||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) \
|
SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) \
|
||||||
FUNC_ATTR_UNUSED; \
|
REAL_FATTR_UNUSED; \
|
||||||
SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) \
|
SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) \
|
||||||
{ \
|
{ \
|
||||||
if (h->n_buckets) { \
|
if (h->n_buckets) { \
|
||||||
@@ -244,7 +242,7 @@ static const double __ac_HASH_UPPER = 0.77;
|
|||||||
} else return 0; \
|
} else return 0; \
|
||||||
} \
|
} \
|
||||||
SCOPE void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
|
SCOPE void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
|
||||||
FUNC_ATTR_UNUSED; \
|
REAL_FATTR_UNUSED; \
|
||||||
SCOPE void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
|
SCOPE void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
|
||||||
{ /* This function uses 0.25*n_buckets bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */ \
|
{ /* This function uses 0.25*n_buckets bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */ \
|
||||||
khint32_t *new_flags = 0; \
|
khint32_t *new_flags = 0; \
|
||||||
@@ -305,7 +303,7 @@ static const double __ac_HASH_UPPER = 0.77;
|
|||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \
|
SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \
|
||||||
FUNC_ATTR_UNUSED; \
|
REAL_FATTR_UNUSED; \
|
||||||
SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \
|
SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \
|
||||||
{ \
|
{ \
|
||||||
khint_t x; \
|
khint_t x; \
|
||||||
@@ -347,7 +345,7 @@ static const double __ac_HASH_UPPER = 0.77;
|
|||||||
return x; \
|
return x; \
|
||||||
} \
|
} \
|
||||||
SCOPE void kh_del_##name(kh_##name##_t *h, khint_t x) \
|
SCOPE void kh_del_##name(kh_##name##_t *h, khint_t x) \
|
||||||
FUNC_ATTR_UNUSED; \
|
REAL_FATTR_UNUSED; \
|
||||||
SCOPE void kh_del_##name(kh_##name##_t *h, khint_t x) \
|
SCOPE void kh_del_##name(kh_##name##_t *h, khint_t x) \
|
||||||
{ \
|
{ \
|
||||||
if (x != h->n_buckets && !__ac_iseither(h->flags, x)) { \
|
if (x != h->n_buckets && !__ac_iseither(h->flags, x)) { \
|
||||||
|
@@ -29,10 +29,8 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define DEFINE_FUNC_ATTRIBUTES
|
|
||||||
#include "nvim/func_attr.h"
|
|
||||||
#undef DEFINE_FUNC_ATTRIBUTES
|
|
||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
|
#include "nvim/func_attr.h"
|
||||||
|
|
||||||
#define KMEMPOOL_INIT(name, kmptype_t, kmpfree_f) \
|
#define KMEMPOOL_INIT(name, kmptype_t, kmpfree_f) \
|
||||||
typedef struct { \
|
typedef struct { \
|
||||||
@@ -89,7 +87,7 @@
|
|||||||
return kl; \
|
return kl; \
|
||||||
} \
|
} \
|
||||||
static inline void kl_destroy_##name(kl_##name##_t *kl) \
|
static inline void kl_destroy_##name(kl_##name##_t *kl) \
|
||||||
FUNC_ATTR_UNUSED; \
|
REAL_FATTR_UNUSED; \
|
||||||
static inline void kl_destroy_##name(kl_##name##_t *kl) { \
|
static inline void kl_destroy_##name(kl_##name##_t *kl) { \
|
||||||
kl1_##name *p; \
|
kl1_##name *p; \
|
||||||
for (p = kl->head; p != kl->tail; p = p->next) \
|
for (p = kl->head; p != kl->tail; p = p->next) \
|
||||||
|
Reference in New Issue
Block a user