46#define USE_MATCH_CACHE
48#if defined(ONIG_DEBUG_PARSE_TREE) || defined(ONIG_DEBUG_MATCH) || \
49 defined(ONIG_DEBUG_SEARCH) || defined(ONIG_DEBUG_COMPILE) || \
50 defined(ONIG_DEBUG_STATISTICS) || defined(ONIG_DEBUG_MEMLEAK)
57#ifndef UNALIGNED_WORD_ACCESS
58# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
59 defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || \
60 defined(__powerpc64__) || defined(__POWERPC__) || defined(__aarch64__) || \
62# define UNALIGNED_WORD_ACCESS 1
64# define UNALIGNED_WORD_ACCESS 0
68#if UNALIGNED_WORD_ACCESS
69# define PLATFORM_UNALIGNED_WORD_ACCESS
74#define USE_NAMED_GROUP
75#define USE_SUBEXP_CALL
76#define USE_PERL_SUBEXP_CALL
77#define USE_CAPITAL_P_NAMED_GROUP
78#define USE_BACKREF_WITH_LEVEL
79#define USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT
80#define USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE
81#define USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR
83#define USE_NO_INVALID_QUANTIFIER
87#define USE_QTFR_PEEK_NEXT
90#define INIT_MATCH_STACK_SIZE 160
91#define DEFAULT_MATCH_STACK_LIMIT_SIZE 0
92#define DEFAULT_PARSE_DEPTH_LIMIT 4096
94#define OPT_EXACT_MAXLEN 24
97#if defined(USE_PERL_SUBEXP_CALL) || defined(USE_CAPITAL_P_NAMED_GROUP)
98# if !defined(USE_NAMED_GROUP) || !defined(USE_SUBEXP_CALL)
99# error USE_NAMED_GROUP and USE_SUBEXP_CALL must be defined.
104# define ARG_UNUSED __attribute__ ((unused))
109#if !defined(RUBY) && defined(RUBY_EXPORT)
113# ifndef RUBY_DEFINES_H
122# if SIZEOF_LONG_LONG > 0
123# define LONG_LONG long long
131#ifdef ONIG_ESCAPE_UCHAR_COLLISION
132# undef ONIG_ESCAPE_UCHAR_COLLISION
135#define USE_WORD_BEGIN_END
137# undef USE_CAPTURE_HISTORY
139# define USE_CAPTURE_HISTORY
141#define USE_VARIABLE_META_CHARS
142#define USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE
147# define xmalloc malloc
148# define xrealloc realloc
149# define xcalloc calloc
155# define CHECK_INTERRUPT_IN_MATCH_AT do { \
157 if (msa->counter >= 128) { \
159 if (rb_reg_timeout_p(reg, &msa->end_time)) { \
162 rb_thread_check_ints(); \
165# define onig_st_init_table st_init_table
166# define onig_st_init_table_with_size st_init_table_with_size
167# define onig_st_init_numtable st_init_numtable
168# define onig_st_init_numtable_with_size st_init_numtable_with_size
169# define onig_st_init_strtable st_init_strtable
170# define onig_st_init_strtable_with_size st_init_strtable_with_size
171# define onig_st_delete st_delete
172# define onig_st_delete_safe st_delete_safe
173# define onig_st_insert st_insert
174# define onig_st_lookup st_lookup
175# define onig_st_foreach st_foreach
176# define onig_st_add_direct st_add_direct
177# define onig_st_free_table st_free_table
178# define onig_st_cleanup_safe st_cleanup_safe
179# define onig_st_copy st_copy
180# define onig_st_nothing_key_clone st_nothing_key_clone
181# define onig_st_nothing_key_free st_nothing_key_free
182# define onig_st_is_member st_is_member
184# define USE_UPPER_CASE_TABLE
187# define CHECK_INTERRUPT_IN_MATCH_AT
189# define st_init_table onig_st_init_table
190# define st_init_table_with_size onig_st_init_table_with_size
191# define st_init_numtable onig_st_init_numtable
192# define st_init_numtable_with_size onig_st_init_numtable_with_size
193# define st_init_strtable onig_st_init_strtable
194# define st_init_strtable_with_size onig_st_init_strtable_with_size
195# define st_delete onig_st_delete
196# define st_delete_safe onig_st_delete_safe
197# define st_insert onig_st_insert
198# define st_lookup onig_st_lookup
199# define st_foreach onig_st_foreach
200# define st_add_direct onig_st_add_direct
201# define st_free_table onig_st_free_table
202# define st_cleanup_safe onig_st_cleanup_safe
203# define st_copy onig_st_copy
204# define st_nothing_key_clone onig_st_nothing_key_clone
205# define st_nothing_key_free onig_st_nothing_key_free
207# define onig_st_is_member st_is_member
211#define STATE_CHECK_STRING_THRESHOLD_LEN 7
212#define STATE_CHECK_BUFF_MAX_SIZE 0x4000
214#define xmemset memset
215#define xmemcpy memcpy
216#define xmemmove memmove
218#if defined(_WIN32) && !defined(__GNUC__)
219# define xalloca _alloca
220# define xvsnprintf(buf,size,fmt,args) _vsnprintf_s(buf,size,_TRUNCATE,fmt,args)
221# define xsnprintf sprintf_s
222# define xstrcat(dest,src,size) strcat_s(dest,size,src)
224# define xalloca alloca
225# define xvsnprintf vsnprintf
226# define xsnprintf snprintf
227# define xstrcat(dest,src,size) strcat(dest,src)
230#if defined(ONIG_DEBUG_MEMLEAK) && defined(_MSC_VER)
231# define _CRTDBG_MAP_ALLOC
238#if defined(HAVE_ALLOCA_H) && (defined(_AIX) || !defined(__GNUC__))
245#ifdef HAVE_SYS_TYPES_H
246# include <sys/types.h>
253#ifdef HAVE_INTTYPES_H
254# include <inttypes.h>
268# define PRIdPTRDIFF PRIdPTR
273RUBY_SYMBOL_EXPORT_BEGIN
281#define MIN(a,b) (((a)>(b))?(b):(a))
282#define MAX(a,b) (((a)<(b))?(b):(a))
284#define IS_NULL(p) (((void*)(p)) == (void*)0)
285#define IS_NOT_NULL(p) (((void*)(p)) != (void*)0)
286#define CHECK_NULL_RETURN(p) if (IS_NULL(p)) return NULL
287#define CHECK_NULL_RETURN_MEMERR(p) if (IS_NULL(p)) return ONIGERR_MEMORY
288#define NULL_UCHARP ((UChar* )0)
290#define ONIG_LAST_CODE_POINT (~((OnigCodePoint )0))
292#define PLATFORM_GET_INC_ARGUMENTS_ASSERT(val, type) \
293 ((void)sizeof(char[2 * (sizeof(val) == sizeof(type)) - 1]))
295#ifdef PLATFORM_UNALIGNED_WORD_ACCESS
297# define PLATFORM_GET_INC(val,p,type) do{\
298 PLATFORM_GET_INC_ARGUMENTS_ASSERT(val, type);\
300 (p) += sizeof(type);\
305# define PLATFORM_GET_INC(val,p,type) do{\
306 PLATFORM_GET_INC_ARGUMENTS_ASSERT(val, type);\
307 type platform_get_value;\
308 xmemcpy(&platform_get_value, (p), sizeof(type));\
309 val = platform_get_value;\
310 (p) += sizeof(type);\
314# define WORD_ALIGNMENT_SIZE SIZEOF_LONG
316# define GET_ALIGNMENT_PAD_SIZE(addr,pad_size) do {\
317 (pad_size) = WORD_ALIGNMENT_SIZE \
318 - ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\
319 if ((pad_size) == WORD_ALIGNMENT_SIZE) (pad_size) = 0;\
322# define ALIGNMENT_RIGHT(addr) do {\
323 (addr) += (WORD_ALIGNMENT_SIZE - 1);\
324 (addr) -= ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\
330#define STACK_POP_LEVEL_FREE 0
331#define STACK_POP_LEVEL_MEM_START 1
332#define STACK_POP_LEVEL_ALL 2
335#define ONIG_OPTIMIZE_NONE 0
336#define ONIG_OPTIMIZE_EXACT 1
337#define ONIG_OPTIMIZE_EXACT_BM 2
338#define ONIG_OPTIMIZE_EXACT_BM_NOT_REV 3
339#define ONIG_OPTIMIZE_EXACT_IC 4
340#define ONIG_OPTIMIZE_MAP 5
341#define ONIG_OPTIMIZE_EXACT_BM_IC 6
342#define ONIG_OPTIMIZE_EXACT_BM_NOT_REV_IC 7
345typedef unsigned int BitStatusType;
347#define BIT_STATUS_BITS_NUM (sizeof(BitStatusType) * 8)
348#define BIT_STATUS_CLEAR(stats) (stats) = 0
349#define BIT_STATUS_ON_ALL(stats) (stats) = ~((BitStatusType )0)
350#define BIT_STATUS_AT(stats,n) \
351 ((n) < (int )BIT_STATUS_BITS_NUM ? ((stats) & ((BitStatusType )1 << n)) : ((stats) & 1))
353#define BIT_STATUS_ON_AT(stats,n) do {\
354 if ((n) < (int )BIT_STATUS_BITS_NUM)\
355 (stats) |= (1 << (n));\
360#define BIT_STATUS_ON_AT_SIMPLE(stats,n) do {\
361 if ((n) < (int )BIT_STATUS_BITS_NUM)\
362 (stats) |= (1 << (n));\
366#define INT_MAX_LIMIT ((1UL << (SIZEOF_INT * 8 - 1)) - 1)
371#define MAX_COMPILED_PROGRAM_SIZE ((unsigned int )(INT_MAX_LIMIT / 4))
373#define DIGITVAL(code) ((code) - '0')
374#define ODIGITVAL(code) DIGITVAL(code)
375#define XDIGITVAL(enc,code) \
376 (ONIGENC_IS_CODE_DIGIT(enc,code) ? DIGITVAL(code) \
377 : (ONIGENC_IS_CODE_UPPER(enc,code) ? (code) - 'A' + 10 : (code) - 'a' + 10))
379#define IS_SINGLELINE(option) ((option) & ONIG_OPTION_SINGLELINE)
380#define IS_MULTILINE(option) ((option) & ONIG_OPTION_MULTILINE)
381#define IS_IGNORECASE(option) ((option) & ONIG_OPTION_IGNORECASE)
382#define IS_EXTEND(option) ((option) & ONIG_OPTION_EXTEND)
383#define IS_FIND_LONGEST(option) ((option) & ONIG_OPTION_FIND_LONGEST)
384#define IS_FIND_NOT_EMPTY(option) ((option) & ONIG_OPTION_FIND_NOT_EMPTY)
385#define IS_FIND_CONDITION(option) ((option) & \
386 (ONIG_OPTION_FIND_LONGEST | ONIG_OPTION_FIND_NOT_EMPTY))
387#define IS_NOTBOL(option) ((option) & ONIG_OPTION_NOTBOL)
388#define IS_NOTEOL(option) ((option) & ONIG_OPTION_NOTEOL)
389#define IS_NOTBOS(option) ((option) & ONIG_OPTION_NOTBOS)
390#define IS_NOTEOS(option) ((option) & ONIG_OPTION_NOTEOS)
391#define IS_ASCII_RANGE(option) ((option) & ONIG_OPTION_ASCII_RANGE)
392#define IS_POSIX_BRACKET_ALL_RANGE(option) ((option) & ONIG_OPTION_POSIX_BRACKET_ALL_RANGE)
393#define IS_WORD_BOUND_ALL_RANGE(option) ((option) & ONIG_OPTION_WORD_BOUND_ALL_RANGE)
394#define IS_NEWLINE_CRLF(option) ((option) & ONIG_OPTION_NEWLINE_CRLF)
401#define IS_DYNAMIC_OPTION(option) 0
403#define DISABLE_CASE_FOLD_MULTI_CHAR(case_fold_flag) \
404 ((case_fold_flag) & ~INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR)
406#define REPEAT_INFINITE -1
407#define IS_REPEAT_INFINITE(n) ((n) == REPEAT_INFINITE)
410#define BITS_PER_BYTE 8
411#define SINGLE_BYTE_SIZE (1 << BITS_PER_BYTE)
412#define BITS_IN_ROOM ((int )sizeof(Bits) * BITS_PER_BYTE)
413#define BITSET_SIZE (SINGLE_BYTE_SIZE / BITS_IN_ROOM)
415#ifdef PLATFORM_UNALIGNED_WORD_ACCESS
416typedef unsigned int Bits;
418typedef unsigned char Bits;
420typedef Bits BitSet[BITSET_SIZE];
421typedef Bits* BitSetRef;
423#define SIZE_BITSET (int )sizeof(BitSet)
425#define BITSET_CLEAR(bs) do {\
427 for (i = 0; i < BITSET_SIZE; i++) { (bs)[i] = 0; } \
430#define BS_ROOM(bs,pos) (bs)[(int )(pos) / BITS_IN_ROOM]
431#define BS_BIT(pos) (1U << ((int )(pos) % BITS_IN_ROOM))
433#define BITSET_AT(bs, pos) (BS_ROOM(bs,pos) & BS_BIT(pos))
434#define BITSET_SET_BIT(bs, pos) BS_ROOM(bs,pos) |= BS_BIT(pos)
435#define BITSET_CLEAR_BIT(bs, pos) BS_ROOM(bs,pos) &= ~(BS_BIT(pos))
436#define BITSET_INVERT_BIT(bs, pos) BS_ROOM(bs,pos) ^= BS_BIT(pos)
445#define BBUF_INIT(buf,size) onig_bbuf_init((BBuf* )(buf), (size))
447#define BBUF_SIZE_INC(buf,inc) do{\
449 (buf)->alloc += (inc);\
450 tmp = (UChar* )xrealloc((buf)->p, (buf)->alloc);\
451 if (IS_NULL(tmp)) return(ONIGERR_MEMORY);\
455#define BBUF_EXPAND(buf,low) do{\
457 do { (buf)->alloc *= 2; } while ((buf)->alloc < (unsigned int )low);\
458 tmp = (UChar* )xrealloc((buf)->p, (buf)->alloc);\
459 if (IS_NULL(tmp)) return(ONIGERR_MEMORY);\
463#define BBUF_ENSURE_SIZE(buf,size) do{\
464 unsigned int new_alloc = (buf)->alloc;\
465 while (new_alloc < (unsigned int )(size)) { new_alloc *= 2; }\
466 if ((buf)->alloc != new_alloc) {\
468 tmp = (UChar* )xrealloc((buf)->p, new_alloc);\
469 if (IS_NULL(tmp)) return(ONIGERR_MEMORY);\
471 (buf)->alloc = new_alloc;\
475#define BBUF_WRITE(buf,pos,bytes,n) do{\
476 int used = (pos) + (int )(n);\
477 if ((buf)->alloc < (unsigned int )used) BBUF_EXPAND((buf),used);\
478 xmemcpy((buf)->p + (pos), (bytes), (n));\
479 if ((buf)->used < (unsigned int )used) (buf)->used = used;\
482#define BBUF_WRITE1(buf,pos,byte) do{\
483 int used = (pos) + 1;\
484 if ((buf)->alloc < (unsigned int )used) BBUF_EXPAND((buf),used);\
485 (buf)->p[(pos)] = (UChar )(byte);\
486 if ((buf)->used < (unsigned int )used) (buf)->used = used;\
489#define BBUF_ADD(buf,bytes,n) BBUF_WRITE((buf),(buf)->used,(bytes),(n))
490#define BBUF_ADD1(buf,byte) BBUF_WRITE1((buf),(buf)->used,(byte))
491#define BBUF_GET_ADD_ADDRESS(buf) ((buf)->p + (buf)->used)
492#define BBUF_GET_OFFSET_POS(buf) ((buf)->used)
495#define BBUF_MOVE_RIGHT(buf,from,to,n) do {\
496 if ((unsigned int )((to)+(n)) > (buf)->alloc) BBUF_EXPAND((buf),(to) + (n));\
497 xmemmove((buf)->p + (to), (buf)->p + (from), (n));\
498 if ((unsigned int )((to)+(n)) > (buf)->used) (buf)->used = (to) + (n);\
502#define BBUF_MOVE_LEFT(buf,from,to,n) do {\
503 xmemmove((buf)->p + (to), (buf)->p + (from), (n));\
507#define BBUF_MOVE_LEFT_REDUCE(buf,from,to) do {\
508 xmemmove((buf)->p + (to), (buf)->p + (from), (buf)->used - (from));\
509 (buf)->used -= (from - to);\
512#define BBUF_INSERT(buf,pos,bytes,n) do {\
513 if (pos >= (buf)->used) {\
514 BBUF_WRITE(buf,pos,bytes,n);\
517 BBUF_MOVE_RIGHT((buf),(pos),(pos) + (n),((buf)->used - (pos)));\
518 xmemcpy((buf)->p + (pos), (bytes), (n));\
522#define BBUF_GET_BYTE(buf, pos) (buf)->p[(pos)]
525#define ANCHOR_BEGIN_BUF (1<<0)
526#define ANCHOR_BEGIN_LINE (1<<1)
527#define ANCHOR_BEGIN_POSITION (1<<2)
528#define ANCHOR_END_BUF (1<<3)
529#define ANCHOR_SEMI_END_BUF (1<<4)
530#define ANCHOR_END_LINE (1<<5)
532#define ANCHOR_WORD_BOUND (1<<6)
533#define ANCHOR_NOT_WORD_BOUND (1<<7)
534#define ANCHOR_WORD_BEGIN (1<<8)
535#define ANCHOR_WORD_END (1<<9)
536#define ANCHOR_PREC_READ (1<<10)
537#define ANCHOR_PREC_READ_NOT (1<<11)
538#define ANCHOR_LOOK_BEHIND (1<<12)
539#define ANCHOR_LOOK_BEHIND_NOT (1<<13)
541#define ANCHOR_ANYCHAR_STAR (1<<14)
542#define ANCHOR_ANYCHAR_STAR_ML (1<<15)
544#define ANCHOR_KEEP (1<<16)
578 OP_ANYCHAR_STAR_PEEK_NEXT,
579 OP_ANYCHAR_ML_STAR_PEEK_NEXT,
591 OP_NOT_ASCII_WORD_BOUND,
608 OP_BACKREF_WITH_LEVEL,
611 OP_MEMORY_START_PUSH,
613 OP_MEMORY_END_PUSH_REC,
623 OP_PUSH_OR_JUMP_EXACT1,
624 OP_PUSH_IF_PEEK_NEXT,
633 OP_NULL_CHECK_END_MEMST,
634 OP_NULL_CHECK_END_MEMST_PUSH,
643 OP_PUSH_LOOK_BEHIND_NOT,
644 OP_FAIL_LOOK_BEHIND_NOT,
655 OP_STATE_CHECK_PUSH_OR_JUMP,
657 OP_STATE_CHECK_ANYCHAR_STAR,
658 OP_STATE_CHECK_ANYCHAR_ML_STAR,
665typedef int RelAddrType;
666typedef int AbsAddrType;
667typedef int LengthType;
668typedef int RepeatNumType;
669typedef short int MemNumType;
670typedef short int StateCheckNumType;
671typedef void* PointerType;
674#define SIZE_RELADDR (int )sizeof(RelAddrType)
675#define SIZE_ABSADDR (int )sizeof(AbsAddrType)
676#define SIZE_LENGTH (int )sizeof(LengthType)
677#define SIZE_MEMNUM (int )sizeof(MemNumType)
678#define SIZE_STATE_CHECK_NUM (int )sizeof(StateCheckNumType)
679#define SIZE_REPEATNUM (int )sizeof(RepeatNumType)
680#define SIZE_OPTION (int )sizeof(OnigOptionType)
681#define SIZE_CODE_POINT (int )sizeof(OnigCodePoint)
682#define SIZE_POINTER (int )sizeof(PointerType)
685#define GET_RELADDR_INC(addr,p) PLATFORM_GET_INC(addr, p, RelAddrType)
686#define GET_ABSADDR_INC(addr,p) PLATFORM_GET_INC(addr, p, AbsAddrType)
687#define GET_LENGTH_INC(len,p) PLATFORM_GET_INC(len, p, LengthType)
688#define GET_MEMNUM_INC(num,p) PLATFORM_GET_INC(num, p, MemNumType)
689#define GET_REPEATNUM_INC(num,p) PLATFORM_GET_INC(num, p, RepeatNumType)
690#define GET_OPTION_INC(option,p) PLATFORM_GET_INC(option, p, OnigOptionType)
691#define GET_POINTER_INC(ptr,p) PLATFORM_GET_INC(ptr, p, PointerType)
692#define GET_STATE_CHECK_NUM_INC(num,p) PLATFORM_GET_INC(num, p, StateCheckNumType)
695#define GET_CODE_POINT(code,p) code = *((OnigCodePoint* )(p))
696#define GET_BYTE_INC(byte,p) do{\
703#define SIZE_OP_ANYCHAR_STAR SIZE_OPCODE
704#define SIZE_OP_ANYCHAR_STAR_PEEK_NEXT (SIZE_OPCODE + 1)
705#define SIZE_OP_JUMP (SIZE_OPCODE + SIZE_RELADDR)
706#define SIZE_OP_PUSH (SIZE_OPCODE + SIZE_RELADDR)
707#define SIZE_OP_POP SIZE_OPCODE
708#define SIZE_OP_PUSH_OR_JUMP_EXACT1 (SIZE_OPCODE + SIZE_RELADDR + 1)
709#define SIZE_OP_PUSH_IF_PEEK_NEXT (SIZE_OPCODE + SIZE_RELADDR + 1)
710#define SIZE_OP_REPEAT_INC (SIZE_OPCODE + SIZE_MEMNUM)
711#define SIZE_OP_REPEAT_INC_NG (SIZE_OPCODE + SIZE_MEMNUM)
712#define SIZE_OP_PUSH_POS SIZE_OPCODE
713#define SIZE_OP_PUSH_POS_NOT (SIZE_OPCODE + SIZE_RELADDR)
714#define SIZE_OP_POP_POS SIZE_OPCODE
715#define SIZE_OP_FAIL_POS SIZE_OPCODE
716#define SIZE_OP_SET_OPTION (SIZE_OPCODE + SIZE_OPTION)
717#define SIZE_OP_SET_OPTION_PUSH (SIZE_OPCODE + SIZE_OPTION)
718#define SIZE_OP_FAIL SIZE_OPCODE
719#define SIZE_OP_MEMORY_START (SIZE_OPCODE + SIZE_MEMNUM)
720#define SIZE_OP_MEMORY_START_PUSH (SIZE_OPCODE + SIZE_MEMNUM)
721#define SIZE_OP_MEMORY_END_PUSH (SIZE_OPCODE + SIZE_MEMNUM)
722#define SIZE_OP_MEMORY_END_PUSH_REC (SIZE_OPCODE + SIZE_MEMNUM)
723#define SIZE_OP_MEMORY_END (SIZE_OPCODE + SIZE_MEMNUM)
724#define SIZE_OP_MEMORY_END_REC (SIZE_OPCODE + SIZE_MEMNUM)
725#define SIZE_OP_PUSH_STOP_BT SIZE_OPCODE
726#define SIZE_OP_POP_STOP_BT SIZE_OPCODE
727#define SIZE_OP_NULL_CHECK_START (SIZE_OPCODE + SIZE_MEMNUM)
728#define SIZE_OP_NULL_CHECK_END (SIZE_OPCODE + SIZE_MEMNUM)
729#define SIZE_OP_LOOK_BEHIND (SIZE_OPCODE + SIZE_LENGTH)
730#define SIZE_OP_PUSH_LOOK_BEHIND_NOT (SIZE_OPCODE + SIZE_RELADDR + SIZE_LENGTH)
731#define SIZE_OP_FAIL_LOOK_BEHIND_NOT SIZE_OPCODE
732#define SIZE_OP_CALL (SIZE_OPCODE + SIZE_ABSADDR)
733#define SIZE_OP_RETURN SIZE_OPCODE
734#define SIZE_OP_CONDITION (SIZE_OPCODE + SIZE_MEMNUM + SIZE_RELADDR)
735#define SIZE_OP_PUSH_ABSENT_POS SIZE_OPCODE
736#define SIZE_OP_ABSENT (SIZE_OPCODE + SIZE_RELADDR)
737#define SIZE_OP_ABSENT_END SIZE_OPCODE
739#ifdef USE_COMBINATION_EXPLOSION_CHECK
740# define SIZE_OP_STATE_CHECK (SIZE_OPCODE + SIZE_STATE_CHECK_NUM)
741# define SIZE_OP_STATE_CHECK_PUSH (SIZE_OPCODE + SIZE_STATE_CHECK_NUM + SIZE_RELADDR)
742# define SIZE_OP_STATE_CHECK_PUSH_OR_JUMP (SIZE_OPCODE + SIZE_STATE_CHECK_NUM + SIZE_RELADDR)
743# define SIZE_OP_STATE_CHECK_ANYCHAR_STAR (SIZE_OPCODE + SIZE_STATE_CHECK_NUM)
746#define MC_ESC(syn) (syn)->meta_char_table.esc
747#define MC_ANYCHAR(syn) (syn)->meta_char_table.anychar
748#define MC_ANYTIME(syn) (syn)->meta_char_table.anytime
749#define MC_ZERO_OR_ONE_TIME(syn) (syn)->meta_char_table.zero_or_one_time
750#define MC_ONE_OR_MORE_TIME(syn) (syn)->meta_char_table.one_or_more_time
751#define MC_ANYCHAR_ANYTIME(syn) (syn)->meta_char_table.anychar_anytime
753#define IS_MC_ESC_CODE(code, syn) \
754 ((code) == MC_ESC(syn) && \
755 !IS_SYNTAX_OP2((syn), ONIG_SYN_OP2_INEFFECTIVE_ESCAPE))
758#define SYN_POSIX_COMMON_OP \
759 ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_POSIX_BRACKET | \
760 ONIG_SYN_OP_DECIMAL_BACKREF | \
761 ONIG_SYN_OP_BRACKET_CC | ONIG_SYN_OP_ASTERISK_ZERO_INF | \
762 ONIG_SYN_OP_LINE_ANCHOR | \
763 ONIG_SYN_OP_ESC_CONTROL_CHARS )
765#define SYN_GNU_REGEX_OP \
766 ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_BRACKET_CC | \
767 ONIG_SYN_OP_POSIX_BRACKET | ONIG_SYN_OP_DECIMAL_BACKREF | \
768 ONIG_SYN_OP_BRACE_INTERVAL | ONIG_SYN_OP_LPAREN_SUBEXP | \
769 ONIG_SYN_OP_VBAR_ALT | \
770 ONIG_SYN_OP_ASTERISK_ZERO_INF | ONIG_SYN_OP_PLUS_ONE_INF | \
771 ONIG_SYN_OP_QMARK_ZERO_ONE | \
772 ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR | ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR | \
773 ONIG_SYN_OP_ESC_W_WORD | \
774 ONIG_SYN_OP_ESC_B_WORD_BOUND | ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END | \
775 ONIG_SYN_OP_ESC_S_WHITE_SPACE | ONIG_SYN_OP_ESC_D_DIGIT | \
776 ONIG_SYN_OP_LINE_ANCHOR )
778#define SYN_GNU_REGEX_BV \
779 ( ONIG_SYN_CONTEXT_INDEP_ANCHORS | ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS | \
780 ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS | ONIG_SYN_ALLOW_INVALID_INTERVAL | \
781 ONIG_SYN_BACKSLASH_ESCAPE_IN_CC | ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC )
784#define NCCLASS_FLAGS(cc) ((cc)->flags)
785#define NCCLASS_FLAG_SET(cc,flag) (NCCLASS_FLAGS(cc) |= (flag))
786#define NCCLASS_FLAG_CLEAR(cc,flag) (NCCLASS_FLAGS(cc) &= ~(flag))
787#define IS_NCCLASS_FLAG_ON(cc,flag) ((NCCLASS_FLAGS(cc) & (flag)) != 0)
790#define FLAG_NCCLASS_NOT (1<<0)
792#define NCCLASS_SET_NOT(nd) NCCLASS_FLAG_SET(nd, FLAG_NCCLASS_NOT)
793#define NCCLASS_CLEAR_NOT(nd) NCCLASS_FLAG_CLEAR(nd, FLAG_NCCLASS_NOT)
794#define IS_NCCLASS_NOT(nd) IS_NCCLASS_FLAG_ON(nd, FLAG_NCCLASS_NOT)
809typedef intptr_t OnigStackIndex;
813 OnigStackIndex null_check;
819#ifdef USE_COMBINATION_EXPLOSION_CHECK
820 unsigned int state_check;
836 OnigStackIndex start;
843#ifdef USE_SUBEXP_CALL
852 const UChar *end_pstr;
854#ifdef USE_MATCH_CACHE
863#ifdef USE_MATCH_CACHE
867 int outer_repeat_mem;
868 long num_cache_points_at_outer_repeat;
869 long num_cache_points_in_outer_repeat;
870 int lookaround_nesting;
878 OnigOptionType options;
882#ifdef USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE
883 OnigPosition best_len;
886#ifdef USE_COMBINATION_EXPLOSION_CHECK
887 void* state_check_buff;
888 int state_check_buff_size;
892#ifdef MY_RUBY_BUILD_MAY_TIME_TRAVEL
897#ifdef USE_MATCH_CACHE
898 int match_cache_status;
899 OnigPosition num_fails;
900 long num_cache_opcodes;
902 long num_cache_points;
903 uint8_t* match_cache_buf;
907#define NUM_CACHE_OPCODES_UNINIT 1
908#define NUM_CACHE_OPCODES_IMPOSSIBLE -1
910#define MATCH_CACHE_STATUS_UNINIT 1
911#define MATCH_CACHE_STATUS_INIT 2
912#define MATCH_CACHE_STATUS_DISABLED -1
913#define MATCH_CACHE_STATUS_ENABLED 0
915#define IS_CODE_SB_WORD(enc,code) \
916 (ONIGENC_IS_CODE_ASCII(code) && ONIGENC_IS_CODE_WORD(enc,code))
923extern void onig_add_end_call(
void (*func)(
void));
934extern OnigOpInfoType OnigOpInfo[];
937extern void onig_print_compiled_byte_code(
FILE* f, UChar* bp, UChar* bpend, UChar** nextp,
OnigEncoding enc);
939# ifdef ONIG_DEBUG_STATISTICS
940extern void onig_statistics_init(
void);
941extern void onig_print_statistics(
FILE* f);
946#define PRINTF_ARGS(func, fmt, vargs) func
949extern UChar* onig_error_code_to_format(OnigPosition code);
950PRINTF_ARGS(
extern void onig_vsnprintf_with_pattern(UChar buf[],
int bufsize,
OnigEncoding enc, UChar* pat, UChar* pat_end,
const char *fmt, va_list args), 6, 0);
951PRINTF_ARGS(
extern void onig_snprintf_with_pattern(UChar buf[],
int bufsize,
OnigEncoding enc, UChar* pat, UChar* pat_end,
const char *fmt, ...), 6, 7);
952extern int onig_bbuf_init(
BBuf* buf, OnigDistance size);
953extern int onig_compile(
regex_t* reg,
const UChar* pattern,
const UChar* pattern_end,
OnigErrorInfo* einfo);
955extern int onig_compile_ruby(
regex_t* reg,
const UChar* pattern,
const UChar* pattern_end,
OnigErrorInfo* einfo,
const char *sourcefile,
int sourceline);
959extern int onig_is_code_in_cc_len(
int enclen, OnigCodePoint code,
CClassNode* cc);
962typedef void hash_table_type;
968typedef st_data_t hash_data_type;
970extern hash_table_type* onig_st_init_strend_table_with_size(st_index_t size);
971extern int onig_st_lookup_strend(hash_table_type* table,
const UChar* str_key,
const UChar* end_key, hash_data_type *value);
972extern int onig_st_insert_strend(hash_table_type* table,
const UChar* str_key,
const UChar* end_key, hash_data_type value);
975extern size_t onig_memsize(
const regex_t *reg);
976extern size_t onig_region_memsize(
const struct re_registers *regs);
977bool rb_reg_timeout_p(
regex_t *reg,
void *end_time);
980RUBY_SYMBOL_EXPORT_END