ruby-changes:48315
From: mame <ko1@a...>
Date: Wed, 25 Oct 2017 22:38:58 +0900 (JST)
Subject: [ruby-changes:48315] mame:r60429 (trunk): Refactoring by adding `rb_imemo_alloc_new` to create imemo_alloc buffer
mame 2017-10-25 22:38:53 +0900 (Wed, 25 Oct 2017) New Revision: 60429 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60429 Log: Refactoring by adding `rb_imemo_alloc_new` to create imemo_alloc buffer Modified files: trunk/gc.c trunk/internal.h trunk/parse.y Index: internal.h =================================================================== --- internal.h (revision 60428) +++ internal.h (revision 60429) @@ -938,6 +938,8 @@ typedef struct rb_imemo_alloc_struct { https://github.com/ruby/ruby/blob/trunk/internal.h#L938 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 Index: gc.c =================================================================== --- gc.c (revision 60428) +++ gc.c (revision 60429) @@ -8110,20 +8110,25 @@ ruby_mimfree(void *ptr) https://github.com/ruby/ruby/blob/trunk/gc.c#L8110 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; } Index: parse.y =================================================================== --- parse.y (revision 60428) +++ parse.y (revision 60429) @@ -11528,7 +11528,7 @@ rb_parser_set_yydebug(VALUE self, VALUE https://github.com/ruby/ruby/blob/trunk/parse.y#L11528 #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 *p https://github.com/ruby/ruby/blob/trunk/parse.y#L11538 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 *p https://github.com/ruby/ruby/blob/trunk/parse.y#L11548 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 * https://github.com/ruby/ruby/blob/trunk/parse.y#L11569 } n = NEWHEAP(); ptr = xrealloc(ptr, size); - rb_gc_writebarrier_unprotect((VALUE)n); return ADD2HEAP(n, cnt, ptr); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/