summaryrefslogtreecommitdiff
path: root/include/ruby/defines.h
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2019-11-01 16:48:31 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2019-11-01 16:58:19 +0900
commit72f997edf66cb766b97feac709888c57852be084 (patch)
tree0d98781c0340a00d5fa348df6659f65898c3a50e /include/ruby/defines.h
parentf5e406327200672f95d61c4ca4ffc9de03e6a5a7 (diff)
downloadruby-72f997edf66cb766b97feac709888c57852be084.tar.gz
mark functions that do not return NULL as such.
Apply __attribute__((__returns_nonnull__)) when available.
Diffstat (limited to 'include/ruby/defines.h')
-rw-r--r--include/ruby/defines.h29
1 files changed, 19 insertions, 10 deletions
diff --git a/include/ruby/defines.h b/include/ruby/defines.h
index 213956c3eb..5e03d49985 100644
--- a/include/ruby/defines.h
+++ b/include/ruby/defines.h
@@ -235,11 +235,20 @@ RUBY_SYMBOL_EXPORT_BEGIN
# 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));
+#ifdef __has_attribute
+# if __has_attribute(returns_nonnull)
+# define RUBY_ATTR_RETURNS_NONNULL __attribute__((__returns_nonnull__))
+# endif
+#endif
+#ifndef RUBY_ATTR_RETURNS_NONNULL
+# define RUBY_ATTR_RETURNS_NONNULL
+#endif
+
+void *ruby_xmalloc(size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1));
+void *ruby_xmalloc2(size_t,size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1,2));
+void *ruby_xcalloc(size_t,size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1,2));
+void *ruby_xrealloc(void*,size_t) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2));
+void *ruby_xrealloc2(void*,size_t,size_t) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2,3));
void ruby_xfree(void*);
#ifndef USE_GC_MALLOC_OBJ_INFO_DETAILS
@@ -248,11 +257,11 @@ void ruby_xfree(void*);
#if USE_GC_MALLOC_OBJ_INFO_DETAILS
-void *ruby_xmalloc_body(size_t) RUBY_ATTR_ALLOC_SIZE((1));
-void *ruby_xmalloc2_body(size_t,size_t) RUBY_ATTR_ALLOC_SIZE((1,2));
-void *ruby_xcalloc_body(size_t,size_t) RUBY_ATTR_ALLOC_SIZE((1,2));
-void *ruby_xrealloc_body(void*,size_t) RUBY_ATTR_ALLOC_SIZE((2));
-void *ruby_xrealloc2_body(void*,size_t,size_t) RUBY_ATTR_ALLOC_SIZE((2,3));
+void *ruby_xmalloc_body(size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1));
+void *ruby_xmalloc2_body(size_t,size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1,2));
+void *ruby_xcalloc_body(size_t,size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1,2));
+void *ruby_xrealloc_body(void*,size_t) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2));
+void *ruby_xrealloc2_body(void*,size_t,size_t) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2,3));
#define ruby_xmalloc(s1) ruby_xmalloc_with_location(s1, __FILE__, __LINE__)
#define ruby_xmalloc2(s1, s2) ruby_xmalloc2_with_location(s1, s2, __FILE__, __LINE__)