summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--include/ruby/oniguruma.h32
-rw-r--r--regcomp.c6
-rw-r--r--regenc.c6
-rw-r--r--regexec.c15
-rw-r--r--regint.h2
-rw-r--r--regparse.c26
-rw-r--r--regparse.h2
-rw-r--r--regsyntax.c22
9 files changed, 66 insertions, 54 deletions
diff --git a/ChangeLog b/ChangeLog
index bc05238..765b49e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Tue Jul 1 17:21:42 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* include/ruby/st.h (struct st_table): type of bit-field
diff --git a/include/ruby/oniguruma.h b/include/ruby/oniguruma.h
index 6d08f61..fe016d2 100644
--- a/include/ruby/oniguruma.h
+++ b/include/ruby/oniguruma.h
@@ -364,16 +364,16 @@ typedef struct {
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 @@ ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby;
#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 @@ typedef struct re_pattern_buffer {
OnigEncoding enc;
OnigOptionType options;
- OnigSyntaxType* syntax;
+ const OnigSyntaxType* syntax;
OnigCaseFoldType case_fold_flag;
void* name_table;
@@ -683,7 +683,7 @@ void onig_set_warn_func P_((OnigWarnFunc f));
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 @@ OnigOptionType onig_get_options P_((OnigRegex reg));
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
diff --git a/regcomp.c b/regcomp.c
index 19cd91f..cb54c44 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -4380,7 +4380,7 @@ add_char_amb_opt_map_info(OptMapInfo* map, UChar* p, UChar* end,
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 @@ static int onig_inited = 0;
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 @@ onig_alloc_init(regex_t** reg, OnigOptionType option,
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;
diff --git a/regenc.c b/regenc.c
index 4267ebc..75a6a03 100644
--- a/regenc.c
+++ b/regenc.c
@@ -451,7 +451,7 @@ static int
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 @@ onigenc_mb4_code_to_mbc(OnigEncoding enc, OnigCodePoint code, UChar *buf)
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 @@ onigenc_minimum_property_name_to_ctype(OnigEncoding enc, UChar* p, UChar* end)
{ (UChar* )NULL, -1, 0 }
};
- PosixBracketEntryType *pb;
+ const PosixBracketEntryType *pb;
int len;
len = onigenc_strlen(enc, p, end);
diff --git a/regexec.c b/regexec.c
index 684c5c8..b0cc664 100644
--- a/regexec.c
+++ b/regexec.c
@@ -454,12 +454,13 @@ stack_double(OnigStackType** arg_stk_base, OnigStackType** arg_stk_end,
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 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
#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 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
(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 @@ onig_search(regex_t* reg, const UChar* str, const UChar* end,
}
}
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 @@ onig_get_case_fold_flag(regex_t* reg)
return reg->case_fold_flag;
}
-extern OnigSyntaxType*
+extern const OnigSyntaxType*
onig_get_syntax(regex_t* reg)
{
return reg->syntax;
diff --git a/regint.h b/regint.h
index 660e975..c597fff 100644
--- a/regint.h
+++ b/regint.h
@@ -802,7 +802,7 @@ extern void onig_print_statistics P_((FILE* f));
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));
diff --git a/regparse.c b/regparse.c
index 8d74efa..4a5e861 100644
--- a/regparse.c
+++ b/regparse.c
@@ -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 OnigSyntaxRuby = {
}
};
-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 @@ str_end_hash(st_str_end_key* x)
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 @@ enum ReduceType {
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 @@ find_str_position(OnigCodePoint s[], int n, UChar* from, UChar* to,
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 @@ fetch_token_in_cc(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env)
{
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 @@ fetch_token(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env)
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 @@ parse_posix_bracket(CClassNode* cc, UChar** src, UChar* end, ScanEnv* env)
#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 @@ parse_posix_bracket(CClassNode* cc, UChar** src, UChar* end, ScanEnv* env)
{ (UChar* )NULL, -1, 0 }
};
- PosixBracketEntryType *pb;
+ const PosixBracketEntryType *pb;
int not, i, r;
OnigCodePoint c;
OnigEncoding enc = env->enc;
@@ -4742,11 +4742,11 @@ parse_enclose(Node** np, OnigToken* tok, int term, UChar** src, UChar* end,
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 @@ static int type_cclass_hash(type_cclass_key* key)
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 @@ i_free_shared_class(type_cclass_key* key, Node* node, void* arg ARG_UNUSED)
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;
}
diff --git a/regparse.h b/regparse.h
index 26ebb11..cd653f5 100644
--- a/regparse.h
+++ b/regparse.h
@@ -279,7 +279,7 @@ typedef struct {
OnigOptionType option;
OnigCaseFoldType case_fold_flag;
OnigEncoding enc;
- OnigSyntaxType* syntax;
+ const OnigSyntaxType* syntax;
BitStatusType capture_history;
BitStatusType bt_mem_start;
BitStatusType bt_mem_end;
diff --git a/regsyntax.c b/regsyntax.c
index ade5b55..96348b0 100644
--- a/regsyntax.c
+++ b/regsyntax.c
@@ -29,7 +29,7 @@
#include "regint.h"
-OnigSyntaxType OnigSyntaxASIS = {
+const OnigSyntaxType OnigSyntaxASIS = {
0
, ONIG_SYN_OP2_INEFFECTIVE_ESCAPE
, 0
@@ -45,7 +45,7 @@ OnigSyntaxType OnigSyntaxASIS = {
}
};
-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 OnigSyntaxPosixBasic = {
}
};
-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 OnigSyntaxPosixExtended = {
}
};
-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 OnigSyntaxEmacs = {
}
};
-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 OnigSyntaxGrep = {
}
};
-OnigSyntaxType OnigSyntaxGnuRegex = {
+const OnigSyntaxType OnigSyntaxGnuRegex = {
SYN_GNU_REGEX_OP
, 0
, SYN_GNU_REGEX_BV
@@ -142,7 +142,7 @@ OnigSyntaxType OnigSyntaxGnuRegex = {
}
};
-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 OnigSyntaxJava = {
}
};
-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 @@ OnigSyntaxType OnigSyntaxPerl = {
};
/* 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 @@ OnigSyntaxType OnigSyntaxPerl_NG = {
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 @@ onig_set_default_syntax(OnigSyntaxType* syntax)
}
extern void
-onig_copy_syntax(OnigSyntaxType* to, OnigSyntaxType* from)
+onig_copy_syntax(OnigSyntaxType* to, const OnigSyntaxType* from)
{
*to = *from;
}