45#define USE_CACHE_MATCH_OPT
47#ifdef USE_CACHE_MATCH_OPT
48# define NUM_CACHE_OPCODE_FAIL -1
49# define NUM_CACHE_OPCODE_UNINIT -2
52#if defined(ONIG_DEBUG_PARSE_TREE) || defined(ONIG_DEBUG_MATCH) || \
53 defined(ONIG_DEBUG_SEARCH) || defined(ONIG_DEBUG_COMPILE) || \
54 defined(ONIG_DEBUG_STATISTICS) || defined(ONIG_DEBUG_MEMLEAK)
61#ifndef UNALIGNED_WORD_ACCESS
62# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
63 defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || \
64 defined(__powerpc64__) || defined(__POWERPC__) || defined(__aarch64__) || \
66# define UNALIGNED_WORD_ACCESS 1
68# define UNALIGNED_WORD_ACCESS 0
72#if UNALIGNED_WORD_ACCESS
73# define PLATFORM_UNALIGNED_WORD_ACCESS
78#define USE_NAMED_GROUP
79#define USE_SUBEXP_CALL
80#define USE_PERL_SUBEXP_CALL
81#define USE_CAPITAL_P_NAMED_GROUP
82#define USE_BACKREF_WITH_LEVEL
83#define USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT
84#define USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE
85#define USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR
87#define USE_NO_INVALID_QUANTIFIER
91#define USE_QTFR_PEEK_NEXT
93#define USE_SUNDAY_QUICK_SEARCH
95#define INIT_MATCH_STACK_SIZE 160
96#define DEFAULT_MATCH_STACK_LIMIT_SIZE 0
97#define DEFAULT_PARSE_DEPTH_LIMIT 4096
99#define OPT_EXACT_MAXLEN 24
102#if defined(USE_PERL_SUBEXP_CALL) || defined(USE_CAPITAL_P_NAMED_GROUP)
103# if !defined(USE_NAMED_GROUP) || !defined(USE_SUBEXP_CALL)
104# error USE_NAMED_GROUP and USE_SUBEXP_CALL must be defined.
109# define ARG_UNUSED __attribute__ ((unused))
114#if !defined(RUBY) && defined(RUBY_EXPORT)
118# ifndef RUBY_DEFINES_H
127# if SIZEOF_LONG_LONG > 0
128# define LONG_LONG long long
136#ifdef ONIG_ESCAPE_UCHAR_COLLISION
137# undef ONIG_ESCAPE_UCHAR_COLLISION
140#define USE_WORD_BEGIN_END
142# undef USE_CAPTURE_HISTORY
144# define USE_CAPTURE_HISTORY
146#define USE_VARIABLE_META_CHARS
147#define USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE
152# define xmalloc malloc
153# define xrealloc realloc
154# define xcalloc calloc
160# define CHECK_INTERRUPT_IN_MATCH_AT do { \
162 if (msa->counter >= 128) { \
164 rb_reg_check_timeout(reg, &msa->end_time); \
165 rb_thread_check_ints(); \
168# define onig_st_init_table st_init_table
169# define onig_st_init_table_with_size st_init_table_with_size
170# define onig_st_init_numtable st_init_numtable
171# define onig_st_init_numtable_with_size st_init_numtable_with_size
172# define onig_st_init_strtable st_init_strtable
173# define onig_st_init_strtable_with_size st_init_strtable_with_size
174# define onig_st_delete st_delete
175# define onig_st_delete_safe st_delete_safe
176# define onig_st_insert st_insert
177# define onig_st_lookup st_lookup
178# define onig_st_foreach st_foreach
179# define onig_st_add_direct st_add_direct
180# define onig_st_free_table st_free_table
181# define onig_st_cleanup_safe st_cleanup_safe
182# define onig_st_copy st_copy
183# define onig_st_nothing_key_clone st_nothing_key_clone
184# define onig_st_nothing_key_free st_nothing_key_free
185# define onig_st_is_member st_is_member
187# define USE_UPPER_CASE_TABLE
190# define CHECK_INTERRUPT_IN_MATCH_AT
192# define st_init_table onig_st_init_table
193# define st_init_table_with_size onig_st_init_table_with_size
194# define st_init_numtable onig_st_init_numtable
195# define st_init_numtable_with_size onig_st_init_numtable_with_size
196# define st_init_strtable onig_st_init_strtable
197# define st_init_strtable_with_size onig_st_init_strtable_with_size
198# define st_delete onig_st_delete
199# define st_delete_safe onig_st_delete_safe
200# define st_insert onig_st_insert
201# define st_lookup onig_st_lookup
202# define st_foreach onig_st_foreach
203# define st_add_direct onig_st_add_direct
204# define st_free_table onig_st_free_table
205# define st_cleanup_safe onig_st_cleanup_safe
206# define st_copy onig_st_copy
207# define st_nothing_key_clone onig_st_nothing_key_clone
208# define st_nothing_key_free onig_st_nothing_key_free
210# define onig_st_is_member st_is_member
214#define STATE_CHECK_STRING_THRESHOLD_LEN 7
215#define STATE_CHECK_BUFF_MAX_SIZE 0x4000
217#define xmemset memset
218#define xmemcpy memcpy
219#define xmemmove memmove
221#if ((defined(RUBY_MSVCRT_VERSION) && RUBY_MSVCRT_VERSION >= 90) \
222 || (!defined(RUBY_MSVCRT_VERSION) && defined(_WIN32))) \
223 && !defined(__GNUC__)
224# define xalloca _alloca
225# define xvsnprintf(buf,size,fmt,args) _vsnprintf_s(buf,size,_TRUNCATE,fmt,args)
226# define xsnprintf sprintf_s
227# define xstrcat(dest,src,size) strcat_s(dest,size,src)
229# define xalloca alloca
230# define xvsnprintf vsnprintf
231# define xsnprintf snprintf
232# define xstrcat(dest,src,size) strcat(dest,src)
235#if defined(ONIG_DEBUG_MEMLEAK) && defined(_MSC_VER)
236# define _CRTDBG_MAP_ALLOC
243#if defined(HAVE_ALLOCA_H) && (defined(_AIX) || !defined(__GNUC__))
250#ifdef HAVE_SYS_TYPES_H
251# include <sys/types.h>
258#ifdef HAVE_INTTYPES_H
259# include <inttypes.h>
273# if defined(_MSC_VER) && (_MSC_VER < 1300)
274# ifndef _INTPTR_T_DEFINED
275# define _INTPTR_T_DEFINED
278# ifndef _UINTPTR_T_DEFINED
279# define _UINTPTR_T_DEFINED
280typedef unsigned int uintptr_t;
287# define PRIdPTR "I64d"
288# define PRIuPTR "I64u"
289# define PRIxPTR "I64x"
298# define PRIdPTRDIFF PRIdPTR
303RUBY_SYMBOL_EXPORT_BEGIN
311#define MIN(a,b) (((a)>(b))?(b):(a))
312#define MAX(a,b) (((a)<(b))?(b):(a))
314#define IS_NULL(p) (((void*)(p)) == (void*)0)
315#define IS_NOT_NULL(p) (((void*)(p)) != (void*)0)
316#define CHECK_NULL_RETURN(p) if (IS_NULL(p)) return NULL
317#define CHECK_NULL_RETURN_MEMERR(p) if (IS_NULL(p)) return ONIGERR_MEMORY
318#define NULL_UCHARP ((UChar* )0)
320#define ONIG_LAST_CODE_POINT (~((OnigCodePoint )0))
322#ifdef PLATFORM_UNALIGNED_WORD_ACCESS
324# define PLATFORM_GET_INC(val,p,type) do{\
326 (p) += sizeof(type);\
331# define PLATFORM_GET_INC(val,p,type) do{\
332 xmemcpy(&val, (p), sizeof(type));\
333 (p) += sizeof(type);\
337# define WORD_ALIGNMENT_SIZE SIZEOF_LONG
339# define GET_ALIGNMENT_PAD_SIZE(addr,pad_size) do {\
340 (pad_size) = WORD_ALIGNMENT_SIZE \
341 - ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\
342 if ((pad_size) == WORD_ALIGNMENT_SIZE) (pad_size) = 0;\
345# define ALIGNMENT_RIGHT(addr) do {\
346 (addr) += (WORD_ALIGNMENT_SIZE - 1);\
347 (addr) -= ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\
353#define STACK_POP_LEVEL_FREE 0
354#define STACK_POP_LEVEL_MEM_START 1
355#define STACK_POP_LEVEL_ALL 2
358#define ONIG_OPTIMIZE_NONE 0
359#define ONIG_OPTIMIZE_EXACT 1
360#define ONIG_OPTIMIZE_EXACT_BM 2
361#define ONIG_OPTIMIZE_EXACT_BM_NOT_REV 3
362#define ONIG_OPTIMIZE_EXACT_IC 4
363#define ONIG_OPTIMIZE_MAP 5
364#define ONIG_OPTIMIZE_EXACT_BM_IC 6
365#define ONIG_OPTIMIZE_EXACT_BM_NOT_REV_IC 7
368typedef unsigned int BitStatusType;
370#define BIT_STATUS_BITS_NUM (sizeof(BitStatusType) * 8)
371#define BIT_STATUS_CLEAR(stats) (stats) = 0
372#define BIT_STATUS_ON_ALL(stats) (stats) = ~((BitStatusType )0)
373#define BIT_STATUS_AT(stats,n) \
374 ((n) < (int )BIT_STATUS_BITS_NUM ? ((stats) & ((BitStatusType )1 << n)) : ((stats) & 1))
376#define BIT_STATUS_ON_AT(stats,n) do {\
377 if ((n) < (int )BIT_STATUS_BITS_NUM)\
378 (stats) |= (1 << (n));\
383#define BIT_STATUS_ON_AT_SIMPLE(stats,n) do {\
384 if ((n) < (int )BIT_STATUS_BITS_NUM)\
385 (stats) |= (1 << (n));\
389#define INT_MAX_LIMIT ((1UL << (SIZEOF_INT * 8 - 1)) - 1)
390#define LONG_MAX_LIMIT ((1UL << (SIZEOF_LONG * 8 - 1)) - 1)
392#define DIGITVAL(code) ((code) - '0')
393#define ODIGITVAL(code) DIGITVAL(code)
394#define XDIGITVAL(enc,code) \
395 (ONIGENC_IS_CODE_DIGIT(enc,code) ? DIGITVAL(code) \
396 : (ONIGENC_IS_CODE_UPPER(enc,code) ? (code) - 'A' + 10 : (code) - 'a' + 10))
398#define IS_SINGLELINE(option) ((option) & ONIG_OPTION_SINGLELINE)
399#define IS_MULTILINE(option) ((option) & ONIG_OPTION_MULTILINE)
400#define IS_IGNORECASE(option) ((option) & ONIG_OPTION_IGNORECASE)
401#define IS_EXTEND(option) ((option) & ONIG_OPTION_EXTEND)
402#define IS_FIND_LONGEST(option) ((option) & ONIG_OPTION_FIND_LONGEST)
403#define IS_FIND_NOT_EMPTY(option) ((option) & ONIG_OPTION_FIND_NOT_EMPTY)
404#define IS_FIND_CONDITION(option) ((option) & \
405 (ONIG_OPTION_FIND_LONGEST | ONIG_OPTION_FIND_NOT_EMPTY))
406#define IS_NOTBOL(option) ((option) & ONIG_OPTION_NOTBOL)
407#define IS_NOTEOL(option) ((option) & ONIG_OPTION_NOTEOL)
408#define IS_NOTBOS(option) ((option) & ONIG_OPTION_NOTBOS)
409#define IS_NOTEOS(option) ((option) & ONIG_OPTION_NOTEOS)
410#define IS_ASCII_RANGE(option) ((option) & ONIG_OPTION_ASCII_RANGE)
411#define IS_POSIX_BRACKET_ALL_RANGE(option) ((option) & ONIG_OPTION_POSIX_BRACKET_ALL_RANGE)
412#define IS_WORD_BOUND_ALL_RANGE(option) ((option) & ONIG_OPTION_WORD_BOUND_ALL_RANGE)
413#define IS_NEWLINE_CRLF(option) ((option) & ONIG_OPTION_NEWLINE_CRLF)
420#define IS_DYNAMIC_OPTION(option) 0
422#define DISABLE_CASE_FOLD_MULTI_CHAR(case_fold_flag) \
423 ((case_fold_flag) & ~INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR)
425#define REPEAT_INFINITE -1
426#define IS_REPEAT_INFINITE(n) ((n) == REPEAT_INFINITE)
429#define BITS_PER_BYTE 8
430#define SINGLE_BYTE_SIZE (1 << BITS_PER_BYTE)
431#define BITS_IN_ROOM ((int )sizeof(Bits) * BITS_PER_BYTE)
432#define BITSET_SIZE (SINGLE_BYTE_SIZE / BITS_IN_ROOM)
434#ifdef PLATFORM_UNALIGNED_WORD_ACCESS
435typedef unsigned int Bits;
437typedef unsigned char Bits;
439typedef Bits BitSet[BITSET_SIZE];
440typedef Bits* BitSetRef;
442#define SIZE_BITSET (int )sizeof(BitSet)
444#define BITSET_CLEAR(bs) do {\
446 for (i = 0; i < BITSET_SIZE; i++) { (bs)[i] = 0; } \
449#define BS_ROOM(bs,pos) (bs)[(int )(pos) / BITS_IN_ROOM]
450#define BS_BIT(pos) (1U << ((int )(pos) % BITS_IN_ROOM))
452#define BITSET_AT(bs, pos) (BS_ROOM(bs,pos) & BS_BIT(pos))
453#define BITSET_SET_BIT(bs, pos) BS_ROOM(bs,pos) |= BS_BIT(pos)
454#define BITSET_CLEAR_BIT(bs, pos) BS_ROOM(bs,pos) &= ~(BS_BIT(pos))
455#define BITSET_INVERT_BIT(bs, pos) BS_ROOM(bs,pos) ^= BS_BIT(pos)
464#define BBUF_INIT(buf,size) onig_bbuf_init((BBuf* )(buf), (size))
466#define BBUF_SIZE_INC(buf,inc) do{\
468 (buf)->alloc += (inc);\
469 tmp = (UChar* )xrealloc((buf)->p, (buf)->alloc);\
470 if (IS_NULL(tmp)) return(ONIGERR_MEMORY);\
474#define BBUF_EXPAND(buf,low) do{\
476 do { (buf)->alloc *= 2; } while ((buf)->alloc < (unsigned int )low);\
477 tmp = (UChar* )xrealloc((buf)->p, (buf)->alloc);\
478 if (IS_NULL(tmp)) return(ONIGERR_MEMORY);\
482#define BBUF_ENSURE_SIZE(buf,size) do{\
483 unsigned int new_alloc = (buf)->alloc;\
484 while (new_alloc < (unsigned int )(size)) { new_alloc *= 2; }\
485 if ((buf)->alloc != new_alloc) {\
487 tmp = (UChar* )xrealloc((buf)->p, new_alloc);\
488 if (IS_NULL(tmp)) return(ONIGERR_MEMORY);\
490 (buf)->alloc = new_alloc;\
494#define BBUF_WRITE(buf,pos,bytes,n) do{\
495 int used = (pos) + (int )(n);\
496 if ((buf)->alloc < (unsigned int )used) BBUF_EXPAND((buf),used);\
497 xmemcpy((buf)->p + (pos), (bytes), (n));\
498 if ((buf)->used < (unsigned int )used) (buf)->used = used;\
501#define BBUF_WRITE1(buf,pos,byte) do{\
502 int used = (pos) + 1;\
503 if ((buf)->alloc < (unsigned int )used) BBUF_EXPAND((buf),used);\
504 (buf)->p[(pos)] = (UChar )(byte);\
505 if ((buf)->used < (unsigned int )used) (buf)->used = used;\
508#define BBUF_ADD(buf,bytes,n) BBUF_WRITE((buf),(buf)->used,(bytes),(n))
509#define BBUF_ADD1(buf,byte) BBUF_WRITE1((buf),(buf)->used,(byte))
510#define BBUF_GET_ADD_ADDRESS(buf) ((buf)->p + (buf)->used)
511#define BBUF_GET_OFFSET_POS(buf) ((buf)->used)
514#define BBUF_MOVE_RIGHT(buf,from,to,n) do {\
515 if ((unsigned int )((to)+(n)) > (buf)->alloc) BBUF_EXPAND((buf),(to) + (n));\
516 xmemmove((buf)->p + (to), (buf)->p + (from), (n));\
517 if ((unsigned int )((to)+(n)) > (buf)->used) (buf)->used = (to) + (n);\
521#define BBUF_MOVE_LEFT(buf,from,to,n) do {\
522 xmemmove((buf)->p + (to), (buf)->p + (from), (n));\
526#define BBUF_MOVE_LEFT_REDUCE(buf,from,to) do {\
527 xmemmove((buf)->p + (to), (buf)->p + (from), (buf)->used - (from));\
528 (buf)->used -= (from - to);\
531#define BBUF_INSERT(buf,pos,bytes,n) do {\
532 if (pos >= (buf)->used) {\
533 BBUF_WRITE(buf,pos,bytes,n);\
536 BBUF_MOVE_RIGHT((buf),(pos),(pos) + (n),((buf)->used - (pos)));\
537 xmemcpy((buf)->p + (pos), (bytes), (n));\
541#define BBUF_GET_BYTE(buf, pos) (buf)->p[(pos)]
544#define ANCHOR_BEGIN_BUF (1<<0)
545#define ANCHOR_BEGIN_LINE (1<<1)
546#define ANCHOR_BEGIN_POSITION (1<<2)
547#define ANCHOR_END_BUF (1<<3)
548#define ANCHOR_SEMI_END_BUF (1<<4)
549#define ANCHOR_END_LINE (1<<5)
551#define ANCHOR_WORD_BOUND (1<<6)
552#define ANCHOR_NOT_WORD_BOUND (1<<7)
553#define ANCHOR_WORD_BEGIN (1<<8)
554#define ANCHOR_WORD_END (1<<9)
555#define ANCHOR_PREC_READ (1<<10)
556#define ANCHOR_PREC_READ_NOT (1<<11)
557#define ANCHOR_LOOK_BEHIND (1<<12)
558#define ANCHOR_LOOK_BEHIND_NOT (1<<13)
560#define ANCHOR_ANYCHAR_STAR (1<<14)
561#define ANCHOR_ANYCHAR_STAR_ML (1<<15)
563#define ANCHOR_KEEP (1<<16)
597 OP_ANYCHAR_STAR_PEEK_NEXT,
598 OP_ANYCHAR_ML_STAR_PEEK_NEXT,
610 OP_NOT_ASCII_WORD_BOUND,
627 OP_BACKREF_WITH_LEVEL,
630 OP_MEMORY_START_PUSH,
632 OP_MEMORY_END_PUSH_REC,
642 OP_PUSH_OR_JUMP_EXACT1,
643 OP_PUSH_IF_PEEK_NEXT,
652 OP_NULL_CHECK_END_MEMST,
653 OP_NULL_CHECK_END_MEMST_PUSH,
662 OP_PUSH_LOOK_BEHIND_NOT,
663 OP_FAIL_LOOK_BEHIND_NOT,
674 OP_STATE_CHECK_PUSH_OR_JUMP,
676 OP_STATE_CHECK_ANYCHAR_STAR,
677 OP_STATE_CHECK_ANYCHAR_ML_STAR,
684typedef int RelAddrType;
685typedef int AbsAddrType;
686typedef int LengthType;
687typedef int RepeatNumType;
688typedef short int MemNumType;
689typedef short int StateCheckNumType;
690typedef void* PointerType;
693#define SIZE_RELADDR (int )sizeof(RelAddrType)
694#define SIZE_ABSADDR (int )sizeof(AbsAddrType)
695#define SIZE_LENGTH (int )sizeof(LengthType)
696#define SIZE_MEMNUM (int )sizeof(MemNumType)
697#define SIZE_STATE_CHECK_NUM (int )sizeof(StateCheckNumType)
698#define SIZE_REPEATNUM (int )sizeof(RepeatNumType)
699#define SIZE_OPTION (int )sizeof(OnigOptionType)
700#define SIZE_CODE_POINT (int )sizeof(OnigCodePoint)
701#define SIZE_POINTER (int )sizeof(PointerType)
704#define GET_RELADDR_INC(addr,p) PLATFORM_GET_INC(addr, p, RelAddrType)
705#define GET_ABSADDR_INC(addr,p) PLATFORM_GET_INC(addr, p, AbsAddrType)
706#define GET_LENGTH_INC(len,p) PLATFORM_GET_INC(len, p, LengthType)
707#define GET_MEMNUM_INC(num,p) PLATFORM_GET_INC(num, p, MemNumType)
708#define GET_REPEATNUM_INC(num,p) PLATFORM_GET_INC(num, p, RepeatNumType)
709#define GET_OPTION_INC(option,p) PLATFORM_GET_INC(option, p, OnigOptionType)
710#define GET_POINTER_INC(ptr,p) PLATFORM_GET_INC(ptr, p, PointerType)
711#define GET_STATE_CHECK_NUM_INC(num,p) PLATFORM_GET_INC(num, p, StateCheckNumType)
714#define GET_CODE_POINT(code,p) code = *((OnigCodePoint* )(p))
715#define GET_BYTE_INC(byte,p) do{\
722#define SIZE_OP_ANYCHAR_STAR SIZE_OPCODE
723#define SIZE_OP_ANYCHAR_STAR_PEEK_NEXT (SIZE_OPCODE + 1)
724#define SIZE_OP_JUMP (SIZE_OPCODE + SIZE_RELADDR)
725#define SIZE_OP_PUSH (SIZE_OPCODE + SIZE_RELADDR)
726#define SIZE_OP_POP SIZE_OPCODE
727#define SIZE_OP_PUSH_OR_JUMP_EXACT1 (SIZE_OPCODE + SIZE_RELADDR + 1)
728#define SIZE_OP_PUSH_IF_PEEK_NEXT (SIZE_OPCODE + SIZE_RELADDR + 1)
729#define SIZE_OP_REPEAT_INC (SIZE_OPCODE + SIZE_MEMNUM)
730#define SIZE_OP_REPEAT_INC_NG (SIZE_OPCODE + SIZE_MEMNUM)
731#define SIZE_OP_PUSH_POS SIZE_OPCODE
732#define SIZE_OP_PUSH_POS_NOT (SIZE_OPCODE + SIZE_RELADDR)
733#define SIZE_OP_POP_POS SIZE_OPCODE
734#define SIZE_OP_FAIL_POS SIZE_OPCODE
735#define SIZE_OP_SET_OPTION (SIZE_OPCODE + SIZE_OPTION)
736#define SIZE_OP_SET_OPTION_PUSH (SIZE_OPCODE + SIZE_OPTION)
737#define SIZE_OP_FAIL SIZE_OPCODE
738#define SIZE_OP_MEMORY_START (SIZE_OPCODE + SIZE_MEMNUM)
739#define SIZE_OP_MEMORY_START_PUSH (SIZE_OPCODE + SIZE_MEMNUM)
740#define SIZE_OP_MEMORY_END_PUSH (SIZE_OPCODE + SIZE_MEMNUM)
741#define SIZE_OP_MEMORY_END_PUSH_REC (SIZE_OPCODE + SIZE_MEMNUM)
742#define SIZE_OP_MEMORY_END (SIZE_OPCODE + SIZE_MEMNUM)
743#define SIZE_OP_MEMORY_END_REC (SIZE_OPCODE + SIZE_MEMNUM)
744#define SIZE_OP_PUSH_STOP_BT SIZE_OPCODE
745#define SIZE_OP_POP_STOP_BT SIZE_OPCODE
746#define SIZE_OP_NULL_CHECK_START (SIZE_OPCODE + SIZE_MEMNUM)
747#define SIZE_OP_NULL_CHECK_END (SIZE_OPCODE + SIZE_MEMNUM)
748#define SIZE_OP_LOOK_BEHIND (SIZE_OPCODE + SIZE_LENGTH)
749#define SIZE_OP_PUSH_LOOK_BEHIND_NOT (SIZE_OPCODE + SIZE_RELADDR + SIZE_LENGTH)
750#define SIZE_OP_FAIL_LOOK_BEHIND_NOT SIZE_OPCODE
751#define SIZE_OP_CALL (SIZE_OPCODE + SIZE_ABSADDR)
752#define SIZE_OP_RETURN SIZE_OPCODE
753#define SIZE_OP_CONDITION (SIZE_OPCODE + SIZE_MEMNUM + SIZE_RELADDR)
754#define SIZE_OP_PUSH_ABSENT_POS SIZE_OPCODE
755#define SIZE_OP_ABSENT (SIZE_OPCODE + SIZE_RELADDR)
756#define SIZE_OP_ABSENT_END SIZE_OPCODE
758#ifdef USE_COMBINATION_EXPLOSION_CHECK
759# define SIZE_OP_STATE_CHECK (SIZE_OPCODE + SIZE_STATE_CHECK_NUM)
760# define SIZE_OP_STATE_CHECK_PUSH (SIZE_OPCODE + SIZE_STATE_CHECK_NUM + SIZE_RELADDR)
761# define SIZE_OP_STATE_CHECK_PUSH_OR_JUMP (SIZE_OPCODE + SIZE_STATE_CHECK_NUM + SIZE_RELADDR)
762# define SIZE_OP_STATE_CHECK_ANYCHAR_STAR (SIZE_OPCODE + SIZE_STATE_CHECK_NUM)
765#define MC_ESC(syn) (syn)->meta_char_table.esc
766#define MC_ANYCHAR(syn) (syn)->meta_char_table.anychar
767#define MC_ANYTIME(syn) (syn)->meta_char_table.anytime
768#define MC_ZERO_OR_ONE_TIME(syn) (syn)->meta_char_table.zero_or_one_time
769#define MC_ONE_OR_MORE_TIME(syn) (syn)->meta_char_table.one_or_more_time
770#define MC_ANYCHAR_ANYTIME(syn) (syn)->meta_char_table.anychar_anytime
772#define IS_MC_ESC_CODE(code, syn) \
773 ((code) == MC_ESC(syn) && \
774 !IS_SYNTAX_OP2((syn), ONIG_SYN_OP2_INEFFECTIVE_ESCAPE))
777#define SYN_POSIX_COMMON_OP \
778 ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_POSIX_BRACKET | \
779 ONIG_SYN_OP_DECIMAL_BACKREF | \
780 ONIG_SYN_OP_BRACKET_CC | ONIG_SYN_OP_ASTERISK_ZERO_INF | \
781 ONIG_SYN_OP_LINE_ANCHOR | \
782 ONIG_SYN_OP_ESC_CONTROL_CHARS )
784#define SYN_GNU_REGEX_OP \
785 ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_BRACKET_CC | \
786 ONIG_SYN_OP_POSIX_BRACKET | ONIG_SYN_OP_DECIMAL_BACKREF | \
787 ONIG_SYN_OP_BRACE_INTERVAL | ONIG_SYN_OP_LPAREN_SUBEXP | \
788 ONIG_SYN_OP_VBAR_ALT | \
789 ONIG_SYN_OP_ASTERISK_ZERO_INF | ONIG_SYN_OP_PLUS_ONE_INF | \
790 ONIG_SYN_OP_QMARK_ZERO_ONE | \
791 ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR | ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR | \
792 ONIG_SYN_OP_ESC_W_WORD | \
793 ONIG_SYN_OP_ESC_B_WORD_BOUND | ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END | \
794 ONIG_SYN_OP_ESC_S_WHITE_SPACE | ONIG_SYN_OP_ESC_D_DIGIT | \
795 ONIG_SYN_OP_LINE_ANCHOR )
797#define SYN_GNU_REGEX_BV \
798 ( ONIG_SYN_CONTEXT_INDEP_ANCHORS | ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS | \
799 ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS | ONIG_SYN_ALLOW_INVALID_INTERVAL | \
800 ONIG_SYN_BACKSLASH_ESCAPE_IN_CC | ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC )
803#define NCCLASS_FLAGS(cc) ((cc)->flags)
804#define NCCLASS_FLAG_SET(cc,flag) (NCCLASS_FLAGS(cc) |= (flag))
805#define NCCLASS_FLAG_CLEAR(cc,flag) (NCCLASS_FLAGS(cc) &= ~(flag))
806#define IS_NCCLASS_FLAG_ON(cc,flag) ((NCCLASS_FLAGS(cc) & (flag)) != 0)
809#define FLAG_NCCLASS_NOT (1<<0)
811#define NCCLASS_SET_NOT(nd) NCCLASS_FLAG_SET(nd, FLAG_NCCLASS_NOT)
812#define NCCLASS_CLEAR_NOT(nd) NCCLASS_FLAG_CLEAR(nd, FLAG_NCCLASS_NOT)
813#define IS_NCCLASS_NOT(nd) IS_NCCLASS_FLAG_ON(nd, FLAG_NCCLASS_NOT)
828typedef intptr_t OnigStackIndex;
832 OnigStackIndex null_check;
838#ifdef USE_COMBINATION_EXPLOSION_CHECK
839 unsigned int state_check;
855 OnigStackIndex start;
862#ifdef USE_SUBEXP_CALL
871 const UChar *end_pstr;
876#ifdef USE_CACHE_MATCH_OPT
887 OnigOptionType options;
891#ifdef USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE
892 OnigPosition best_len;
895#ifdef USE_COMBINATION_EXPLOSION_CHECK
896 void* state_check_buff;
897 int state_check_buff_size;
901#ifdef MY_RUBY_BUILD_MAY_TIME_TRAVEL
906#ifdef USE_CACHE_MATCH_OPT
908 int enable_cache_match_opt;
909 long num_cache_opcode;
910 long num_cache_table;
912 uint8_t* match_cache;
917#define IS_CODE_SB_WORD(enc,code) \
918 (ONIGENC_IS_CODE_ASCII(code) && ONIGENC_IS_CODE_WORD(enc,code))
925extern void onig_add_end_call(
void (*func)(
void));
936extern OnigOpInfoType OnigOpInfo[];
939extern void onig_print_compiled_byte_code(
FILE* f, UChar* bp, UChar* bpend, UChar** nextp,
OnigEncoding enc);
941# ifdef ONIG_DEBUG_STATISTICS
942extern void onig_statistics_init(
void);
943extern void onig_print_statistics(
FILE* f);
948#define PRINTF_ARGS(func, fmt, vargs) func
951extern UChar* onig_error_code_to_format(OnigPosition code);
952PRINTF_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);
953PRINTF_ARGS(
extern void onig_snprintf_with_pattern(UChar buf[],
int bufsize,
OnigEncoding enc, UChar* pat, UChar* pat_end,
const char *fmt, ...), 6, 7);
954extern int onig_bbuf_init(
BBuf* buf, OnigDistance size);
955extern int onig_compile(
regex_t* reg,
const UChar* pattern,
const UChar* pattern_end,
OnigErrorInfo* einfo);
957extern int onig_compile_ruby(
regex_t* reg,
const UChar* pattern,
const UChar* pattern_end,
OnigErrorInfo* einfo,
const char *sourcefile,
int sourceline);
961extern int onig_is_code_in_cc_len(
int enclen, OnigCodePoint code,
CClassNode* cc);
964typedef void hash_table_type;
970typedef st_data_t hash_data_type;
972extern hash_table_type* onig_st_init_strend_table_with_size(st_index_t size);
973extern int onig_st_lookup_strend(hash_table_type* table,
const UChar* str_key,
const UChar* end_key, hash_data_type *value);
974extern int onig_st_insert_strend(hash_table_type* table,
const UChar* str_key,
const UChar* end_key, hash_data_type value);
977extern size_t onig_memsize(
const regex_t *reg);
978extern size_t onig_region_memsize(
const struct re_registers *regs);
979void rb_reg_check_timeout(
regex_t *reg,
void *end_time);
982RUBY_SYMBOL_EXPORT_END