1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
naruse 2016-02-02 04:39:44 +00:00
parent 7373320615
commit 21daa56b2a
7 changed files with 52 additions and 35 deletions

View file

@ -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

View file

@ -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;

4
gc.c
View file

@ -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:

View file

@ -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)

View file

@ -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;

52
re.c
View file

@ -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);
}

View file

@ -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);
}