aboutsummaryrefslogtreecommitdiffstats
path: root/gc.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-21 20:59:40 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-21 20:59:40 +0000
commit68d0123ba8522ce97041928b1ad94adc74f3b331 (patch)
tree0e4259a2b8c8ba9a3466526ad7931ea95c22b054 /gc.c
parentd4710ff2964be7f5687b3cd684336e688d519849 (diff)
downloadruby-68d0123ba8522ce97041928b1ad94adc74f3b331.tar.gz
* gc.c (rb_alloc_tmp_buffer_with_count): added like xmalloc2 to
avoid duplicated check of size. * gc.c (ruby_xmalloc2): added to keep separate layers. * include/ruby/ruby.h (rb_alloc_tmp_buffer2): added to check the size more statically. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54664 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/gc.c b/gc.c
index feb5c2ed0f..b7e4ff681d 100644
--- a/gc.c
+++ b/gc.c
@@ -7850,6 +7850,12 @@ objspace_xfree(rb_objspace_t *objspace, void *ptr, size_t old_size)
objspace_malloc_increase(objspace, ptr, 0, old_size, MEMOP_TYPE_FREE);
}
+static void *
+ruby_xmalloc0(size_t size)
+{
+ return objspace_xmalloc0(&rb_objspace, size);
+}
+
void *
ruby_xmalloc(size_t size)
{
@@ -7972,24 +7978,31 @@ ruby_mimfree(void *ptr)
}
void *
-rb_alloc_tmp_buffer(volatile VALUE *store, long len)
+rb_alloc_tmp_buffer_with_count(volatile VALUE *store, size_t size, size_t cnt)
{
NODE *s;
- long cnt;
void *ptr;
- if (len < 0 || (cnt = (long)roomof(len, sizeof(VALUE))) < 0) {
- rb_raise(rb_eArgError, "negative buffer size (or size too big)");
- }
-
s = rb_node_newnode(NODE_ALLOCA, 0, 0, 0);
- ptr = ruby_xmalloc(cnt * sizeof(VALUE));
+ ptr = ruby_xmalloc0(size);
s->u1.value = (VALUE)ptr;
s->u3.cnt = cnt;
*store = (VALUE)s;
return ptr;
}
+void *
+rb_alloc_tmp_buffer(volatile VALUE *store, long len)
+{
+ long cnt;
+
+ if (len < 0 || (cnt = (long)roomof(len, sizeof(VALUE))) < 0) {
+ rb_raise(rb_eArgError, "negative buffer size (or size too big)");
+ }
+
+ return rb_alloc_tmp_buffer_with_count(store, len, cnt);
+}
+
void
rb_free_tmp_buffer(volatile VALUE *store)
{