[前][次][番号順一覧][スレッド一覧]

ruby-changes:51164

From: mame <ko1@a...>
Date: Wed, 9 May 2018 16:08:58 +0900 (JST)
Subject: [ruby-changes:51164] mame:r63371 (trunk): gc.c (rb_imemo_alloc_new): split for each purpose

mame	2018-05-09 16:08:53 +0900 (Wed, 09 May 2018)

  New Revision: 63371

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63371

  Log:
    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.

  Modified files:
    trunk/gc.c
    trunk/internal.h
    trunk/parse.y
Index: internal.h
===================================================================
--- internal.h	(revision 63370)
+++ internal.h	(revision 63371)
@@ -960,7 +960,9 @@ typedef struct rb_imemo_alloc_struct { https://github.com/ruby/ruby/blob/trunk/internal.h#L960
     size_t cnt; /* buffer size in VALUE */
 } rb_imemo_alloc_t;
 
-rb_imemo_alloc_t *rb_imemo_alloc_new(void *buf);
+VALUE rb_imemo_alloc_auto_free_pointer(void *buf);
+VALUE rb_imemo_alloc_auto_free_maybe_mark_buffer(void *buf, size_t cnt);
+rb_imemo_alloc_t *rb_imemo_alloc_parser_heap(void *buf, rb_imemo_alloc_t *old_heap, size_t cnt);
 
 void rb_strterm_mark(VALUE obj);
 
Index: parse.y
===================================================================
--- parse.y	(revision 63370)
+++ parse.y	(revision 63371)
@@ -2505,7 +2505,7 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2505
 			NODE *args, *scope, *internal_var = NEW_DVAR(id, &@2);
 			ID *tbl = ALLOC_N(ID, 2);
 			tbl[0] = 1 /* length of local var table */; tbl[1] = id /* internal id */;
-			add_mark_object(p, (VALUE)rb_imemo_alloc_new(tbl));
+			add_mark_object(p, rb_imemo_alloc_auto_free_pointer(tbl));
 
 			switch (nd_type($2)) {
 			  case NODE_LASGN:
@@ -9988,7 +9988,7 @@ new_args_tail(struct parser_params *p, N https://github.com/ruby/ruby/blob/trunk/parse.y#L9988
     NODE *node;
 
     args = ZALLOC(struct rb_args_info);
-    add_mark_object(p, (VALUE)rb_imemo_alloc_new(args));
+    add_mark_object(p, rb_imemo_alloc_auto_free_pointer(args));
     node = NEW_NODE(NODE_ARGS, 0, 0, args, &NULL_LOC);
     if (p->error_p) return node;
 
@@ -10350,7 +10350,7 @@ local_tbl(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L10350
     if (--j < cnt) REALLOC_N(buf, ID, (cnt = j) + 1);
     buf[0] = cnt;
 
-    add_mark_object(p, (VALUE)rb_imemo_alloc_new(buf));
+    add_mark_object(p, rb_imemo_alloc_auto_free_pointer(buf));
 
     return buf;
 }
@@ -10975,10 +10975,8 @@ rb_parser_malloc(struct parser_params *p https://github.com/ruby/ruby/blob/trunk/parse.y#L10975
 {
     size_t cnt = HEAPCNT(1, size);
     void *ptr = xmalloc(size);
-    rb_imemo_alloc_t *n = rb_imemo_alloc_new(ptr);
-    n->next = p->heap;
-
-    return ADD2HEAP(n, cnt, ptr);
+    p->heap = rb_imemo_alloc_parser_heap(ptr, p->heap, cnt);
+    return p->heap->ptr;
 }
 
 void *
@@ -10986,10 +10984,8 @@ rb_parser_calloc(struct parser_params *p https://github.com/ruby/ruby/blob/trunk/parse.y#L10984
 {
     size_t cnt = HEAPCNT(nelem, size);
     void *ptr = xcalloc(nelem, size);
-    rb_imemo_alloc_t *n = rb_imemo_alloc_new(ptr);
-    n->next = p->heap;
-
-    return ADD2HEAP(n, cnt, ptr);
+    p->heap = rb_imemo_alloc_parser_heap(ptr, p->heap, cnt);
+    return p->heap->ptr;
 }
 
 void *
@@ -11008,9 +11004,8 @@ rb_parser_realloc(struct parser_params * https://github.com/ruby/ruby/blob/trunk/parse.y#L11004
 	} while ((n = n->next) != NULL);
     }
     ptr = xrealloc(ptr, size);
-    n = rb_imemo_alloc_new(ptr);
-    n->next = p->heap;
-    return ADD2HEAP(n, cnt, ptr);
+    p->heap = rb_imemo_alloc_parser_heap(ptr, p->heap, cnt);
+    return p->heap->ptr;
 }
 
 void
Index: gc.c
===================================================================
--- gc.c	(revision 63370)
+++ gc.c	(revision 63371)
@@ -2024,11 +2024,29 @@ rb_imemo_new(enum imemo_type type, VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L2024
     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) https://github.com/ruby/ruby/blob/trunk/gc.c#L8140
 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;
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]