ruby-changes:46558
From: nobu <ko1@a...>
Date: Fri, 12 May 2017 16:48:12 +0900 (JST)
Subject: [ruby-changes:46558] nobu:r58674 (trunk): gc.c: checks of sizes
nobu 2017-05-12 16:48:08 +0900 (Fri, 12 May 2017) New Revision: 58674 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58674 Log: gc.c: checks of sizes * gc.c (ruby_xmalloc, ruby_xmalloc2, ruby_xcalloc): move checks of sizes from objspace_xmalloc, objspace_xmalloc2, objspace_xcalloc, respectively. Modified files: trunk/gc.c Index: gc.c =================================================================== --- gc.c (revision 58673) +++ gc.c (revision 58674) @@ -7838,8 +7838,8 @@ objspace_malloc_fixup(rb_objspace_t *obj https://github.com/ruby/ruby/blob/trunk/gc.c#L7838 } \ } while (0) -/* this shouldn't be called directly. - * objspace_xmalloc and objspace_xmalloc2 checks allocation size. +/* these shouldn't be called directly. + * objspace_* functinos do not check allocation size. */ static void * objspace_xmalloc0(rb_objspace_t *objspace, size_t size) @@ -7851,15 +7851,6 @@ objspace_xmalloc0(rb_objspace_t *objspac https://github.com/ruby/ruby/blob/trunk/gc.c#L7851 return objspace_malloc_fixup(objspace, mem, size); } -static void * -objspace_xmalloc(rb_objspace_t *objspace, size_t size) -{ - if ((ssize_t)size < 0) { - negative_size_allocation_error("too large allocation size"); - } - return objspace_xmalloc0(objspace, size); -} - static inline size_t xmalloc2_size(const size_t count, const size_t elsize) { @@ -7871,12 +7862,6 @@ xmalloc2_size(const size_t count, const https://github.com/ruby/ruby/blob/trunk/gc.c#L7862 } static void * -objspace_xmalloc2(rb_objspace_t *objspace, size_t n, size_t size) -{ - return objspace_xmalloc0(objspace, xmalloc2_size(n, size)); -} - -static void * objspace_xrealloc(rb_objspace_t *objspace, void *ptr, size_t new_size, size_t old_size) { void *mem; @@ -7936,7 +7921,10 @@ ruby_xmalloc0(size_t size) https://github.com/ruby/ruby/blob/trunk/gc.c#L7921 void * ruby_xmalloc(size_t size) { - return objspace_xmalloc(&rb_objspace, size); + if ((ssize_t)size < 0) { + negative_size_allocation_error("too large allocation size"); + } + return ruby_xmalloc0(size); } void @@ -7950,18 +7938,15 @@ ruby_malloc_size_overflow(size_t count, https://github.com/ruby/ruby/blob/trunk/gc.c#L7938 void * ruby_xmalloc2(size_t n, size_t size) { - return objspace_xmalloc2(&rb_objspace, n, size); + return objspace_xmalloc0(&rb_objspace, xmalloc2_size(n, size)); } static void * -objspace_xcalloc(rb_objspace_t *objspace, size_t count, size_t elsize) +objspace_xcalloc(rb_objspace_t *objspace, size_t size) { void *mem; - size_t size; - size = xmalloc2_size(count, elsize); size = objspace_malloc_prepare(objspace, size); - TRY_WITH_GC(mem = calloc(1, size)); return objspace_malloc_fixup(objspace, mem, size); } @@ -7969,7 +7954,7 @@ objspace_xcalloc(rb_objspace_t *objspace https://github.com/ruby/ruby/blob/trunk/gc.c#L7954 void * ruby_xcalloc(size_t n, size_t size) { - return objspace_xcalloc(&rb_objspace, n, size); + return objspace_xcalloc(&rb_objspace, xmalloc2_size(n, size)); } #ifdef ruby_sized_xrealloc -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/