diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-21 20:59:40 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-21 20:59:40 +0000 |
commit | feaa82a42ba238d9192d219f72229f4c3948957f (patch) | |
tree | 0e4259a2b8c8ba9a3466526ad7931ea95c22b054 /gc.c | |
parent | f056071cdc1541e60c80d9034c75e374b1790ea1 (diff) | |
download | ruby-feaa82a42ba238d9192d219f72229f4c3948957f.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.c | 27 |
1 files changed, 20 insertions, 7 deletions
@@ -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) { |