1 diff -urN oniguruma-185/Makefile.in oniguruma/Makefile.in
2 --- oniguruma-185/Makefile.in 2006-11-07 22:45:50.000000000 -0700
3 +++ oniguruma/Makefile.in 2007-02-19 22:34:07.000000000 -0700
6 patch -d $(RUBYDIR) -p0 < $(srcdir)/ruby185.patch
10 + patch -d $(RUBYDIR) -p0 < $(srcdir)/ruby186.patch
16 diff -urN oniguruma-185/ruby186.patch oniguruma/ruby186.patch
17 --- oniguruma-185/ruby186.patch 1969-12-31 17:00:00.000000000 -0700
18 +++ oniguruma/ruby186.patch 2007-02-19 22:34:54.000000000 -0700
20 +--- gc.c.ruby_orig 2006-08-25 17:12:46.000000000 +0900
21 ++++ gc.c 2006-11-08 14:11:06.000000000 +0900
22 +@@ -968,6 +968,7 @@ gc_mark_children(ptr, lev)
26 ++ gc_mark(obj->as.match.regexp, lev);
27 + if (obj->as.match.str) {
28 + ptr = obj->as.match.str;
30 +--- re.h.ruby_orig 2003-03-04 23:12:19.000000000 +0900
31 ++++ re.h 2006-11-08 14:11:06.000000000 +0900
32 +@@ -24,13 +24,14 @@ struct RMatch {
33 + struct RBasic basic;
35 + struct re_registers *regs;
36 ++ VALUE regexp; /* RRegexp */
39 + #define RMATCH(obj) (R_CAST(RMatch)(obj))
41 + VALUE rb_reg_regcomp _((VALUE));
42 + long rb_reg_search _((VALUE, VALUE, long, long));
43 +-VALUE rb_reg_regsub _((VALUE, VALUE, struct re_registers *));
44 ++VALUE rb_reg_regsub _((VALUE, VALUE, struct re_registers *, VALUE));
45 + long rb_reg_adjust_startpos _((VALUE, VALUE, long, long));
46 + void rb_match_busy _((VALUE));
47 + VALUE rb_reg_quote _((VALUE));
48 +--- re.c.ruby_orig 2007-02-12 16:01:19.000000000 -0700
49 ++++ re.c 2007-02-19 22:32:31.000000000 -0700
50 +@@ -486,10 +486,12 @@
52 + if (*ptr == ':' && ptr[len-1] == ')') {
55 + rb_kcode_set_option(re);
56 +- rp = ALLOC(Regexp);
57 +- MEMZERO((char *)rp, Regexp, 1);
58 +- err = re_compile_pattern(++ptr, len -= 2, rp) != 0;
59 ++ r = re_alloc_pattern(&rp);
61 ++ err = (re_compile_pattern(++ptr, len -= 2, rp, NULL) != 0);
63 + rb_kcode_reset_option();
64 + re_free_pattern(rp);
71 ++ char err[ONIG_MAX_ERROR_MESSAGE_LEN];
75 + /* Handle escaped characters first. */
77 +@@ -632,17 +636,18 @@
81 +- rp = ALLOC(Regexp);
82 +- MEMZERO((char *)rp, Regexp, 1);
83 +- rp->buffer = ALLOC_N(char, 16);
84 +- rp->allocated = 16;
85 +- rp->fastmap = ALLOC_N(char, 256);
86 ++ r = re_alloc_pattern(&rp);
88 ++ re_error_code_to_str((UChar* )err, r);
89 ++ rb_reg_raise(s, len, err, 0);
93 + rp->options = flags;
95 +- err = re_compile_pattern(s, len, rp);
96 ++ r = re_compile_pattern(s, len, rp, err);
100 + re_free_pattern(rp);
101 + rb_reg_raise(s, len, err, 0);
107 ++ match->regexp = 0;
108 + match->regs = ALLOC(struct re_registers);
109 + MEMZERO(match->regs, struct re_registers, 1);
112 + rb_raise(rb_eTypeError, "wrong argument class");
114 + RMATCH(obj)->str = RMATCH(orig)->str;
115 ++ RMATCH(obj)->regexp = RMATCH(orig)->regexp;
116 + re_free_registers(RMATCH(obj)->regs);
117 + RMATCH(obj)->regs->allocated = 0;
118 + re_copy_registers(RMATCH(obj)->regs, RMATCH(orig)->regs);
119 +@@ -846,14 +853,15 @@
122 + if (need_recompile) {
124 ++ char err[ONIG_MAX_ERROR_MESSAGE_LEN];
128 + if (FL_TEST(re, KCODE_FIXED))
129 + rb_kcode_set_option(re);
131 +- RREGEXP(re)->ptr->fastmap_accurate = 0;
132 +- err = re_compile_pattern(RREGEXP(re)->str, RREGEXP(re)->len, RREGEXP(re)->ptr);
133 +- if (err != NULL) {
134 ++ r = re_recompile_pattern(RREGEXP(re)->str, RREGEXP(re)->len, RREGEXP(re)->ptr, err);
136 + rb_reg_raise(RREGEXP(re)->str, RREGEXP(re)->len, err, re);
139 +@@ -920,14 +928,16 @@
140 + if (FL_TEST(re, KCODE_FIXED))
141 + rb_kcode_reset_option();
143 +- if (result == -2) {
144 +- rb_reg_raise(RREGEXP(re)->str, RREGEXP(re)->len,
145 +- "Stack overflow in regexp matcher", re);
149 +- rb_backref_set(Qnil);
151 ++ if (result == ONIG_MISMATCH) {
152 ++ rb_backref_set(Qnil);
156 ++ char err[ONIG_MAX_ERROR_MESSAGE_LEN];
157 ++ re_error_code_to_str((UChar* )err, result);
158 ++ rb_reg_raise(RREGEXP(re)->str, RREGEXP(re)->len, err, 0);
162 + match = rb_backref_get();
165 + re_copy_registers(RMATCH(match)->regs, ®s);
166 + RMATCH(match)->str = rb_str_new4(str);
167 ++ RMATCH(match)->regexp = re;
168 + rb_backref_set(match);
170 + OBJ_INFECT(match, re);
171 +@@ -1170,6 +1181,23 @@
176 ++name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end)
180 ++ num = onig_name_to_backref_number(RREGEXP(regexp)->ptr,
181 ++ (unsigned char* )name, (unsigned char* )name_end, regs);
186 ++ VALUE s = rb_str_new(name, (long )(name_end - name));
187 ++ rb_raise(rb_eRuntimeError, "undefined group name reference: %s",
188 ++ StringValuePtr(s));
195 +@@ -1199,10 +1227,37 @@
197 + rb_scan_args(argc, argv, "11", &idx, &rest);
199 +- if (!NIL_P(rest) || !FIXNUM_P(idx) || FIX2INT(idx) < 0) {
200 +- return rb_ary_aref(argc, argv, match_to_a(match));
201 ++ if (NIL_P(rest)) {
202 ++ if (FIXNUM_P(idx)) {
203 ++ if (FIX2INT(idx) >= 0) {
204 ++ return rb_reg_nth_match(FIX2INT(idx), match);
211 ++ switch (TYPE(idx)) {
213 ++ p = rb_id2name(SYM2ID(idx));
214 ++ goto name_to_backref;
217 ++ p = StringValuePtr(idx);
220 ++ num = name_to_backref_number(RMATCH(match)->regs,
221 ++ RMATCH(match)->regexp, p, p + strlen(p));
222 ++ return rb_reg_nth_match(num, match);
230 +- return rb_reg_nth_match(FIX2INT(idx), match);
232 ++ return rb_ary_aref(argc, argv, match_to_a(match));
235 + static VALUE match_entry _((VALUE, long));
236 +@@ -2001,12 +2056,14 @@
240 +-rb_reg_regsub(str, src, regs)
241 ++rb_reg_regsub(str, src, regs, regexp)
243 + struct re_registers *regs;
247 +- char *p, *s, *e, c;
252 + p = s = RSTRING(str)->ptr;
253 +@@ -2015,12 +2072,12 @@
258 +- if (ismbchar(c)) {
259 +- s += mbclen(c) - 1;
260 ++ uc = (unsigned char )*s++;
261 ++ if (ismbchar(uc)) {
262 ++ s += mbclen(uc) - 1;
265 +- if (c != '\\' || s == e) continue;
266 ++ if (uc != '\\' || s == e) continue;
269 + val = rb_str_buf_new(ss-p);
270 +@@ -2030,13 +2087,38 @@
271 + rb_str_buf_cat(val, p, ss-p);
275 ++ uc = (unsigned char )*s++;
278 +- case '0': case '1': case '2': case '3': case '4':
280 ++ case '1': case '2': case '3': case '4':
281 + case '5': case '6': case '7': case '8': case '9':
287 ++ if (s < e && *s == '<') {
288 ++ char *name, *name_end;
290 ++ name_end = name = s + 1;
291 ++ while (name_end < e) {
292 ++ if (*name_end == '>') break;
293 ++ uc = (unsigned char)*name_end;
294 ++ name_end += mbclen(uc);
296 ++ if (name_end < e) {
297 ++ no = name_to_backref_number(regs, regexp, name, name_end);
298 ++ p = s = name_end + 1;
302 ++ rb_raise(rb_eRuntimeError, "invalid group name reference format");
306 ++ rb_str_buf_cat(val, s-2, 2);
313 +@@ -2282,6 +2364,7 @@
314 + rb_define_const(rb_cRegexp, "IGNORECASE", INT2FIX(RE_OPTION_IGNORECASE));
315 + rb_define_const(rb_cRegexp, "EXTENDED", INT2FIX(RE_OPTION_EXTENDED));
316 + rb_define_const(rb_cRegexp, "MULTILINE", INT2FIX(RE_OPTION_MULTILINE));
317 ++ rb_define_const(rb_cRegexp, "ENGINE", rb_obj_freeze(rb_str_new2("Oniguruma")));
319 + rb_global_variable(®_cache);
321 +--- string.c.ruby_orig 2006-07-31 15:34:10.000000000 +0900
322 ++++ string.c 2006-11-08 14:11:06.000000000 +0900
323 +@@ -1977,7 +1977,7 @@ rb_str_sub_bang(argc, argv, str)
324 + rb_backref_set(match);
327 +- repl = rb_reg_regsub(repl, str, regs);
328 ++ repl = rb_reg_regsub(repl, str, regs, pat);
330 + if (OBJ_TAINTED(repl)) tainted = 1;
331 + plen = END(0) - BEG(0);
332 +@@ -2100,7 +2100,7 @@ str_gsub(argc, argv, str, bang)
333 + rb_backref_set(match);
336 +- val = rb_reg_regsub(repl, str, regs);
337 ++ val = rb_reg_regsub(repl, str, regs, pat);
339 + if (OBJ_TAINTED(val)) tainted = 1;
340 + len = (bp - buf) + (beg - offset) + RSTRING(val)->len + 3;