From 4105b595684bb9f1e176563f819de2917d0471fd Mon Sep 17 00:00:00 2001 From: Mitchell Blank Jr Date: Sat, 19 May 2012 22:18:34 -0700 Subject: C++ compilability -- make mrb_object() macro return an RObject, not void --- include/mruby.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/mruby.h b/include/mruby.h index 9e7d20351..ed5fe79d2 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -81,7 +81,7 @@ typedef struct mrb_value { #define mrb_fixnum(o) (o).value.i #define mrb_float(o) (o).value.f #define mrb_symbol(o) (o).value.sym -#define mrb_object(o) (o).value.p +#define mrb_object(o) ((struct RObject *) (o).value.p) #define FIXNUM_P(o) ((o).tt == MRB_TT_FIXNUM) #define UNDEF_P(o) ((o).tt == MRB_TT_UNDEF) @@ -368,11 +368,11 @@ int mrb_gc_arena_save(mrb_state*); void mrb_gc_arena_restore(mrb_state*,int); void mrb_gc_mark(mrb_state*,struct RBasic*); #define mrb_gc_mark_value(mrb,val) do {\ - if ((val).tt >= MRB_TT_OBJECT) mrb_gc_mark((mrb), mrb_object(val));\ + if ((val).tt >= MRB_TT_OBJECT) mrb_gc_mark((mrb), (struct RBasic *) mrb_object(val));\ } while (0); void mrb_field_write_barrier(mrb_state *, struct RBasic*, struct RBasic*); #define mrb_field_write_barrier_value(mrb, obj, val) do{\ - if ((val.tt >= MRB_TT_OBJECT)) mrb_field_write_barrier((mrb), (obj), mrb_object(val));\ + if ((val.tt >= MRB_TT_OBJECT)) mrb_field_write_barrier((mrb), (obj), (struct RBasic *) mrb_object(val));\ } while (0); void mrb_write_barrier(mrb_state *, struct RBasic*); -- cgit v1.2.3 From 3471e2b1340cb84504272da26051f149f350ee94 Mon Sep 17 00:00:00 2001 From: Mitchell Blank Jr Date: Sat, 19 May 2012 22:40:57 -0700 Subject: C++ compilability - don't define types inside others The following is legal code in both C and C++: struct foo { struct bar { int a } x; int y; }; ...however in C++ it defines a type called "foo::bar" instead of "bar". Just avoid this construct altogether --- include/mruby/range.h | 10 ++++++---- src/codegen.c | 16 +++++++++------- src/gc.h | 10 ++++++---- src/pool.c | 16 +++++++++------- src/transcode.c | 12 +++++++----- 5 files changed, 37 insertions(+), 27 deletions(-) diff --git a/include/mruby/range.h b/include/mruby/range.h index b95838375..036cdd574 100644 --- a/include/mruby/range.h +++ b/include/mruby/range.h @@ -11,12 +11,14 @@ extern "C" { #endif +struct mrb_range_edges { + mrb_value beg; + mrb_value end; +}; + struct RRange { MRUBY_OBJECT_HEADER; - struct mrb_range_edges { - mrb_value beg; - mrb_value end; - } *edges; + struct mrb_range_edges *edges; int excl; }; diff --git a/src/codegen.c b/src/codegen.c index 769f9e538..263490f27 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -20,14 +20,16 @@ typedef mrb_ast_node node; typedef struct mrb_parser_state parser_state; +enum looptype { + LOOP_NORMAL, + LOOP_BLOCK, + LOOP_FOR, + LOOP_BEGIN, + LOOP_RESCUE, +} type; + struct loopinfo { - enum looptype { - LOOP_NORMAL, - LOOP_BLOCK, - LOOP_FOR, - LOOP_BEGIN, - LOOP_RESCUE, - } type; + enum looptype type; int pc1, pc2, pc3, acc; int ensure_level; struct loopinfo *prev; diff --git a/src/gc.h b/src/gc.h index 0a4bc1c51..fea761d1b 100644 --- a/src/gc.h +++ b/src/gc.h @@ -11,12 +11,14 @@ extern "C" { #endif +struct free_obj { + MRUBY_OBJECT_HEADER; + struct RBasic *next; +}; + typedef struct { union { - struct free_obj { - MRUBY_OBJECT_HEADER; - struct RBasic *next; - } free; + struct free_obj free; struct RBasic basic; struct RObject object; struct RClass klass; diff --git a/src/pool.c b/src/pool.c index a367a30a5..3cbb2b163 100644 --- a/src/pool.c +++ b/src/pool.c @@ -8,15 +8,17 @@ #include #include +struct mrb_pool_page { + struct mrb_pool_page *next; + size_t offset; + size_t len; + void *last; + char page[1]; +}; + struct mrb_pool { mrb_state *mrb; - struct mrb_pool_page { - struct mrb_pool_page *next; - size_t offset; - size_t len; - void *last; - char page[1]; - } *pages; + struct mrb_pool_page *pages; }; #undef TEST_POOL diff --git a/src/transcode.c b/src/transcode.c index 42c86d167..d6d41b667 100644 --- a/src/transcode.c +++ b/src/transcode.c @@ -65,6 +65,12 @@ allocate_converted_string(mrb_state *mrb, unsigned char *caller_dst_buf, size_t caller_dst_bufsize, size_t *dst_len_ptr); +union mrb_transcoding_state_t { /* opaque data for stateful encoding */ + void *ptr; + char ary[sizeof(double) > sizeof(void*) ? sizeof(double) : sizeof(void*)]; + double dummy_for_alignment; +}; + /* dynamic structure, one per conversion (similar to iconv_t) */ /* may carry conversion state (e.g. for iso-2022-jp) */ typedef struct mrb_transcoding { @@ -92,11 +98,7 @@ typedef struct mrb_transcoding { unsigned char *ptr; /* length: max_output */ } writebuf; - union mrb_transcoding_state_t { /* opaque data for stateful encoding */ - void *ptr; - char ary[sizeof(double) > sizeof(void*) ? sizeof(double) : sizeof(void*)]; - double dummy_for_alignment; - } state; + union mrb_transcoding_state_t state; } mrb_transcoding; #define TRANSCODING_READBUF(tc) \ ((tc)->transcoder->max_input <= (int)sizeof((tc)->readbuf.ary) ? \ -- cgit v1.2.3 From 4ebd0361e4cc6edb0483f3280db50fa56621f0fc Mon Sep 17 00:00:00 2001 From: Mitchell Blank Jr Date: Sat, 19 May 2012 23:16:54 -0700 Subject: Helper functions for st_foreach() return "enum st_retval" not "int" Just making this a bit more consistent throughout the code --- src/encoding.c | 12 ++++++------ src/regparse.c | 10 +++++----- src/st.c | 4 ++-- src/st.h | 2 +- src/transcode.c | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/encoding.c b/src/encoding.c index 8a3bd8ef2..cfe21b581 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -913,11 +913,11 @@ enc_name(mrb_state *mrb, mrb_value self) struct fn_arg { mrb_state *mrb; - int (*func)(ANYARGS); + enum st_retval (*func)(ANYARGS); void *a; }; -static int +static enum st_retval fn_i(st_data_t key, st_data_t val, st_data_t arg) { struct fn_arg *a = (struct fn_arg*)arg; @@ -925,7 +925,7 @@ fn_i(st_data_t key, st_data_t val, st_data_t arg) { } static int -st_foreachNew(mrb_state *mrb, st_table *tbl, int (*func)(ANYARGS), void *a) +st_foreachNew(mrb_state *mrb, st_table *tbl, enum st_retval (*func)(ANYARGS), void *a) { struct fn_arg arg = { mrb, @@ -936,7 +936,7 @@ st_foreachNew(mrb_state *mrb, st_table *tbl, int (*func)(ANYARGS), void *a) return st_foreach(tbl, fn_i, (st_data_t)&arg); } -static int +static enum st_retval enc_names_i(mrb_state *mrb, st_data_t name, st_data_t idx, st_data_t args) { mrb_value *arg = (mrb_value *)args; @@ -1521,7 +1521,7 @@ set_encoding_const(mrb_state *mrb, const char *name, mrb_encoding *enc) } } } -static int +static enum st_retval mrb_enc_name_list_i(mrb_state *mrb, st_data_t name, st_data_t idx, mrb_value *arg) { mrb_value ary = *arg; @@ -1554,7 +1554,7 @@ mrb_enc_name_list(mrb_state *mrb, mrb_value klass) return ary; } -static int +static enum st_retval mrb_enc_aliases_enc_i(mrb_state *mrb, st_data_t name, st_data_t orig, st_data_t arg) { mrb_value *p = (mrb_value *)arg; diff --git a/src/regparse.c b/src/regparse.c index ee933662c..6c23f5561 100644 --- a/src/regparse.c +++ b/src/regparse.c @@ -416,7 +416,7 @@ typedef st_data_t HashDataType; /* 1.6 st.h doesn't define st_data_t type */ #define NAMEBUF_SIZE_1 25 #ifdef ONIG_DEBUG -static int +static enum st_retval i_print_name_entry(UChar* key, NameEntry* e, void* arg) { int i; @@ -451,7 +451,7 @@ onig_print_names(FILE* fp, regex_t* reg) } #endif /* ONIG_DEBUG */ -static int +static enum st_retval i_free_name_entry(UChar* key, NameEntry* e, void* arg ARG_UNUSED) { xfree(e->name); @@ -508,7 +508,7 @@ typedef struct { OnigEncoding enc; } INamesArg; -static int +static enum st_retval i_names(UChar* key ARG_UNUSED, NameEntry* e, INamesArg* arg) { int r = (*(arg->func))(e->name, @@ -541,7 +541,7 @@ onig_foreach_name(regex_t* reg, return narg.ret; } -static int +static enum st_retval i_renumber_name(UChar* key ARG_UNUSED, NameEntry* e, GroupNumRemap* map) { int i; @@ -4922,7 +4922,7 @@ static const struct st_hash_type type_type_cclass_hash = { static st_table* OnigTypeCClassTable; -static int +static enum st_retval i_free_shared_class(type_cclass_key* key, Node* node, void* arg ARG_UNUSED) { if (IS_NOT_NULL(node)) { diff --git a/src/st.c b/src/st.c index 777a03bd2..c0597395d 100644 --- a/src/st.c +++ b/src/st.c @@ -404,7 +404,7 @@ st_delete(register st_table *table, register st_data_t *key, st_data_t *value) } int -st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg) +st_foreach(st_table *table, enum st_retval (*func)(ANYARGS), st_data_t arg) { st_table_entry *ptr, **last, *tmp; enum st_retval retval; @@ -572,7 +572,7 @@ numhash(long n) } #if 0 -static int +static enum st_retval f(st_data_t key, st_data_t val, st_data_t a) { printf("tbl=%p key=%s val=%s\n", (st_table*)a, (char*)key, (char*)val); diff --git a/src/st.h b/src/st.h index 24db1fd23..2be618041 100644 --- a/src/st.h +++ b/src/st.h @@ -74,7 +74,7 @@ int st_delete(st_table *, st_data_t *, st_data_t *); int st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t); int st_insert(st_table *, st_data_t, st_data_t); int st_lookup(st_table *, st_data_t, st_data_t *); -int st_foreach(st_table *, int (*)(ANYARGS), st_data_t); +int st_foreach(st_table *, enum st_retval (*)(ANYARGS), st_data_t); void st_add_direct(st_table *, st_data_t, st_data_t); void st_free_table(st_table *); void st_cleanup_safe(st_table *, st_data_t); diff --git a/src/transcode.c b/src/transcode.c index d6d41b667..39dc42bdc 100644 --- a/src/transcode.c +++ b/src/transcode.c @@ -273,7 +273,7 @@ typedef struct { const char *base_enc; } search_path_bfs_t; -static int +static enum st_retval transcode_search_path_i(st_data_t key, st_data_t val, st_data_t arg) { const char *dname = (const char *)key; @@ -1797,7 +1797,7 @@ struct asciicompat_encoding_t { const char *ascii_incompat_name; }; -static int +static enum st_retval asciicompat_encoding_i(mrb_state *mrb, st_data_t key, st_data_t val, st_data_t arg) { struct asciicompat_encoding_t *data = (struct asciicompat_encoding_t *)arg; -- cgit v1.2.3 From be0e3fdf5159006277bad7acf1e38fa66efab0d7 Mon Sep 17 00:00:00 2001 From: Mitchell Blank Jr Date: Sat, 19 May 2012 23:18:47 -0700 Subject: C++ compilability -- "try" is a keyword, avoid as variable name --- src/transcode.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/transcode.c b/src/transcode.c index 39dc42bdc..ae78f20d4 100644 --- a/src/transcode.c +++ b/src/transcode.c @@ -1127,16 +1127,16 @@ trans_sweep(mrb_state *mrb, mrb_econv_t *ec, int flags, int start) { - int try; + int should_try; int i, f; const unsigned char **ipp, *is, *iold; unsigned char **opp, *os, *oold; mrb_econv_result_t res; - try = 1; - while (try) { - try = 0; + should_try = 1; + while (should_try) { + should_try = 0; for (i = start; i < ec->num_trans; i++) { mrb_econv_elem_t *te = &ec->elems[i]; @@ -1179,7 +1179,7 @@ trans_sweep(mrb_state *mrb, mrb_econv_t *ec, oold = *opp; te->last_result = res = mrb_transcoding_convert(mrb, te->tc, ipp, is, opp, os, f); if (iold != *ipp || oold != *opp) - try = 1; + should_try = 1; switch (res) { case econv_invalid_byte_sequence: -- cgit v1.2.3 From 365cc40ac5cef4b9ad661e133d5ca8526b65f415 Mon Sep 17 00:00:00 2001 From: Mitchell Blank Jr Date: Sat, 19 May 2012 23:20:44 -0700 Subject: C++ compilabilty -- "new" is a C++ keyword, avoid it --- src/class.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/class.c b/src/class.c index ee8cb8f48..eda3f87a0 100644 --- a/src/class.c +++ b/src/class.c @@ -1003,10 +1003,10 @@ mrb_value mrb_mod_alias(mrb_state *mrb, mrb_value mod) { struct RClass *c = mrb_class_ptr(mod); - mrb_value new, old; + mrb_value new_value, old_value; - mrb_get_args(mrb, "oo", &new, &old); - mrb_alias_method(mrb, c, mrb_symbol(new), mrb_symbol(old)); + mrb_get_args(mrb, "oo", &new_value, &old_value); + mrb_alias_method(mrb, c, mrb_symbol(new_value), mrb_symbol(old_value)); return mrb_nil_value(); } -- cgit v1.2.3 From e3abf333847f3fd21a5bd62cd52efdf80cc6aa15 Mon Sep 17 00:00:00 2001 From: Mitchell Blank Jr Date: Sat, 19 May 2012 23:28:40 -0700 Subject: C++ compilability: "not" is a C++ keyword, avoid it see http://en.cppreference.com/w/cpp/language/operator_alternative --- src/regcomp.c | 18 ++++---- src/regparse.c | 138 ++++++++++++++++++++++++++++----------------------------- src/regparse.h | 2 +- 3 files changed, 79 insertions(+), 79 deletions(-) diff --git a/src/regcomp.c b/src/regcomp.c index 816e219c7..bb45b3db4 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -1640,8 +1640,8 @@ compile_tree(Node* node, regex_t* reg) switch (NCTYPE(node)->ctype) { case ONIGENC_CTYPE_WORD: - if (NCTYPE(node)->not != 0) op = OP_NOT_WORD; - else op = OP_WORD; + if (NCTYPE(node)->is_not != 0) op = OP_NOT_WORD; + else op = OP_WORD; break; default: return ONIGERR_TYPE_BUG; @@ -2440,8 +2440,8 @@ is_not_included(Node* x, Node* y, regex_t* reg) { switch (ytype) { case NT_CTYPE: - if (NCTYPE(y)->ctype == NCTYPE(x)->ctype && - NCTYPE(y)->not != NCTYPE(x)->not) + if (NCTYPE(y)->ctype == NCTYPE(x)->ctype && + NCTYPE(y)->is_not != NCTYPE(x)->is_not) return 1; else return 0; @@ -2473,7 +2473,7 @@ is_not_included(Node* x, Node* y, regex_t* reg) case NT_CTYPE: switch (NCTYPE(y)->ctype) { case ONIGENC_CTYPE_WORD: - if (NCTYPE(y)->not == 0) { + if (NCTYPE(y)->is_not == 0) { if (IS_NULL(xc->mbuf) && !IS_NCCLASS_NOT(xc)) { for (i = 0; i < SINGLE_BYTE_SIZE; i++) { if (BITSET_AT(xc->bs, i)) { @@ -2550,9 +2550,9 @@ is_not_included(Node* x, Node* y, regex_t* reg) switch (NCTYPE(y)->ctype) { case ONIGENC_CTYPE_WORD: if (ONIGENC_IS_MBC_WORD(reg->enc, xs->s, xs->end)) - return NCTYPE(y)->not; + return NCTYPE(y)->is_not; else - return !(NCTYPE(y)->not); + return !(NCTYPE(y)->is_not); break; default: break; @@ -4668,7 +4668,7 @@ optimize_node_left(Node* node, NodeOptInfo* opt, OptEnv* env) switch (NCTYPE(node)->ctype) { case ONIGENC_CTYPE_WORD: - if (NCTYPE(node)->not != 0) { + if (NCTYPE(node)->is_not != 0) { for (i = 0; i < SINGLE_BYTE_SIZE; i++) { if (! ONIGENC_IS_CODE_WORD(env->enc, i)) { add_char_opt_map_info(&opt->map, (UChar )i, env->enc); @@ -6170,7 +6170,7 @@ print_indent_tree(FILE* f, Node* node, int indent) fprintf(f, " ", (int )node); switch (NCTYPE(node)->ctype) { case ONIGENC_CTYPE_WORD: - if (NCTYPE(node)->not != 0) + if (NCTYPE(node)->is_not != 0) fputs("not word", f); else fputs("word", f); diff --git a/src/regparse.c b/src/regparse.c index 6c23f5561..f98e82ff2 100644 --- a/src/regparse.c +++ b/src/regparse.c @@ -1151,7 +1151,7 @@ node_new_cclass(void) } static Node* -node_new_cclass_by_codepoint_range(int not, OnigCodePoint sb_out, +node_new_cclass_by_codepoint_range(int is_not, OnigCodePoint sb_out, const OnigCodePoint ranges[]) { int n, i; @@ -1162,7 +1162,7 @@ node_new_cclass_by_codepoint_range(int not, OnigCodePoint sb_out, CHECK_NULL_RETURN(node); cc = NCCLASS(node); - if (not != 0) NCCLASS_SET_NOT(cc); + if (is_not != 0) NCCLASS_SET_NOT(cc); BITSET_CLEAR(cc->bs); if (sb_out > 0 && IS_NOT_NULL(ranges)) { @@ -1201,14 +1201,14 @@ node_new_cclass_by_codepoint_range(int not, OnigCodePoint sb_out, } static Node* -node_new_ctype(int type, int not) +node_new_ctype(int type, int is_not) { Node* node = node_new(); CHECK_NULL_RETURN(node); SET_NTYPE(node, NT_CTYPE); - NCTYPE(node)->ctype = type; - NCTYPE(node)->not = not; + NCTYPE(node)->ctype = type; + NCTYPE(node)->is_not = is_not; return node; } @@ -2285,7 +2285,7 @@ typedef struct { } call; struct { int ctype; - int not; + int is_not; } prop; } u; } OnigToken; @@ -2954,45 +2954,45 @@ fetch_token_in_cc(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env) switch (c) { case 'w': tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_W; - tok->u.prop.not = 0; + tok->u.prop.ctype = ONIGENC_CTYPE_W; + tok->u.prop.is_not = 0; break; case 'W': tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_W; - tok->u.prop.not = 1; + tok->u.prop.ctype = ONIGENC_CTYPE_W; + tok->u.prop.is_not = 1; break; case 'd': tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_D; - tok->u.prop.not = 0; + tok->u.prop.ctype = ONIGENC_CTYPE_D; + tok->u.prop.is_not = 0; break; case 'D': tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_D; - tok->u.prop.not = 1; + tok->u.prop.ctype = ONIGENC_CTYPE_D; + tok->u.prop.is_not = 1; break; case 's': tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_S; - tok->u.prop.not = 0; + tok->u.prop.ctype = ONIGENC_CTYPE_S; + tok->u.prop.is_not = 0; break; case 'S': tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_S; - tok->u.prop.not = 1; + tok->u.prop.ctype = ONIGENC_CTYPE_S; + tok->u.prop.is_not = 1; break; case 'h': if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break; tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT; - tok->u.prop.not = 0; + tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT; + tok->u.prop.is_not = 0; break; case 'H': if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break; tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT; - tok->u.prop.not = 1; + tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT; + tok->u.prop.is_not = 1; break; case 'p': @@ -3002,12 +3002,12 @@ fetch_token_in_cc(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env) IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY)) { PINC; tok->type = TK_CHAR_PROPERTY; - tok->u.prop.not = (c == 'P' ? 1 : 0); + tok->u.prop.is_not = (c == 'P' ? 1 : 0); if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT)) { PFETCH(c2); if (c2 == '^') { - tok->u.prop.not = (tok->u.prop.not == 0 ? 1 : 0); + tok->u.prop.is_not = (tok->u.prop.is_not == 0 ? 1 : 0); } else PUNFETCH; @@ -3244,15 +3244,15 @@ fetch_token(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env) case 'w': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_W_WORD)) break; tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_W; - tok->u.prop.not = 0; + tok->u.prop.ctype = ONIGENC_CTYPE_W; + tok->u.prop.is_not = 0; break; case 'W': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_W_WORD)) break; tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_W; - tok->u.prop.not = 1; + tok->u.prop.ctype = ONIGENC_CTYPE_W; + tok->u.prop.is_not = 1; break; case 'b': @@ -3284,43 +3284,43 @@ fetch_token(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env) case 's': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_S_WHITE_SPACE)) break; tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_S; - tok->u.prop.not = 0; + tok->u.prop.ctype = ONIGENC_CTYPE_S; + tok->u.prop.is_not = 0; break; case 'S': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_S_WHITE_SPACE)) break; tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_S; - tok->u.prop.not = 1; + tok->u.prop.ctype = ONIGENC_CTYPE_S; + tok->u.prop.is_not = 1; break; case 'd': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_D_DIGIT)) break; tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_D; - tok->u.prop.not = 0; + tok->u.prop.ctype = ONIGENC_CTYPE_D; + tok->u.prop.is_not = 0; break; case 'D': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_D_DIGIT)) break; tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_D; - tok->u.prop.not = 1; + tok->u.prop.ctype = ONIGENC_CTYPE_D; + tok->u.prop.is_not = 1; break; case 'h': if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break; tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT; - tok->u.prop.not = 0; + tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT; + tok->u.prop.is_not = 0; break; case 'H': if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break; tok->type = TK_CHAR_TYPE; - tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT; - tok->u.prop.not = 1; + tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT; + tok->u.prop.is_not = 1; break; case 'A': @@ -3574,12 +3574,12 @@ fetch_token(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env) IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY)) { PINC; tok->type = TK_CHAR_PROPERTY; - tok->u.prop.not = (c == 'P' ? 1 : 0); + tok->u.prop.is_not = (c == 'P' ? 1 : 0); if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT)) { PFETCH(c); if (c == '^') { - tok->u.prop.not = (tok->u.prop.not == 0 ? 1 : 0); + tok->u.prop.is_not = (tok->u.prop.is_not == 0 ? 1 : 0); } else PUNFETCH; @@ -3773,7 +3773,7 @@ fetch_token(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env) } static int -add_ctype_to_cc_by_range(CClassNode* cc, int ctype ARG_UNUSED, int not, +add_ctype_to_cc_by_range(CClassNode* cc, int ctype ARG_UNUSED, int is_not, ScanEnv* env, OnigCodePoint sb_out, const OnigCodePoint mbr[]) { @@ -3782,7 +3782,7 @@ add_ctype_to_cc_by_range(CClassNode* cc, int ctype ARG_UNUSED, int not, int n = ONIGENC_CODE_RANGE_NUM(mbr); - if (not == 0) { + if (is_not == 0) { for (i = 0; i < n; i++) { for (j = ONIGENC_CODE_RANGE_FROM(mbr, i); j <= ONIGENC_CODE_RANGE_TO(mbr, i); j++) { @@ -3846,7 +3846,7 @@ add_ctype_to_cc_by_range(CClassNode* cc, int ctype ARG_UNUSED, int not, } static int -add_ctype_to_cc(CClassNode* cc, int ctype, int not, ScanEnv* env) +add_ctype_to_cc(CClassNode* cc, int ctype, int is_not, ScanEnv* env) { int c, r; const OnigCodePoint *ranges; @@ -3858,7 +3858,7 @@ add_ctype_to_cc(CClassNode* cc, int ctype, int not, ScanEnv* env) case ONIGENC_CTYPE_S: case ONIGENC_CTYPE_W: ctype ^= ONIGENC_CTYPE_SPECIAL_MASK; - if (not != 0) { + if (is_not != 0) { for (c = 0; c < SINGLE_BYTE_SIZE; c++) { if (! ONIGENC_IS_ASCII_CODE_CTYPE((OnigCodePoint )c, ctype)) BITSET_SET_BIT_CHKDUP(cc->bs, c); @@ -3877,7 +3877,7 @@ add_ctype_to_cc(CClassNode* cc, int ctype, int not, ScanEnv* env) r = ONIGENC_GET_CTYPE_CODE_RANGE(enc, ctype, &sb_out, &ranges); if (r == 0) { - return add_ctype_to_cc_by_range(cc, ctype, not, env, sb_out, ranges); + return add_ctype_to_cc_by_range(cc, ctype, is_not, env, sb_out, ranges); } else if (r != ONIG_NO_SUPPORT_CONFIG) { return r; @@ -3896,7 +3896,7 @@ add_ctype_to_cc(CClassNode* cc, int ctype, int not, ScanEnv* env) case ONIGENC_CTYPE_XDIGIT: case ONIGENC_CTYPE_ASCII: case ONIGENC_CTYPE_ALNUM: - if (not != 0) { + if (is_not != 0) { for (c = 0; c < SINGLE_BYTE_SIZE; c++) { if (! ONIGENC_IS_CODE_CTYPE(enc, (OnigCodePoint )c, ctype)) BITSET_SET_BIT_CHKDUP(cc->bs, c); @@ -3913,7 +3913,7 @@ add_ctype_to_cc(CClassNode* cc, int ctype, int not, ScanEnv* env) case ONIGENC_CTYPE_GRAPH: case ONIGENC_CTYPE_PRINT: - if (not != 0) { + if (is_not != 0) { for (c = 0; c < SINGLE_BYTE_SIZE; c++) { if (! ONIGENC_IS_CODE_CTYPE(enc, (OnigCodePoint )c, ctype)) BITSET_SET_BIT_CHKDUP(cc->bs, c); @@ -3929,7 +3929,7 @@ add_ctype_to_cc(CClassNode* cc, int ctype, int not, ScanEnv* env) break; case ONIGENC_CTYPE_WORD: - if (not == 0) { + if (is_not == 0) { for (c = 0; c < SINGLE_BYTE_SIZE; c++) { if (IS_CODE_SB_WORD(enc, c)) BITSET_SET_BIT_CHKDUP(cc->bs, c); } @@ -3977,7 +3977,7 @@ parse_posix_bracket(CClassNode* cc, UChar** src, UChar* end, ScanEnv* env) }; const PosixBracketEntryType *pb; - int not, i, r; + int is_not, i, r; OnigCodePoint c; OnigEncoding enc = env->enc; UChar *p = *src; @@ -3985,10 +3985,10 @@ parse_posix_bracket(CClassNode* cc, UChar** src, UChar* end, ScanEnv* env) if (PPEEK_IS('^')) { PINC; - not = 1; + is_not = 1; } else - not = 0; + is_not = 0; if (onigenc_strlen(enc, p, end) < POSIX_BRACKET_NAME_MIN_LEN + 3) goto not_posix_bracket; @@ -3999,7 +3999,7 @@ parse_posix_bracket(CClassNode* cc, UChar** src, UChar* end, ScanEnv* env) if (onigenc_with_ascii_strncmp(enc, p, end, (UChar* )":]", 2) != 0) return ONIGERR_INVALID_POSIX_BRACKET_TYPE; - r = add_ctype_to_cc(cc, pb->ctype, not, env); + r = add_ctype_to_cc(cc, pb->ctype, is_not, env); if (r != 0) return r; PINC; PINC; @@ -4074,7 +4074,7 @@ parse_char_property(Node** np, OnigToken* tok, UChar** src, UChar* end, cc = NCCLASS(*np); r = add_ctype_to_cc(cc, ctype, 0, env); if (r != 0) return r; - if (tok->u.prop.not != 0) NCCLASS_SET_NOT(cc); + if (tok->u.prop.is_not != 0) NCCLASS_SET_NOT(cc); return 0; } @@ -4356,7 +4356,7 @@ parse_char_class(Node** np, OnigToken* tok, UChar** src, UChar* end, break; case TK_CHAR_TYPE: - r = add_ctype_to_cc(cc, tok->u.prop.ctype, tok->u.prop.not, env); + r = add_ctype_to_cc(cc, tok->u.prop.ctype, tok->u.prop.is_not, env); if (r != 0) return r; next_class: @@ -4370,7 +4370,7 @@ parse_char_class(Node** np, OnigToken* tok, UChar** src, UChar* end, ctype = fetch_char_property_to_ctype(&p, end, env); if (ctype < 0) return ctype; - r = add_ctype_to_cc(cc, ctype, tok->u.prop.not, env); + r = add_ctype_to_cc(cc, ctype, tok->u.prop.is_not, env); if (r != 0) return r; goto next_class; } @@ -4881,15 +4881,15 @@ set_quantifier(Node* qnode, Node* target, int group, ScanEnv* env) typedef struct { OnigEncoding enc; - int not; + int is_not; int type; } type_cclass_key; static int type_cclass_cmp(type_cclass_key* x, type_cclass_key* y) { - if (x->type != y->type) return 1; - if (x->enc != y->enc) return 1; - if (x->not != y->not) return 1; + if (x->type != y->type) return 1; + if (x->enc != y->enc) return 1; + if (x->is_not != y->is_not) return 1; return 0; } @@ -4910,7 +4910,7 @@ static st_index_t type_cclass_hash(type_cclass_key* key) val = val * 997 + (int )*p++; } - val += key->not; + val += key->is_not; return val + (val >> 5); } @@ -5208,12 +5208,12 @@ parse_exp(Node** np, OnigToken* tok, int term, CHECK_NULL_RETURN_MEMERR(*np); cc = NCCLASS(*np); add_ctype_to_cc(cc, tok->u.prop.ctype, 0, env); - if (tok->u.prop.not != 0) NCCLASS_SET_NOT(cc); + if (tok->u.prop.is_not != 0) NCCLASS_SET_NOT(cc); } break; case ONIGENC_CTYPE_WORD: - *np = node_new_ctype(tok->u.prop.ctype, tok->u.prop.not); + *np = node_new_ctype(tok->u.prop.ctype, tok->u.prop.is_not); CHECK_NULL_RETURN_MEMERR(*np); break; @@ -5235,9 +5235,9 @@ parse_exp(Node** np, OnigToken* tok, int term, type_cclass_key key; type_cclass_key* new_key; - key.enc = env->enc; - key.not = tok->u.prop.not; - key.type = tok->u.prop.ctype; + key.enc = env->enc; + key.is_not = tok->u.prop.is_not; + key.type = tok->u.prop.ctype; THREAD_ATOMIC_START; @@ -5257,7 +5257,7 @@ parse_exp(Node** np, OnigToken* tok, int term, } } - *np = node_new_cclass_by_codepoint_range(tok->u.prop.not, + *np = node_new_cclass_by_codepoint_range(tok->u.prop.is_not, sb_out, mbr); if (IS_NULL(*np)) { THREAD_ATOMIC_END; @@ -5279,7 +5279,7 @@ parse_exp(Node** np, OnigToken* tok, int term, CHECK_NULL_RETURN_MEMERR(*np); cc = NCCLASS(*np); add_ctype_to_cc(cc, tok->u.prop.ctype, 0, env); - if (tok->u.prop.not != 0) NCCLASS_SET_NOT(cc); + if (tok->u.prop.is_not != 0) NCCLASS_SET_NOT(cc); #ifdef USE_SHARED_CCLASS_TABLE } #endif diff --git a/src/regparse.h b/src/regparse.h index ac8758bd1..1f7855df8 100644 --- a/src/regparse.h +++ b/src/regparse.h @@ -247,7 +247,7 @@ typedef struct { typedef struct { NodeBase base; int ctype; - int not; + int is_not; } CtypeNode; typedef struct _Node { -- cgit v1.2.3 From d9529f198d2aa46f1ce0d06f7ed8d709f7a82147 Mon Sep 17 00:00:00 2001 From: Mitchell Blank Jr Date: Sat, 19 May 2012 23:33:01 -0700 Subject: fix mrb_gc_mark_ht_size() and mrb_gc_free_ht() types mrb_gc_mark_ht_size() and mrb_gc_free_ht() were declared in gc.h as taking a "RHash *" argument, but then they were defined in hash.c as taking a "RClass *" Get these in sync. --- src/hash.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hash.c b/src/hash.c index 3a2399c27..de99065f5 100644 --- a/src/hash.c +++ b/src/hash.c @@ -75,10 +75,10 @@ mrb_gc_mark_ht(mrb_state *mrb, struct RHash *c) } size_t -mrb_gc_mark_ht_size(mrb_state *mrb, struct RClass *c) +mrb_gc_mark_ht_size(mrb_state *mrb, struct RHash *c) { size_t ht_size = 0; - khash_t(ht) *h = ((struct RHash*)c)->ht; + khash_t(ht) *h = c->ht; /* ((struct RHash*)c)->ht */ if (h) ht_size += kh_size(h)*2; @@ -87,9 +87,9 @@ mrb_gc_mark_ht_size(mrb_state *mrb, struct RClass *c) } void -mrb_gc_free_ht(mrb_state *mrb, struct RClass *c) +mrb_gc_free_ht(mrb_state *mrb, struct RHash *c) { - khash_t(ht) *h = ((struct RHash*)c)->ht; + khash_t(ht) *h = c->ht; kh_destroy(ht, h); } -- cgit v1.2.3 From 8c752c73e21d9be1934a8440caa0481c35deb8ad Mon Sep 17 00:00:00 2001 From: Mitchell Blank Jr Date: Sat, 19 May 2012 23:44:43 -0700 Subject: "volatile" no longer needed here See Matz's comment here: https://github.com/mruby/mruby/pull/144#issuecomment-5754054 --- src/sprintf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sprintf.c b/src/sprintf.c index 12d96c92d..6a86a0d04 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -191,7 +191,7 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base) } while (0) static mrb_value -get_hash(mrb_state *mrb, volatile mrb_value *hash, int argc, const mrb_value *argv) +get_hash(mrb_state *mrb, mrb_value *hash, int argc, const mrb_value *argv) { mrb_value tmp; @@ -497,7 +497,7 @@ mrb_str_format(mrb_state *mrb, int argc, const mrb_value *argv, mrb_value fmt) mrb_value nextvalue; mrb_value tmp; mrb_value str; - volatile mrb_value hash = mrb_undef_value(); + mrb_value hash = mrb_undef_value(); #define CHECK_FOR_WIDTH(f) \ if ((f) & FWIDTH) { \ @@ -772,7 +772,7 @@ format_s: case 'B': case 'u': { - volatile mrb_value val = GETARG(); + mrb_value val = GETARG(); char fbuf[32], nbuf[64], *s; const char *prefix = 0; int sign = 0, dots = 0; -- cgit v1.2.3 From 42c6b324db6141d05726beec531ae19bd83e85f0 Mon Sep 17 00:00:00 2001 From: Mitchell Blank Jr Date: Sun, 20 May 2012 00:06:49 -0700 Subject: C++ compilability -- don't jump across variable initialization C++ is picker than C about when you can "goto" across a variable being defined. The fix is to just minimize the variable's scope inside an extra set of brackets. Without this change, g++ has the following errors: transcode.c:590: error: jump to label 'resume_label3' transcode.c:514: error: from here transcode.c:582: error: crosses initialization of 'const unsigned char* p' transcode.c:2124: error: jump to label 'set_encs' transcode.c:2184: error: from here transcode.c:2088: error: skips initialization of 'const char* err' transcode.c:2089: error: skips initialization of 'size_t error_len' transcode.c:2090: error: skips initialization of 'mrb_value bytes' transcode.c:2091: error: skips initialization of 'mrb_value dumped' transcode.c:2092: error: skips initialization of 'size_t readagain_len' transcode.c:2093: error: skips initialization of 'mrb_value bytes2' --- src/transcode.c | 93 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/src/transcode.c b/src/transcode.c index ae78f20d4..e9d9b01ef 100644 --- a/src/transcode.c +++ b/src/transcode.c @@ -579,10 +579,12 @@ transcode_restartable0(mrb_state *mrb, switch (mrb_fixnum(next_info) & 0x1F) { case NOMAP: { - const unsigned char *p = inchar_start; - writebuf_off = 0; - while (p < in_p) { - TRANSCODING_WRITEBUF(tc)[writebuf_off++] = (unsigned char)*p++; + { + const unsigned char *p = inchar_start; + writebuf_off = 0; + while (p < in_p) { + TRANSCODING_WRITEBUF(tc)[writebuf_off++] = (unsigned char)*p++; + } } writebuf_len = writebuf_off; writebuf_off = 0; @@ -2085,51 +2087,54 @@ make_econv_exception(mrb_state *mrb, mrb_econv_t *ec) mrb_value mesg, exc; if (ec->last_error.result == econv_invalid_byte_sequence || ec->last_error.result == econv_incomplete_input) { - const char *err = (const char *)ec->last_error.error_bytes_start; - size_t error_len = ec->last_error.error_bytes_len; - mrb_value bytes = mrb_str_new(mrb, err, error_len); - mrb_value dumped = mrb_str_dump(mrb, bytes); - size_t readagain_len = ec->last_error.readagain_len; - mrb_value bytes2 = mrb_nil_value(); - mrb_value dumped2; - int idx; - if (ec->last_error.result == econv_incomplete_input) { - mesg = mrb_sprintf(mrb, "incomplete %s on %s", - //StringValueCStr(dumped), - mrb_string_value_cstr(mrb, &dumped), - ec->last_error.source_encoding); - } - else if (readagain_len) { - bytes2 = mrb_str_new(mrb, err+error_len, readagain_len); - dumped2 = mrb_str_dump(mrb, bytes2); - mesg = mrb_sprintf(mrb, "%s followed by %s on %s", - //StringValueCStr(dumped), - mrb_string_value_cstr(mrb, &dumped), - //StringValueCStr(dumped2), - mrb_string_value_cstr(mrb, &dumped2), - ec->last_error.source_encoding); - } - else { - mesg = mrb_sprintf(mrb, "%s on %s", - //StringValueCStr(dumped), - mrb_string_value_cstr(mrb, &dumped), - ec->last_error.source_encoding); + { + const char *err = (const char *)ec->last_error.error_bytes_start; + size_t error_len = ec->last_error.error_bytes_len; + mrb_value bytes = mrb_str_new(mrb, err, error_len); + mrb_value dumped = mrb_str_dump(mrb, bytes); + size_t readagain_len = ec->last_error.readagain_len; + mrb_value bytes2 = mrb_nil_value(); + mrb_value dumped2; + if (ec->last_error.result == econv_incomplete_input) { + mesg = mrb_sprintf(mrb, "incomplete %s on %s", + //StringValueCStr(dumped), + mrb_string_value_cstr(mrb, &dumped), + ec->last_error.source_encoding); + } + else if (readagain_len) { + bytes2 = mrb_str_new(mrb, err+error_len, readagain_len); + dumped2 = mrb_str_dump(mrb, bytes2); + mesg = mrb_sprintf(mrb, "%s followed by %s on %s", + //StringValueCStr(dumped), + mrb_string_value_cstr(mrb, &dumped), + //StringValueCStr(dumped2), + mrb_string_value_cstr(mrb, &dumped2), + ec->last_error.source_encoding); + } + else { + mesg = mrb_sprintf(mrb, "%s on %s", + //StringValueCStr(dumped), + mrb_string_value_cstr(mrb, &dumped), + ec->last_error.source_encoding); + } + + exc = mrb_exc_new3(mrb, E_INVALIDBYTESEQUENCE_ERROR, mesg); + mrb_iv_set(mrb, exc, mrb_intern(mrb, "error_bytes"), bytes); + mrb_iv_set(mrb, exc, mrb_intern(mrb, "readagain_bytes"), bytes2); + mrb_iv_set(mrb, exc, mrb_intern(mrb, "incomplete_input"), ec->last_error.result == econv_incomplete_input ? mrb_true_value() : mrb_false_value()); } - exc = mrb_exc_new3(mrb, E_INVALIDBYTESEQUENCE_ERROR, mesg); - mrb_iv_set(mrb, exc, mrb_intern(mrb, "error_bytes"), bytes); - mrb_iv_set(mrb, exc, mrb_intern(mrb, "readagain_bytes"), bytes2); - mrb_iv_set(mrb, exc, mrb_intern(mrb, "incomplete_input"), ec->last_error.result == econv_incomplete_input ? mrb_true_value() : mrb_false_value()); - set_encs: mrb_iv_set(mrb, exc, mrb_intern(mrb, "source_encoding_name"), mrb_str_new2(mrb, ec->last_error.source_encoding)); mrb_iv_set(mrb, exc, mrb_intern(mrb, "destination_encoding_name"), mrb_str_new2(mrb, ec->last_error.destination_encoding)); - idx = mrb_enc_find_index(mrb, ec->last_error.source_encoding); - if (0 <= idx) - mrb_iv_set(mrb, exc, mrb_intern(mrb, "source_encoding"), mrb_enc_from_encoding(mrb, mrb_enc_from_index(mrb, idx))); - idx = mrb_enc_find_index(mrb, ec->last_error.destination_encoding); - if (0 <= idx) - mrb_iv_set(mrb, exc, mrb_intern(mrb, "destination_encoding"), mrb_enc_from_encoding(mrb, mrb_enc_from_index(mrb, idx))); + { + int idx = mrb_enc_find_index(mrb, ec->last_error.source_encoding); + if (0 <= idx) + mrb_iv_set(mrb, exc, mrb_intern(mrb, "source_encoding"), mrb_enc_from_encoding(mrb, mrb_enc_from_index(mrb, idx))); + idx = mrb_enc_find_index(mrb, ec->last_error.destination_encoding); + if (0 <= idx) + mrb_iv_set(mrb, exc, mrb_intern(mrb, "destination_encoding"), mrb_enc_from_encoding(mrb, mrb_enc_from_index(mrb, idx))); + } return exc; } if (ec->last_error.result == econv_undefined_conversion) { -- cgit v1.2.3 From 1ad7a1e3d8da7b00a9e589c201fe79e5b9541692 Mon Sep 17 00:00:00 2001 From: Mitchell Blank Jr Date: Sun, 20 May 2012 00:19:38 -0700 Subject: C++ compilability: don't use "node" as both a type and a member I originally solved this by renaming the "node" type to "node_t", but Matz didn't like that. He suggested renaming the member variable "nd" instead: https://github.com/mruby/mruby/pull/144#issuecomment-5743153 --- src/parse.y | 94 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/src/parse.y b/src/parse.y index 4b1f02106..9a7748d30 100644 --- a/src/parse.y +++ b/src/parse.y @@ -813,7 +813,7 @@ var_reference(parser_state *p, node *lhs) %lex-param {parser_state *p} %union { - node *node; + node *nd; mrb_sym id; int num; unsigned int stack; @@ -871,28 +871,28 @@ var_reference(parser_state *p, node *lhs) keyword__ENCODING__ %token tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL -%token tINTEGER tFLOAT tCHAR tREGEXP -%token tSTRING tSTRING_PART -%token tNTH_REF tBACK_REF +%token tINTEGER tFLOAT tCHAR tREGEXP +%token tSTRING tSTRING_PART +%token tNTH_REF tBACK_REF %token tREGEXP_END -%type singleton string string_interp regexp -%type literal numeric cpath -%type top_compstmt top_stmts top_stmt -%type bodystmt compstmt stmts stmt expr arg primary command command_call method_call -%type expr_value arg_value primary_value -%type if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure -%type args call_args opt_call_args -%type paren_args opt_paren_args variable -%type command_args aref_args opt_block_arg block_arg var_ref var_lhs -%type command_asgn mrhs superclass block_call block_command -%type f_block_optarg f_block_opt -%type f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs -%type assoc_list assocs assoc undef_list backref for_var -%type block_param opt_block_param block_param_def f_opt -%type bv_decls opt_bv_decl bvar f_larglist lambda_body -%type brace_block cmd_brace_block do_block lhs none fitem f_bad_arg -%type mlhs mlhs_list mlhs_post mlhs_basic mlhs_item mlhs_node mlhs_inner +%type singleton string string_interp regexp +%type literal numeric cpath +%type top_compstmt top_stmts top_stmt +%type bodystmt compstmt stmts stmt expr arg primary command command_call method_call +%type expr_value arg_value primary_value +%type if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure +%type args call_args opt_call_args +%type paren_args opt_paren_args variable +%type command_args aref_args opt_block_arg block_arg var_ref var_lhs +%type command_asgn mrhs superclass block_call block_command +%type f_block_optarg f_block_opt +%type f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs +%type assoc_list assocs assoc undef_list backref for_var +%type block_param opt_block_param block_param_def f_opt +%type bv_decls opt_bv_decl bvar f_larglist lambda_body +%type brace_block cmd_brace_block do_block lhs none fitem f_bad_arg +%type mlhs mlhs_list mlhs_post mlhs_basic mlhs_item mlhs_node mlhs_inner %type fsym sym symbol operation operation2 operation3 %type cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg @@ -1007,12 +1007,12 @@ top_stmt : stmt if (p->in_def || p->in_single) { yyerror(p, "BEGIN in method"); } - $$ = local_switch(p); + $$ = local_switch(p); } '{' top_compstmt '}' { p->begin_tree = push(p->begin_tree, $4); - local_resume(p, $2); + local_resume(p, $2); $$ = 0; } ; @@ -1980,13 +1980,13 @@ primary : literal { if (p->in_def || p->in_single) yyerror(p, "class definition in method body"); - $$ = local_switch(p); + $$ = local_switch(p); } bodystmt keyword_end { $$ = new_class(p, $2, $3, $5); - local_resume(p, $4); + local_resume(p, $4); } | keyword_class tLSHFT expr { @@ -1995,54 +1995,54 @@ primary : literal } term { - $$ = cons(local_switch(p), (node*)(intptr_t)p->in_single); + $$ = cons(local_switch(p), (node*)(intptr_t)p->in_single); p->in_single = 0; } bodystmt keyword_end { $$ = new_sclass(p, $3, $7); - local_resume(p, $6->car); + local_resume(p, $6->car); p->in_def = $4; - p->in_single = (int)(intptr_t)$6->cdr; + p->in_single = (int)(intptr_t)$6->cdr; } | keyword_module cpath { if (p->in_def || p->in_single) yyerror(p, "module definition in method body"); - $$ = local_switch(p); + $$ = local_switch(p); } bodystmt keyword_end { $$ = new_module(p, $2, $4); - local_resume(p, $3); + local_resume(p, $3); } | keyword_def fname { p->in_def++; - $$ = local_switch(p); + $$ = local_switch(p); } f_arglist bodystmt keyword_end { $$ = new_def(p, $2, $4, $5); - local_resume(p, $3); + local_resume(p, $3); p->in_def--; } | keyword_def singleton dot_or_colon {p->lstate = EXPR_FNAME;} fname { p->in_single++; p->lstate = EXPR_ENDFN; /* force for args */ - $$ = local_switch(p); + $$ = local_switch(p); } f_arglist bodystmt keyword_end { $$ = new_sdef(p, $2, $5, $7, $8); - local_resume(p, $6); + local_resume(p, $6); p->in_single--; } | keyword_break @@ -3355,7 +3355,7 @@ parse_string(parser_state *p, int term) p->lstate = EXPR_BEG; p->sterm = term; p->cmd_start = TRUE; - yylval.node = new_str(p, tok(p), toklen(p)); + yylval.nd = new_str(p, tok(p), toklen(p)); return tSTRING_PART; } tokadd(p, '#'); @@ -3368,7 +3368,7 @@ parse_string(parser_state *p, int term) tokfix(p); p->lstate = EXPR_END; p->sterm = 0; - yylval.node = new_str(p, tok(p), toklen(p)); + yylval.nd = new_str(p, tok(p), toklen(p)); return tSTRING; } @@ -3409,7 +3409,7 @@ parse_qstring(parser_state *p, int term) } tokfix(p); - yylval.node = new_str(p, tok(p), toklen(p)); + yylval.nd = new_str(p, tok(p), toklen(p)); p->lstate = EXPR_END; return tSTRING; } @@ -3717,7 +3717,7 @@ parser_yylex(parser_state *p) tokadd(p, c); } tokfix(p); - yylval.node = new_str(p, tok(p), toklen(p)); + yylval.nd = new_str(p, tok(p), toklen(p)); p->lstate = EXPR_END; return tCHAR; @@ -3894,7 +3894,7 @@ parser_yylex(parser_state *p) no_digits(); } else if (nondigit) goto trailing_uc; - yylval.node = new_int(p, tok(p), 16); + yylval.nd = new_int(p, tok(p), 16); return tINTEGER; } if (c == 'b' || c == 'B') { @@ -3918,7 +3918,7 @@ parser_yylex(parser_state *p) no_digits(); } else if (nondigit) goto trailing_uc; - yylval.node = new_int(p, tok(p), 2); + yylval.nd = new_int(p, tok(p), 2); return tINTEGER; } if (c == 'd' || c == 'D') { @@ -3942,7 +3942,7 @@ parser_yylex(parser_state *p) no_digits(); } else if (nondigit) goto trailing_uc; - yylval.node = new_int(p, tok(p), 10); + yylval.nd = new_int(p, tok(p), 10); return tINTEGER; } if (c == '_') { @@ -3975,7 +3975,7 @@ parser_yylex(parser_state *p) pushback(p, c); tokfix(p); if (nondigit) goto trailing_uc; - yylval.node = new_int(p, tok(p), 8); + yylval.nd = new_int(p, tok(p), 8); return tINTEGER; } if (nondigit) { @@ -3992,7 +3992,7 @@ parser_yylex(parser_state *p) } else { pushback(p, c); - yylval.node = new_int(p, "0", 10); + yylval.nd = new_int(p, "0", 10); return tINTEGER; } } @@ -4069,10 +4069,10 @@ parser_yylex(parser_state *p) yywarning_s(p, "float %s out of range", tok(p)); errno = 0; } - yylval.node = new_float(p, tok(p)); + yylval.nd = new_float(p, tok(p)); return tFLOAT; } - yylval.node = new_int(p, tok(p), 10); + yylval.nd = new_int(p, tok(p), 10); return tINTEGER; } @@ -4404,7 +4404,7 @@ parser_yylex(parser_state *p) tokadd(p, c); goto gvar; } - yylval.node = new_back_ref(p, c); + yylval.nd = new_back_ref(p, c); return tBACK_REF; case '1': case '2': case '3': @@ -4417,7 +4417,7 @@ parser_yylex(parser_state *p) pushback(p, c); if (last_state == EXPR_FNAME) goto gvar; tokfix(p); - yylval.node = new_nth_ref(p, atoi(tok(p))); + yylval.nd = new_nth_ref(p, atoi(tok(p))); return tNTH_REF; default: -- cgit v1.2.3 From 606a1665c5cfff42622687d693b9362b6c1b663a Mon Sep 17 00:00:00 2001 From: Mitchell Blank Jr Date: Sun, 20 May 2012 00:26:49 -0700 Subject: C++ compilability - avoid 'goto' across a variable initialization C++ is pickier about when a 'goto' can cross a variable being delcared. The fix is to just add a set of braces to restrict the variable's scope. Without this, g++ will fail with: regcomp.c:3057: error: jump to label 'set_call_attr' regcomp.c:3087: error: from here regcomp.c:3041: error: skips initialization of 'int gnum' --- src/regcomp.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/regcomp.c b/src/regcomp.c index bb45b3db4..523124b26 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -3038,19 +3038,21 @@ setup_subexp_call(Node* node, ScanEnv* env) Node** nodes = SCANENV_MEM_NODES(env); if (cn->group_num != 0) { - int gnum = cn->group_num; + { + int gnum = cn->group_num; #ifdef USE_NAMED_GROUP - if (env->num_named > 0 && - IS_SYNTAX_BV(env->syntax, ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP) && - !ONIG_IS_OPTION_ON(env->option, ONIG_OPTION_CAPTURE_GROUP)) { - return ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED; - } + if (env->num_named > 0 && + IS_SYNTAX_BV(env->syntax, ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP) && + !ONIG_IS_OPTION_ON(env->option, ONIG_OPTION_CAPTURE_GROUP)) { + return ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED; + } #endif - if (gnum > env->num_mem) { - onig_scan_env_set_error_string(env, - ONIGERR_UNDEFINED_GROUP_REFERENCE, cn->name, cn->name_end); - return ONIGERR_UNDEFINED_GROUP_REFERENCE; + if (gnum > env->num_mem) { + onig_scan_env_set_error_string(env, + ONIGERR_UNDEFINED_GROUP_REFERENCE, cn->name, cn->name_end); + return ONIGERR_UNDEFINED_GROUP_REFERENCE; + } } #ifdef USE_NAMED_GROUP -- cgit v1.2.3