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

ruby-changes:6252

From: nobu <ko1@a...>
Date: Tue, 1 Jul 2008 17:22:03 +0900 (JST)
Subject: [ruby-changes:6252] Ruby:r17765 (trunk): * regexec.c (stack_double): use MatchStackLimitSize atomically.

nobu	2008-07-01 17:21:44 +0900 (Tue, 01 Jul 2008)

  New Revision: 17765

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

  Log:
    * regexec.c (stack_double): use MatchStackLimitSize atomically.
    
    * regparse.c (onig_free_shared_cclass_table): OnigTypeCClassTable
      needs atomicity
    
    * regsyntax.c: constified all predefined OnigSyntaxTypes.



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

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/regcomp.c?r1=17765&r2=17764&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/oniguruma.h?r1=17765&r2=17764&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/regparse.h?r1=17765&r2=17764&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/regexec.c?r1=17765&r2=17764&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=17765&r2=17764&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/regenc.c?r1=17765&r2=17764&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/regint.h?r1=17765&r2=17764&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/regsyntax.c?r1=17765&r2=17764&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/regparse.c?r1=17765&r2=17764&diff_format=u

Index: regparse.c
===================================================================
--- regparse.c	(revision 17764)
+++ regparse.c	(revision 17765)
@@ -34,7 +34,7 @@
 #define CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS
 
 
-OnigSyntaxType OnigSyntaxRuby = {
+const OnigSyntaxType OnigSyntaxRuby = {
   (( SYN_GNU_REGEX_OP | ONIG_SYN_OP_QMARK_NON_GREEDY |
      ONIG_SYN_OP_ESC_OCTAL3 | ONIG_SYN_OP_ESC_X_HEX2 |
      ONIG_SYN_OP_ESC_X_BRACE_HEX8 | ONIG_SYN_OP_ESC_CONTROL_CHARS |
@@ -70,7 +70,7 @@
   }
 };
 
-OnigSyntaxType*  OnigDefaultSyntax = ONIG_SYNTAX_RUBY;
+const OnigSyntaxType*  OnigDefaultSyntax = ONIG_SYNTAX_RUBY;
 
 extern void onig_null_warn(const char* s ARG_UNUSED) { }
 
@@ -342,7 +342,7 @@
 extern hash_table_type*
 onig_st_init_strend_table_with_size(int size)
 {
-  static struct st_hash_type hashType = {
+  static const struct st_hash_type hashType = {
     str_end_cmp,
     str_end_hash,
   };
@@ -2177,7 +2177,7 @@
   RQ_PQ_Q      /* to '+?)?' */
 };
 
-static enum ReduceType ReduceTypeTable[6][6] = {
+static enum ReduceType const ReduceTypeTable[6][6] = {
   {RQ_DEL,  RQ_A,    RQ_A,   RQ_QQ,   RQ_AQ,   RQ_ASIS}, /* '?'  */
   {RQ_DEL,  RQ_DEL,  RQ_DEL, RQ_P_QQ, RQ_P_QQ, RQ_DEL},  /* '*'  */
   {RQ_A,    RQ_A,    RQ_DEL, RQ_ASIS, RQ_P_QQ, RQ_DEL},  /* '+'  */
@@ -2862,7 +2862,7 @@
 
 static int
 str_exist_check_with_esc(OnigCodePoint s[], int n, UChar* from, UChar* to,
-		 OnigCodePoint bad, OnigEncoding enc, OnigSyntaxType* syn)
+		 OnigCodePoint bad, OnigEncoding enc, const OnigSyntaxType* syn)
 {
   int i, in_esc;
   OnigCodePoint x;
@@ -2903,7 +2903,7 @@
 {
   int num;
   OnigCodePoint c, c2;
-  OnigSyntaxType* syn = env->syntax;
+  const OnigSyntaxType* syn = env->syntax;
   OnigEncoding enc = env->enc;
   UChar* prev;
   UChar* p = *src;
@@ -3122,7 +3122,7 @@
   int r, num;
   OnigCodePoint c;
   OnigEncoding enc = env->enc;
-  OnigSyntaxType* syn = env->syntax;
+  const OnigSyntaxType* syn = env->syntax;
   UChar* prev;
   UChar* p = *src;
   PFETCH_READY;
@@ -3911,7 +3911,7 @@
 #define POSIX_BRACKET_CHECK_LIMIT_LENGTH  20
 #define POSIX_BRACKET_NAME_MIN_LEN         4
 
-  static PosixBracketEntryType PBS[] = {
+  static const PosixBracketEntryType PBS[] = {
     { (UChar* )"alnum",  ONIGENC_CTYPE_ALNUM,  5 },
     { (UChar* )"alpha",  ONIGENC_CTYPE_ALPHA,  5 },
     { (UChar* )"blank",  ONIGENC_CTYPE_BLANK,  5 },
@@ -3929,7 +3929,7 @@
     { (UChar* )NULL,     -1, 0 }
   };
 
-  PosixBracketEntryType *pb;
+  const PosixBracketEntryType *pb;
   int not, i, r;
   OnigCodePoint c;
   OnigEncoding enc = env->enc;
@@ -4742,11 +4742,11 @@
   return 0;
 }
 
-static const char* PopularQStr[] = {
+static const char* const PopularQStr[] = {
   "?", "*", "+", "??", "*?", "+?"
 };
 
-static const char* ReduceQStr[] = {
+static const char* const ReduceQStr[] = {
   "", "", "*", "*?", "??", "+ and ??", "+? and ?"
 };
 
@@ -4882,7 +4882,7 @@
   return val + (val >> 5);
 }
 
-static struct st_hash_type type_type_cclass_hash = {
+static const struct st_hash_type type_type_cclass_hash = {
     type_cclass_cmp,
     type_cclass_hash,
 };
@@ -4906,11 +4906,13 @@
 extern int
 onig_free_shared_cclass_table(void)
 {
+  THREAD_ATOMIC_START;
   if (IS_NOT_NULL(OnigTypeCClassTable)) {
     onig_st_foreach(OnigTypeCClassTable, i_free_shared_class, 0);
     onig_st_free_table(OnigTypeCClassTable);
     OnigTypeCClassTable = NULL;
   }
+  THREAD_ATOMIC_END;
 
   return 0;
 }
Index: regparse.h
===================================================================
--- regparse.h	(revision 17764)
+++ regparse.h	(revision 17765)
@@ -279,7 +279,7 @@
   OnigOptionType   option;
   OnigCaseFoldType case_fold_flag;
   OnigEncoding     enc;
-  OnigSyntaxType*  syntax;
+  const OnigSyntaxType* syntax;
   BitStatusType    capture_history;
   BitStatusType    bt_mem_start;
   BitStatusType    bt_mem_end;
Index: regcomp.c
===================================================================
--- regcomp.c	(revision 17764)
+++ regcomp.c	(revision 17765)
@@ -4380,7 +4380,7 @@
 static void
 select_opt_map_info(OptMapInfo* now, OptMapInfo* alt)
 {
-  static int z = 1<<15; /* 32768: something big value */
+  const int z = 1<<15; /* 32768: something big value */
 
   int v1, v2;
 
@@ -5547,7 +5547,7 @@
 extern int
 onig_alloc_init(regex_t** reg, OnigOptionType option,
 		OnigCaseFoldType case_fold_flag,
-                OnigEncoding enc, OnigSyntaxType* syntax)
+                OnigEncoding enc, const OnigSyntaxType* syntax)
 {
   if (! onig_inited)
     onig_init();
@@ -5591,7 +5591,7 @@
 
 extern int
 onig_new(regex_t** reg, const UChar* pattern, const UChar* pattern_end,
-	  OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax,
+	  OnigOptionType option, OnigEncoding enc, const OnigSyntaxType* syntax,
 	  OnigErrorInfo* einfo)
 {
   int r;
Index: include/ruby/oniguruma.h
===================================================================
--- include/ruby/oniguruma.h	(revision 17764)
+++ include/ruby/oniguruma.h	(revision 17765)
@@ -364,16 +364,16 @@
   OnigMetaCharTableType meta_char_table;
 } OnigSyntaxType;
 
-ONIG_EXTERN OnigSyntaxType OnigSyntaxASIS;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixBasic;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixExtended;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxEmacs;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxGrep;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxGnuRegex;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxJava;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl_NG;
-ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby;
+ONIG_EXTERN const OnigSyntaxType OnigSyntaxASIS;
+ONIG_EXTERN const OnigSyntaxType OnigSyntaxPosixBasic;
+ONIG_EXTERN const OnigSyntaxType OnigSyntaxPosixExtended;
+ONIG_EXTERN const OnigSyntaxType OnigSyntaxEmacs;
+ONIG_EXTERN const OnigSyntaxType OnigSyntaxGrep;
+ONIG_EXTERN const OnigSyntaxType OnigSyntaxGnuRegex;
+ONIG_EXTERN const OnigSyntaxType OnigSyntaxJava;
+ONIG_EXTERN const OnigSyntaxType OnigSyntaxPerl;
+ONIG_EXTERN const OnigSyntaxType OnigSyntaxPerl_NG;
+ONIG_EXTERN const OnigSyntaxType OnigSyntaxRuby;
 
 /* predefined syntaxes (see regsyntax.c) */
 #define ONIG_SYNTAX_ASIS               (&OnigSyntaxASIS)
@@ -388,7 +388,7 @@
 #define ONIG_SYNTAX_RUBY               (&OnigSyntaxRuby)
 
 /* default syntax */
-ONIG_EXTERN OnigSyntaxType*   OnigDefaultSyntax;
+ONIG_EXTERN const OnigSyntaxType*   OnigDefaultSyntax;
 #define ONIG_SYNTAX_DEFAULT   OnigDefaultSyntax
 
 /* syntax (operators) */
@@ -634,7 +634,7 @@
 
   OnigEncoding      enc;
   OnigOptionType    options;
-  OnigSyntaxType*   syntax;
+  const OnigSyntaxType* syntax;
   OnigCaseFoldType  case_fold_flag;
   void*             name_table;
 
@@ -683,7 +683,7 @@
 ONIG_EXTERN
 void onig_set_verb_warn_func P_((OnigWarnFunc f));
 ONIG_EXTERN
-int onig_new P_((OnigRegex*, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
+int onig_new P_((OnigRegex*, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, const OnigSyntaxType* syntax, OnigErrorInfo* einfo));
 ONIG_EXTERN
 int onig_new_deluxe P_((OnigRegex* reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
 ONIG_EXTERN
@@ -735,11 +735,11 @@
 ONIG_EXTERN
 OnigCaseFoldType onig_get_case_fold_flag P_((OnigRegex reg));
 ONIG_EXTERN
-OnigSyntaxType* onig_get_syntax P_((OnigRegex reg));
+const OnigSyntaxType* onig_get_syntax P_((OnigRegex reg));
 ONIG_EXTERN
-int onig_set_default_syntax P_((OnigSyntaxType* syntax));
+int onig_set_default_syntax P_((const OnigSyntaxType* syntax));
 ONIG_EXTERN
-void onig_copy_syntax P_((OnigSyntaxType* to, OnigSyntaxType* from));
+void onig_copy_syntax P_((OnigSyntaxType* to, const OnigSyntaxType* from));
 ONIG_EXTERN
 unsigned int onig_get_syntax_op P_((OnigSyntaxType* syntax));
 ONIG_EXTERN
Index: regenc.c
===================================================================
--- regenc.c	(revision 17764)
+++ regenc.c	(revision 17765)
@@ -451,7 +451,7 @@
 ss_apply_all_case_fold(OnigCaseFoldType flag ARG_UNUSED,
 		       OnigApplyAllCaseFoldFunc f, void* arg)
 {
-  static OnigCodePoint ss[] = { 0x73, 0x73 };
+  OnigCodePoint ss[] = { 0x73, 0x73 };
 
   return (*f)((OnigCodePoint )0xdf, ss, 2, arg);
 }
@@ -783,7 +783,7 @@
 extern int
 onigenc_minimum_property_name_to_ctype(OnigEncoding enc, UChar* p, UChar* end)
 {
-  static PosixBracketEntryType PBS[] = {
+  static const PosixBracketEntryType PBS[] = {
     { (UChar* )"Alnum",  ONIGENC_CTYPE_ALNUM,  5 },
     { (UChar* )"Alpha",  ONIGENC_CTYPE_ALPHA,  5 },
     { (UChar* )"Blank",  ONIGENC_CTYPE_BLANK,  5 },
@@ -801,7 +801,7 @@
     { (UChar* )NULL, -1, 0 }
   };
 
-  PosixBracketEntryType *pb;
+  const PosixBracketEntryType *pb;
   int len;
 
   len = onigenc_strlen(enc, p, end);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 17764)
+++ ChangeLog	(revision 17765)
@@ -1,3 +1,12 @@
+Tue Jul  1 17:21:42 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* regexec.c (stack_double): use MatchStackLimitSize atomically.
+
+	* regparse.c (onig_free_shared_cclass_table): OnigTypeCClassTable
+	  needs atomicity
+
+	* regsyntax.c: constified all predefined OnigSyntaxTypes.
+
 Tue Jul  1 16:57:44 2008  URABE Shyouhei  <shyouhei@r...>
 
 	* include/ruby/st.h (struct st_table): type of bit-field
Index: regint.h
===================================================================
--- regint.h	(revision 17764)
+++ regint.h	(revision 17765)
@@ -802,7 +802,7 @@
 extern UChar* onig_error_code_to_format P_((int code));
 extern void  onig_snprintf_with_pattern PV_((UChar buf[], int bufsize, OnigEncoding enc, UChar* pat, UChar* pat_end, const UChar *fmt, ...));
 extern int  onig_bbuf_init P_((BBuf* buf, int size));
-extern int  onig_alloc_init P_((regex_t** reg, OnigOptionType option, OnigCaseFoldType case_fold_flag, OnigEncoding enc, OnigSyntaxType* syntax));
+extern int  onig_alloc_init P_((regex_t** reg, OnigOptionType option, OnigCaseFoldType case_fold_flag, OnigEncoding enc, const OnigSyntaxType* syntax));
 extern int  onig_compile P_((regex_t* reg, const UChar* pattern, const UChar* pattern_end, OnigErrorInfo* einfo));
 extern void onig_chain_reduce P_((regex_t* reg));
 extern void onig_chain_link_add P_((regex_t* to, regex_t* add));
Index: regexec.c
===================================================================
--- regexec.c	(revision 17764)
+++ regexec.c	(revision 17765)
@@ -454,12 +454,13 @@
     n *= 2;
   }
   else {
+    unsigned int limit_size = MatchStackLimitSize;
     n *= 2;
-    if (MatchStackLimitSize != 0 && n > MatchStackLimitSize) {
-      if ((unsigned int )(stk_end - stk_base) == MatchStackLimitSize)
+    if (limit_size != 0 && n > limit_size) {
+      if ((unsigned int )(stk_end - stk_base) == limit_size)
         return ONIGERR_MATCH_STACK_LIMIT_OVER;
       else
-        n = MatchStackLimitSize;
+        n = limit_size;
     }
     x = (OnigStackType* )xrealloc(stk_base, sizeof(OnigStackType) * n);
     if (IS_NULL(x)) {
@@ -1249,7 +1250,7 @@
 #endif
 	 const UChar* sstart, UChar* sprev, OnigMatchArg* msa)
 {
-  static UChar FinishCode[] = { OP_FINISH };
+  static const UChar FinishCode[] = { OP_FINISH };
 
   int i, n, num_mem, best_len, pop_level;
   LengthType tlen, tlen2;
@@ -1295,7 +1296,7 @@
 	  (int )(end - str), (int )(sstart - str));
 #endif
 
-  STACK_PUSH_ENSURED(STK_ALT, FinishCode);  /* bottom stack */
+  STACK_PUSH_ENSURED(STK_ALT, (UChar *)FinishCode);  /* bottom stack */
   best_len = ONIG_MISMATCH;
   s = (UChar* )sstart;
   while (1) {
@@ -3555,7 +3556,7 @@
     }
   }
   else if (str == end) { /* empty string */
-    static const UChar* address_for_empty_string = (UChar* )"";
+    static const UChar address_for_empty_string[] = "";
 
 #ifdef ONIG_DEBUG_SEARCH
     fprintf(stderr, "onig_search: empty string.\n");
@@ -3785,7 +3786,7 @@
   return reg->case_fold_flag;
 }
 
-extern OnigSyntaxType*
+extern const OnigSyntaxType*
 onig_get_syntax(regex_t* reg)
 {
   return reg->syntax;
Index: regsyntax.c
===================================================================
--- regsyntax.c	(revision 17764)
+++ regsyntax.c	(revision 17765)
@@ -29,7 +29,7 @@
 
 #include "regint.h"
 
-OnigSyntaxType OnigSyntaxASIS = {
+const OnigSyntaxType OnigSyntaxASIS = {
     0
   , ONIG_SYN_OP2_INEFFECTIVE_ESCAPE
   , 0
@@ -45,7 +45,7 @@
   }
 };
 
-OnigSyntaxType OnigSyntaxPosixBasic = {
+const OnigSyntaxType OnigSyntaxPosixBasic = {
   ( SYN_POSIX_COMMON_OP | ONIG_SYN_OP_ESC_LPAREN_SUBEXP |
     ONIG_SYN_OP_ESC_BRACE_INTERVAL )
   , 0
@@ -62,7 +62,7 @@
   }
 };
 
-OnigSyntaxType OnigSyntaxPosixExtended = {
+const OnigSyntaxType OnigSyntaxPosixExtended = {
   ( SYN_POSIX_COMMON_OP | ONIG_SYN_OP_LPAREN_SUBEXP |
     ONIG_SYN_OP_BRACE_INTERVAL |
     ONIG_SYN_OP_PLUS_ONE_INF | ONIG_SYN_OP_QMARK_ZERO_ONE | ONIG_SYN_OP_VBAR_ALT )
@@ -83,7 +83,7 @@
   }
 };
 
-OnigSyntaxType OnigSyntaxEmacs = {
+const OnigSyntaxType OnigSyntaxEmacs = {
   ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_BRACKET_CC |
     ONIG_SYN_OP_ESC_BRACE_INTERVAL |
     ONIG_SYN_OP_ESC_LPAREN_SUBEXP | ONIG_SYN_OP_ESC_VBAR_ALT |
@@ -104,7 +104,7 @@
   }
 };
 
-OnigSyntaxType OnigSyntaxGrep = {
+const OnigSyntaxType OnigSyntaxGrep = {
   ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_BRACKET_CC | ONIG_SYN_OP_POSIX_BRACKET |
     ONIG_SYN_OP_ESC_BRACE_INTERVAL | ONIG_SYN_OP_ESC_LPAREN_SUBEXP |
     ONIG_SYN_OP_ESC_VBAR_ALT |
@@ -126,7 +126,7 @@
   }
 };
 
-OnigSyntaxType OnigSyntaxGnuRegex = {
+const OnigSyntaxType OnigSyntaxGnuRegex = {
   SYN_GNU_REGEX_OP
   , 0
   , SYN_GNU_REGEX_BV
@@ -142,7 +142,7 @@
   }
 };
 
-OnigSyntaxType OnigSyntaxJava = {
+const OnigSyntaxType OnigSyntaxJava = {
   (( SYN_GNU_REGEX_OP | ONIG_SYN_OP_QMARK_NON_GREEDY |
      ONIG_SYN_OP_ESC_CONTROL_CHARS | ONIG_SYN_OP_ESC_C_CONTROL |
      ONIG_SYN_OP_ESC_OCTAL3 | ONIG_SYN_OP_ESC_X_HEX2 )
@@ -165,7 +165,7 @@
   }
 };
 
-OnigSyntaxType OnigSyntaxPerl = {
+const OnigSyntaxType OnigSyntaxPerl = {
   (( SYN_GNU_REGEX_OP | ONIG_SYN_OP_QMARK_NON_GREEDY |
      ONIG_SYN_OP_ESC_OCTAL3 | ONIG_SYN_OP_ESC_X_HEX2 |
      ONIG_SYN_OP_ESC_X_BRACE_HEX8 | ONIG_SYN_OP_ESC_CONTROL_CHARS |
@@ -189,7 +189,7 @@
 };
 
 /* Perl + named group */
-OnigSyntaxType OnigSyntaxPerl_NG = {
+const OnigSyntaxType OnigSyntaxPerl_NG = {
   (( SYN_GNU_REGEX_OP | ONIG_SYN_OP_QMARK_NON_GREEDY |
      ONIG_SYN_OP_ESC_OCTAL3 | ONIG_SYN_OP_ESC_X_HEX2 |
      ONIG_SYN_OP_ESC_X_BRACE_HEX8 | ONIG_SYN_OP_ESC_CONTROL_CHARS |
@@ -220,7 +220,7 @@
 
 
 extern int
-onig_set_default_syntax(OnigSyntaxType* syntax)
+onig_set_default_syntax(const OnigSyntaxType* syntax)
 {
   if (IS_NULL(syntax))
     syntax = ONIG_SYNTAX_RUBY;
@@ -230,7 +230,7 @@
 }
 
 extern void
-onig_copy_syntax(OnigSyntaxType* to, OnigSyntaxType* from)
+onig_copy_syntax(OnigSyntaxType* to, const OnigSyntaxType* from)
 {
   *to = *from;
 }

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

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