mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Remove NODE-related pieces of code from GC
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
417eca103f
commit
deb5693149
3 changed files with 21 additions and 187 deletions
34
gc.c
34
gc.c
|
@ -420,7 +420,6 @@ typedef struct RVALUE {
|
|||
struct RStruct rstruct;
|
||||
struct RBignum bignum;
|
||||
struct RFile file;
|
||||
struct RNode node;
|
||||
struct RMatch match;
|
||||
struct RRational rational;
|
||||
struct RComplex complex;
|
||||
|
@ -2001,14 +2000,6 @@ rb_newobj_of(VALUE klass, VALUE flags)
|
|||
return newobj_of(klass, flags & ~FL_WB_PROTECTED, 0, 0, 0, flags & FL_WB_PROTECTED);
|
||||
}
|
||||
|
||||
NODE*
|
||||
rb_node_newnode(enum node_type type, VALUE a0, VALUE a1, VALUE a2)
|
||||
{
|
||||
NODE *n = (NODE *)newobj_of(0, T_NODE, a0, a1, a2, FALSE); /* TODO: node also should be wb protected */
|
||||
nd_set_type(n, type);
|
||||
return n;
|
||||
}
|
||||
|
||||
#undef rb_imemo_new
|
||||
|
||||
VALUE
|
||||
|
@ -2329,8 +2320,9 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
|
|||
break;
|
||||
|
||||
case T_NODE:
|
||||
rb_gc_free_node(obj);
|
||||
break; /* no need to free iv_tbl */
|
||||
rb_bug("obj_free(): GC does not handle T_NODE 0x%x(%p) 0x%"PRIxVALUE,
|
||||
BUILTIN_TYPE(obj), (void*)obj, RBASIC(obj)->flags);
|
||||
break;
|
||||
|
||||
case T_STRUCT:
|
||||
if ((RBASIC(obj)->flags & RSTRUCT_EMBED_LEN_MASK) == 0 &&
|
||||
|
@ -2533,10 +2525,13 @@ internal_object_p(VALUE obj)
|
|||
|
||||
if (p->as.basic.flags) {
|
||||
switch (BUILTIN_TYPE(p)) {
|
||||
case T_NODE:
|
||||
rb_bug("internal_object_p(): GC does not handle T_NODE 0x%x(%p) 0x%"PRIxVALUE,
|
||||
BUILTIN_TYPE(obj), (void*)obj, RBASIC(obj)->flags);
|
||||
break;
|
||||
case T_NONE:
|
||||
case T_IMEMO:
|
||||
case T_ICLASS:
|
||||
case T_NODE:
|
||||
case T_ZOMBIE:
|
||||
break;
|
||||
case T_CLASS:
|
||||
|
@ -3307,7 +3302,8 @@ obj_memsize_of(VALUE obj, int use_all_types)
|
|||
break;
|
||||
|
||||
case T_NODE:
|
||||
if (use_all_types) size += rb_node_memsize(obj);
|
||||
rb_bug("obj_memsize_of(): GC does not handle T_NODE 0x%x(%p) 0x%"PRIxVALUE,
|
||||
BUILTIN_TYPE(obj), (void*)obj, RBASIC(obj)->flags);
|
||||
break;
|
||||
|
||||
case T_STRUCT:
|
||||
|
@ -3449,7 +3445,6 @@ count_objects(int argc, VALUE *argv, VALUE os)
|
|||
COUNT_TYPE(T_FIXNUM);
|
||||
COUNT_TYPE(T_IMEMO);
|
||||
COUNT_TYPE(T_UNDEF);
|
||||
COUNT_TYPE(T_NODE);
|
||||
COUNT_TYPE(T_ICLASS);
|
||||
COUNT_TYPE(T_ZOMBIE);
|
||||
#undef COUNT_TYPE
|
||||
|
@ -4573,9 +4568,9 @@ gc_mark_children(rb_objspace_t *objspace, VALUE obj)
|
|||
break;
|
||||
|
||||
case T_NODE:
|
||||
obj = rb_gc_mark_node(&any->as.node);
|
||||
if (obj) gc_mark(objspace, obj);
|
||||
return; /* no need to mark class. */
|
||||
rb_bug("rb_gc_mark(): GC does not handle T_NODE 0x%x(%p) 0x%"PRIxVALUE,
|
||||
BUILTIN_TYPE(obj), (void*)obj, RBASIC(obj)->flags);
|
||||
break;
|
||||
|
||||
case T_IMEMO:
|
||||
gc_mark_imemo(objspace, obj);
|
||||
|
@ -9228,7 +9223,6 @@ type_name(int type, VALUE obj)
|
|||
TYPE_NAME(T_FIXNUM);
|
||||
TYPE_NAME(T_UNDEF);
|
||||
TYPE_NAME(T_IMEMO);
|
||||
TYPE_NAME(T_NODE);
|
||||
TYPE_NAME(T_ICLASS);
|
||||
TYPE_NAME(T_ZOMBIE);
|
||||
case T_DATA:
|
||||
|
@ -9333,8 +9327,8 @@ rb_raw_obj_info(char *buff, const int buff_size, VALUE obj)
|
|||
|
||||
switch (type) {
|
||||
case T_NODE:
|
||||
snprintf(buff, buff_size, "%s (%s)", buff,
|
||||
ruby_node_name(nd_type(obj)));
|
||||
rb_bug("rb_raw_obj_info(): GC does not handle T_NODE 0x%x(%p) 0x%"PRIxVALUE,
|
||||
BUILTIN_TYPE(obj), (void*)obj, RBASIC(obj)->flags);
|
||||
break;
|
||||
case T_ARRAY:
|
||||
snprintf(buff, buff_size, "%s [%s%s] len: %d", buff,
|
||||
|
|
170
node.c
170
node.c
|
@ -1048,179 +1048,23 @@ rb_parser_dump_tree(NODE *node, int comment)
|
|||
return buf;
|
||||
}
|
||||
|
||||
void
|
||||
rb_gc_free_node(VALUE obj)
|
||||
{
|
||||
switch (nd_type(obj)) {
|
||||
case NODE_SCOPE:
|
||||
if (RNODE(obj)->nd_tbl) {
|
||||
xfree(RNODE(obj)->nd_tbl);
|
||||
}
|
||||
break;
|
||||
case NODE_ARGS:
|
||||
if (RNODE(obj)->nd_ainfo) {
|
||||
xfree(RNODE(obj)->nd_ainfo);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Setup NODE strucutre.
|
||||
* NODE is not an object managed by GC, but it imitates an object
|
||||
* so that it can work with `RB_TYPE_P(obj, T_NODE)`.
|
||||
* This dirty hack is needed because Ripper jumbles NODEs and other type
|
||||
* objects.
|
||||
*/
|
||||
void
|
||||
rb_node_init(NODE *n, enum node_type type, VALUE a0, VALUE a1, VALUE a2)
|
||||
{
|
||||
VALUE klass = 0;
|
||||
n->flags = T_NODE;
|
||||
RBASIC_SET_CLASS_RAW((VALUE)n, klass);
|
||||
n->nd_location = 0;
|
||||
n->u1.value = a0;
|
||||
n->u2.value = a1;
|
||||
n->u3.value = a2;
|
||||
nd_set_type(n, type);
|
||||
}
|
||||
|
||||
size_t
|
||||
rb_node_memsize(VALUE obj)
|
||||
{
|
||||
size_t size = 0;
|
||||
switch (nd_type(obj)) {
|
||||
case NODE_SCOPE:
|
||||
if (RNODE(obj)->nd_tbl) {
|
||||
size += (RNODE(obj)->nd_tbl[0]+1) * sizeof(*RNODE(obj)->nd_tbl);
|
||||
}
|
||||
break;
|
||||
case NODE_ARGS:
|
||||
if (RNODE(obj)->nd_ainfo) {
|
||||
size += sizeof(*RNODE(obj)->nd_ainfo);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_gc_mark_node(NODE *obj)
|
||||
{
|
||||
switch (nd_type(obj)) {
|
||||
case NODE_IF: /* 1,2,3 */
|
||||
case NODE_FOR:
|
||||
case NODE_ITER:
|
||||
case NODE_WHEN:
|
||||
case NODE_MASGN:
|
||||
case NODE_RESCUE:
|
||||
case NODE_RESBODY:
|
||||
case NODE_CLASS:
|
||||
case NODE_MATCH2:
|
||||
rb_gc_mark(RNODE(obj)->u2.value);
|
||||
/* fall through */
|
||||
case NODE_BLOCK: /* 1,3 */
|
||||
case NODE_ARRAY:
|
||||
case NODE_DSTR:
|
||||
case NODE_DXSTR:
|
||||
case NODE_DREGX:
|
||||
case NODE_ENSURE:
|
||||
case NODE_CALL:
|
||||
case NODE_DEFS:
|
||||
case NODE_OP_ASGN1:
|
||||
rb_gc_mark(RNODE(obj)->u1.value);
|
||||
/* fall through */
|
||||
case NODE_SUPER: /* 3 */
|
||||
case NODE_FCALL:
|
||||
case NODE_DEFN:
|
||||
case NODE_ARGS_AUX:
|
||||
return RNODE(obj)->u3.value;
|
||||
|
||||
case NODE_WHILE: /* 1,2 */
|
||||
case NODE_UNTIL:
|
||||
case NODE_AND:
|
||||
case NODE_OR:
|
||||
case NODE_CASE:
|
||||
case NODE_CASE2:
|
||||
case NODE_SCLASS:
|
||||
case NODE_DOT2:
|
||||
case NODE_DOT3:
|
||||
case NODE_FLIP2:
|
||||
case NODE_FLIP3:
|
||||
case NODE_MATCH3:
|
||||
case NODE_OP_ASGN_OR:
|
||||
case NODE_OP_ASGN_AND:
|
||||
case NODE_MODULE:
|
||||
case NODE_ALIAS:
|
||||
case NODE_VALIAS:
|
||||
case NODE_ARGSCAT:
|
||||
case NODE_BLOCK_PASS:
|
||||
rb_gc_mark(RNODE(obj)->u1.value);
|
||||
/* fall through */
|
||||
case NODE_GASGN: /* 2 */
|
||||
case NODE_LASGN:
|
||||
case NODE_DASGN:
|
||||
case NODE_DASGN_CURR:
|
||||
case NODE_IASGN:
|
||||
case NODE_CVASGN:
|
||||
case NODE_COLON3:
|
||||
case NODE_EVSTR:
|
||||
case NODE_UNDEF:
|
||||
case NODE_POSTEXE:
|
||||
return RNODE(obj)->u2.value;
|
||||
|
||||
case NODE_HASH: /* 1 */
|
||||
case NODE_LIT:
|
||||
case NODE_STR:
|
||||
case NODE_XSTR:
|
||||
case NODE_DEFINED:
|
||||
case NODE_MATCH:
|
||||
case NODE_RETURN:
|
||||
case NODE_BREAK:
|
||||
case NODE_NEXT:
|
||||
case NODE_YIELD:
|
||||
case NODE_COLON2:
|
||||
case NODE_SPLAT:
|
||||
return RNODE(obj)->u1.value;
|
||||
|
||||
case NODE_SCOPE: /* 2,3 */
|
||||
case NODE_CDECL:
|
||||
case NODE_OPT_ARG:
|
||||
rb_gc_mark(RNODE(obj)->u3.value);
|
||||
return RNODE(obj)->u2.value;
|
||||
|
||||
case NODE_ARGS: /* custom */
|
||||
{
|
||||
struct rb_args_info *args = obj->u3.args;
|
||||
if (args) {
|
||||
if (args->pre_init) rb_gc_mark((VALUE)args->pre_init);
|
||||
if (args->post_init) rb_gc_mark((VALUE)args->post_init);
|
||||
if (args->opt_args) rb_gc_mark((VALUE)args->opt_args);
|
||||
if (args->kw_args) rb_gc_mark((VALUE)args->kw_args);
|
||||
if (args->kw_rest_arg) rb_gc_mark((VALUE)args->kw_rest_arg);
|
||||
}
|
||||
}
|
||||
return RNODE(obj)->u2.value;
|
||||
|
||||
case NODE_ZARRAY: /* - */
|
||||
case NODE_ZSUPER:
|
||||
case NODE_VCALL:
|
||||
case NODE_GVAR:
|
||||
case NODE_LVAR:
|
||||
case NODE_DVAR:
|
||||
case NODE_IVAR:
|
||||
case NODE_CVAR:
|
||||
case NODE_NTH_REF:
|
||||
case NODE_BACK_REF:
|
||||
case NODE_REDO:
|
||||
case NODE_RETRY:
|
||||
case NODE_SELF:
|
||||
case NODE_NIL:
|
||||
case NODE_TRUE:
|
||||
case NODE_FALSE:
|
||||
case NODE_ERRINFO:
|
||||
break;
|
||||
|
||||
default: /* unlisted NODE */
|
||||
rb_gc_mark_maybe(RNODE(obj)->u1.value);
|
||||
rb_gc_mark_maybe(RNODE(obj)->u2.value);
|
||||
rb_gc_mark_maybe(RNODE(obj)->u3.value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct node_buffer_elem_struct {
|
||||
struct node_buffer_elem_struct *next;
|
||||
NODE buf[1]; /* flexible array */
|
||||
|
|
4
node.h
4
node.h
|
@ -484,10 +484,6 @@ rb_ast_t *rb_compile_string(const char*, VALUE, int);
|
|||
rb_ast_t *rb_compile_file(const char*, VALUE, int);
|
||||
|
||||
void rb_node_init(NODE *n, enum node_type type, VALUE a0, VALUE a1, VALUE a2);
|
||||
NODE *rb_node_newnode(enum node_type,VALUE,VALUE,VALUE);
|
||||
void rb_gc_free_node(VALUE obj);
|
||||
size_t rb_node_memsize(VALUE obj);
|
||||
VALUE rb_gc_mark_node(NODE *obj);
|
||||
|
||||
const struct kwtable *rb_reserved_word(const char *, unsigned int);
|
||||
|
||||
|
|
Loading…
Reference in a new issue