summaryrefslogtreecommitdiff
path: root/include/ruby/defines.h
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2019-10-07 13:16:42 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2019-10-09 12:12:28 +0900
commita220410be70264a0e4089c4d63a9c22dd688ca7c (patch)
tree71bcf4612a1afe003c38cec3e9f4a9eb460fcf1b /include/ruby/defines.h
parent2f3b4029da1b64ffb989916a8b74e17c366e45b0 (diff)
annotate malloc-ish functions
Make them gcc friendly. Note that realloc canot be __malloc__ attributed, according to the GCC manual.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2540
Diffstat (limited to 'include/ruby/defines.h')
-rw-r--r--include/ruby/defines.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/include/ruby/defines.h b/include/ruby/defines.h
index 72ec11d89f..0d95209b02 100644
--- a/include/ruby/defines.h
+++ b/include/ruby/defines.h
@@ -221,9 +221,18 @@ RUBY_SYMBOL_EXPORT_BEGIN
# define RUBY_ATTR_ALLOC_SIZE(params)
#endif
-void *ruby_xmalloc(size_t) RUBY_ATTR_ALLOC_SIZE((1));
-void *ruby_xmalloc2(size_t,size_t) RUBY_ATTR_ALLOC_SIZE((1,2));
-void *ruby_xcalloc(size_t,size_t) RUBY_ATTR_ALLOC_SIZE((1,2));
+#ifdef __has_attribute
+# if __has_attribute(malloc)
+# define RUBY_ATTR_MALLOC __attribute__((__malloc__))
+# endif
+#endif
+#ifndef RUBY_ATTR_MALLOC
+# define RUBY_ATTR_MALLOC
+#endif
+
+void *ruby_xmalloc(size_t) RUBY_ATTR_MALLOC RUBY_ATTR_ALLOC_SIZE((1));
+void *ruby_xmalloc2(size_t,size_t) RUBY_ATTR_MALLOC RUBY_ATTR_ALLOC_SIZE((1,2));
+void *ruby_xcalloc(size_t,size_t) RUBY_ATTR_MALLOC RUBY_ATTR_ALLOC_SIZE((1,2));
void *ruby_xrealloc(void*,size_t) RUBY_ATTR_ALLOC_SIZE((2));
void *ruby_xrealloc2(void*,size_t,size_t) RUBY_ATTR_ALLOC_SIZE((2,3));
void ruby_xfree(void*);