summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-30 02:08:54 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-30 02:08:54 +0000
commit23a32d6444cea5b1719edc42d63911e108d3086e (patch)
treeccbb65883a860cf72c3427345134b8edafe735c0
parent88ca298efbb004600e1853cef872038f78843252 (diff)
* include/ruby/oniguruma.h, include/ruby/re.h, re.c, regcomp.c,
regenc.c, regerror.c, regexec.c, regint.h, regparse.c: use long. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--include/ruby/oniguruma.h6
-rw-r--r--include/ruby/re.h8
-rw-r--r--re.c39
-rw-r--r--regcomp.c8
-rw-r--r--regenc.c8
-rw-r--r--regerror.c8
-rw-r--r--regexec.c14
-rw-r--r--regint.h22
-rw-r--r--regparse.c11
10 files changed, 72 insertions, 57 deletions
diff --git a/ChangeLog b/ChangeLog
index 070513235a..ed84290c87 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Jun 30 11:08:49 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * include/ruby/oniguruma.h, include/ruby/re.h, re.c, regcomp.c,
+ regenc.c, regerror.c, regexec.c, regint.h, regparse.c: use long.
+
Tue Jun 30 11:05:59 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* dln.c (dln_find_1): fixed index overrun.
diff --git a/include/ruby/oniguruma.h b/include/ruby/oniguruma.h
index a8fa62208f..34707d2693 100644
--- a/include/ruby/oniguruma.h
+++ b/include/ruby/oniguruma.h
@@ -106,7 +106,7 @@ extern "C" {
typedef unsigned char OnigUChar;
typedef unsigned int OnigCodePoint;
typedef unsigned int OnigCtype;
-typedef unsigned int OnigDistance;
+typedef size_t OnigDistance;
#define ONIG_INFINITE_DISTANCE ~((OnigDistance )0)
@@ -692,9 +692,9 @@ int onig_recompile P_((OnigRegex, const OnigUChar* pattern, const OnigUChar* pat
ONIG_EXTERN
int onig_recompile_deluxe P_((OnigRegex reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
ONIG_EXTERN
-int onig_search P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* start, const OnigUChar* range, OnigRegion* region, OnigOptionType option));
+long onig_search P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* start, const OnigUChar* range, OnigRegion* region, OnigOptionType option));
ONIG_EXTERN
-int onig_match P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* at, OnigRegion* region, OnigOptionType option));
+long onig_match P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* at, OnigRegion* region, OnigOptionType option));
ONIG_EXTERN
OnigRegion* onig_region_new P_((void));
ONIG_EXTERN
diff --git a/include/ruby/re.h b/include/ruby/re.h
index cc7f6025a7..c60ab96016 100644
--- a/include/ruby/re.h
+++ b/include/ruby/re.h
@@ -27,8 +27,8 @@ extern "C" {
typedef struct re_pattern_buffer Regexp;
struct rmatch_offset {
- int beg;
- int end;
+ long beg;
+ long end;
};
struct rmatch {
@@ -50,9 +50,9 @@ struct RMatch {
#define RMATCH_REGS(obj) (&(R_CAST(RMatch)(obj))->rmatch->regs)
VALUE rb_reg_regcomp(VALUE);
-int rb_reg_search(VALUE, VALUE, int, int);
+long rb_reg_search(VALUE, VALUE, long, int);
VALUE rb_reg_regsub(VALUE, VALUE, struct re_registers *, VALUE);
-int rb_reg_adjust_startpos(VALUE, VALUE, int, int);
+long rb_reg_adjust_startpos(VALUE, VALUE, long, int);
void rb_match_busy(VALUE);
VALUE rb_reg_quote(VALUE);
diff --git a/re.c b/re.c
index b05d78bb39..528e94a829 100644
--- a/re.c
+++ b/re.c
@@ -792,14 +792,19 @@ match_alloc(VALUE klass)
}
typedef struct {
- int byte_pos;
- int char_pos;
+ long byte_pos;
+ long char_pos;
} pair_t;
static int
pair_byte_cmp(const void *pair1, const void *pair2)
{
- return ((pair_t*)pair1)->byte_pos - ((pair_t*)pair2)->byte_pos;
+ long diff = ((pair_t*)pair1)->byte_pos - ((pair_t*)pair2)->byte_pos;
+#if SIZEOF_LONG > SIZEOF_INT
+ return diff ? diff > 0 ? 1 : -1 : 0;
+#else
+ return (int)diff;
+#endif
}
static void
@@ -1254,10 +1259,10 @@ rb_reg_prepare_re(VALUE re, VALUE str)
return reg;
}
-int
-rb_reg_adjust_startpos(VALUE re, VALUE str, int pos, int reverse)
+long
+rb_reg_adjust_startpos(VALUE re, VALUE str, long pos, int reverse)
{
- int range;
+ long range;
rb_encoding *enc;
UChar *p, *string;
@@ -1285,10 +1290,10 @@ rb_reg_adjust_startpos(VALUE re, VALUE str, int pos, int reverse)
return pos;
}
-int
-rb_reg_search(VALUE re, VALUE str, int pos, int reverse)
+long
+rb_reg_search(VALUE re, VALUE str, long pos, int reverse)
{
- int result;
+ long result;
VALUE match;
struct re_registers regi, *regs = &regi;
char *range = RSTRING_PTR(str);
@@ -1344,7 +1349,7 @@ rb_reg_search(VALUE re, VALUE str, int pos, int reverse)
}
else {
onig_errmsg_buffer err = "";
- onig_error_code_to_str((UChar*)err, result);
+ onig_error_code_to_str((UChar*)err, (int)result);
rb_reg_raise(RREGEXP_SRC_PTR(re), RREGEXP_SRC_LEN(re), err, 0);
}
}
@@ -1686,7 +1691,8 @@ match_aref(int argc, VALUE *argv, VALUE match)
static VALUE
match_entry(VALUE match, long n)
{
- return rb_reg_nth_match(n, match);
+ /* n should not exceed num_regs */
+ return rb_reg_nth_match((int)n, match);
}
@@ -1875,12 +1881,12 @@ again:
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
p--;
- code = ruby_scan_oct(p, end < p+3 ? end-p : 3, &len);
+ code = scan_oct(p, end < p+3 ? end-p : 3, &len);
p += len;
break;
case 'x': /* \xHH */
- code = ruby_scan_hex(p, end < p+2 ? end-p : 2, &len);
+ code = scan_hex(p, end < p+2 ? end-p : 2, &len);
if (len < 1) {
errcpy(err, "invalid hex escape");
return -1;
@@ -2307,7 +2313,7 @@ rb_reg_preprocess_dregexp(VALUE ary)
}
static int
-rb_reg_initialize(VALUE obj, const char *s, int len, rb_encoding *enc,
+rb_reg_initialize(VALUE obj, const char *s, long len, rb_encoding *enc,
int options, onig_errmsg_buffer err)
{
struct RRegexp *re = RREGEXP(obj);
@@ -2476,7 +2482,8 @@ rb_reg_regcomp(VALUE str)
static VALUE
rb_reg_hash(VALUE re)
{
- int hashval, len;
+ unsigned long hashval;
+ long len;
char *p;
rb_reg_check(re);
@@ -2488,7 +2495,7 @@ rb_reg_hash(VALUE re)
}
hashval = hashval + (hashval>>5);
- return INT2FIX(hashval);
+ return LONG2FIX(hashval);
}
diff --git a/regcomp.c b/regcomp.c
index b8a0723d01..a7346d3d8e 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -52,7 +52,7 @@ static unsigned char PadBuf[WORD_ALIGNMENT_SIZE];
static UChar*
str_dup(UChar* s, UChar* end)
{
- int len = end - s;
+ ptrdiff_t len = end - s;
if (len > 0) {
UChar* r = (UChar* )xmalloc(len + 1);
@@ -73,7 +73,7 @@ swap_node(Node* a, Node* b)
if (NTYPE(a) == NT_STR) {
StrNode* sn = NSTR(a);
if (sn->capa == 0) {
- int len = sn->end - sn->s;
+ size_t len = sn->end - sn->s;
sn->s = sn->buf;
sn->end = sn->s + len;
}
@@ -82,7 +82,7 @@ swap_node(Node* a, Node* b)
if (NTYPE(b) == NT_STR) {
StrNode* sn = NSTR(b);
if (sn->capa == 0) {
- int len = sn->end - sn->s;
+ size_t len = sn->end - sn->s;
sn->s = sn->buf;
sn->end = sn->s + len;
}
@@ -416,7 +416,7 @@ compile_tree_n_times(Node* node, int n, regex_t* reg)
}
static int
-add_compile_string_length(UChar* s ARG_UNUSED, int mb_len, int str_len,
+add_compile_string_length(UChar* s ARG_UNUSED, int mb_len, OnigDistance str_len,
regex_t* reg ARG_UNUSED, int ignore_case)
{
int len;
diff --git a/regenc.c b/regenc.c
index b625e63048..bb180367da 100644
--- a/regenc.c
+++ b/regenc.c
@@ -57,7 +57,7 @@ onigenc_mbclen_approximate(const OnigUChar* p,const OnigUChar* e, struct OnigEnc
if (ONIGENC_MBCLEN_CHARFOUND_P(ret))
return ONIGENC_MBCLEN_CHARFOUND_LEN(ret);
else if (ONIGENC_MBCLEN_NEEDMORE_P(ret))
- return e-p+ONIGENC_MBCLEN_NEEDMORE_LEN(ret);
+ return (int)(e-p)+ONIGENC_MBCLEN_NEEDMORE_LEN(ret);
return 1;
}
@@ -757,7 +757,7 @@ onigenc_mb2_code_to_mbc(OnigEncoding enc, OnigCodePoint code, UChar *buf)
if (enclen(enc, buf, p) != (p - buf))
return ONIGERR_INVALID_CODE_POINT_VALUE;
#endif
- return p - buf;
+ return (int)(p - buf);
}
extern int
@@ -780,7 +780,7 @@ onigenc_mb4_code_to_mbc(OnigEncoding enc, OnigCodePoint code, UChar *buf)
if (enclen(enc, buf, p) != (p - buf))
return ONIGERR_INVALID_CODE_POINT_VALUE;
#endif
- return p - buf;
+ return (int)(p - buf);
}
extern int
@@ -870,7 +870,7 @@ onigenc_with_ascii_strncmp(OnigEncoding enc, const UChar* p, const UChar* end,
static int
resize_property_list(int new_size, const OnigCodePoint*** plist, int* psize)
{
- int size;
+ size_t size;
const OnigCodePoint **list = *plist;
size = sizeof(OnigCodePoint*) * new_size;
diff --git a/regerror.c b/regerror.c
index 0a92c67b5d..eb671386f1 100644
--- a/regerror.c
+++ b/regerror.c
@@ -232,7 +232,7 @@ static int to_ascii(OnigEncoding enc, UChar *s, UChar *end,
*is_over = ((p < end) ? 1 : 0);
}
else {
- len = MIN((end - s), buf_size);
+ len = (int)MIN((end - s), buf_size);
xmemcpy(buf, s, (size_t )len);
*is_over = ((buf_size < (end - s)) ? 1 : 0);
}
@@ -256,7 +256,8 @@ onig_error_code_to_str(s, code, va_alist)
{
UChar *p, *q;
OnigErrorInfo* einfo;
- int len, is_over;
+ size_t len;
+ int is_over;
UChar parbuf[MAX_ERROR_PAR_LEN];
va_list vargs;
@@ -327,7 +328,8 @@ onig_snprintf_with_pattern(buf, bufsize, enc, pat, pat_end, fmt, va_alist)
va_dcl
#endif
{
- int n, need, len;
+ size_t need;
+ int n, len;
UChar *p, *s, *bp;
UChar bs[6];
va_list args;
diff --git a/regexec.c b/regexec.c
index 946e47be60..cfe28836ba 100644
--- a/regexec.c
+++ b/regexec.c
@@ -413,7 +413,7 @@ onig_region_copy(OnigRegion* to, OnigRegion* from)
#define STACK_SAVE do{\
if (stk_base != stk_alloc) {\
msa->stack_p = stk_base;\
- msa->stack_n = stk_end - stk_base;\
+ msa->stack_n = stk_end - stk_base; /* TODO: check overflow */\
};\
} while(0)
@@ -436,7 +436,7 @@ static int
stack_double(OnigStackType** arg_stk_base, OnigStackType** arg_stk_end,
OnigStackType** arg_stk, OnigStackType* stk_alloc, OnigMatchArg* msa)
{
- unsigned int n;
+ size_t n;
OnigStackType *x, *stk_base, *stk_end, *stk;
stk_base = *arg_stk_base;
@@ -1242,7 +1242,7 @@ typedef struct {
/* match data(str - end) from position (sstart). */
/* if sstart == str then set sprev to NULL. */
-static int
+static long
match_at(regex_t* reg, const UChar* str, const UChar* end,
#ifdef USE_MATCH_RANGE_MUST_BE_INSIDE_OF_SPECIFIED_RANGE
const UChar* right_range,
@@ -3064,11 +3064,11 @@ map_search_backward(OnigEncoding enc, UChar map[],
return (UChar* )NULL;
}
-extern int
+extern long
onig_match(regex_t* reg, const UChar* str, const UChar* end, const UChar* at, OnigRegion* region,
OnigOptionType option)
{
- int r;
+ long r;
UChar *prev;
OnigMatchArg msa;
@@ -3260,7 +3260,7 @@ static int set_bm_backward_skip P_((UChar* s, UChar* end, OnigEncoding enc,
#define BM_BACKWARD_SEARCH_LENGTH_THRESHOLD 100
-static int
+static long
backward_search_range(regex_t* reg, const UChar* str, const UChar* end,
UChar* s, const UChar* range, UChar* adjrange,
UChar** low, UChar** high)
@@ -3365,7 +3365,7 @@ backward_search_range(regex_t* reg, const UChar* str, const UChar* end,
}
-extern int
+extern long
onig_search(regex_t* reg, const UChar* str, const UChar* end,
const UChar* start, const UChar* range, OnigRegion* region, OnigOptionType option)
{
diff --git a/regint.h b/regint.h
index fc37f65680..db698de5d2 100644
--- a/regint.h
+++ b/regint.h
@@ -352,7 +352,7 @@ typedef unsigned char Bits;
typedef Bits BitSet[BITSET_SIZE];
typedef Bits* BitSetRef;
-#define SIZE_BITSET sizeof(BitSet)
+#define SIZE_BITSET (int)sizeof(BitSet)
#define BITSET_CLEAR(bs) do {\
int i;\
@@ -582,15 +582,15 @@ typedef short int StateCheckNumType;
typedef void* PointerType;
#define SIZE_OPCODE 1
-#define SIZE_RELADDR sizeof(RelAddrType)
-#define SIZE_ABSADDR sizeof(AbsAddrType)
-#define SIZE_LENGTH sizeof(LengthType)
-#define SIZE_MEMNUM sizeof(MemNumType)
-#define SIZE_STATE_CHECK_NUM sizeof(StateCheckNumType)
-#define SIZE_REPEATNUM sizeof(RepeatNumType)
-#define SIZE_OPTION sizeof(OnigOptionType)
-#define SIZE_CODE_POINT sizeof(OnigCodePoint)
-#define SIZE_POINTER sizeof(PointerType)
+#define SIZE_RELADDR (int)sizeof(RelAddrType)
+#define SIZE_ABSADDR (int)sizeof(AbsAddrType)
+#define SIZE_LENGTH (int)sizeof(LengthType)
+#define SIZE_MEMNUM (int)sizeof(MemNumType)
+#define SIZE_STATE_CHECK_NUM (int)sizeof(StateCheckNumType)
+#define SIZE_REPEATNUM (int)sizeof(RepeatNumType)
+#define SIZE_OPTION (int)sizeof(OnigOptionType)
+#define SIZE_CODE_POINT (int)sizeof(OnigCodePoint)
+#define SIZE_POINTER (int)sizeof(PointerType)
#define GET_RELADDR_INC(addr,p) PLATFORM_GET_INC(addr, p, RelAddrType)
@@ -760,7 +760,7 @@ typedef struct _OnigStackType {
typedef struct {
void* stack_p;
- int stack_n;
+ size_t stack_n;
OnigOptionType options;
OnigRegion* region;
const UChar* start; /* search start position (for \G: BEGIN_POSITION) */
diff --git a/regparse.c b/regparse.c
index 039e2d4f9d..2a8f984372 100644
--- a/regparse.c
+++ b/regparse.c
@@ -217,7 +217,7 @@ onig_strncmp(const UChar* s1, const UChar* s2, int n)
extern void
onig_strcpy(UChar* dest, const UChar* src, const UChar* end)
{
- int len = end - src;
+ ptrdiff_t len = end - src;
if (len > 0) {
xmemcpy(dest, src, len);
dest[len] = (UChar )0;
@@ -228,7 +228,8 @@ onig_strcpy(UChar* dest, const UChar* src, const UChar* end)
static UChar*
strdup_with_null(OnigEncoding enc, UChar* s, UChar* end)
{
- int slen, term_len, i;
+ ptrdiff_t slen;
+ int term_len, i;
UChar *r;
slen = end - s;
@@ -389,7 +390,7 @@ onig_st_insert_strend(hash_table_type* table, const UChar* str_key,
typedef struct {
UChar* name;
- int name_len; /* byte length */
+ size_t name_len; /* byte length */
int back_num; /* number of backrefs */
int back_alloc;
int back_ref1;
@@ -1413,10 +1414,10 @@ node_new_option(OnigOptionType option)
extern int
onig_node_str_cat(Node* node, const UChar* s, const UChar* end)
{
- int addlen = end - s;
+ ptrdiff_t addlen = end - s;
if (addlen > 0) {
- int len = NSTR(node)->end - NSTR(node)->s;
+ ptrdiff_t len = NSTR(node)->end - NSTR(node)->s;
if (NSTR(node)->capa > 0 || (len + addlen > NODE_STR_BUF_SIZE - 1)) {
UChar* p;