Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Regex class: fix build error and, modify default enable. #454

Closed
wants to merge 2 commits into from

1 participant

@ghost
  • fix build error.
  • implement method
    • ::new
    • #match
  • add enc/ascii.c file from oniguruma-5.9.2
  • but Regex literal doesn't yet support.

Sample code:

puts "### Sample.1 ###"
str = "this is regexp"
rp = Regexp.new("^this is regexp")
p str == str # => true
p rp.match(str) # => #<MatchData "this is regexp">
p Regexp.last_match[0] #=> "this is regexp"

puts ""
puts "### Sample.2 ###"
str = "THIS IS REGEXP"
t1 = Regexp.compile("^this is regexp", Regexp::IGNORECASE)
t = t1.match(str)
puts t # => THIS IS REGEXP
Kouki Ooyatsu added some commits
Kouki Ooyatsu Regex class: fix build error and, modify default enable.
* fix build error.
* implement method
  - ::new
  - #match
* add enc/ascii.c file from oniguruma-5.9.2
3d9e36e
Kouki Ooyatsu Including src/ext/enc directory at build. 824e8eb
@mauceri

Hi Kouki, it would be great your work is merged on the main branch!

@mauceri

It is important I believe to merge this branch because one can keep

 #define DISABLE_REGEXP         /* regular expression classes */

in the settings. It is painful to merge by hand this branch in order to keep on track with the main branch.

@ghost

Hi, mauceri.
Thank you for your comment.

It is important I believe to merge this branch because one can keep

 #define DISABLE_REGEXP         /* regular expression classes */
in the settings. It is painful to merge by hand this branch in order to keep on track with the main branch.

I think so too. but I will close this pull-req is so old.
please refer to #719. (thank you @mattn)

@ghost ghost closed this
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 6, 2012
  1. Regex class: fix build error and, modify default enable.

    Kouki Ooyatsu authored
    * fix build error.
    * implement method
      - ::new
      - #match
    * add enc/ascii.c file from oniguruma-5.9.2
  2. Including src/ext/enc directory at build.

    Kouki Ooyatsu authored
This page is out of date. Refresh to see the latest.
View
4 include/mrbconf.h
@@ -41,13 +41,15 @@
//#define POOL_PAGE_SIZE 16000
/* -DDISABLE_XXXX to drop the feature */
-#define DISABLE_REGEXP /* regular expression classes */
+//#define DISABLE_REGEXP /* regular expression classes */
//#define DISABLE_SPRINTF /* Kernel.sprintf method */
//#define DISABLE_MATH /* Math functions */
//#define DISABLE_TIME /* Time class */
//#define DISABLE_STRUCT /* Struct class */
//#define DISABLE_STDIO /* use of stdio */
+#define INCLUDE_ENCODING
+
#undef HAVE_UNISTD_H /* WINDOWS */
#define HAVE_UNISTD_H /* LINUX */
View
6 include/mruby.h
@@ -107,6 +107,10 @@ typedef struct mrb_state {
struct RClass *nil_class;
struct RClass *symbol_class;
struct RClass *kernel_module;
+#ifdef ENABLE_REGEXP
+ struct RClass *regex_class;
+ struct RClass *match_class;
+#endif
struct heap_page *heaps;
struct heap_page *sweeps;
@@ -128,7 +132,7 @@ typedef struct mrb_state {
mrb_sym symidx;
struct kh_n2s *name2sym; /* symbol table */
-#ifdef INCLUDE_REGEXP
+#ifdef ENABLE_REGEXP
struct RNode *local_svar;/* regexp */
#endif
View
8 include/mruby/class.h
@@ -44,10 +44,12 @@ mrb_class(mrb_state *mrb, mrb_value v)
#ifdef ENABLE_REGEXP
case MRB_TT_REGEX:
+ /* mrb_raise(mrb, E_TYPE_ERROR, "type mismatch: %s given",
+ mrb_obj_classname(mrb, v)); */
+ /* return mrb->nil_class; */ /* not reach */
+ return mrb->regex_class;
case MRB_TT_MATCH:
- mrb_raise(mrb, E_TYPE_ERROR, "type mismatch: %s given",
- mrb_obj_classname(mrb, v));
- return mrb->nil_class; /* not reach */
+ return mrb->match_class;
#endif
default:
return mrb_object(v)->c;
View
5 include/mruby/string.h
@@ -83,6 +83,11 @@ mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2);
int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2);
+#ifdef ENABLE_REGEXP
+mrb_value mrb_str_subseq(mrb_state *mrb, mrb_value str, int beg, int len);
+mrb_value mrb_str_size(mrb_state *mrb, mrb_value self);
+#endif
+
#if defined(__cplusplus)
} /* extern "C" { */
#endif
View
2  src/Makefile
@@ -13,7 +13,7 @@ EXCEPT1 := $(YC) $(BASEDIR)/minimain.c
OBJY := $(patsubst %.c,%.o,$(YC))
OBJ1 := $(patsubst %.c,%.o,$(filter-out $(EXCEPT1),$(wildcard $(BASEDIR)/*.c)))
#OBJ2 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/ext/regex/*.c))
-#OBJ3 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/ext/enc/*.c))
+OBJ3 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/ext/enc/*.c))
OBJS := $(OBJ1) $(OBJ2) $(OBJ3)
# libraries, includes
View
58 src/ext/enc/ascii.c
@@ -0,0 +1,58 @@
+/**********************************************************************
+ ascii.c - Oniguruma (regular expression library)
+**********************************************************************/
+/*-
+ * Copyright (c) 2002-2006 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "regenc.h"
+
+static int
+ascii_is_code_ctype(OnigCodePoint code, unsigned int ctype)
+{
+ if (code < 128)
+ return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);
+ else
+ return 0; /* return FALSE; */
+}
+
+OnigEncodingType OnigEncodingASCII = {
+ onigenc_single_byte_mbc_enc_len,
+ "US-ASCII", /* name */
+ 1, /* max byte length */
+ 1, /* min byte length */
+ onigenc_is_mbc_newline_0x0a,
+ onigenc_single_byte_mbc_to_code,
+ onigenc_single_byte_code_to_mbclen,
+ onigenc_single_byte_code_to_mbc,
+ onigenc_ascii_mbc_case_fold,
+ onigenc_ascii_apply_all_case_fold,
+ onigenc_ascii_get_case_fold_codes_by_str,
+ onigenc_minimum_property_name_to_ctype,
+ ascii_is_code_ctype,
+ onigenc_not_support_get_ctype_code_range,
+ onigenc_single_byte_left_adjust_char_head,
+ onigenc_always_true_is_allowed_reverse_match
+};
View
3  src/load.c
@@ -329,6 +329,9 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32
mrb_int fix_num;
mrb_float f;
int ai = mrb_gc_arena_save(mrb);
+#ifdef ENABLE_REGEXP
+ mrb_value str;
+#endif
recordStart = src;
buf = (char *)mrb_malloc(mrb, bufsize);
View
263 src/re.c
@@ -15,10 +15,38 @@
#include "error.h"
#ifdef ENABLE_REGEXP
+typedef int ID;
+struct RNode {
+ mrb_value flags;
+ mrb_value nd_reserved; /* ex nd_file */
+ union {
+ struct RNode *node;
+ ID id;
+ mrb_value value;
+ mrb_value (*cfunc)(ANYARGS);
+ ID *tbl;
+ } u1;
+ union {
+ struct RNode *node;
+ ID id;
+ long argc;
+ mrb_value value;
+ } u2;
+ union {
+ struct RNode *node;
+ ID id;
+ long state;
+ struct rb_global_entry *entry;
+ long cnt;
+ mrb_value value;
+ } u3;
+};
+
#define REGEX_CLASS (mrb_class_obj_get(mrb, "Regexp"))
#define MATCH_CLASS (mrb_class_obj_get(mrb, "MatchData"))
+#define MATCH_BUSY FL_USER2
-//from opcode.h
+/* from opcode.h */
#define GETARG_A(i) ((((mrb_code)(i)) >> 24) & 0xff)
#define GETARG_B(i) ((((mrb_code)(i)) >> 16) & 0xff)
#define GETARG_C(i) ((((mrb_code)(i)) >> 8) & 0xff)
@@ -63,9 +91,9 @@ static char * option_to_str(char str[4], int options);
*
*/
mrb_value
-mrb_reg_s_new_instance(mrb_state *mrb, /*int argc, mrb_value *argv, */mrb_value self)
+mrb_reg_s_new_instance(mrb_state *mrb, mrb_value self)
{
- mrb_value argv[16];
+ mrb_value *argv;
int argc;
struct RRegexp *re;
@@ -167,7 +195,6 @@ static mrb_value
reg_operand(mrb_state *mrb, mrb_value s, int check)
{
if (mrb_type(s) == MRB_TT_SYMBOL) {
- //return mrb_sym_to_s(s);
return mrb_obj_inspect(mrb, s);
}
else {
@@ -196,7 +223,7 @@ reg_operand(mrb_state *mrb, mrb_value s, int check)
*/
static mrb_value
-mrb_reg_s_quote(mrb_state *mrb, mrb_value c/*, mrb_value str*/)
+mrb_reg_s_quote(mrb_state *mrb, mrb_value c)
{
mrb_value str;
@@ -264,7 +291,6 @@ match_backref_number(mrb_state *mrb, mrb_value match, mrb_value backref)
break;
case MRB_TT_STRING:
- //name = StringValueCStr(backref);
name = mrb_string_value_cstr(mrb, &backref);
break;
}
@@ -305,14 +331,12 @@ match_backref_number(mrb_state *mrb, mrb_value match, mrb_value backref)
* Regexp.last_match(:rhs) #=> "val"
*/
static mrb_value
-mrb_reg_s_last_match(mrb_state *mrb, mrb_value self/*int argc, mrb_value *argv*/)
+mrb_reg_s_last_match(mrb_state *mrb, mrb_value self)
{
- //mrb_value nth;
- mrb_value argv[16];
+ mrb_value *argv;
int argc;
mrb_value match = mrb_backref_get(mrb);
- //if (argc > 0 && mrb_scan_args(argc, argv, "01", &nth) == 1) {
mrb_get_args(mrb, "*", &argv, &argc);
if (argc != 0) {
int n;
@@ -320,15 +344,12 @@ mrb_reg_s_last_match(mrb_state *mrb, mrb_value self/*int argc, mrb_value *argv*/
n = match_backref_number(mrb, match, argv[0]);
return mrb_reg_nth_match(mrb, n, match);
}
- return match;//match_getter();
+ return match;
}
static void
mrb_reg_check(mrb_state *mrb, mrb_value re)
{
- //struct RRegexp *r = mrb_regex_ptr(re);
-
- //if (!(RREGEXP(re)->ptr) || !RREGEXP_SRC(re) || !RREGEXP_SRC_PTR(re)) {
if (!(RREGEXP(re)->ptr)) {
mrb_raise(mrb, E_TYPE_ERROR, "uninitialized Regexp");
}
@@ -356,11 +377,11 @@ mrb_reg_desc(mrb_state *mrb, const char *s, long len, mrb_value re)
mrb_reg_expr_str(mrb, str, s, len);
mrb_str_buf_cat(mrb, str, "/", 1);
- if (re.tt) {
+ if (mrb_type(re)) {
char opts[4];
mrb_reg_check(mrb, re);
if (*option_to_str(opts, RREGEXP(re)->ptr->options))
- mrb_str_buf_cat(mrb, str, opts, strlen(opts));//mrb_str_buf_cat2(str, opts);
+ mrb_str_buf_cat(mrb, str, opts, strlen(opts));
if (RBASIC(re)->flags & REG_ENCODING_NONE)
mrb_str_buf_cat(mrb, str, "n", 1);
}
@@ -384,7 +405,7 @@ mrb_reg_prepare_re(mrb_state *mrb, mrb_value re, mrb_value str)
OnigErrorInfo einfo;
const char *pattern;
mrb_value unescaped;
- mrb_encoding *enc = mrb_ascii8bit_encoding(mrb);
+ mrb_encoding *enc = ONIG_ENCODING_ASCII; /* mrb_ascii8bit_encoding(mrb); */
mrb_reg_check(mrb, re);
reg = RREGEXP(re)->ptr;
@@ -432,18 +453,17 @@ mrb_reg_search(mrb_state *mrb, mrb_value re, mrb_value str, mrb_int pos, mrb_int
match = mrb_backref_get(mrb);
if (!mrb_nil_p(match)) {
- /*if (FL_TEST(match, MATCH_BUSY)) {
- match = Qnil;
+ if (FL_TEST(match, MATCH_BUSY)) {
+ match = mrb_nil_value();
}
else {
regs = RMATCH_REGS(match);
- }*/
- regs = RMATCH_REGS(match);
+ }
}
if (mrb_nil_p(match)) {
memset(regs, 0, sizeof(struct re_registers));
}
-//-->
+
if (!reverse) {
range += RSTRING_LEN(str);
}
@@ -476,14 +496,14 @@ mrb_reg_search(mrb_state *mrb, mrb_value re, mrb_value str, mrb_int pos, mrb_int
mrb_reg_raise(mrb, RREGEXP_SRC_PTR(re), RREGEXP_SRC_LEN(re), err, re);
}
}
-//--<
+
if (mrb_nil_p(match) ) {
match = match_alloc(mrb);
onig_region_copy(RMATCH_REGS(match), regs);
onig_region_free(regs, 0);
}
- RMATCH(match)->str = mrb_str_ptr(str);
+ RMATCH(match)->str = RSTRING(mrb_str_new2(mrb, RSTRING(str)->ptr));
RMATCH(match)->regexp = mrb_regex_ptr(re);
RMATCH(match)->rmatch->char_offset_updated = 0;
mrb_backref_set(mrb, match);
@@ -513,7 +533,7 @@ mrb_reg_adjust_startpos(mrb_state *mrb, mrb_value re, mrb_value str, mrb_int pos
range = s->len - pos;
}
return re_adjust_startpos(r->ptr,
- s->buf, s->len,
+ s->ptr, s->len,
pos, range);
}
@@ -524,7 +544,7 @@ onig_new_with_source(regex_t** reg, const UChar* pattern, const UChar* pattern_e
{
int r;
- *reg = (regex_t* )malloc/*xmalloc*/(sizeof(regex_t));
+ *reg = (regex_t* )malloc(sizeof(regex_t));
if ((void*)(*reg) == (void*)0) return ONIGERR_MEMORY;
r = onig_reg_init(*reg, option, ONIGENC_CASE_FOLD_DEFAULT, enc, syntax);
@@ -644,7 +664,33 @@ ruby_scan_oct(const char *start, size_t len, size_t *retlen)
static mrb_value
mrb_reg_preprocess(mrb_state *mrb, const char *p, const char *end, onig_errmsg_buffer err)
{
- return mrb_nil_value();
+ mrb_value buf;
+
+ buf = mrb_str_new2(mrb, p);
+ /* XXX: NOT IMPLEMENTED yet */
+ /*
+ int has_property = 0;
+ if (mrb_enc_asciicompat(mrb, enc))
+ *fixed_enc = 0;
+ else {
+ *fixed_enc = enc;
+ mrb_enc_associate(mrb, buf, enc);
+ }
+
+ if (unescape_nonascii(mrb, p, end, enc, buf, fixed_enc, &has_property, err) != 0) {
+ return mrb_nil_value();
+ }
+
+ if (has_property && !*fixed_enc) {
+ *fixed_enc = enc;
+ }
+
+ if (*fixed_enc) {
+ mrb_enc_associate(mrb, buf, *fixed_enc);
+ }
+ */
+
+ return buf;
}
static int
@@ -654,7 +700,7 @@ mrb_reg_initialize(mrb_state *mrb, mrb_value obj, const char *s, long len,
{
struct RRegexp *re = RREGEXP(obj);
mrb_value unescaped;
- mrb_encoding *enc = mrb_ascii8bit_encoding(mrb);
+ mrb_encoding *enc = ONIG_ENCODING_ASCII; /* mrb_ascii8bit_encoding(mrb);*/
if (re->ptr)
mrb_raise(mrb, E_TYPE_ERROR, "already initialized regexp");
re->ptr = 0;
@@ -664,7 +710,6 @@ mrb_reg_initialize(mrb_state *mrb, mrb_value obj, const char *s, long len,
return -1;
if ((options & ARG_ENCODING_FIXED)) {
- //re->basic.flags |= KCODE_FIXED;
re->flags|= KCODE_FIXED;
}
if (options & ARG_ENCODING_NONE) {
@@ -729,9 +774,9 @@ mrb_reg_initialize_str(mrb_state *mrb, mrb_value obj, mrb_value str, int options
*/
static mrb_value
-mrb_reg_initialize_m(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value self)
+mrb_reg_initialize_m(mrb_state *mrb, mrb_value self)
{
- mrb_value argv[16];
+ mrb_value *argv;
int argc;
onig_errmsg_buffer err = "";
int flags = 0;
@@ -747,8 +792,7 @@ mrb_reg_initialize_m(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value se
mrb_value re = argv[0];
if (argc > 1) {
- /* mrb_warn("flags ignored"); */
- printf("flags ignored");
+ printf("flags ignored"); /* XXX: need mrb_warn */
}
mrb_reg_check(mrb, re);
flags = mrb_reg_options(mrb, re);
@@ -764,21 +808,18 @@ mrb_reg_initialize_m(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value se
else if (mrb_test(argv[1])) flags = ONIG_OPTION_IGNORECASE;
}
if (argc == 3 && !mrb_nil_p(argv[2])) {
- //char *kcode = StringValuePtr(argv[2]);
char *kcode = mrb_string_value_ptr(mrb, argv[2]);
if (kcode[0] == 'n' || kcode[0] == 'N') {
flags |= ARG_ENCODING_NONE;
}
else {
- /*mrb_warn("encoding option is ignored - %s", kcode); */
- printf("mrb_warn:encoding option is ignored - %s", kcode);
+ printf("mrb_warn:encoding option is ignored - %s", kcode); /* XXX: need mrb_warn */
}
}
str = argv[0];
- //ptr = StringValuePtr(str);
ptr = mrb_string_value_ptr(mrb, str);
if (mrb_reg_initialize_str(mrb, self, str, flags, err, NULL, 0)) {
- //mrb_reg_raise_str(str, flags, err);
+ printf("mrb_reg_raise_str(s, options, err);"); /* XXX: need mrb_reg_raise_str() */
}
}
return self;
@@ -787,7 +828,7 @@ mrb_reg_initialize_m(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value se
/* 15.2.15.7.2 */
/* :nodoc: */
static mrb_value
-mrb_reg_init_copy(mrb_state *mrb, mrb_value re/*, mrb_value copy*/)
+mrb_reg_init_copy(mrb_state *mrb, mrb_value re)
{
mrb_value argv[16];
int argc;
@@ -851,7 +892,7 @@ mrb_reg_equal(mrb_state *mrb, mrb_value re1, mrb_value re2)
*/
static mrb_value
-mrb_reg_equal_m(mrb_state *mrb, mrb_value re1/*, mrb_value re2*/)
+mrb_reg_equal_m(mrb_state *mrb, mrb_value re1)
{
mrb_value re2;
@@ -881,7 +922,7 @@ mrb_reg_equal_m(mrb_state *mrb, mrb_value re1/*, mrb_value re2*/)
*/
mrb_value
-mrb_reg_eqq(mrb_state *mrb, mrb_value re/*, mrb_value str*/)
+mrb_reg_eqq(mrb_state *mrb, mrb_value re)
{
long start;
mrb_value str;
@@ -979,7 +1020,7 @@ mrb_reg_match_str(mrb_state *mrb, mrb_value re, mrb_value str)
*
*/
mrb_value
-mrb_reg_match(mrb_state *mrb, mrb_value re/*, mrb_value str*/)
+mrb_reg_match(mrb_state *mrb, mrb_value re)
{
mrb_value str;
@@ -1037,14 +1078,13 @@ mrb_reg_casefold_p(mrb_state *mrb, mrb_value re)
*/
static mrb_value
-mrb_reg_match_m(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value re)
+mrb_reg_match_m(mrb_state *mrb, mrb_value re)
{
- mrb_value argv[16];
+ mrb_value *argv;
int argc;
mrb_value result, str, initpos, b;
long pos;
- //if (mrb_scan_args(argc, argv, "11", &str, &initpos) == 2) {
mrb_get_args(mrb, "*&", &argv, &argc, &b);
if (argc == 2) {
initpos = argv[1];
@@ -1061,9 +1101,11 @@ mrb_reg_match_m(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value re)
}
result = mrb_backref_get(mrb);
/*mrb_match_busy(result);*/
+ FL_SET(result, MATCH_BUSY); /* XXX */
if (!mrb_nil_p(result) && mrb_block_given_p()) {
return mrb_yield(mrb, result, b);
}
+
return result;
}
@@ -1104,7 +1146,7 @@ name_to_backref_number(mrb_state *mrb, struct re_registers *regs, struct RRegexp
return num;
}
else {
- mrb_value s = mrb_str_new(mrb, name, (long )(name_end - name));//mrb_str_new(name, (long )(name_end - name));
+ mrb_value s = mrb_str_new(mrb, name, (long )(name_end - name));
mrb_raise(mrb, E_INDEX_ERROR, "undefined group name reference: %s",
mrb_string_value_ptr(mrb, s));
return num; /* not reach */
@@ -1133,7 +1175,7 @@ match_alloc(mrb_state *mrb)
m->str = 0;
m->rmatch = 0;
m->regexp = 0;
- m->rmatch = mrb_malloc(mrb, sizeof(struct rmatch));//ALLOC(struct rmatch);
+ m->rmatch = mrb_malloc(mrb, sizeof(struct rmatch));
memset(m->rmatch, 0, sizeof(struct rmatch));
return mrb_obj_value(m);
@@ -1170,14 +1212,13 @@ match_alloc(mrb_state *mrb)
*/
static mrb_value
-mrb_match_aref(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value match)
+mrb_match_aref(mrb_state *mrb, mrb_value match)
{
- mrb_value argv[16];
+ mrb_value *argv;
int argc;
mrb_value idx;
match_check(mrb, match);
- //mrb_scan_args(argc, argv, "11", &idx, &rest);
mrb_get_args(mrb, "*", &argv, &argc);
idx = argv[0];
if (argc<2) {
@@ -1192,12 +1233,10 @@ mrb_match_aref(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value match)
switch (mrb_type(idx)) {
case MRB_TT_SYMBOL:
- //p = mrb_id2name(SYM2ID(idx));
p = mrb_sym2name(mrb, SYM2ID(idx));
goto name_to_backref;
break;
case MRB_TT_STRING:
- //p = StringValuePtr(idx);
p = mrb_string_value_ptr(mrb, idx);
name_to_backref:
num = name_to_backref_number(mrb, RMATCH_REGS(match),
@@ -1210,7 +1249,7 @@ mrb_match_aref(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value match)
}
}
- return mrb_ary_aget(mrb, /*argc, argv,*/ mrb_match_to_a(mrb, match));
+ return mrb_ary_aget(mrb, mrb_match_to_a(mrb, match));
}
typedef struct {
@@ -1232,7 +1271,6 @@ update_char_offset(mrb_state *mrb, mrb_value match)
num_regs = rm->regs.num_regs;
if (rm->char_offset_num_allocated < num_regs) {
- //REALLOC_N(rm->char_offset, struct rmatch_offset, num_regs);
rm->char_offset = mrb_realloc(mrb, rm->char_offset, sizeof(struct rmatch_offset)*num_regs);
rm->char_offset_num_allocated = num_regs;
}
@@ -1264,7 +1302,7 @@ update_char_offset(mrb_state *mrb, mrb_value match)
*/
static mrb_value
-mrb_match_begin(mrb_state *mrb, mrb_value match/*, mrb_value n*/)
+mrb_match_begin(mrb_state *mrb, mrb_value match)
{
mrb_value argv[16];
int argc;
@@ -1298,7 +1336,7 @@ match_array(mrb_state *mrb, mrb_value match, int start)
match_check(mrb, match);
regs = RMATCH_REGS(match);
- ary = mrb_ary_new_capa(mrb, regs->num_regs);//mrb_ary_new2(regs->num_regs);
+ ary = mrb_ary_new_capa(mrb, regs->num_regs);
target = RMATCH(match)->str;
for (i=start; i<regs->num_regs; i++) {
@@ -1351,7 +1389,7 @@ mrb_match_captures(mrb_state *mrb, mrb_value match)
*/
static mrb_value
-mrb_match_end(mrb_state *mrb, mrb_value match/*, mrb_value n*/)
+mrb_match_end(mrb_state *mrb, mrb_value match)
{
mrb_value argv[16];
int argc;
@@ -1378,7 +1416,7 @@ mrb_match_end(mrb_state *mrb, mrb_value match/*, mrb_value n*/)
/* 15.2.16.3.5 */
/* :nodoc: */
static mrb_value
-mrb_match_init_copy(mrb_state *mrb, mrb_value obj/*, mrb_value orig*/)
+mrb_match_init_copy(mrb_state *mrb, mrb_value obj)
{
mrb_value argv[16];
int argc;
@@ -1398,7 +1436,7 @@ mrb_match_init_copy(mrb_state *mrb, mrb_value obj/*, mrb_value orig*/)
RMATCH(obj)->regexp = RMATCH(orig)->regexp;
if (RMATCH(obj)->rmatch == 0) {
- RMATCH(obj)->rmatch = mrb_malloc(mrb, sizeof(struct rmatch));//ALLOC(struct rmatch);
+ RMATCH(obj)->rmatch = mrb_malloc(mrb, sizeof(struct rmatch));
memset(RMATCH(obj)->rmatch, 0, sizeof(struct rmatch));
}
rm = RMATCH(obj)->rmatch;
@@ -1409,7 +1447,6 @@ mrb_match_init_copy(mrb_state *mrb, mrb_value obj/*, mrb_value orig*/)
}
else {
if (rm->char_offset_num_allocated < rm->regs.num_regs) {
- //REALLOC_N(rm->char_offset, struct rmatch_offset, rm->regs.num_regs);
rm->char_offset = mrb_realloc(mrb, rm->char_offset, sizeof(struct rmatch_offset)* rm->regs.num_regs);
rm->char_offset_num_allocated = rm->regs.num_regs;
}
@@ -1462,7 +1499,7 @@ mrb_match_size(mrb_state *mrb, mrb_value match)
*/
static mrb_value
-mrb_match_offset(mrb_state *mrb, mrb_value match/*, mrb_value n*/)
+mrb_match_offset(mrb_state *mrb, mrb_value match)
{
mrb_value n;
struct re_registers *regs = RMATCH_REGS(match);
@@ -1601,7 +1638,7 @@ mrb_match_to_s(mrb_state *mrb, mrb_value match)
mrb_value str = mrb_reg_last_match(mrb, match);
match_check(mrb, match);
- if (mrb_nil_p(str)) str = mrb_str_new(mrb, 0, 0);//mrb_str_new(0,0);
+ if (mrb_nil_p(str)) str = mrb_str_new(mrb, 0, 0);
return str;
}
@@ -1729,7 +1766,7 @@ mrb_reg_to_s(mrb_state *mrb, mrb_value re)
const UChar* ptr;
mrb_value str = mrb_str_new(mrb, "(?", 2);
char optbuf[5];
- mrb_encoding *enc = mrb_enc_get(mrb, re);
+ mrb_encoding *enc = ONIG_ENCODING_ASCII; /* mrb_enc_get(mrb, re); */
mrb_reg_check(mrb, re);
memset(optbuf, 0, 5);
@@ -1829,8 +1866,6 @@ mrb_reg_s_alloc(mrb_state *mrb, mrb_value dummy)
{
struct RRegexp* re;
- //NEWOBJ(re, struct RRegexp);
- //OBJSETUP(re, klass, T_REGEXP);
re = (struct RRegexp*)mrb_obj_alloc(mrb, MRB_TT_REGEX, REGEX_CLASS);
re->ptr = 0;
@@ -1909,8 +1944,6 @@ mrb_match_inspect(mrb_state *mrb, mrb_value match)
return mrb_sprintf(mrb, "#<%s:%p>", cname, (void*)&match);
}
- //names = ALLOCA_N(struct backref_name_tag, num_regs);
- //MEMZERO(names, struct backref_name_tag, num_regs);
names = mrb_malloc(mrb, sizeof(struct backref_name_tag)*num_regs);
memset(names, 0, sizeof(struct backref_name_tag)*num_regs);
@@ -2001,14 +2034,13 @@ void
mrb_init_regexp(mrb_state *mrb)
{
struct RClass *s;
- s = mrb_define_class(mrb, "Regexp", mrb->object_class);
+ s = mrb->regex_class = mrb_define_class(mrb, "Regexp", mrb->object_class);
+ MRB_SET_INSTANCE_TT(s, MRB_TT_REGEX);
mrb_define_class_method(mrb, s, "compile", mrb_reg_s_new_instance, ARGS_ANY()); /* 15.2.15.6.1 */
mrb_define_class_method(mrb, s, "escape", mrb_reg_s_quote, ARGS_REQ(1)); /* 15.2.15.6.2 */
mrb_define_class_method(mrb, s, "last_match", mrb_reg_s_last_match, ARGS_ANY()); /* 15.2.15.6.3 */
mrb_define_class_method(mrb, s, "quote", mrb_reg_s_quote, ARGS_REQ(1)); /* 15.2.15.6.4 */
- //mrb_define_singleton_method(rb_cRegexp, "union", rb_reg_s_union_m, -2);
- //mrb_define_singleton_method(rb_cRegexp, "try_convert", rb_reg_s_try_convert, 1);
mrb_define_method(mrb, s, "initialize", mrb_reg_initialize_m, ARGS_ANY()); /* 15.2.15.7.1 */
mrb_define_method(mrb, s, "initialize_copy", mrb_reg_init_copy, ARGS_REQ(1)); /* 15.2.15.7.2 */
@@ -2018,28 +2050,17 @@ mrb_init_regexp(mrb_state *mrb)
mrb_define_method(mrb, s, "casefold?", mrb_reg_casefold_p, ARGS_NONE()); /* 15.2.15.7.6 */
mrb_define_method(mrb, s, "match", mrb_reg_match_m, ARGS_ANY()); /* 15.2.15.7.7 */
mrb_define_method(mrb, s, "source", mrb_reg_source, ARGS_NONE()); /* 15.2.15.7.8 */
- //mrb_define_method(rb_cRegexp, "hash", rb_reg_hash, 0);
- //mrb_define_method(rb_cRegexp, "~", rb_reg_match2, 0);
mrb_define_method(mrb, s, "to_s", mrb_reg_to_s, ARGS_NONE()); /* 15.2.15.7.9 (x) */
mrb_define_method(mrb, s, "inspect", mrb_reg_inspect, ARGS_NONE()); /* 15.2.15.7.10(x) */
mrb_define_method(mrb, s, "eql?", mrb_reg_equal_m, ARGS_REQ(1)); /* 15.2.15.7.11(x) */
- //mrb_define_method(rb_cRegexp, "options", mrb_reg_options_m, 0);
- //mrb_define_method(rb_cRegexp, "encoding", rb_obj_encoding, 0); /* in encoding.c */
- //mrb_define_method(rb_cRegexp, "fixed_encoding?", mrb_reg_fixed_encoding_p, 0);
- //mrb_define_method(rb_cRegexp, "names", rb_reg_names, 0);
- //mrb_define_method(rb_cRegexp, "named_captures", rb_reg_named_captures, 0);
-
- //mrb_define_const(rb_cRegexp, "IGNORECASE", INT2FIX(ONIG_OPTION_IGNORECASE));
- //mrb_define_const(rb_cRegexp, "EXTENDED", INT2FIX(ONIG_OPTION_EXTEND));
- //mrb_define_const(rb_cRegexp, "MULTILINE", INT2FIX(ONIG_OPTION_MULTILINE));
- //mrb_define_const(rb_cRegexp, "FIXEDENCODING", INT2FIX(ARG_ENCODING_FIXED));
+
mrb_define_const(mrb, s, "IGNORECASE", mrb_fixnum_value(ONIG_OPTION_IGNORECASE));
mrb_define_const(mrb, s, "EXTENDED", mrb_fixnum_value(ONIG_OPTION_EXTEND));
mrb_define_const(mrb, s, "MULTILINE", mrb_fixnum_value(ONIG_OPTION_MULTILINE));
mrb_define_const(mrb, s, "FIXEDENCODING", mrb_fixnum_value(ARG_ENCODING_FIXED));
- s = mrb_define_class(mrb, "MatchData", mrb->object_class);
- //mrb_undef_class_method(CLASS_OF(rb_cMatch), "new");
+ s = mrb->match_class = mrb_define_class(mrb, "MatchData", mrb->object_class);
+ mrb_undef_method(mrb, s, "new");
mrb_define_method(mrb, s, "[]", mrb_match_aref, ARGS_ANY()); /* 15.2.16.3.1 */
mrb_define_method(mrb, s, "begin", mrb_match_begin, ARGS_REQ(1)); /* 15.2.16.3.2 */
@@ -2057,11 +2078,6 @@ mrb_init_regexp(mrb_state *mrb)
mrb_define_method(mrb, s, "inspect", mrb_match_inspect, ARGS_NONE()); /* 15.2.16.3.14(x) */
mrb_define_method(mrb, s, "==", mrb_match_equal, ARGS_REQ(1)); /* 15.2.16.3.15(x) */
mrb_define_method(mrb, s, "eql?", mrb_match_equal, ARGS_REQ(1)); /* 15.2.16.3.16(x) */
- //mrb_define_method(rb_cMatch, "regexp", match_regexp, 0);
- //mrb_define_method(rb_cMatch, "names", match_names, 0);
- //mrb_define_method(rb_cMatch, "values_at", match_values_at, -1);
- //mrb_define_method(rb_cMatch, "hash", match_hash, 0);
- //mrb_define_method(rb_cMatch, "==", match_equal, 1);
}
/* ----------------1_8_7---------------------------------------- */
//`mrb_check_type'
@@ -2076,13 +2092,12 @@ mrb_init_regexp(mrb_state *mrb)
mrb_value
mrb_reg_regsub(mrb_state *mrb, mrb_value str, mrb_value src, struct re_registers *regs, mrb_value regexp)
{
- mrb_value val;
+ mrb_value val = mrb_nil_value();
char *p, *s, *e;
struct RString *ps = mrb_str_ptr(str);
int no;
- val.tt = 0;
- p = s = ps->buf;
+ p = s = ps->ptr;
e = s + ps->len;
while (s < e) {
@@ -2098,8 +2113,7 @@ mrb_reg_regsub(mrb_state *mrb, mrb_value str, mrb_value src, struct re_registers
if (c != '\\' || s == e) continue;
- //if (!val) {
- if (!val.tt) {
+ if (!mrb_type(val)) {
val = mrb_str_buf_new(mrb, ss-p);
}
mrb_str_buf_cat(mrb, val, p, ss-p);
@@ -2181,40 +2195,38 @@ mrb_reg_regsub(mrb_state *mrb, mrb_value str, mrb_value src, struct re_registers
if (BEG(no) == -1) continue;
mrb_str_buf_cat(mrb, val, RSTRING_PTR(src)+BEG(no), END(no)-BEG(no));
}
- } /* while (s < e) { */
+ }
- if (!val.tt) return str;
+ if (!mrb_type(val)) return str;
if (p < e) {
mrb_str_buf_cat(mrb, val, p, e-p);
}
return val;
}
-static inline NODE *
-lfp_svar_place(mrb_state *mrb, /*mrb_thread_t *th,*/ mrb_value *lfp)
+static struct RNode *
+lfp_svar_place(mrb_state *mrb, mrb_value *lfp)
{
- NODE *svar;
+ struct RNode *svar;
+ if (lfp) {
+ svar = (struct RNode *)((lfp)->value.p) - 1; /* [-1] */
+ } else {
+ svar = mrb->local_svar;
+ }
- /*if (lfp && th->local_lfp != lfp) {
- svar = &lfp[-1];
+ if (mrb->local_svar == NULL) {
+ mrb->local_svar = (struct RNode *)mrb_malloc(mrb, sizeof(struct RNode)); /* XXX: Need GC */
+ memset(mrb->local_svar, 0, sizeof(struct RNode));
+ svar = mrb->local_svar;
}
- else {
- svar = mrb->&th->local_svar;
- }*/
- svar = mrb->local_svar;
- /*if (mrb_nil_p(*svar)) {
- *svar = mrb_obj_value(NEW_IF(0, 0, 0));
- }*/
- return svar;//(NODE *)((*svar).value.p);
+ return svar;
}
static mrb_value
-lfp_svar_get(mrb_state *mrb, /*mrb_thread_t *th,*/ mrb_value *lfp, mrb_int key)
+lfp_svar_get(mrb_state *mrb, mrb_value *lfp, mrb_int key)
{
- //mrb_value *regs;
- NODE *svar = lfp_svar_place(mrb, /*th,*/ lfp);
- //regs = mrb->stack;
+ struct RNode *svar = lfp_svar_place(mrb, lfp);
switch (key) {
case 0:
@@ -2236,11 +2248,9 @@ lfp_svar_get(mrb_state *mrb, /*mrb_thread_t *th,*/ mrb_value *lfp, mrb_int key)
}
static void
-lfp_svar_set(mrb_state *mrb, /*mrb_thread_t *th,*/ mrb_value *lfp, mrb_int key, mrb_value val)
+lfp_svar_set(mrb_state *mrb, mrb_value *lfp, mrb_int key, mrb_value val)
{
- //mrb_value *regs;
- NODE *svar = lfp_svar_place(mrb, /*th,*/ lfp);
- //regs = mrb->stack;
+ struct RNode *svar = lfp_svar_place(mrb, lfp);
switch (key) {
case 0:
@@ -2263,31 +2273,27 @@ lfp_svar_set(mrb_state *mrb, /*mrb_thread_t *th,*/ mrb_value *lfp, mrb_int key,
}
static mrb_value
-vm_cfp_svar_get(mrb_state *mrb, /*mrb_thread_t *th, mrb_control_frame_t *cfp,*/ mrb_int key)
+vm_cfp_svar_get(mrb_state *mrb, mrb_int key)
{
- //cfp = vm_normal_frame(th, cfp);
- return lfp_svar_get(mrb, /*th, cfp ? cfp->lfp :*/ 0, key);
+ return lfp_svar_get(mrb, 0, key);
}
static void
-vm_cfp_svar_set(mrb_state *mrb, /*mrb_thread_t *th, mrb_control_frame_t *cfp,*/ mrb_int key, const mrb_value val)
+vm_cfp_svar_set(mrb_state *mrb, mrb_int key, const mrb_value val)
{
- //cfp = vm_normal_frame(th, cfp);
- lfp_svar_set(mrb, /*th, cfp ? cfp->lfp : */0, key, val);
+ lfp_svar_set(mrb, 0, key, val);
}
static mrb_value
vm_svar_get(mrb_state *mrb, mrb_int key)
{
- //mrb_thread_t *th = GET_THREAD();
- return vm_cfp_svar_get(mrb,/*th, th->cfp,*/ key);
+ return vm_cfp_svar_get(mrb, key);
}
static void
vm_svar_set(mrb_state *mrb, mrb_int key, mrb_value val)
{
- //mrb_thread_t *th = GET_THREAD();
- vm_cfp_svar_set(mrb,/*th, th->cfp,*/ key, val);
+ vm_cfp_svar_set(mrb, key, val);
}
@@ -2418,8 +2424,7 @@ mrb_reg_init_str(mrb_state *mrb, mrb_value re, mrb_value s, int options)
onig_errmsg_buffer err = "";
if (mrb_reg_initialize_str(mrb, re, s, options, err, NULL, 0) != 0) {
- //mrb_reg_raise_str(s, options, err);
- printf("mrb_reg_raise_str(s, options, err);");
+ printf("mrb_reg_raise_str(s, options, err);"); /* XXX: need mrb_reg_raise_str() */
}
return re;
View
7 src/re.h
@@ -7,7 +7,6 @@
#ifndef RE_H
#define RE_H
-//#include <sys/types.h>
#include <stdio.h>
#include "node.h"
@@ -48,13 +47,12 @@ struct RRegexp {
#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) (RREGEXP_SRC(r)->buf)
+#define RREGEXP_SRC_PTR(r) (RREGEXP_SRC(r)->ptr)
#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;
-//#define RMATCH(obj) (R_CAST(RMatch)(obj))
#define RMATCH_REGS(v) (&((struct RMatch*)((v).value.p))->rmatch->regs)
#define RMATCH(v) ((struct RMatch*)((v).value.p))
#define mrb_match_ptr(v) ((struct RMatch*)((v).value.p))
@@ -63,7 +61,6 @@ int mrb_memcmp(const void *p1, const void *p2, int len);
mrb_int mrb_reg_search (mrb_state *mrb, mrb_value, mrb_value, mrb_int, mrb_int);
mrb_value mrb_reg_regsub (mrb_state *mrb, mrb_value, mrb_value, struct re_registers *, mrb_value);
-//mrb_value mrb_reg_regsub(mrb_value, mrb_value, struct re_registers *, mrb_value);
mrb_int mrb_reg_adjust_startpos(mrb_state *mrb, mrb_value re, mrb_value str, mrb_int pos, mrb_int reverse);
void mrb_match_busy (mrb_value);
@@ -72,10 +69,10 @@ mrb_value mrb_reg_regcomp(mrb_state *mrb, mrb_value str);
mrb_value mrb_reg_match_str(mrb_state *mrb, mrb_value re, mrb_value str);
mrb_value mrb_reg_nth_match(mrb_state *mrb, mrb_int nth, mrb_value match);
mrb_value mrb_backref_get(mrb_state *mrb);
-//mrb_int mrb_memsearch(const void *x0, mrb_int m, const void *y0, mrb_int n);
mrb_value mrb_reg_to_s(mrb_state *mrb, mrb_value re);
void mrb_backref_set(mrb_state *mrb, mrb_value val);
mrb_value match_alloc(mrb_state *mrb);
int mrb_reg_backref_number(mrb_state *mrb, mrb_value match, mrb_value backref);
+mrb_value mrb_reg_regcomp(mrb_state *mrb, mrb_value str);
#endif
View
48 src/regcomp.c
@@ -58,7 +58,7 @@ str_dup(UChar* s, UChar* end)
ptrdiff_t len = end - s;
if (len > 0) {
- UChar* r = (UChar* )xmalloc(len + 1);
+ UChar* r = (UChar* )malloc(len + 1);
CHECK_NULL_RETURN(r);
xmemcpy(r, s, len);
r[len] = (UChar )0;
@@ -146,7 +146,7 @@ onig_bbuf_init(BBuf* buf, int size)
buf->p = NULL;
}
else {
- buf->p = (UChar* )xmalloc(size);
+ buf->p = (UChar* )malloc(size);
if (IS_NULL(buf->p)) return(ONIGERR_MEMORY);
}
@@ -163,7 +163,7 @@ unset_addr_list_init(UnsetAddrList* uslist, int size)
{
UnsetAddr* p;
- p = (UnsetAddr* )xmalloc(sizeof(UnsetAddr)* size);
+ p = (UnsetAddr* )malloc(sizeof(UnsetAddr)* size);
CHECK_NULL_RETURN_MEMERR(p);
uslist->num = 0;
uslist->alloc = size;
@@ -175,7 +175,7 @@ static void
unset_addr_list_end(UnsetAddrList* uslist)
{
if (IS_NOT_NULL(uslist->us))
- xfree(uslist->us);
+ free(uslist->us);
}
static int
@@ -186,7 +186,7 @@ unset_addr_list_add(UnsetAddrList* uslist, int offset, struct _Node* node)
if (uslist->num >= uslist->alloc) {
size = uslist->alloc * 2;
- p = (UnsetAddr* )xrealloc(uslist->us, sizeof(UnsetAddr) * size);
+ p = (UnsetAddr* )realloc(uslist->us, sizeof(UnsetAddr) * size);
CHECK_NULL_RETURN_MEMERR(p);
uslist->alloc = size;
uslist->us = p;
@@ -657,7 +657,7 @@ entry_repeat_range(regex_t* reg, int id, int lower, int upper)
OnigRepeatRange* p;
if (reg->repeat_range_alloc == 0) {
- p = (OnigRepeatRange* )xmalloc(sizeof(OnigRepeatRange) * REPEAT_RANGE_ALLOC);
+ p = (OnigRepeatRange* )malloc(sizeof(OnigRepeatRange) * REPEAT_RANGE_ALLOC);
CHECK_NULL_RETURN_MEMERR(p);
reg->repeat_range = p;
reg->repeat_range_alloc = REPEAT_RANGE_ALLOC;
@@ -665,7 +665,7 @@ entry_repeat_range(regex_t* reg, int id, int lower, int upper)
else if (reg->repeat_range_alloc <= id) {
int n;
n = reg->repeat_range_alloc + REPEAT_RANGE_ALLOC;
- p = (OnigRepeatRange* )xrealloc(reg->repeat_range,
+ p = (OnigRepeatRange* )realloc(reg->repeat_range,
sizeof(OnigRepeatRange) * n);
CHECK_NULL_RETURN_MEMERR(p);
reg->repeat_range = p;
@@ -3229,7 +3229,7 @@ update_string_node_case_fold(regex_t* reg, Node *node)
end = sn->end;
sbuf_size = (end - sn->s) * 2;
- sbuf = (UChar* )xmalloc(sbuf_size);
+ sbuf = (UChar* )malloc(sbuf_size);
CHECK_NULL_RETURN_MEMERR(sbuf);
ebuf = sbuf + sbuf_size;
@@ -3240,7 +3240,7 @@ update_string_node_case_fold(regex_t* reg, Node *node)
q = buf;
for (i = 0; i < len; i++) {
if (sp >= ebuf) {
- sbuf = (UChar* )xrealloc(sbuf, sbuf_size * 2);
+ sbuf = (UChar* )realloc(sbuf, sbuf_size * 2);
CHECK_NULL_RETURN_MEMERR(sbuf);
sp = sbuf + sbuf_size;
sbuf_size *= 2;
@@ -3253,11 +3253,11 @@ update_string_node_case_fold(regex_t* reg, Node *node)
r = onig_node_str_set(node, sbuf, sp);
if (r != 0) {
- xfree(sbuf);
+ free(sbuf);
return r;
}
- xfree(sbuf);
+ free(sbuf);
return 0;
}
@@ -3936,7 +3936,7 @@ set_bm_skip(UChar* s, UChar* end, OnigEncoding enc ARG_UNUSED,
}
else {
if (IS_NULL(*int_skip)) {
- *int_skip = (int* )xmalloc(sizeof(int) * ONIG_CHAR_TABLE_SIZE);
+ *int_skip = (int* )malloc(sizeof(int) * ONIG_CHAR_TABLE_SIZE);
if (IS_NULL(*int_skip)) return ONIGERR_MEMORY;
}
for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) (*int_skip)[i] = len;
@@ -4900,7 +4900,7 @@ set_optimize_exact_info(regex_t* reg, OptExactInfo* e)
if (e->len == 0) return 0;
if (e->ignore_case) {
- reg->exact = (UChar* )xmalloc(e->len);
+ reg->exact = (UChar* )malloc(e->len);
CHECK_NULL_RETURN_MEMERR(reg->exact);
xmemcpy(reg->exact, e->s, e->len);
reg->exact_end = reg->exact + e->len;
@@ -5033,7 +5033,7 @@ clear_optimize_info(regex_t* reg)
reg->exact_end = (UChar* )NULL;
reg->threshold_len = 0;
if (IS_NOT_NULL(reg->exact)) {
- xfree(reg->exact);
+ free(reg->exact);
reg->exact = (UChar* )NULL;
}
}
@@ -5195,11 +5195,11 @@ extern void
onig_free_body(regex_t* reg)
{
if (IS_NOT_NULL(reg)) {
- if (IS_NOT_NULL(reg->p)) xfree(reg->p);
- if (IS_NOT_NULL(reg->exact)) xfree(reg->exact);
- if (IS_NOT_NULL(reg->int_map)) xfree(reg->int_map);
- if (IS_NOT_NULL(reg->int_map_backward)) xfree(reg->int_map_backward);
- if (IS_NOT_NULL(reg->repeat_range)) xfree(reg->repeat_range);
+ if (IS_NOT_NULL(reg->p)) free(reg->p);
+ if (IS_NOT_NULL(reg->exact)) free(reg->exact);
+ if (IS_NOT_NULL(reg->int_map)) free(reg->int_map);
+ if (IS_NOT_NULL(reg->int_map_backward)) free(reg->int_map_backward);
+ if (IS_NOT_NULL(reg->repeat_range)) free(reg->repeat_range);
if (IS_NOT_NULL(reg->chain)) onig_free(reg->chain);
#ifdef USE_NAMED_GROUP
@@ -5213,7 +5213,7 @@ onig_free(regex_t* reg)
{
if (IS_NOT_NULL(reg)) {
onig_free_body(reg);
- xfree(reg);
+ free(reg);
}
}
@@ -5235,7 +5235,7 @@ onig_memsize(regex_t *reg)
(to)->state = ONIG_STATE_MODIFY;\
onig_free_body(to);\
xmemcpy(to, from, sizeof(regex_t));\
- xfree(from);\
+ free(from);\
} while (0)
extern void
@@ -5413,7 +5413,7 @@ onig_compile(regex_t* reg, const UChar* pattern, const UChar* pattern_end,
#endif
if (IS_NOT_NULL(scan_env.mem_nodes_dynamic)) {
- xfree(scan_env.mem_nodes_dynamic);
+ free(scan_env.mem_nodes_dynamic);
scan_env.mem_nodes_dynamic = (Node** )NULL;
}
@@ -5472,7 +5472,7 @@ onig_compile(regex_t* reg, const UChar* pattern, const UChar* pattern_end,
onig_node_free(root);
if (IS_NOT_NULL(scan_env.mem_nodes_dynamic))
- xfree(scan_env.mem_nodes_dynamic);
+ free(scan_env.mem_nodes_dynamic);
return r;
}
@@ -5566,7 +5566,7 @@ onig_new(regex_t** reg, const UChar* pattern, const UChar* pattern_end,
{
int r;
- *reg = (regex_t* )xmalloc(sizeof(regex_t));
+ *reg = (regex_t* )malloc(sizeof(regex_t));
if (IS_NULL(*reg)) return ONIGERR_MEMORY;
r = onig_reg_init(*reg, option, ONIGENC_CASE_FOLD_DEFAULT, enc, syntax);
View
4 src/regenc.c
@@ -844,10 +844,10 @@ resize_property_list(int new_size, const OnigCodePoint*** plist, int* psize)
size = sizeof(OnigCodePoint*) * new_size;
if (IS_NULL(list)) {
- list = (const OnigCodePoint** )xmalloc(size);
+ list = (const OnigCodePoint** )malloc(size);
}
else {
- list = (const OnigCodePoint** )xrealloc((void* )list, size);
+ list = (const OnigCodePoint** )realloc((void* )list, size);
}
if (IS_NULL(list)) return ONIGERR_MEMORY;
View
54 src/regexec.c
@@ -68,7 +68,7 @@ static void
history_tree_free(OnigCaptureTreeNode* node)
{
history_tree_clear(node);
- xfree(node);
+ free(node);
}
static void
@@ -85,7 +85,7 @@ history_node_new(void)
{
OnigCaptureTreeNode* node;
- node = (OnigCaptureTreeNode* )xmalloc(sizeof(OnigCaptureTreeNode));
+ node = (OnigCaptureTreeNode* )malloc(sizeof(OnigCaptureTreeNode));
CHECK_NULL_RETURN(node);
node->childs = (OnigCaptureTreeNode** )0;
node->allocated = 0;
@@ -108,12 +108,12 @@ history_tree_add_child(OnigCaptureTreeNode* parent, OnigCaptureTreeNode* child)
if (IS_NULL(parent->childs)) {
n = HISTORY_TREE_INIT_ALLOC_SIZE;
parent->childs =
- (OnigCaptureTreeNode** )xmalloc(sizeof(OnigCaptureTreeNode*) * n);
+ (OnigCaptureTreeNode** )malloc(sizeof(OnigCaptureTreeNode*) * n);
}
else {
n = parent->allocated * 2;
parent->childs =
- (OnigCaptureTreeNode** )xrealloc(parent->childs,
+ (OnigCaptureTreeNode** )realloc(parent->childs,
sizeof(OnigCaptureTreeNode*) * n);
}
CHECK_NULL_RETURN_MEMERR(parent->childs);
@@ -180,35 +180,21 @@ onig_region_resize(OnigRegion* region, int n)
n = ONIG_NREGION;
if (region->allocated == 0) {
- region->beg = (int* )xmalloc(n * sizeof(int));
+ region->beg = (int* )malloc(n * sizeof(int));
if (region->beg == 0)
return ONIGERR_MEMORY;
- region->end = (int* )xmalloc(n * sizeof(int));
+ region->end = (int* )malloc(n * sizeof(int));
if (region->end == 0) {
- xfree(region->beg);
+ free(region->beg);
return ONIGERR_MEMORY;
}
region->allocated = n;
}
else if (region->allocated < n) {
- int *tmp;
-
- region->allocated = 0;
- tmp = (int* )xrealloc(region->beg, n * sizeof(int));
- if (tmp == 0) {
- xfree(region->beg);
- xfree(region->end);
- return ONIGERR_MEMORY;
- }
- region->beg = tmp;
- tmp = (int* )xrealloc(region->end, n * sizeof(int));
- if (tmp == 0) {
- xfree(region->beg);
- return ONIGERR_MEMORY;
- }
- region->end = tmp;
+ region->beg = (int *)realloc(region->beg, n * sizeof(int));
+ region->end = (int *)realloc(region->end, n * sizeof(int));
if (region->beg == 0 || region->end == 0)
return ONIGERR_MEMORY;
@@ -260,7 +246,7 @@ onig_region_new(void)
{
OnigRegion* r;
- r = (OnigRegion* )xmalloc(sizeof(OnigRegion));
+ r = (OnigRegion* )malloc(sizeof(OnigRegion));
if (r)
onig_region_init(r);
return r;
@@ -271,14 +257,14 @@ onig_region_free(OnigRegion* r, int free_self)
{
if (r) {
if (r->allocated > 0) {
- if (r->beg) xfree(r->beg);
- if (r->end) xfree(r->end);
+ if (r->beg) free(r->beg);
+ if (r->end) free(r->end);
r->allocated = 0;
}
#ifdef USE_CAPTURE_HISTORY
history_root_free(r);
#endif
- if (free_self) xfree(r);
+ if (free_self) free(r);
}
}
@@ -363,7 +349,7 @@ onig_region_copy(OnigRegion* to, OnigRegion* from)
offset = ((offset) * (state_num)) >> 3;\
if (size > 0 && offset < size && size < STATE_CHECK_BUFF_MAX_SIZE) {\
if (size >= STATE_CHECK_BUFF_MALLOC_THRESHOLD_SIZE) {\
- (msa).state_check_buff = (void* )xmalloc(size);\
+ (msa).state_check_buff = (void* )malloc(size);\
CHECK_NULL_RETURN_MEMERR((msa).state_check_buff);\
}\
else \
@@ -384,13 +370,13 @@ onig_region_copy(OnigRegion* to, OnigRegion* from)
} while(0)
#define MATCH_ARG_FREE(msa) do {\
- if ((msa).stack_p) xfree((msa).stack_p);\
+ if ((msa).stack_p) free((msa).stack_p);\
if ((msa).state_check_buff_size >= STATE_CHECK_BUFF_MALLOC_THRESHOLD_SIZE) { \
- if ((msa).state_check_buff) xfree((msa).state_check_buff);\
+ if ((msa).state_check_buff) free((msa).state_check_buff);\
}\
} while(0)
#else
-#define MATCH_ARG_FREE(msa) if ((msa).stack_p) xfree((msa).stack_p)
+#define MATCH_ARG_FREE(msa) if ((msa).stack_p) free((msa).stack_p)
#endif
@@ -448,7 +434,7 @@ stack_double(OnigStackType** arg_stk_base, OnigStackType** arg_stk_end,
n = stk_end - stk_base;
if (stk_base == stk_alloc && IS_NULL(msa->stack_p)) {
- x = (OnigStackType* )xmalloc(sizeof(OnigStackType) * n * 2);
+ x = (OnigStackType* )malloc(sizeof(OnigStackType) * n * 2);
if (IS_NULL(x)) {
STACK_SAVE;
return ONIGERR_MEMORY;
@@ -465,7 +451,7 @@ stack_double(OnigStackType** arg_stk_base, OnigStackType** arg_stk_end,
else
n = limit_size;
}
- x = (OnigStackType* )xrealloc(stk_base, sizeof(OnigStackType) * n);
+ x = (OnigStackType* )realloc(stk_base, sizeof(OnigStackType) * n);
if (IS_NULL(x)) {
STACK_SAVE;
return ONIGERR_MEMORY;
@@ -2944,7 +2930,7 @@ set_bm_backward_skip(UChar* s, UChar* end, OnigEncoding enc ARG_UNUSED,
int i, len;
if (IS_NULL(*skip)) {
- *skip = (int* )xmalloc(sizeof(int) * ONIG_CHAR_TABLE_SIZE);
+ *skip = (int* )malloc(sizeof(int) * ONIG_CHAR_TABLE_SIZE);
if (IS_NULL(*skip)) return ONIGERR_MEMORY;
}
View
6 src/regint.h
@@ -374,13 +374,13 @@ typedef struct _BBuf {
#define BBUF_SIZE_INC(buf,inc) do{\
(buf)->alloc += (inc);\
- (buf)->p = (UChar* )xrealloc((buf)->p, (buf)->alloc);\
+ (buf)->p = (UChar* )realloc((buf)->p, (buf)->alloc);\
if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
} while (0)
#define BBUF_EXPAND(buf,low) do{\
do { (buf)->alloc *= 2; } while ((buf)->alloc < (unsigned int )low);\
- (buf)->p = (UChar* )xrealloc((buf)->p, (buf)->alloc);\
+ (buf)->p = (UChar* )realloc((buf)->p, (buf)->alloc);\
if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
} while (0)
@@ -388,7 +388,7 @@ typedef struct _BBuf {
unsigned int new_alloc = (buf)->alloc;\
while (new_alloc < (unsigned int )(size)) { new_alloc *= 2; }\
if ((buf)->alloc != new_alloc) {\
- (buf)->p = (UChar* )xrealloc((buf)->p, new_alloc);\
+ (buf)->p = (UChar* )realloc((buf)->p, new_alloc);\
if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
(buf)->alloc = new_alloc;\
}\
View
82 src/regparse.c
@@ -108,8 +108,8 @@ static void
bbuf_free(BBuf* bbuf)
{
if (IS_NOT_NULL(bbuf)) {
- if (IS_NOT_NULL(bbuf->p)) xfree(bbuf->p);
- xfree(bbuf);
+ if (IS_NOT_NULL(bbuf->p)) free(bbuf->p);
+ free(bbuf);
}
}
@@ -119,7 +119,7 @@ bbuf_clone(BBuf** rto, BBuf* from)
int r;
BBuf *to;
- *rto = to = (BBuf* )xmalloc(sizeof(BBuf));
+ *rto = to = (BBuf* )malloc(sizeof(BBuf));
CHECK_NULL_RETURN_MEMERR(to);
r = BBUF_INIT(to, from->alloc);
if (r != 0) return r;
@@ -239,7 +239,7 @@ strdup_with_null(OnigEncoding enc, UChar* s, UChar* end)
slen = end - s;
term_len = ONIGENC_MBC_MINLEN(enc);
- r = (UChar* )xmalloc(slen + term_len);
+ r = (UChar* )malloc(slen + term_len);
CHECK_NULL_RETURN(r);
xmemcpy(r, s, slen);
@@ -276,9 +276,9 @@ strcat_capa(UChar* dest, UChar* dest_end, const UChar* src, const UChar* src_end
UChar* r;
if (dest)
- r = (UChar* )xrealloc(dest, capa + 1);
+ r = (UChar* )realloc(dest, capa + 1);
else
- r = (UChar* )xmalloc(capa + 1);
+ r = (UChar* )malloc(capa + 1);
CHECK_NULL_RETURN(r);
onig_strcpy(r + (dest_end - dest), src, src_end);
@@ -292,7 +292,7 @@ strcat_capa_from_static(UChar* dest, UChar* dest_end,
{
UChar* r;
- r = (UChar* )xmalloc(capa + 1);
+ r = (UChar* )malloc(capa + 1);
CHECK_NULL_RETURN(r);
onig_strcpy(r, dest, dest_end);
onig_strcpy(r + (dest_end - dest), src, src_end);
@@ -380,12 +380,12 @@ onig_st_insert_strend(hash_table_type* table, const UChar* str_key,
st_str_end_key* key;
int result;
- key = (st_str_end_key* )xmalloc(sizeof(st_str_end_key));
+ key = (st_str_end_key* )malloc(sizeof(st_str_end_key));
key->s = (UChar* )str_key;
key->end = (UChar* )end_key;
result = onig_st_insert(table, (st_data_t )key, value);
if (result) {
- xfree(key);
+ free(key);
}
return result;
}
@@ -454,10 +454,10 @@ onig_print_names(FILE* fp, regex_t* reg)
static enum st_retval
i_free_name_entry(UChar* key, NameEntry* e, void* arg ARG_UNUSED)
{
- xfree(e->name);
- if (IS_NOT_NULL(e->back_refs)) xfree(e->back_refs);
- xfree(key);
- xfree(e);
+ free(e->name);
+ if (IS_NOT_NULL(e->back_refs)) free(e->back_refs);
+ free(key);
+ free(e);
return ST_DELETE;
}
@@ -635,17 +635,17 @@ names_clear(regex_t* reg)
for (i = 0; i < t->num; i++) {
e = &(t->e[i]);
if (IS_NOT_NULL(e->name)) {
- xfree(e->name);
+ free(e->name);
e->name = NULL;
e->name_len = 0;
e->back_num = 0;
e->back_alloc = 0;
- if (IS_NOT_NULL(e->back_refs)) xfree(e->back_refs);
+ if (IS_NOT_NULL(e->back_refs)) free(e->back_refs);
e->back_refs = (int* )NULL;
}
}
if (IS_NOT_NULL(t->e)) {
- xfree(t->e);
+ free(t->e);
t->e = NULL;
}
t->num = 0;
@@ -663,7 +663,7 @@ onig_names_free(regex_t* reg)
if (r) return r;
t = (NameTable* )reg->name_table;
- if (IS_NOT_NULL(t)) xfree(t);
+ if (IS_NOT_NULL(t)) free(t);
reg->name_table = NULL;
return 0;
}
@@ -736,12 +736,12 @@ name_add(regex_t* reg, UChar* name, UChar* name_end, int backref, ScanEnv* env)
t = onig_st_init_strend_table_with_size(5);
reg->name_table = (void* )t;
}
- e = (NameEntry* )xmalloc(sizeof(NameEntry));
+ e = (NameEntry* )malloc(sizeof(NameEntry));
CHECK_NULL_RETURN_MEMERR(e);
e->name = strdup_with_null(reg->enc, name, name_end);
if (IS_NULL(e->name)) {
- xfree(e);
+ free(e);
return ONIGERR_MEMORY;
}
onig_st_insert_strend(t, e->name, (e->name + (name_end - name)),
@@ -756,15 +756,15 @@ name_add(regex_t* reg, UChar* name, UChar* name_end, int backref, ScanEnv* env)
if (IS_NULL(t)) {
alloc = INIT_NAMES_ALLOC_NUM;
- t = (NameTable* )xmalloc(sizeof(NameTable));
+ t = (NameTable* )malloc(sizeof(NameTable));
CHECK_NULL_RETURN_MEMERR(t);
t->e = NULL;
t->alloc = 0;
t->num = 0;
- t->e = (NameEntry* )xmalloc(sizeof(NameEntry) * alloc);
+ t->e = (NameEntry* )malloc(sizeof(NameEntry) * alloc);
if (IS_NULL(t->e)) {
- xfree(t);
+ free(t);
return ONIGERR_MEMORY;
}
t->alloc = alloc;
@@ -775,7 +775,7 @@ name_add(regex_t* reg, UChar* name, UChar* name_end, int backref, ScanEnv* env)
int i;
alloc = t->alloc * 2;
- t->e = (NameEntry* )xrealloc(t->e, sizeof(NameEntry) * alloc);
+ t->e = (NameEntry* )realloc(t->e, sizeof(NameEntry) * alloc);
CHECK_NULL_RETURN_MEMERR(t->e);
t->alloc = alloc;
@@ -810,7 +810,7 @@ name_add(regex_t* reg, UChar* name, UChar* name_end, int backref, ScanEnv* env)
else {
if (e->back_num == 2) {
alloc = INIT_NAME_BACKREFS_ALLOC_NUM;
- e->back_refs = (int* )xmalloc(sizeof(int) * alloc);
+ e->back_refs = (int* )malloc(sizeof(int) * alloc);
CHECK_NULL_RETURN_MEMERR(e->back_refs);
e->back_alloc = alloc;
e->back_refs[0] = e->back_ref1;
@@ -819,7 +819,7 @@ name_add(regex_t* reg, UChar* name, UChar* name_end, int backref, ScanEnv* env)
else {
if (e->back_num > e->back_alloc) {
alloc = e->back_alloc * 2;
- e->back_refs = (int* )xrealloc(e->back_refs, sizeof(int) * alloc);
+ e->back_refs = (int* )realloc(e->back_refs, sizeof(int) * alloc);
CHECK_NULL_RETURN_MEMERR(e->back_refs);
e->back_alloc = alloc;
}
@@ -968,13 +968,13 @@ scan_env_add_mem_entry(ScanEnv* env)
if (env->mem_alloc <= need) {
if (IS_NULL(env->mem_nodes_dynamic)) {
alloc = INIT_SCANENV_MEMNODES_ALLOC_SIZE;
- p = (Node** )xmalloc(sizeof(Node*) * alloc);
+ p = (Node** )malloc(sizeof(Node*) * alloc);
xmemcpy(p, env->mem_nodes_static,
sizeof(Node*) * SCANENV_MEMNODES_SIZE);
}
else {
alloc = env->mem_alloc * 2;
- p = (Node** )xrealloc(env->mem_nodes_dynamic, sizeof(Node*) * alloc);
+ p = (Node** )realloc(env->mem_nodes_dynamic, sizeof(Node*) * alloc);
}
CHECK_NULL_RETURN_MEMERR(p);
@@ -1019,7 +1019,7 @@ onig_node_free(Node* node)
case NT_STR:
if (NSTR(node)->capa != 0 &&
IS_NOT_NULL(NSTR(node)->s) && NSTR(node)->s != NSTR(node)->buf) {
- xfree(NSTR(node)->s);
+ free(NSTR(node)->s);
}
break;
@@ -1039,7 +1039,7 @@ onig_node_free(Node* node)
THREAD_ATOMIC_END;
}
#else
- xfree(node);
+ free(node);
#endif
node = next_node;
goto start;
@@ -1068,7 +1068,7 @@ onig_node_free(Node* node)
case NT_BREF:
if (IS_NOT_NULL(NBREF(node)->back_dynamic))
- xfree(NBREF(node)->back_dynamic);
+ free(NBREF(node)->back_dynamic);
break;
case NT_ANCHOR:
@@ -1087,7 +1087,7 @@ onig_node_free(Node* node)
THREAD_ATOMIC_END;
}
#else
- xfree(node);
+ free(node);
#endif
}
@@ -1101,7 +1101,7 @@ onig_free_node_list(void)
while (IS_NOT_NULL(FreeNodeList)) {
n = FreeNodeList;
FreeNodeList = FreeNodeList->next;
- xfree(n);
+ free(n);
}
/* THREAD_ATOMIC_END; */
return 0;
@@ -1124,7 +1124,7 @@ node_new(void)
THREAD_ATOMIC_END;
#endif
- node = (Node* )xmalloc(sizeof(Node));
+ node = (Node* )malloc(sizeof(Node));
/* xmemset(node, 0, sizeof(Node)); */
return node;
}
@@ -1188,7 +1188,7 @@ node_new_cclass_by_codepoint_range(int is_not, OnigCodePoint sb_out,
n = ONIGENC_CODE_RANGE_NUM(ranges);
if (n == 0) goto is_null;
- bbuf = (BBuf* )xmalloc(sizeof(BBuf));
+ bbuf = (BBuf* )malloc(sizeof(BBuf));
CHECK_NULL_RETURN(bbuf);
bbuf->alloc = n + 1;
bbuf->used = n + 1;
@@ -1322,7 +1322,7 @@ node_new_backref(int back_num, int* backrefs, int by_name,
NBREF(node)->back_static[i] = backrefs[i];
}
else {
- int* p = (int* )xmalloc(sizeof(int) * back_num);
+ int* p = (int* )malloc(sizeof(int) * back_num);
if (IS_NULL(p)) {
onig_node_free(node);
return NULL;
@@ -1490,7 +1490,7 @@ onig_node_str_clear(Node* node)
{
if (NSTR(node)->capa != 0 &&
IS_NOT_NULL(NSTR(node)->s) && NSTR(node)->s != NSTR(node)->buf) {
- xfree(NSTR(node)->s);
+ free(NSTR(node)->s);
}
NSTR(node)->capa = 0;
@@ -1672,7 +1672,7 @@ new_code_range(BBuf** pbuf)
OnigCodePoint n;
BBuf* bbuf;
- bbuf = *pbuf = (BBuf* )xmalloc(sizeof(BBuf));
+ bbuf = *pbuf = (BBuf* )malloc(sizeof(BBuf));
CHECK_NULL_RETURN_MEMERR(*pbuf);
r = BBUF_INIT(*pbuf, INIT_MULTI_BYTE_RANGE_SIZE);
if (r) return r;
@@ -4927,11 +4927,11 @@ i_free_shared_class(type_cclass_key* key, Node* node, void* arg ARG_UNUSED)
{
if (IS_NOT_NULL(node)) {
CClassNode* cc = NCCLASS(node);
- if (IS_NOT_NULL(cc->mbuf)) xfree(cc->mbuf);
- xfree(node);
+ if (IS_NOT_NULL(cc->mbuf)) free(cc->mbuf);
+ free(node);
}
- if (IS_NOT_NULL(key)) xfree(key);
+ if (IS_NOT_NULL(key)) free(key);
return ST_DELETE;
}
@@ -5266,7 +5266,7 @@ parse_exp(Node** np, OnigToken* tok, int term,
cc = NCCLASS(*np);
NCCLASS_SET_SHARE(cc);
- new_key = (type_cclass_key* )xmalloc(sizeof(type_cclass_key));
+ new_key = (type_cclass_key* )malloc(sizeof(type_cclass_key));
xmemcpy(new_key, &key, sizeof(type_cclass_key));
onig_st_add_direct(OnigTypeCClassTable, (st_data_t )new_key,
(st_data_t )*np);
View
51 src/string.c
@@ -26,7 +26,9 @@ const char mrb_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz";
static mrb_value get_pat(mrb_state *mrb, mrb_value pat, mrb_int quote);
#endif //ENABLE_REGEXP
static mrb_value str_replace(mrb_state *mrb, struct RString *s1, struct RString *s2);
+#ifndef ENABLE_REGEXP
static mrb_value mrb_str_subseq(mrb_state *mrb, mrb_value str, int beg, int len);
+#endif
#define RESIZE_CAPA(s,capacity) do {\
s->ptr = (char *)mrb_realloc(mrb, s->ptr, (capacity)+1);\
@@ -638,7 +640,14 @@ mrb_string_value_ptr(mrb_state *mrb, mrb_value ptr)
static mrb_value
mrb_str_match(mrb_state *mrb, mrb_value self/* x */)
{
+#ifdef ENABLE_REGEXP
+ mrb_value re;
+
+ mrb_get_args(mrb, "o", &re);
+ return mrb_funcall(mrb, get_pat(mrb, re, 0), "=~", 1, self);
+#else
return mrb_nil_value();
+#endif
}
static inline long
@@ -720,6 +729,19 @@ mrb_str_dup(mrb_state *mrb, mrb_value str)
return mrb_str_new(mrb, s->ptr, s->len);
}
+#ifdef ENABLE_REGEXP
+static mrb_value
+mrb_str_subpat(mrb_state *mrb, mrb_value str, mrb_value re, mrb_value backref)
+{
+ if (mrb_reg_search(mrb, re, str, 0, 0) >= 0) {
+ mrb_value match = mrb_backref_get(mrb);
+ int nth = mrb_reg_backref_number(mrb, match, backref);
+ return mrb_reg_nth_match(mrb, nth, match);
+ }
+ return mrb_nil_value();
+}
+#endif
+
static mrb_value
mrb_str_aref(mrb_state *mrb, mrb_value str, mrb_value indx)
{
@@ -736,7 +758,7 @@ mrb_str_aref(mrb_state *mrb, mrb_value str, mrb_value indx)
case MRB_TT_REGEX:
#ifdef ENABLE_REGEXP
- return mrb_str_subpat(mrb, str, indx, 0); //mrb_str_subpat(str, indx, INT2FIX(0));
+ return mrb_str_subpat(mrb, str, indx, mrb_fixnum_value(0));
#else
mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported");
return mrb_nil_value();
@@ -828,7 +850,7 @@ mrb_str_aref_m(mrb_state *mrb, mrb_value str)
if (argc == 2) {
if (mrb_type(a1) == MRB_TT_REGEX) {
#ifdef ENABLE_REGEXP
- return mrb_str_subpat(mrb, str, argv[0], mrb_fixnum(argv[1]));
+ return mrb_str_subpat(mrb, str, a1, a2);
#else
mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported");
return mrb_nil_value();
@@ -1188,7 +1210,11 @@ mrb_str_eql(mrb_state *mrb, mrb_value self)
return mrb_false_value();
}
+#ifdef ENABLE_REGEXP
+mrb_value
+#else
static mrb_value
+#endif
mrb_str_subseq(mrb_state *mrb, mrb_value str, int beg, int len)
{
struct RString *orig, *s;
@@ -1251,7 +1277,7 @@ str_gsub(mrb_state *mrb, mrb_value str, mrb_int bang)
mrb_int offset, blen, len, last;
char *sp, *cp;
- if (bang) str_modify(mrb, mrb_str_ptr(self));
+ if (bang) str_modify(mrb, mrb_str_ptr(str));
mrb_get_args(mrb, "*", &argv, &argc);
switch (argc) {
case 1:
@@ -1369,10 +1395,10 @@ mrb_str_gsub(mrb_state *mrb, mrb_value self)
static mrb_value
mrb_str_gsub_bang(mrb_state *mrb, mrb_value self)
{
- striuct RString *s = mrb_str_ptr(self);
+ struct RString *s = mrb_str_ptr(self);
str_modify(mrb, s);
- return str_gsub(mrb, s, 1);
+ return str_gsub(mrb, self, 1);
}
#endif //ENABLE_REGEXP
@@ -1836,7 +1862,7 @@ mrb_str_rindex(mrb_state *mrb, mrb_value str, mrb_value sub, mrb_int pos)
#ifdef INCLUDE_ENCODING
/* byte offset to char offset */
int
-mrb_str_sublen(mrb_state *mrb, mrb_value str, long pos)
+mrb_str_sublen(mrb_state *mrb, mrb_value str, int pos)
{
return pos;
}
@@ -2240,14 +2266,17 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
break;
}
else if (last_null == 1) {
- mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, beg, len));
+ long enc_len = ONIGENC_MBC_ENC_LEN(ONIG_ENCODING_ASCII, (UChar *)ptr+beg, (UChar *)ptr+len);
+ mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, beg, enc_len));
beg = start;
}
else {
- if (ptr+start == ptr+len)
+ if (ptr+start == ptr+len) {
start++;
- else
- start += len;
+ } else {
+ long enc_len = ONIGENC_MBC_ENC_LEN(ONIG_ENCODING_ASCII, (UChar *)ptr+start, (UChar *)ptr+len);
+ start += enc_len;
+ }
last_null = 1;
continue;
}
@@ -2312,7 +2341,7 @@ mrb_block_given_p()
static mrb_value
mrb_str_sub_bang(mrb_state *mrb, mrb_value str)
{
- str_modify(mrb, str);
+ str_modify(mrb, RSTRING(str));
return mrb_nil_value();
}
#endif //ENABLE_REGEXP
Something went wrong with that request. Please try again.