summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2017-12-01 20:32:34 +0300
committerIvan Maidanski <ivmai@mail.ru>2017-12-11 10:23:03 +0300
commit231065a2f58afa5f20ab92436ae75cd30d44bc6a (patch)
tree00d51e1e328a43c46f7404aee070cbaff613a81a /src
parent00bdd889702fe6dea13b835c7f633bc0d36f88bf (diff)
downloadlibatomic_ops-231065a2f58afa5f20ab92436ae75cd30d44bc6a.tar.gz
Annotate AO_malloc with 'alloc_size' and 'malloc' attributes
* src/atomic_ops_malloc.h [!AO_ATTR_MALLOC] (AO_ATTR_MALLOC): New macro. * src/atomic_ops_malloc.h [!AO_ATTR_ALLOC_SIZE] (AO_ATTR_ALLOC_SIZE): Likewise. * src/atomic_ops_malloc.h (AO_malloc): Add AO_ATTR_MALLOC, AO_ATTR_ALLOC_SIZE attributes.
Diffstat (limited to 'src')
-rw-r--r--src/atomic_ops_malloc.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/atomic_ops_malloc.h b/src/atomic_ops_malloc.h
index e324d5b..3ffe173 100644
--- a/src/atomic_ops_malloc.h
+++ b/src/atomic_ops_malloc.h
@@ -34,8 +34,37 @@
# define AO_MALLOC_IS_LOCK_FREE
#endif
+#ifndef AO_ATTR_MALLOC
+# if AO_GNUC_PREREQ(3, 1)
+# define AO_ATTR_MALLOC __attribute__((__malloc__))
+# elif defined(_MSC_VER) && (_MSC_VER >= 1900) && !defined(__EDG__)
+# define AO_ATTR_MALLOC \
+ __declspec(allocator) __declspec(noalias) __declspec(restrict)
+# elif defined(_MSC_VER) && _MSC_VER >= 1400
+# define AO_ATTR_MALLOC __declspec(noalias) __declspec(restrict)
+# else
+# define AO_ATTR_MALLOC /* empty */
+# endif
+#endif
+
+#ifndef AO_ATTR_ALLOC_SIZE
+# ifdef __clang__
+# if __has_attribute(__alloc_size__)
+# define AO_ATTR_ALLOC_SIZE(argnum) \
+ __attribute__((__alloc_size__(argnum)))
+# else
+# define AO_ATTR_ALLOC_SIZE(argnum) /* empty */
+# endif
+# elif AO_GNUC_PREREQ(4, 3) && !defined(__ICC)
+# define AO_ATTR_ALLOC_SIZE(argnum) __attribute__((__alloc_size__(argnum)))
+# else
+# define AO_ATTR_ALLOC_SIZE(argnum) /* empty */
+# endif
+#endif
+
void AO_free(void *);
+AO_ATTR_MALLOC AO_ATTR_ALLOC_SIZE(1)
void * AO_malloc(size_t);
/* Allow use of mmap to grow the heap. No-op on some platforms. */