ruby-changes:12974
From: naruse <ko1@a...>
Date: Sun, 30 Aug 2009 17:00:47 +0900 (JST)
Subject: [ruby-changes:12974] Ruby:r24716 (trunk): *regparse.c (CC_DUP_WARN): use rb_compile_warn if ScanEnv has source
naruse 2009-08-30 17:00:31 +0900 (Sun, 30 Aug 2009) New Revision: 24716 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24716 Log: *regparse.c (CC_DUP_WARN): use rb_compile_warn if ScanEnv has source information. [ruby-dev:39105] *re.c (rb_reg_compile): add sourcefile and sourceline to the arguments. *re.c (make_regexp): ditto. *re.c (rb_reg_initialize): ditto. *re.c (rb_reg_initialize_str): ditto. *re.c (rb_reg_compile): ditto. *regcomp.c (onig_compile): ditto. *regint.h (onig_compile): ditto. *re.c (reg_compile_gen): follow above. *re.c (rb_reg_to_s): ditto. *re.c (make_regexp): ditto. *re.c (rb_reg_initialize): ditto. *re.c (rb_reg_initialize_str): ditto. *re.c (rb_reg_new_str): ditto. *re.c (rb_enc_reg_new): ditto. *re.c (rb_reg_initialize_m): ditto. *re.c (rb_reg_init_copy): ditto. *regcomp.c (onig_new): ditto. *regcomp.c (onig_compile): set sourcefile and sourceline to scan_env. *regparse.h (ScanEnv): add sourcefile and sourceline. Modified files: trunk/parse.y trunk/re.c trunk/regcomp.c trunk/regint.h trunk/regparse.c trunk/regparse.h Index: regparse.c =================================================================== --- regparse.c (revision 24715) +++ regparse.c (revision 24716) @@ -2877,7 +2877,11 @@ onig_snprintf_with_pattern(buf, WARN_BUFSIZE, env->enc, env->pattern, env->pattern_end, (UChar* )"character class has duplicated range"); - (*onig_warn)((char* )buf); + + if (env->sourcefile == NULL) + (*onig_warn)((char* )buf); + else + rb_compile_warn(env->sourcefile, env->sourceline, (char* )buf); } } Index: regparse.h =================================================================== --- regparse.h (revision 24715) +++ regparse.h (revision 24716) @@ -307,6 +307,8 @@ int has_recursion; #endif int warnings_flag; + const char* sourcefile; + int sourceline; } ScanEnv; Index: regcomp.c =================================================================== --- regcomp.c (revision 24715) +++ regcomp.c (revision 24716) @@ -5351,7 +5351,7 @@ extern int onig_compile(regex_t* reg, const UChar* pattern, const UChar* pattern_end, - OnigErrorInfo* einfo) + OnigErrorInfo* einfo, const char *sourcefile, int sourceline) { #define COMPILE_INIT_SIZE 20 @@ -5362,6 +5362,8 @@ UnsetAddrList uslist; #endif + scan_env.sourcefile = sourcefile; + scan_env.sourceline = sourceline; reg->state = ONIG_STATE_COMPILING; #ifdef ONIG_DEBUG @@ -5616,7 +5618,7 @@ enc, syntax); if (r) return r; - r = onig_compile(*reg, pattern, pattern_end, einfo); + r = onig_compile(*reg, pattern, pattern_end, einfo, NULL, 0); if (r) { onig_free(*reg); *reg = NULL; Index: re.c =================================================================== --- re.c (revision 24715) +++ re.c (revision 24716) @@ -528,7 +528,7 @@ if (r == 0) { ++ptr; len -= 2; - err = (onig_compile(rp, ptr, ptr + len, NULL) != 0); + err = (onig_compile(rp, ptr, ptr + len, NULL, NULL, 0) != 0); } onig_free(rp); } @@ -731,7 +731,8 @@ } static Regexp* -make_regexp(const char *s, long len, rb_encoding *enc, int flags, onig_errmsg_buffer err) +make_regexp(const char *s, long len, rb_encoding *enc, int flags, onig_errmsg_buffer err, + const char *sourcefile, int sourceline) { Regexp *rp; int r; @@ -751,7 +752,7 @@ return 0; } - r = onig_compile(rp, (UChar*)s, (UChar*)(s + len), &einfo); + r = onig_compile(rp, (UChar*)s, (UChar*)(s + len), &einfo, sourcefile, sourceline); if (r != 0) { onig_free(rp); @@ -2323,7 +2324,8 @@ static int rb_reg_initialize(VALUE obj, const char *s, long len, rb_encoding *enc, - int options, onig_errmsg_buffer err) + int options, onig_errmsg_buffer err, + const char *sourcefile, int sourceline) { struct RRegexp *re = RREGEXP(obj); VALUE unescaped; @@ -2372,7 +2374,8 @@ } re->ptr = make_regexp(RSTRING_PTR(unescaped), RSTRING_LEN(unescaped), enc, - options & ARG_REG_OPTION_MASK, err); + options & ARG_REG_OPTION_MASK, err, + sourcefile, sourceline); if (!re->ptr) return -1; re->src = rb_enc_str_new(s, len, enc); OBJ_FREEZE(re->src); @@ -2381,7 +2384,8 @@ } static int -rb_reg_initialize_str(VALUE obj, VALUE str, int options, onig_errmsg_buffer err) +rb_reg_initialize_str(VALUE obj, VALUE str, int options, onig_errmsg_buffer err, + const char *sourcefile, int sourceline) { int ret; rb_encoding *enc = rb_enc_get(str); @@ -2396,7 +2400,7 @@ } } ret = rb_reg_initialize(obj, RSTRING_PTR(str), RSTRING_LEN(str), enc, - options, err); + options, err, sourcefile, sourceline); RB_GC_GUARD(str); return ret; } @@ -2420,7 +2424,7 @@ VALUE re = rb_reg_s_alloc(rb_cRegexp); onig_errmsg_buffer err = ""; - if (rb_reg_initialize_str(re, s, options, err) != 0) { + if (rb_reg_initialize_str(re, s, options, err, NULL, 0) != 0) { rb_reg_raise_str(s, options, err); } @@ -2439,7 +2443,7 @@ VALUE re = rb_reg_s_alloc(rb_cRegexp); onig_errmsg_buffer err = ""; - if (rb_reg_initialize(re, s, len, enc, options, err) != 0) { + if (rb_reg_initialize(re, s, len, enc, options, err, NULL, 0) != 0) { rb_enc_reg_raise(s, len, enc, options, err); } @@ -2453,13 +2457,13 @@ } VALUE -rb_reg_compile(VALUE str, int options) +rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline) { VALUE re = rb_reg_s_alloc(rb_cRegexp); onig_errmsg_buffer err = ""; if (!str) str = rb_str_new(0,0); - if (rb_reg_initialize_str(re, str, options, err) != 0) { + if (rb_reg_initialize_str(re, str, options, err, sourcefile, sourceline) != 0) { rb_set_errinfo(rb_reg_error_desc(str, options, err)); return Qnil; } @@ -2809,7 +2813,7 @@ ptr = RREGEXP_SRC_PTR(re); len = RREGEXP_SRC_LEN(re); enc = rb_enc_get(re); - if (rb_reg_initialize(self, ptr, len, enc, flags, err)) { + if (rb_reg_initialize(self, ptr, len, enc, flags, err, NULL, 0)) { str = rb_enc_str_new(ptr, len, enc); rb_reg_raise_str(str, flags, err); } @@ -2833,8 +2837,8 @@ str = argv[0]; ptr = StringValuePtr(str); if (enc - ? rb_reg_initialize(self, ptr, RSTRING_LEN(str), enc, flags, err) - : rb_reg_initialize_str(self, str, flags, err)) { + ? rb_reg_initialize(self, ptr, RSTRING_LEN(str), enc, flags, err, NULL, 0) + : rb_reg_initialize_str(self, str, flags, err, NULL, 0)) { rb_reg_raise_str(str, flags, err); } } @@ -3159,7 +3163,8 @@ rb_reg_check(re); s = RREGEXP_SRC_PTR(re); len = RREGEXP_SRC_LEN(re); - if (rb_reg_initialize(copy, s, len, rb_enc_get(re), rb_reg_options(re), err) != 0) { + if (rb_reg_initialize(copy, s, len, rb_enc_get(re), rb_reg_options(re), + err, NULL, 0) != 0) { rb_reg_raise(s, len, err, re); } return copy; Index: regint.h =================================================================== --- regint.h (revision 24715) +++ regint.h (revision 24716) @@ -800,7 +800,7 @@ extern void onig_snprintf_with_pattern PV_((UChar buf[], int bufsize, OnigEncoding enc, UChar* pat, UChar* pat_end, const UChar *fmt, ...)); extern int onig_bbuf_init P_((BBuf* buf, int size)); extern int onig_alloc_init P_((regex_t** reg, OnigOptionType option, OnigCaseFoldType case_fold_flag, OnigEncoding enc, const OnigSyntaxType* syntax)); -extern int onig_compile P_((regex_t* reg, const UChar* pattern, const UChar* pattern_end, OnigErrorInfo* einfo)); +extern int onig_compile P_((regex_t* reg, const UChar* pattern, const UChar* pattern_end, OnigErrorInfo* einfo, const char *sourcefile, int sourceline)); extern void onig_chain_reduce P_((regex_t* reg)); extern void onig_chain_link_add P_((regex_t* to, regex_t* add)); extern void onig_transfer P_((regex_t* to, regex_t* from)); Index: parse.y =================================================================== --- parse.y (revision 24715) +++ parse.y (revision 24716) @@ -8888,7 +8888,7 @@ vtable_included(lvtbl->vars, id)); } -VALUE rb_reg_compile(VALUE str, int options); +VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline); VALUE rb_reg_check_preprocess(VALUE); static void @@ -9030,7 +9030,7 @@ reg_fragment_setenc(str, options); err = rb_errinfo(); - re = rb_reg_compile(str, options & RE_OPTION_MASK); + re = rb_reg_compile(str, options & RE_OPTION_MASK, ruby_sourcefile, ruby_sourceline); if (NIL_P(re)) { ID mesg = rb_intern("mesg"); VALUE m = rb_attr_get(rb_errinfo(), mesg); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/