diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-12 07:48:08 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-12 07:48:08 +0000 |
commit | f2cf6a2b10d697d8104f2f3623a12d65ccdb1917 (patch) | |
tree | 9c2a0555b077dd57aed0cd71b6ce3ff80fbcb5c9 | |
parent | 497f646b88b6161febb638b9c1ab7ddceea759e7 (diff) | |
download | ruby-f2cf6a2b10d697d8104f2f3623a12d65ccdb1917.tar.gz |
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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | gc.c | 33 |
1 files changed, 9 insertions, 24 deletions
@@ -7838,8 +7838,8 @@ objspace_malloc_fixup(rb_objspace_t *objspace, void *mem, size_t size) } \ } 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 *objspace, size_t size) 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 size_t elsize) } 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) 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, size_t elsize) 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, size_t count, size_t elsize) 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 |