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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2018-05-09 06:12:17 +00:00
Родитель 75d5cf55de
Коммит 58823392b4
3 изменённых файлов: 14 добавлений и 14 удалений

7
gc.c
Просмотреть файл

@ -2025,10 +2025,10 @@ rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0)
}
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 VALUE *store, size_t size, size_t cnt)
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;

Просмотреть файл

@ -960,7 +960,7 @@ typedef struct rb_imemo_alloc_struct {
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);

19
parse.y
Просмотреть файл

@ -2505,7 +2505,7 @@ primary : literal
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, NODE *kw_args, ID kw_rest_arg, ID block,
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)
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 flag)
#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 *
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 *p, void *ptr, size_t size)
}
} 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);
}