From 9b89888ddafcfd8f13f3f7535ce1744e005bac3b Mon Sep 17 00:00:00 2001 From: kosaki Date: Fri, 3 May 2013 21:03:58 +0000 Subject: * include/ruby/defines.h (RUBY_ATTR_ALLOC_SIZE): New for attribute((alloc_size(params))). * include/ruby/defines.h (xmalloc, xmalloc2, xcalloc) (xrealloc, xrealloc2): Annotated by RUBY_ATTR_ALLOC_SIZE. * include/ruby/ruby.h (rb_alloc_tmp_buffer): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ include/ruby/defines.h | 16 +++++++++++----- include/ruby/ruby.h | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4bc30eeacb..0f388cd96d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Sat May 4 04:13:27 2013 KOSAKI Motohiro + + * include/ruby/defines.h (RUBY_ATTR_ALLOC_SIZE): New for + attribute((alloc_size(params))). + + * include/ruby/defines.h (xmalloc, xmalloc2, xcalloc) + (xrealloc, xrealloc2): Annotated by RUBY_ATTR_ALLOC_SIZE. + * include/ruby/ruby.h (rb_alloc_tmp_buffer): ditto. + Fri May 3 19:32:13 2013 Takeyuki FUJIOKA * lib/cgi/util.rb: All class methods moduleized. diff --git a/include/ruby/defines.h b/include/ruby/defines.h index f6fe2c9832..ec6a1a94d5 100644 --- a/include/ruby/defines.h +++ b/include/ruby/defines.h @@ -106,11 +106,17 @@ RUBY_SYMBOL_EXPORT_BEGIN #define xrealloc2 ruby_xrealloc2 #define xfree ruby_xfree -void *xmalloc(size_t); -void *xmalloc2(size_t,size_t); -void *xcalloc(size_t,size_t); -void *xrealloc(void*,size_t); -void *xrealloc2(void*,size_t,size_t); +#if defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 +# define RUBY_ATTR_ALLOC_SIZE(params) __attribute__ ((__alloc_size__ params)) +#else +# define RUBY_ATTR_ALLOC_SIZE(params) +#endif + +void *xmalloc(size_t) RUBY_ATTR_ALLOC_SIZE((1)); +void *xmalloc2(size_t,size_t) RUBY_ATTR_ALLOC_SIZE((1,2)); +void *xcalloc(size_t,size_t) RUBY_ATTR_ALLOC_SIZE((1,2)); +void *xrealloc(void*,size_t) RUBY_ATTR_ALLOC_SIZE((2)); +void *xrealloc2(void*,size_t,size_t) RUBY_ATTR_ALLOC_SIZE((2,3)); void xfree(void*); #define STRINGIZE(expr) STRINGIZE0(expr) diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 43c5de6057..c01242e274 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1210,7 +1210,7 @@ rb_num2char_inline(VALUE x) #define ALLOCA_N(type,n) ((type*)alloca(sizeof(type)*(n))) -void *rb_alloc_tmp_buffer(volatile VALUE *store, long len); +void *rb_alloc_tmp_buffer(volatile VALUE *store, long len) RUBY_ATTR_ALLOC_SIZE((2)); void rb_free_tmp_buffer(volatile VALUE *store); /* allocates _n_ bytes temporary buffer and stores VALUE including it * in _v_. _n_ may be evaluated twice. */ -- cgit v1.2.3