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

* 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
This commit is contained in:
nobu 2009-06-30 02:08:54 +00:00
parent 88ca298efb
commit 23a32d6444
10 changed files with 72 additions and 57 deletions

View file

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

View file

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

View file

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

39
re.c
View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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