summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-02 04:39:44 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-02 04:39:44 +0000
commit21daa56b2aa2d4afc6e61b0e6b0f4dd78df620ca (patch)
tree44af7c3cce6e6197bf7a15fd3c8ab323fb8a343a
parent737332061566781684501216991e5a20edcca03b (diff)
* re.c: Introduce RREGEXP_PTR.
patch by dbussink. partially merge https://github.com/ruby/ruby/pull/497 * include/ruby/ruby.h: ditto. * gc.c: ditto. * ext/strscan/strscan.c: ditto. * parse.y: ditto. * string.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog16
-rw-r--r--ext/strscan/strscan.c8
-rw-r--r--gc.c4
-rw-r--r--include/ruby/ruby.h3
-rw-r--r--parse.y2
-rw-r--r--re.c52
-rw-r--r--string.c2
7 files changed, 52 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index 998e538..fbe05c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+Tue Feb 2 13:02:03 2016 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * re.c: Introduce RREGEXP_PTR.
+ patch by dbussink.
+ partially merge https://github.com/ruby/ruby/pull/497
+
+ * include/ruby/ruby.h: ditto.
+
+ * gc.c: ditto.
+
+ * ext/strscan/strscan.c: ditto.
+
+ * parse.y: ditto.
+
+ * string.c: ditto.
+
Tue Feb 2 09:08:27 2016 SHIBATA Hiroshi <hsbt@ruby-lang.org>
* lib/rubygems/specification.rb: `coding` is effective only first
diff --git a/ext/strscan/strscan.c b/ext/strscan/strscan.c
index f7592c9..e75bf66 100644
--- a/ext/strscan/strscan.c
+++ b/ext/strscan/strscan.c
@@ -460,7 +460,7 @@ strscan_do_scan(VALUE self, VALUE regex, int succptr, int getstr, int headonly)
p->regex = regex;
re = rb_reg_prepare_re(regex, p->str);
- tmpreg = re != RREGEXP(regex)->ptr;
+ tmpreg = re != RREGEXP_PTR(regex);
if (!tmpreg) RREGEXP(regex)->usecnt++;
if (headonly) {
@@ -480,8 +480,8 @@ strscan_do_scan(VALUE self, VALUE regex, int succptr, int getstr, int headonly)
onig_free(re);
}
else {
- onig_free(RREGEXP(regex)->ptr);
- RREGEXP(regex)->ptr = re;
+ onig_free(RREGEXP_PTR(regex));
+ RREGEXP_PTR(regex) = re;
}
}
@@ -978,7 +978,7 @@ name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name
{
int num;
- num = onig_name_to_backref_number(RREGEXP(regexp)->ptr,
+ num = onig_name_to_backref_number(RREGEXP_PTR(regexp),
(const unsigned char* )name, (const unsigned char* )name_end, regs);
if (num >= 1) {
return num;
diff --git a/gc.c b/gc.c
index 9adb384..acb7ec9 100644
--- a/gc.c
+++ b/gc.c
@@ -3107,8 +3107,8 @@ obj_memsize_of(VALUE obj, int use_all_types)
}
break;
case T_REGEXP:
- if (RREGEXP(obj)->ptr) {
- size += onig_memsize(RREGEXP(obj)->ptr);
+ if (RREGEXP_PTR(obj)) {
+ size += onig_memsize(RREGEXP_PTR(obj));
}
break;
case T_DATA:
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 82dca14..bc9c080 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -1071,7 +1071,8 @@ struct RRegexp {
const VALUE src;
unsigned long usecnt;
};
-#define RREGEXP_SRC(r) RREGEXP(r)->src
+#define RREGEXP_PTR(r) (RREGEXP(r)->ptr)
+#define RREGEXP_SRC(r) (RREGEXP(r)->src)
#define RREGEXP_SRC_PTR(r) RSTRING_PTR(RREGEXP(r)->src)
#define RREGEXP_SRC_LEN(r) RSTRING_LEN(RREGEXP(r)->src)
#define RREGEXP_SRC_END(r) RSTRING_END(RREGEXP(r)->src)
diff --git a/parse.y b/parse.y
index 4475277..5f3a8e3 100644
--- a/parse.y
+++ b/parse.y
@@ -10625,7 +10625,7 @@ reg_named_capture_assign_gen(struct parser_params* parser, VALUE regexp, NODE *m
arg.succ_block = 0;
arg.fail_block = 0;
arg.num = 0;
- onig_foreach_name(RREGEXP(regexp)->ptr, reg_named_capture_assign_iter, &arg);
+ onig_foreach_name(RREGEXP_PTR(regexp), reg_named_capture_assign_iter, &arg);
if (arg.num == 0)
return match;
diff --git a/re.c b/re.c
index f8ea30f..3f7d227 100644
--- a/re.c
+++ b/re.c
@@ -357,7 +357,7 @@ rb_char_to_option_kcode(int c, int *option, int *kcode)
static void
rb_reg_check(VALUE re)
{
- if (!RREGEXP(re)->ptr || !RREGEXP_SRC(re) || !RREGEXP_SRC_PTR(re)) {
+ if (!RREGEXP_PTR(re) || !RREGEXP_SRC(re) || !RREGEXP_SRC_PTR(re)) {
rb_raise(rb_eTypeError, "uninitialized Regexp");
}
}
@@ -470,7 +470,7 @@ rb_reg_desc(const char *s, long len, VALUE re)
if (re) {
char opts[4];
rb_reg_check(re);
- if (*option_to_str(opts, RREGEXP(re)->ptr->options))
+ if (*option_to_str(opts, RREGEXP_PTR(re)->options))
rb_str_buf_cat2(str, opts);
if (RBASIC(re)->flags & REG_ENCODING_NONE)
rb_str_buf_cat2(str, "n");
@@ -520,7 +520,7 @@ rb_reg_source(VALUE re)
static VALUE
rb_reg_inspect(VALUE re)
{
- if (!RREGEXP(re)->ptr || !RREGEXP_SRC(re) || !RREGEXP_SRC_PTR(re)) {
+ if (!RREGEXP_PTR(re) || !RREGEXP_SRC(re) || !RREGEXP_SRC_PTR(re)) {
return rb_any_to_s(re);
}
return rb_reg_desc(RREGEXP_SRC_PTR(re), RREGEXP_SRC_LEN(re), re);
@@ -561,7 +561,7 @@ rb_reg_to_s(VALUE re)
rb_reg_check(re);
rb_enc_copy(str, re);
- options = RREGEXP(re)->ptr->options;
+ options = RREGEXP_PTR(re)->options;
ptr = (UChar*)RREGEXP_SRC_PTR(re);
len = RREGEXP_SRC_LEN(re);
again:
@@ -612,7 +612,7 @@ rb_reg_to_s(VALUE re)
ruby_verbose = verbose;
}
if (err) {
- options = RREGEXP(re)->ptr->options;
+ options = RREGEXP_PTR(re)->options;
ptr = (UChar*)RREGEXP_SRC_PTR(re);
len = RREGEXP_SRC_LEN(re);
}
@@ -717,7 +717,7 @@ static VALUE
rb_reg_casefold_p(VALUE re)
{
rb_reg_check(re);
- if (RREGEXP(re)->ptr->options & ONIG_OPTION_IGNORECASE) return Qtrue;
+ if (RREGEXP_PTR(re)->options & ONIG_OPTION_IGNORECASE) return Qtrue;
return Qfalse;
}
@@ -782,7 +782,7 @@ rb_reg_names(VALUE re)
{
VALUE ary = rb_ary_new();
rb_reg_check(re);
- onig_foreach_name(RREGEXP(re)->ptr, reg_names_iter, (void*)ary);
+ onig_foreach_name(RREGEXP_PTR(re), reg_names_iter, (void*)ary);
return ary;
}
@@ -829,7 +829,7 @@ rb_reg_named_captures(VALUE re)
{
VALUE hash = rb_hash_new();
rb_reg_check(re);
- onig_foreach_name(RREGEXP(re)->ptr, reg_named_captures_iter, (void*)hash);
+ onig_foreach_name(RREGEXP_PTR(re), reg_named_captures_iter, (void*)hash);
return hash;
}
@@ -1133,7 +1133,7 @@ match_backref_number(VALUE match, VALUE backref)
break;
}
- num = onig_name_to_backref_number(RREGEXP(regexp)->ptr,
+ num = onig_name_to_backref_number(RREGEXP_PTR(regexp),
(const unsigned char*)name,
(const unsigned char*)name + strlen(name),
regs);
@@ -1384,17 +1384,17 @@ rb_reg_prepare_enc(VALUE re, VALUE str, int warn)
rb_reg_check(re);
enc = rb_enc_get(str);
if (!rb_enc_str_asciicompat_p(str)) {
- if (RREGEXP(re)->ptr->enc != enc) {
+ if (RREGEXP_PTR(re)->enc != enc) {
reg_enc_error(re, str);
}
}
else if (rb_reg_fixed_encoding_p(re)) {
- if (RREGEXP(re)->ptr->enc != enc &&
- (!rb_enc_asciicompat(RREGEXP(re)->ptr->enc) ||
+ if (RREGEXP_PTR(re)->enc != enc &&
+ (!rb_enc_asciicompat(RREGEXP_PTR(re)->enc) ||
rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT)) {
reg_enc_error(re, str);
}
- enc = RREGEXP(re)->ptr->enc;
+ enc = RREGEXP_PTR(re)->enc;
}
if (warn && (RBASIC(re)->flags & REG_ENCODING_NONE) &&
enc != rb_ascii8bit_encoding() &&
@@ -1408,7 +1408,7 @@ rb_reg_prepare_enc(VALUE re, VALUE str, int warn)
regex_t *
rb_reg_prepare_re(VALUE re, VALUE str)
{
- regex_t *reg = RREGEXP(re)->ptr;
+ regex_t *reg = RREGEXP_PTR(re);
onig_errmsg_buffer err = "";
int r;
OnigErrorInfo einfo;
@@ -1420,7 +1420,7 @@ rb_reg_prepare_re(VALUE re, VALUE str)
if (reg->enc == enc) return reg;
rb_reg_check(re);
- reg = RREGEXP(re)->ptr;
+ reg = RREGEXP_PTR(re);
pattern = RREGEXP_SRC_PTR(re);
unescaped = rb_reg_preprocess(
@@ -1492,7 +1492,7 @@ rb_reg_search0(VALUE re, VALUE str, long pos, int reverse, int set_backref_str)
}
reg = rb_reg_prepare_re(re, str);
- tmpreg = reg != RREGEXP(re)->ptr;
+ tmpreg = reg != RREGEXP_PTR(re);
if (!tmpreg) RREGEXP(re)->usecnt++;
match = rb_backref_get();
@@ -1522,8 +1522,8 @@ rb_reg_search0(VALUE re, VALUE str, long pos, int reverse, int set_backref_str)
onig_free(reg);
}
else {
- onig_free(RREGEXP(re)->ptr);
- RREGEXP(re)->ptr = reg;
+ onig_free(RREGEXP_PTR(re));
+ RREGEXP_PTR(re) = reg;
}
}
if (result < 0) {
@@ -1797,7 +1797,7 @@ match_captures(VALUE match)
static int
name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end)
{
- return onig_name_to_backref_number(RREGEXP(regexp)->ptr,
+ return onig_name_to_backref_number(RREGEXP_PTR(regexp),
(const unsigned char* )name, (const unsigned char* )name_end, regs);
}
@@ -1861,7 +1861,7 @@ match_aref(int argc, VALUE *argv, VALUE match)
case T_STRING:
p = StringValuePtr(idx);
re = RMATCH(match)->regexp;
- if (NIL_P(re) || !rb_enc_compatible(RREGEXP(re)->src, idx) ||
+ if (NIL_P(re) || !rb_enc_compatible(RREGEXP_SRC(re), idx) ||
(num = name_to_backref_number(RMATCH_REGS(match), RMATCH(match)->regexp,
p, p + RSTRING_LEN(idx))) < 1) {
name_to_backref_error(idx);
@@ -2010,7 +2010,7 @@ match_inspect(VALUE match)
names = ALLOCA_N(struct backref_name_tag, num_regs);
MEMZERO(names, struct backref_name_tag, num_regs);
- onig_foreach_name(RREGEXP(regexp)->ptr,
+ onig_foreach_name(RREGEXP_PTR(regexp),
match_inspect_name_iter, names);
str = rb_str_buf_new2("#<");
@@ -2714,7 +2714,7 @@ reg_hash(VALUE re)
st_index_t hashval;
rb_reg_check(re);
- hashval = RREGEXP(re)->ptr->options;
+ hashval = RREGEXP_PTR(re)->options;
hashval = rb_hash_uint(hashval, rb_memhash(RREGEXP_SRC_PTR(re), RREGEXP_SRC_LEN(re)));
return rb_hash_end(hashval);
}
@@ -2742,7 +2742,7 @@ rb_reg_equal(VALUE re1, VALUE re2)
if (!RB_TYPE_P(re2, T_REGEXP)) return Qfalse;
rb_reg_check(re1); rb_reg_check(re2);
if (FL_TEST(re1, KCODE_FIXED) != FL_TEST(re2, KCODE_FIXED)) return Qfalse;
- if (RREGEXP(re1)->ptr->options != RREGEXP(re2)->ptr->options) return Qfalse;
+ if (RREGEXP_PTR(re1)->options != RREGEXP_PTR(re2)->options) return Qfalse;
if (RREGEXP_SRC_LEN(re1) != RREGEXP_SRC_LEN(re2)) return Qfalse;
if (ENCODING_GET(re1) != ENCODING_GET(re2)) return Qfalse;
if (memcmp(RREGEXP_SRC_PTR(re1), RREGEXP_SRC_PTR(re2), RREGEXP_SRC_LEN(re1)) == 0) {
@@ -3229,7 +3229,7 @@ rb_reg_options(VALUE re)
int options;
rb_reg_check(re);
- options = RREGEXP(re)->ptr->options & ARG_REG_OPTION_MASK;
+ options = RREGEXP_PTR(re)->options & ARG_REG_OPTION_MASK;
if (RBASIC(re)->flags & KCODE_FIXED) options |= ARG_ENCODING_FIXED;
if (RBASIC(re)->flags & REG_ENCODING_NONE) options |= ARG_ENCODING_NONE;
return options;
@@ -3474,7 +3474,7 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
switch (c) {
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
- if (!NIL_P(regexp) && onig_noname_group_capture_is_active(RREGEXP(regexp)->ptr)) {
+ if (!NIL_P(regexp) && onig_noname_group_capture_is_active(RREGEXP_PTR(regexp))) {
no = c - '0';
}
else {
@@ -3495,7 +3495,7 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
if (name_end < e) {
VALUE n = rb_str_subseq(str, (long)(name - RSTRING_PTR(str)),
(long)(name_end - name));
- if (!rb_enc_compatible(RREGEXP(regexp)->src, n) ||
+ if (!rb_enc_compatible(RREGEXP_SRC(regexp), n) ||
(no = name_to_backref_number(regs, regexp, name, name_end)) < 1) {
name_to_backref_error(n);
}
diff --git a/string.c b/string.c
index b499fa2..7af14c8 100644
--- a/string.c
+++ b/string.c
@@ -3239,7 +3239,7 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos,
enc, single_byte_optimizable(str));
- if (!RREGEXP(sub)->ptr || RREGEXP_SRC_LEN(sub)) {
+ if (!RREGEXP_PTR(sub) || RREGEXP_SRC_LEN(sub)) {
pos = rb_reg_search(sub, str, pos, 1);
pos = rb_str_sublen(str, pos);
}