[前][次][番号順一覧][スレッド一覧]

ruby-changes:12222

From: nobu <ko1@a...>
Date: Tue, 30 Jun 2009 11:09:15 +0900 (JST)
Subject: [ruby-changes:12222] Ruby:r23907 (trunk): * include/ruby/oniguruma.h, include/ruby/re.h, re.c, regcomp.c,

nobu	2009-06-30 11:08:54 +0900 (Tue, 30 Jun 2009)

  New Revision: 23907

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23907

  Log:
    * include/ruby/oniguruma.h, include/ruby/re.h, re.c, regcomp.c,
      regenc.c, regerror.c, regexec.c, regint.h, regparse.c: use long.

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/oniguruma.h
    trunk/include/ruby/re.h
    trunk/re.c
    trunk/regcomp.c
    trunk/regenc.c
    trunk/regerror.c
    trunk/regexec.c
    trunk/regint.h
    trunk/regparse.c

Index: regparse.c
===================================================================
--- regparse.c	(revision 23906)
+++ regparse.c	(revision 23907)
@@ -217,7 +217,7 @@
 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 @@
 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 @@
 
 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 @@
 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;
Index: regcomp.c
===================================================================
--- regcomp.c	(revision 23906)
+++ regcomp.c	(revision 23907)
@@ -52,7 +52,7 @@
 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 @@
   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 @@
   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 @@
 }
 
 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;
Index: include/ruby/oniguruma.h
===================================================================
--- include/ruby/oniguruma.h	(revision 23906)
+++ include/ruby/oniguruma.h	(revision 23907)
@@ -106,7 +106,7 @@
 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 @@
 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
Index: include/ruby/re.h
===================================================================
--- include/ruby/re.h	(revision 23906)
+++ include/ruby/re.h	(revision 23907)
@@ -27,8 +27,8 @@
 typedef struct re_pattern_buffer Regexp;
 
 struct rmatch_offset {
-    int beg;
-    int end;
+    long beg;
+    long end;
 };
 
 struct rmatch {
@@ -50,9 +50,9 @@
 #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);
 
Index: regenc.c
===================================================================
--- regenc.c	(revision 23906)
+++ regenc.c	(revision 23907)
@@ -57,7 +57,7 @@
   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 @@
   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 @@
   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 @@
 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;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 23906)
+++ ChangeLog	(revision 23907)
@@ -1,3 +1,8 @@
+Tue Jun 30 11:08:49 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* dln.c (dln_find_1): fixed index overrun.
Index: re.c
===================================================================
--- re.c	(revision 23906)
+++ re.c	(revision 23907)
@@ -792,14 +792,19 @@
 }
 
 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 @@
     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 @@
     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 @@
 	}
 	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 @@
 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 @@
       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 @@
 }
 
 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 @@
 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 @@
     }
     hashval = hashval + (hashval>>5);
 
-    return INT2FIX(hashval);
+    return LONG2FIX(hashval);
 }
 
 
Index: regerror.c
===================================================================
--- regerror.c	(revision 23906)
+++ regerror.c	(revision 23907)
@@ -232,7 +232,7 @@
     *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 @@
 {
   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 @@
     va_dcl
 #endif
 {
-  int n, need, len;
+  size_t need;
+  int n, len;
   UChar *p, *s, *bp;
   UChar bs[6];
   va_list args;
Index: regint.h
===================================================================
--- regint.h	(revision 23906)
+++ regint.h	(revision 23907)
@@ -352,7 +352,7 @@
 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 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 {
   void* stack_p;
-  int   stack_n;
+  size_t stack_n;
   OnigOptionType options;
   OnigRegion*    region;
   const UChar* start;   /* search start position (for \G: BEGIN_POSITION) */
Index: regexec.c
===================================================================
--- regexec.c	(revision 23906)
+++ regexec.c	(revision 23907)
@@ -413,7 +413,7 @@
 #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 @@
 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 @@
 
 /* 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 @@
   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 @@
 
 #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 @@
 }
 
 
-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)
 {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]