[前][次][番号順一覧][スレッド一覧]

ruby-changes:58168

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Wed, 9 Oct 2019 12:12:47 +0900 (JST)
Subject: [ruby-changes:58168] a220410be7 (master): annotate malloc-ish functions

https://git.ruby-lang.org/ruby.git/commit/?id=a220410be7

From a220410be70264a0e4089c4d63a9c22dd688ca7c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Mon, 7 Oct 2019 13:16:42 +0900
Subject: annotate malloc-ish functions

Make them gcc friendly.  Note that realloc canot be __malloc__
attributed, according to the GCC manual.

diff --git a/include/ruby/defines.h b/include/ruby/defines.h
index 72ec11d..0d95209 100644
--- a/include/ruby/defines.h
+++ b/include/ruby/defines.h
@@ -221,9 +221,18 @@ RUBY_SYMBOL_EXPORT_BEGIN https://github.com/ruby/ruby/blob/trunk/include/ruby/defines.h#L221
 # 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*);
diff --git a/internal.h b/internal.h
index 6956427..3f57523 100644
--- a/internal.h
+++ b/internal.h
@@ -1639,7 +1639,12 @@ RUBY_SYMBOL_EXPORT_END https://github.com/ruby/ruby/blob/trunk/internal.h#L1639
 			rb_wb_unprotected_newobj_of(klass, flags))
 #define NEWOBJ_OF(obj,type,klass,flags) RB_NEWOBJ_OF(obj,type,klass,flags)
 
-void *rb_aligned_malloc(size_t, size_t);
+#ifdef __has_attribute
+#if __has_attribute(alloc_align)
+__attribute__((__alloc_align__(1)))
+#endif
+#endif
+void *rb_aligned_malloc(size_t, size_t) RUBY_ATTR_MALLOC RUBY_ATTR_ALLOC_SIZE((2));
 void rb_aligned_free(void *);
 
 /* hash.c */
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]