ruby-changes:49758
From: mame <ko1@a...>
Date: Wed, 17 Jan 2018 00:12:13 +0900 (JST)
Subject: [ruby-changes:49758] mame:r61876 (trunk): node.c: Separately allocate a struct having flexible array
mame 2018-01-17 00:12:09 +0900 (Wed, 17 Jan 2018) New Revision: 61876 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61876 Log: node.c: Separately allocate a struct having flexible array Modified files: trunk/node.c Index: node.c =================================================================== --- node.c (revision 61875) +++ node.c (revision 61876) @@ -1042,22 +1042,22 @@ rb_node_init(NODE *n, enum node_type typ https://github.com/ruby/ruby/blob/trunk/node.c#L1042 typedef struct node_buffer_elem_struct { struct node_buffer_elem_struct *next; - NODE buf[1]; + NODE buf[FLEX_ARY_LEN]; } node_buffer_elem_t; struct node_buffer_struct { long idx, len; node_buffer_elem_t *head; - node_buffer_elem_t body; /* this should be a last, because body has flexible array */ + node_buffer_elem_t *last; }; static node_buffer_t * rb_node_buffer_new(void) { - node_buffer_t *nb = xmalloc(sizeof(node_buffer_t) + 16 * sizeof(NODE)); + node_buffer_t *nb = xmalloc(sizeof(node_buffer_t) + offsetof(node_buffer_elem_t, buf) + 16 * sizeof(NODE)); nb->idx = 0; nb->len = 16; - nb->head = &nb->body; + nb->head = nb->last = (node_buffer_elem_t*) &nb[1]; nb->head->next = NULL; return nb; } @@ -1067,7 +1067,7 @@ rb_node_buffer_free(node_buffer_t *nb) https://github.com/ruby/ruby/blob/trunk/node.c#L1067 { node_buffer_elem_t *nbe = nb->head; - while (nbe != &nb->body) { + while (nbe != nb->last) { void *buf = nbe; nbe = nbe->next; xfree(buf); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/