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

ruby-changes:51162

From: mame <ko1@a...>
Date: Wed, 9 May 2018 15:12:24 +0900 (JST)
Subject: [ruby-changes:51162] mame:r63369 (trunk): gc.c (rb_imemo_alloc_new): improve the API interface

mame	2018-05-09 15:12:17 +0900 (Wed, 09 May 2018)

  New Revision: 63369

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

  Log:
    gc.c (rb_imemo_alloc_new): improve the API interface
    
    rb_imemo_alloc_new returns rb_imemo_alloc_t*, but took VALUEs, which is
    inconsistent.  To make the intention clear, it now takes only a pointer
    to the buffer.

  Modified files:
    trunk/gc.c
    trunk/internal.h
    trunk/parse.y
Index: gc.c
===================================================================
--- gc.c	(revision 63368)
+++ gc.c	(revision 63369)
@@ -2025,10 +2025,10 @@ rb_imemo_new(enum imemo_type type, VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L2025
 }
 
 rb_imemo_alloc_t *
-rb_imemo_alloc_new(VALUE v1, VALUE v2, VALUE v3, VALUE v0)
+rb_imemo_alloc_new(void *buf)
 {
     VALUE flags = T_IMEMO | (imemo_alloc << FL_USHIFT);
-    return (rb_imemo_alloc_t *)newobj_of(v0, flags, v1, v2, v3, FALSE);
+    return (rb_imemo_alloc_t *)newobj_of(0, flags, (VALUE)buf, 0, 0, FALSE);
 }
 
 #if IMEMO_DEBUG
@@ -8125,9 +8125,8 @@ rb_alloc_tmp_buffer_with_count(volatile https://github.com/ruby/ruby/blob/trunk/gc.c#L8125
     rb_imemo_alloc_t *s;
     void *ptr;
 
-    s = rb_imemo_alloc_new(0, 0, 0, 0);
     ptr = ruby_xmalloc0(size);
-    s->ptr = (VALUE*)ptr;
+    s = rb_imemo_alloc_new(ptr);
     s->cnt = cnt;
     *store = (VALUE)s;
     return ptr;
Index: parse.y
===================================================================
--- parse.y	(revision 63368)
+++ parse.y	(revision 63369)
@@ -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((VALUE)tbl, 0, 0, 0));
+			add_mark_object(p, (VALUE)rb_imemo_alloc_new(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((VALUE)args, 0, 0, 0));
+    add_mark_object(p, (VALUE)rb_imemo_alloc_new(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((VALUE)buf, 0, 0, 0));
+    add_mark_object(p, (VALUE)rb_imemo_alloc_new(buf));
 
     return buf;
 }
@@ -10968,16 +10968,15 @@ rb_parser_set_yydebug(VALUE self, VALUE https://github.com/ruby/ruby/blob/trunk/parse.y#L10968
 #ifndef RIPPER
 #ifdef YYMALLOC
 #define HEAPCNT(n, size) ((n) * (size) / sizeof(YYSTYPE))
-#define NEWHEAP() rb_imemo_alloc_new(0, (VALUE)p->heap, 0, 0)
-#define ADD2HEAP(new, cnt, ptr) ((p->heap = (new))->ptr = (ptr), \
-			   (new)->cnt = (cnt), (ptr))
+#define ADD2HEAP(new, cnt, ptr) (p->heap = (new), (new)->cnt = (cnt), (ptr))
 
 void *
 rb_parser_malloc(struct parser_params *p, size_t size)
 {
     size_t cnt = HEAPCNT(1, size);
-    rb_imemo_alloc_t *n = NEWHEAP();
     void *ptr = xmalloc(size);
+    rb_imemo_alloc_t *n = rb_imemo_alloc_new(ptr);
+    n->next = p->heap;
 
     return ADD2HEAP(n, cnt, ptr);
 }
@@ -10986,8 +10985,9 @@ void * https://github.com/ruby/ruby/blob/trunk/parse.y#L10985
 rb_parser_calloc(struct parser_params *p, size_t nelem, size_t size)
 {
     size_t cnt = HEAPCNT(nelem, size);
-    rb_imemo_alloc_t *n = NEWHEAP();
     void *ptr = xcalloc(nelem, size);
+    rb_imemo_alloc_t *n = rb_imemo_alloc_new(ptr);
+    n->next = p->heap;
 
     return ADD2HEAP(n, cnt, ptr);
 }
@@ -11007,8 +11007,9 @@ rb_parser_realloc(struct parser_params * https://github.com/ruby/ruby/blob/trunk/parse.y#L11007
 	    }
 	} while ((n = n->next) != NULL);
     }
-    n = NEWHEAP();
     ptr = xrealloc(ptr, size);
+    n = rb_imemo_alloc_new(ptr);
+    n->next = p->heap;
     return ADD2HEAP(n, cnt, ptr);
 }
 
Index: internal.h
===================================================================
--- internal.h	(revision 63368)
+++ internal.h	(revision 63369)
@@ -960,7 +960,7 @@ 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(VALUE, VALUE, VALUE, VALUE);
+rb_imemo_alloc_t *rb_imemo_alloc_new(void *buf);
 
 void rb_strterm_mark(VALUE obj);
 

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

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