aboutsummaryrefslogtreecommitdiffstats
path: root/gc.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-09 07:08:53 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-09 07:08:53 +0000
commit1dd7f2c8170080318025632172ec1f6044f3514c (patch)
tree19dfdcfdb6817d35069fb6310554c660f7ccc60c /gc.c
parent30602eca9514db5e0000a84c81d6ff7c77c760f9 (diff)
downloadruby-1dd7f2c8170080318025632172ec1f6044f3514c.tar.gz
gc.c (rb_imemo_alloc_new): split for each purpose
imemo_alloc is used for three purposes: auto-free pointer (alternative of alloca), alloc_tmp_buffer, and heap allocation for bison. To make it clear, this change introduces three functions: rb_imemo_alloc_auto_free_pointer, rb_imemo_alloc_auto_free_maybe_mark_buffer, and rb_imemo_alloc_parser_heap. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/gc.c b/gc.c
index 210bef053f..c93a00694a 100644
--- a/gc.c
+++ b/gc.c
@@ -2024,11 +2024,29 @@ rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0)
return newobj_of(v0, flags, v1, v2, v3, TRUE);
}
-rb_imemo_alloc_t *
-rb_imemo_alloc_new(void *buf)
+static VALUE
+rb_imemo_alloc_new(VALUE v1, VALUE v2, VALUE v3, VALUE v0)
{
VALUE flags = T_IMEMO | (imemo_alloc << FL_USHIFT);
- return (rb_imemo_alloc_t *)newobj_of(0, flags, (VALUE)buf, 0, 0, FALSE);
+ return newobj_of(v0, flags, v1, v2, v3, FALSE);
+}
+
+VALUE
+rb_imemo_alloc_auto_free_pointer(void *buf)
+{
+ return rb_imemo_new(imemo_alloc, (VALUE)buf, 0, 0, 0);
+}
+
+VALUE
+rb_imemo_alloc_auto_free_maybe_mark_buffer(void *buf, size_t cnt)
+{
+ return rb_imemo_alloc_new((VALUE)buf, 0, (VALUE)cnt, 0);
+}
+
+rb_imemo_alloc_t *
+rb_imemo_alloc_parser_heap(void *buf, rb_imemo_alloc_t *old_heap, size_t cnt)
+{
+ return (rb_imemo_alloc_t *)rb_imemo_alloc_new((VALUE)buf, (VALUE)old_heap, (VALUE)cnt, 0);
}
#if IMEMO_DEBUG
@@ -8122,13 +8140,10 @@ ruby_mimfree(void *ptr)
void *
rb_alloc_tmp_buffer_with_count(volatile VALUE *store, size_t size, size_t cnt)
{
- rb_imemo_alloc_t *s;
void *ptr;
ptr = ruby_xmalloc0(size);
- s = rb_imemo_alloc_new(ptr);
- s->cnt = cnt;
- *store = (VALUE)s;
+ *store = rb_imemo_alloc_auto_free_maybe_mark_buffer(ptr, cnt);
return ptr;
}