1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Refactoring by adding rb_imemo_alloc_new to create imemo_alloc buffer

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60429 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2017-10-25 13:38:53 +00:00
parent 8a67b59c31
commit 09ea07e02c
3 changed files with 16 additions and 12 deletions

21
gc.c
View file

@ -8110,20 +8110,25 @@ ruby_mimfree(void *ptr)
free(mem);
}
rb_imemo_alloc_t *
rb_imemo_alloc_new(VALUE v1, VALUE v2, VALUE v3, VALUE v0)
{
VALUE s = rb_imemo_new(imemo_alloc, v1, v2, v3, v0);
rb_gc_writebarrier_unprotect(s);
return (rb_imemo_alloc_t *)s;
}
void *
rb_alloc_tmp_buffer_with_count(volatile VALUE *store, size_t size, size_t cnt)
{
VALUE s;
rb_imemo_alloc_t *a;
rb_imemo_alloc_t *s;
void *ptr;
s = rb_imemo_new(imemo_alloc, 0, 0, 0, 0);
rb_gc_writebarrier_unprotect(s);
s = rb_imemo_alloc_new(0, 0, 0, 0);
ptr = ruby_xmalloc0(size);
a = (rb_imemo_alloc_t*)s;
a->ptr = (VALUE*)ptr;
a->cnt = cnt;
*store = s;
s->ptr = (VALUE*)ptr;
s->cnt = cnt;
*store = (VALUE)s;
return ptr;
}

View file

@ -938,6 +938,8 @@ 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);
/*! MEMO
*
* @see imemo_type

View file

@ -11528,7 +11528,7 @@ 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_t *)rb_imemo_new(imemo_alloc, 0, (VALUE)parser->heap, 0, 0)
#define NEWHEAP() rb_imemo_alloc_new(0, (VALUE)parser->heap, 0, 0)
#define ADD2HEAP(n, c, p) ((parser->heap = (n))->ptr = (p), \
(n)->cnt = (c), (p))
@ -11538,7 +11538,6 @@ rb_parser_malloc(struct parser_params *parser, size_t size)
size_t cnt = HEAPCNT(1, size);
rb_imemo_alloc_t *n = NEWHEAP();
void *ptr = xmalloc(size);
rb_gc_writebarrier_unprotect((VALUE)n);
return ADD2HEAP(n, cnt, ptr);
}
@ -11549,7 +11548,6 @@ rb_parser_calloc(struct parser_params *parser, size_t nelem, size_t size)
size_t cnt = HEAPCNT(nelem, size);
rb_imemo_alloc_t *n = NEWHEAP();
void *ptr = xcalloc(nelem, size);
rb_gc_writebarrier_unprotect((VALUE)n);
return ADD2HEAP(n, cnt, ptr);
}
@ -11571,7 +11569,6 @@ rb_parser_realloc(struct parser_params *parser, void *ptr, size_t size)
}
n = NEWHEAP();
ptr = xrealloc(ptr, size);
rb_gc_writebarrier_unprotect((VALUE)n);
return ADD2HEAP(n, cnt, ptr);
}