summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-12 07:48:08 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-12 07:48:08 +0000
commitebd763c1f7a3033164db3d04442ee5df339882c7 (patch)
tree9c2a0555b077dd57aed0cd71b6ce3ff80fbcb5c9 /gc.c
parent6ed69699cd38b26f1788916ae8e2191d548229ac (diff)
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
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c33
1 files changed, 9 insertions, 24 deletions
diff --git a/gc.c b/gc.c
index 54865d0924..f0fb88d320 100644
--- a/gc.c
+++ b/gc.c
@@ -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