summaryrefslogtreecommitdiff
path: root/regint.h
diff options
context:
space:
mode:
Diffstat (limited to 'regint.h')
-rw-r--r--regint.h96
1 files changed, 51 insertions, 45 deletions
diff --git a/regint.h b/regint.h
index 75073e6377..3f4aa919e5 100644
--- a/regint.h
+++ b/regint.h
@@ -5,7 +5,7 @@
**********************************************************************/
/*-
* Copyright (c) 2002-2013 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
- * Copyright (c) 2011-2016 K.Takata <kentkt AT csc DOT jp>
+ * Copyright (c) 2011-2019 K.Takata <kentkt AT csc DOT jp>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -35,19 +35,15 @@
/* #define ONIG_DEBUG_COMPILE */
/* #define ONIG_DEBUG_SEARCH */
/* #define ONIG_DEBUG_MATCH */
+/* #define ONIG_DEBUG_MATCH_CACHE */
/* #define ONIG_DEBUG_MEMLEAK */
/* #define ONIG_DONT_OPTIMIZE */
/* for byte-code statistical data. */
/* #define ONIG_DEBUG_STATISTICS */
-/* enable matching optimization by using cache. */
-#define USE_CACHE_MATCH_OPT
-
-#ifdef USE_CACHE_MATCH_OPT
-# define NUM_CACHE_OPCODE_FAIL -1
-# define NUM_CACHE_OPCODE_UNINIT -2
-#endif
+/* enable the match optimization by using a cache. */
+#define USE_MATCH_CACHE
#if defined(ONIG_DEBUG_PARSE_TREE) || defined(ONIG_DEBUG_MATCH) || \
defined(ONIG_DEBUG_SEARCH) || defined(ONIG_DEBUG_COMPILE) || \
@@ -90,13 +86,12 @@
/* #define USE_OP_PUSH_OR_JUMP_EXACT */
#define USE_QTFR_PEEK_NEXT
#define USE_ST_LIBRARY
-#define USE_SUNDAY_QUICK_SEARCH
#define INIT_MATCH_STACK_SIZE 160
#define DEFAULT_MATCH_STACK_LIMIT_SIZE 0 /* unlimited */
#define DEFAULT_PARSE_DEPTH_LIMIT 4096
-#define OPT_EXACT_MAXLEN 24
+#define OPT_EXACT_MAXLEN 24 /* This must be smaller than ONIG_CHAR_TABLE_SIZE. */
/* check config */
#if defined(USE_PERL_SUBEXP_CALL) || defined(USE_CAPITAL_P_NAMED_GROUP)
@@ -158,12 +153,14 @@
#ifdef RUBY
# define CHECK_INTERRUPT_IN_MATCH_AT do { \
- msa->counter++; \
- if (msa->counter >= 128) { \
- msa->counter = 0; \
- rb_reg_check_timeout(reg, &msa->end_time); \
- rb_thread_check_ints(); \
- } \
+ msa->counter++; \
+ if (msa->counter >= 128) { \
+ msa->counter = 0; \
+ if (rb_reg_timeout_p(reg, &msa->end_time)) { \
+ goto timeout; \
+ } \
+ rb_thread_check_ints(); \
+ } \
} while(0)
# define onig_st_init_table st_init_table
# define onig_st_init_table_with_size st_init_table_with_size
@@ -218,9 +215,7 @@
#define xmemcpy memcpy
#define xmemmove memmove
-#if ((defined(RUBY_MSVCRT_VERSION) && RUBY_MSVCRT_VERSION >= 90) \
- || (!defined(RUBY_MSVCRT_VERSION) && defined(_WIN32))) \
- && !defined(__GNUC__)
+#if defined(_WIN32) && !defined(__GNUC__)
# define xalloca _alloca
# define xvsnprintf(buf,size,fmt,args) _vsnprintf_s(buf,size,_TRUNCATE,fmt,args)
# define xsnprintf sprintf_s
@@ -269,19 +264,6 @@
# include <stdio.h>
#endif
-#ifdef _WIN32
-# if defined(_MSC_VER) && (_MSC_VER < 1300)
-# ifndef _INTPTR_T_DEFINED
-# define _INTPTR_T_DEFINED
-typedef int intptr_t;
-# endif
-# ifndef _UINTPTR_T_DEFINED
-# define _UINTPTR_T_DEFINED
-typedef unsigned int uintptr_t;
-# endif
-# endif
-#endif /* _WIN32 */
-
#ifndef PRIdPTR
# ifdef _WIN64
# define PRIdPTR "I64d"
@@ -319,9 +301,13 @@ RUBY_SYMBOL_EXPORT_BEGIN
#define ONIG_LAST_CODE_POINT (~((OnigCodePoint )0))
+#define PLATFORM_GET_INC_ARGUMENTS_ASSERT(val, type) \
+ ((void)sizeof(char[2 * (sizeof(val) == sizeof(type)) - 1]))
+
#ifdef PLATFORM_UNALIGNED_WORD_ACCESS
# define PLATFORM_GET_INC(val,p,type) do{\
+ PLATFORM_GET_INC_ARGUMENTS_ASSERT(val, type);\
val = *(type* )p;\
(p) += sizeof(type);\
} while(0)
@@ -329,7 +315,10 @@ RUBY_SYMBOL_EXPORT_BEGIN
#else
# define PLATFORM_GET_INC(val,p,type) do{\
- xmemcpy(&val, (p), sizeof(type));\
+ PLATFORM_GET_INC_ARGUMENTS_ASSERT(val, type);\
+ type platform_get_value;\
+ xmemcpy(&platform_get_value, (p), sizeof(type));\
+ val = platform_get_value;\
(p) += sizeof(type);\
} while(0)
@@ -870,15 +859,25 @@ typedef struct _OnigStackType {
UChar *abs_pstr; /* absent start position */
const UChar *end_pstr; /* end position */
} absent_pos;
+#ifdef USE_MATCH_CACHE
+ struct {
+ long index; /* index of the match cache buffer */
+ uint8_t mask; /* bit-mask for the match cache buffer */
+ } match_cache_point;
+#endif
} u;
} OnigStackType;
-#ifdef USE_CACHE_MATCH_OPT
+#ifdef USE_MATCH_CACHE
typedef struct {
UChar *addr;
- long num;
- int outer_repeat;
-} OnigCacheIndex;
+ long cache_point;
+ int outer_repeat_mem;
+ long num_cache_points_at_outer_repeat;
+ long num_cache_points_in_outer_repeat;
+ int lookaround_nesting;
+ UChar *match_addr;
+} OnigCacheOpcode;
#endif
typedef struct {
@@ -903,16 +902,23 @@ typedef struct {
#else
uint64_t end_time;
#endif
-#ifdef USE_CACHE_MATCH_OPT
- long num_fail;
- int enable_cache_match_opt;
- long num_cache_opcode;
- long num_cache_table;
- OnigCacheIndex* cache_index_table;
- uint8_t* match_cache;
+#ifdef USE_MATCH_CACHE
+ int match_cache_status;
+ long num_fails;
+ long num_cache_opcodes;
+ OnigCacheOpcode* cache_opcodes;
+ long num_cache_points;
+ uint8_t* match_cache_buf;
#endif
} OnigMatchArg;
+#define NUM_CACHE_OPCODES_UNINIT 1
+#define NUM_CACHE_OPCODES_IMPOSSIBLE -1
+
+#define MATCH_CACHE_STATUS_UNINIT 1
+#define MATCH_CACHE_STATUS_INIT 2
+#define MATCH_CACHE_STATUS_DISABLED -1
+#define MATCH_CACHE_STATUS_ENABLED 0
#define IS_CODE_SB_WORD(enc,code) \
(ONIGENC_IS_CODE_ASCII(code) && ONIGENC_IS_CODE_WORD(enc,code))
@@ -976,7 +982,7 @@ extern int onig_st_insert_strend(hash_table_type* table, const UChar* str_key, c
#ifdef RUBY
extern size_t onig_memsize(const regex_t *reg);
extern size_t onig_region_memsize(const struct re_registers *regs);
-void rb_reg_check_timeout(regex_t *reg, void *end_time);
+bool rb_reg_timeout_p(regex_t *reg, void *end_time);
#endif
RUBY_SYMBOL_EXPORT_END