Skip to content

Commit

Permalink
Macros can't be expressions, so make a function
Browse files Browse the repository at this point in the history
Macros can't be expressions, that is a GNU extension (I didn't know
that).  This commit converts the macro to a function so that everything
will compile correctly on non-GNU compatible compilers.
  • Loading branch information
tenderlove committed Sep 10, 2019
1 parent 1395102 commit 91ee958
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 2 additions & 6 deletions node.h
Expand Up @@ -281,15 +281,11 @@ typedef struct RNode {
#define nd_apinfo u3.apinfo

#define NEW_NODE(t,a0,a1,a2,loc) rb_node_newnode((t),(VALUE)(a0),(VALUE)(a1),(VALUE)(a2),loc)
#define NEW_NODE_WITH_LOCALS(t,a1,a2,loc) node_newnode_with_locals(p, (t),(VALUE)(a1),(VALUE)(a2),loc)

#define NEW_DEFN(i,a,d,loc) NEW_NODE(NODE_DEFN,0,i,NEW_SCOPE(a,d,loc),loc)
#define NEW_DEFS(r,i,a,d,loc) NEW_NODE(NODE_DEFS,r,i,NEW_SCOPE(a,d,loc),loc)
#define NEW_SCOPE(a,b,loc) ({ \
VALUE tbl = 0; \
NODE * _n = NEW_NODE(NODE_SCOPE,local_tbl(p, &tbl),b,a,loc); \
tbl && RB_OBJ_WRITTEN(p->ast, Qnil, tbl); \
_n; \
})
#define NEW_SCOPE(a,b,loc) NEW_NODE_WITH_LOCALS(NODE_SCOPE,b,a,loc)
#define NEW_BLOCK(a,loc) NEW_NODE(NODE_BLOCK,a,0,0,loc)
#define NEW_IF(c,t,e,loc) NEW_NODE(NODE_IF,c,t,e,loc)
#define NEW_UNLESS(c,t,e,loc) NEW_NODE(NODE_UNLESS,c,t,e,loc)
Expand Down
16 changes: 16 additions & 0 deletions parse.y
Expand Up @@ -347,6 +347,8 @@ add_mark_object(struct parser_params *p, VALUE obj)
}
return obj;
}
#else
static NODE* node_newnode_with_locals(struct parser_params *, enum node_type, VALUE, VALUE, const rb_code_location_t*);
#endif

static NODE* node_newnode(struct parser_params *, enum node_type, VALUE, VALUE, VALUE, const rb_code_location_t*);
Expand Down Expand Up @@ -11660,6 +11662,20 @@ local_tbl(struct parser_params *p, VALUE *tmp)

return buf;
}

static NODE*
node_newnode_with_locals(struct parser_params *p, enum node_type type, VALUE a1, VALUE a2, const rb_code_location_t *loc)
{
ID *a0;
NODE *n;
VALUE tbl = 0;

a0 = local_tbl(p, &tbl);
n = NEW_NODE(type, a0, a1, a2, loc);
tbl && RB_OBJ_WRITTEN(p->ast, Qnil, tbl);
return n;
}

#endif

static void
Expand Down

1 comment on commit 91ee958

@nobu
Copy link
Member

@nobu nobu commented on 91ee958 Sep 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Macros can't be expressions" isn't true.
It is a statement-expression, a GCC extension.

Please sign in to comment.