diff --git a/gc.c b/gc.c index 6e32997b8e..2b9d5b1029 100644 --- a/gc.c +++ b/gc.c @@ -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; } diff --git a/internal.h b/internal.h index 743e83187c..401dfa5c74 100644 --- a/internal.h +++ b/internal.h @@ -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 diff --git a/parse.y b/parse.y index 7a5b680da0..27611d5f46 100644 --- a/parse.y +++ b/parse.y @@ -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); }