diff options
| author | Yukihiro Matsumoto <[email protected]> | 2012-05-07 17:38:03 +0900 |
|---|---|---|
| committer | Yukihiro Matsumoto <[email protected]> | 2012-05-07 17:38:03 +0900 |
| commit | 9182ab8764b669b18a949343839481711ce5a4a9 (patch) | |
| tree | 484a2f40679c5004adbd144808b8b1a4885a58af /src | |
| parent | d0e63a3a03ddbe3fd03cde3817c63c49723f2b69 (diff) | |
| download | mruby-9182ab8764b669b18a949343839481711ce5a4a9.tar.gz mruby-9182ab8764b669b18a949343839481711ce5a4a9.zip | |
RRegexp.src should not be mrb_value
Diffstat (limited to 'src')
| -rw-r--r-- | src/re.c | 20 | ||||
| -rw-r--r-- | src/re.h | 6 |
2 files changed, 11 insertions, 15 deletions
@@ -90,7 +90,7 @@ mrb_reg_s_new_instance(mrb_state *mrb, /*int argc, mrb_value *argv, */mrb_value struct RRegexp *re; re = mrb_obj_alloc(mrb, MRB_TT_REGEX, mrb->regex_class); re->ptr = 0; - re->src = mrb_nil_value(); + re->src = 0; re->usecnt = 0; return mrb_funcall_argv(mrb, mrb_obj_value(re), "initialize", argc, argv); } @@ -361,10 +361,7 @@ mrb_reg_check(mrb_state *mrb, mrb_value re) if (!(RREGEXP(re)->ptr)) { mrb_raise(mrb, E_TYPE_ERROR, "uninitialized Regexp"); } - if (RREGEXP_SRC(re).tt == 0) { - mrb_raise(mrb, E_TYPE_ERROR, "uninitialized Regexp"); - } - if (!RREGEXP_SRC_PTR(re)) { + if (RREGEXP(re)->src == 0) { mrb_raise(mrb, E_TYPE_ERROR, "uninitialized Regexp"); } } @@ -488,7 +485,7 @@ mrb_reg_prepare_re(mrb_state *mrb, mrb_value re, mrb_value str) pattern = RREGEXP_SRC_PTR(re); unescaped = mrb_reg_preprocess(mrb, - pattern, pattern + RREGEXP_SRC_LEN(re), enc, + pattern, pattern + RREGEXP(re)->src->len, enc, &fixed_enc, err); if (mrb_nil_p(unescaped)) { @@ -1209,10 +1206,8 @@ mrb_reg_initialize(mrb_state *mrb, mrb_value obj, const char *s, long len, mrb_e options & ARG_REG_OPTION_MASK, err, sourcefile, sourceline); if (!re->ptr) return -1; - re->src = mrb_enc_str_new(mrb, s, len, enc); + re->src = mrb_str_ptr(mrb_enc_str_new(mrb, s, len, enc)); - /*OBJ_FREEZE(re->src); - RB_GC_GUARD(unescaped);*/ return 0; } @@ -1361,7 +1356,8 @@ static int reg_equal(mrb_state *mrb, struct RRegexp *re1, struct RRegexp *re2) { if (re1->ptr->options != re2->ptr->options) return FALSE; - if (!mrb_equal(mrb, re1->src, re2->src)) return FALSE; + if (!mrb_equal(mrb, mrb_obj_value(re1->src), mrb_obj_value(re2->src))) + return FALSE; return TRUE; } @@ -2436,7 +2432,7 @@ again: static mrb_value mrb_reg_inspect(mrb_state *mrb, mrb_value re) { - if (!RREGEXP(re)->ptr || mrb_nil_p(RREGEXP_SRC(re)) || !RREGEXP_SRC_PTR(re)) { + if (!RREGEXP(re)->ptr || !RREGEXP_SRC(re) || !RREGEXP_SRC_PTR(re)) { return mrb_any_to_s(mrb, re); } return mrb_reg_desc(mrb, RREGEXP_SRC_PTR(re), RREGEXP_SRC_LEN(re), re); @@ -2452,7 +2448,7 @@ mrb_reg_s_alloc(mrb_state *mrb, mrb_value dummy) re = mrb_obj_alloc(mrb, MRB_TT_REGEX, mrb->regex_class); re->ptr = 0; - re->src.tt = 0; + re->src = 0; re->usecnt = 0; return mrb_obj_value(re); @@ -45,15 +45,15 @@ struct RMatch { struct RRegexp { MRUBY_OBJECT_HEADER; struct re_pattern_buffer *ptr; - mrb_value src; + struct RString *src; unsigned long usecnt; }; #define mrb_regex_ptr(r) ((struct RRegexp*)((r).value.p)) #define RREGEXP(r) ((struct RRegexp*)((r).value.p)) #define RREGEXP_SRC(r) (RREGEXP(r)->src) -#define RREGEXP_SRC_PTR(r) (((struct RString*)(RREGEXP_SRC(r).value.p))->buf) -#define RREGEXP_SRC_LEN(r) RSTRING_LEN(RREGEXP(r)->src) +#define RREGEXP_SRC_PTR(r) (RREGEXP_SRC(r)->buf) +#define RREGEXP_SRC_LEN(r) (RREGEXP_SRC(r)->len) int re_adjust_startpos(struct re_pattern_buffer *bufp, const char *string, int size, int startpos, int range); typedef struct re_pattern_buffer Regexp; |
