/src/cpython/Modules/_sre/sre_lib.h
Line | Count | Source |
1 | | /* |
2 | | * Secret Labs' Regular Expression Engine |
3 | | * |
4 | | * regular expression matching engine |
5 | | * |
6 | | * Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved. |
7 | | * |
8 | | * See the sre.c file for information on usage and redistribution. |
9 | | */ |
10 | | |
11 | | /* String matching engine */ |
12 | | |
13 | | /* This file is included three times, with different character settings */ |
14 | | |
15 | | LOCAL(int) |
16 | | SRE(at)(SRE_STATE* state, const SRE_CHAR* ptr, SRE_CODE at) |
17 | 15.7M | { |
18 | | /* check if pointer is at given position */ |
19 | | |
20 | 15.7M | Py_ssize_t thisp, thatp; |
21 | | |
22 | 15.7M | switch (at) { |
23 | | |
24 | 6.24M | case SRE_AT_BEGINNING: |
25 | 6.24M | case SRE_AT_BEGINNING_STRING: |
26 | 6.24M | return ((void*) ptr == state->beginning); |
27 | | |
28 | 0 | case SRE_AT_BEGINNING_LINE: |
29 | 0 | return ((void*) ptr == state->beginning || |
30 | 0 | SRE_IS_LINEBREAK((int) ptr[-1])); |
31 | | |
32 | 3.26M | case SRE_AT_END: |
33 | 3.26M | return (((SRE_CHAR *)state->end - ptr == 1 && |
34 | 23.2k | SRE_IS_LINEBREAK((int) ptr[0])) || |
35 | 3.26M | ((void*) ptr == state->end)); |
36 | | |
37 | 0 | case SRE_AT_END_LINE: |
38 | 0 | return ((void*) ptr == state->end || |
39 | 0 | SRE_IS_LINEBREAK((int) ptr[0])); |
40 | | |
41 | 6.24M | case SRE_AT_END_STRING: |
42 | 6.24M | return ((void*) ptr == state->end); |
43 | | |
44 | 0 | case SRE_AT_BOUNDARY: |
45 | 0 | thatp = ((void*) ptr > state->beginning) ? |
46 | 0 | SRE_IS_WORD((int) ptr[-1]) : 0; |
47 | 0 | thisp = ((void*) ptr < state->end) ? |
48 | 0 | SRE_IS_WORD((int) ptr[0]) : 0; |
49 | 0 | return thisp != thatp; |
50 | | |
51 | 0 | case SRE_AT_NON_BOUNDARY: |
52 | 0 | thatp = ((void*) ptr > state->beginning) ? |
53 | 0 | SRE_IS_WORD((int) ptr[-1]) : 0; |
54 | 0 | thisp = ((void*) ptr < state->end) ? |
55 | 0 | SRE_IS_WORD((int) ptr[0]) : 0; |
56 | 0 | return thisp == thatp; |
57 | | |
58 | 0 | case SRE_AT_LOC_BOUNDARY: |
59 | 0 | thatp = ((void*) ptr > state->beginning) ? |
60 | 0 | SRE_LOC_IS_WORD((int) ptr[-1]) : 0; |
61 | 0 | thisp = ((void*) ptr < state->end) ? |
62 | 0 | SRE_LOC_IS_WORD((int) ptr[0]) : 0; |
63 | 0 | return thisp != thatp; |
64 | | |
65 | 0 | case SRE_AT_LOC_NON_BOUNDARY: |
66 | 0 | thatp = ((void*) ptr > state->beginning) ? |
67 | 0 | SRE_LOC_IS_WORD((int) ptr[-1]) : 0; |
68 | 0 | thisp = ((void*) ptr < state->end) ? |
69 | 0 | SRE_LOC_IS_WORD((int) ptr[0]) : 0; |
70 | 0 | return thisp == thatp; |
71 | | |
72 | 0 | case SRE_AT_UNI_BOUNDARY: |
73 | 0 | thatp = ((void*) ptr > state->beginning) ? |
74 | 0 | SRE_UNI_IS_WORD((int) ptr[-1]) : 0; |
75 | 0 | thisp = ((void*) ptr < state->end) ? |
76 | 0 | SRE_UNI_IS_WORD((int) ptr[0]) : 0; |
77 | 0 | return thisp != thatp; |
78 | | |
79 | 0 | case SRE_AT_UNI_NON_BOUNDARY: |
80 | 0 | thatp = ((void*) ptr > state->beginning) ? |
81 | 0 | SRE_UNI_IS_WORD((int) ptr[-1]) : 0; |
82 | 0 | thisp = ((void*) ptr < state->end) ? |
83 | 0 | SRE_UNI_IS_WORD((int) ptr[0]) : 0; |
84 | 0 | return thisp == thatp; |
85 | | |
86 | 15.7M | } |
87 | | |
88 | 0 | return 0; |
89 | 15.7M | } Line | Count | Source | 17 | 12.3M | { | 18 | | /* check if pointer is at given position */ | 19 | | | 20 | 12.3M | Py_ssize_t thisp, thatp; | 21 | | | 22 | 12.3M | switch (at) { | 23 | | | 24 | 6.21M | case SRE_AT_BEGINNING: | 25 | 6.21M | case SRE_AT_BEGINNING_STRING: | 26 | 6.21M | return ((void*) ptr == state->beginning); | 27 | | | 28 | 0 | case SRE_AT_BEGINNING_LINE: | 29 | 0 | return ((void*) ptr == state->beginning || | 30 | 0 | SRE_IS_LINEBREAK((int) ptr[-1])); | 31 | | | 32 | 3.17M | case SRE_AT_END: | 33 | 3.17M | return (((SRE_CHAR *)state->end - ptr == 1 && | 34 | 23.1k | SRE_IS_LINEBREAK((int) ptr[0])) || | 35 | 3.17M | ((void*) ptr == state->end)); | 36 | | | 37 | 0 | case SRE_AT_END_LINE: | 38 | 0 | return ((void*) ptr == state->end || | 39 | 0 | SRE_IS_LINEBREAK((int) ptr[0])); | 40 | | | 41 | 2.93M | case SRE_AT_END_STRING: | 42 | 2.93M | return ((void*) ptr == state->end); | 43 | | | 44 | 0 | case SRE_AT_BOUNDARY: | 45 | 0 | thatp = ((void*) ptr > state->beginning) ? | 46 | 0 | SRE_IS_WORD((int) ptr[-1]) : 0; | 47 | 0 | thisp = ((void*) ptr < state->end) ? | 48 | 0 | SRE_IS_WORD((int) ptr[0]) : 0; | 49 | 0 | return thisp != thatp; | 50 | | | 51 | 0 | case SRE_AT_NON_BOUNDARY: | 52 | 0 | thatp = ((void*) ptr > state->beginning) ? | 53 | 0 | SRE_IS_WORD((int) ptr[-1]) : 0; | 54 | 0 | thisp = ((void*) ptr < state->end) ? | 55 | 0 | SRE_IS_WORD((int) ptr[0]) : 0; | 56 | 0 | return thisp == thatp; | 57 | | | 58 | 0 | case SRE_AT_LOC_BOUNDARY: | 59 | 0 | thatp = ((void*) ptr > state->beginning) ? | 60 | 0 | SRE_LOC_IS_WORD((int) ptr[-1]) : 0; | 61 | 0 | thisp = ((void*) ptr < state->end) ? | 62 | 0 | SRE_LOC_IS_WORD((int) ptr[0]) : 0; | 63 | 0 | return thisp != thatp; | 64 | | | 65 | 0 | case SRE_AT_LOC_NON_BOUNDARY: | 66 | 0 | thatp = ((void*) ptr > state->beginning) ? | 67 | 0 | SRE_LOC_IS_WORD((int) ptr[-1]) : 0; | 68 | 0 | thisp = ((void*) ptr < state->end) ? | 69 | 0 | SRE_LOC_IS_WORD((int) ptr[0]) : 0; | 70 | 0 | return thisp == thatp; | 71 | | | 72 | 0 | case SRE_AT_UNI_BOUNDARY: | 73 | 0 | thatp = ((void*) ptr > state->beginning) ? | 74 | 0 | SRE_UNI_IS_WORD((int) ptr[-1]) : 0; | 75 | 0 | thisp = ((void*) ptr < state->end) ? | 76 | 0 | SRE_UNI_IS_WORD((int) ptr[0]) : 0; | 77 | 0 | return thisp != thatp; | 78 | | | 79 | 0 | case SRE_AT_UNI_NON_BOUNDARY: | 80 | 0 | thatp = ((void*) ptr > state->beginning) ? | 81 | 0 | SRE_UNI_IS_WORD((int) ptr[-1]) : 0; | 82 | 0 | thisp = ((void*) ptr < state->end) ? | 83 | 0 | SRE_UNI_IS_WORD((int) ptr[0]) : 0; | 84 | 0 | return thisp == thatp; | 85 | | | 86 | 12.3M | } | 87 | | | 88 | 0 | return 0; | 89 | 12.3M | } |
Line | Count | Source | 17 | 1.70M | { | 18 | | /* check if pointer is at given position */ | 19 | | | 20 | 1.70M | Py_ssize_t thisp, thatp; | 21 | | | 22 | 1.70M | switch (at) { | 23 | | | 24 | 29.0k | case SRE_AT_BEGINNING: | 25 | 29.0k | case SRE_AT_BEGINNING_STRING: | 26 | 29.0k | return ((void*) ptr == state->beginning); | 27 | | | 28 | 0 | case SRE_AT_BEGINNING_LINE: | 29 | 0 | return ((void*) ptr == state->beginning || | 30 | 0 | SRE_IS_LINEBREAK((int) ptr[-1])); | 31 | | | 32 | 51.8k | case SRE_AT_END: | 33 | 51.8k | return (((SRE_CHAR *)state->end - ptr == 1 && | 34 | 52 | SRE_IS_LINEBREAK((int) ptr[0])) || | 35 | 51.8k | ((void*) ptr == state->end)); | 36 | | | 37 | 0 | case SRE_AT_END_LINE: | 38 | 0 | return ((void*) ptr == state->end || | 39 | 0 | SRE_IS_LINEBREAK((int) ptr[0])); | 40 | | | 41 | 1.62M | case SRE_AT_END_STRING: | 42 | 1.62M | return ((void*) ptr == state->end); | 43 | | | 44 | 0 | case SRE_AT_BOUNDARY: | 45 | 0 | thatp = ((void*) ptr > state->beginning) ? | 46 | 0 | SRE_IS_WORD((int) ptr[-1]) : 0; | 47 | 0 | thisp = ((void*) ptr < state->end) ? | 48 | 0 | SRE_IS_WORD((int) ptr[0]) : 0; | 49 | 0 | return thisp != thatp; | 50 | | | 51 | 0 | case SRE_AT_NON_BOUNDARY: | 52 | 0 | thatp = ((void*) ptr > state->beginning) ? | 53 | 0 | SRE_IS_WORD((int) ptr[-1]) : 0; | 54 | 0 | thisp = ((void*) ptr < state->end) ? | 55 | 0 | SRE_IS_WORD((int) ptr[0]) : 0; | 56 | 0 | return thisp == thatp; | 57 | | | 58 | 0 | case SRE_AT_LOC_BOUNDARY: | 59 | 0 | thatp = ((void*) ptr > state->beginning) ? | 60 | 0 | SRE_LOC_IS_WORD((int) ptr[-1]) : 0; | 61 | 0 | thisp = ((void*) ptr < state->end) ? | 62 | 0 | SRE_LOC_IS_WORD((int) ptr[0]) : 0; | 63 | 0 | return thisp != thatp; | 64 | | | 65 | 0 | case SRE_AT_LOC_NON_BOUNDARY: | 66 | 0 | thatp = ((void*) ptr > state->beginning) ? | 67 | 0 | SRE_LOC_IS_WORD((int) ptr[-1]) : 0; | 68 | 0 | thisp = ((void*) ptr < state->end) ? | 69 | 0 | SRE_LOC_IS_WORD((int) ptr[0]) : 0; | 70 | 0 | return thisp == thatp; | 71 | | | 72 | 0 | case SRE_AT_UNI_BOUNDARY: | 73 | 0 | thatp = ((void*) ptr > state->beginning) ? | 74 | 0 | SRE_UNI_IS_WORD((int) ptr[-1]) : 0; | 75 | 0 | thisp = ((void*) ptr < state->end) ? | 76 | 0 | SRE_UNI_IS_WORD((int) ptr[0]) : 0; | 77 | 0 | return thisp != thatp; | 78 | | | 79 | 0 | case SRE_AT_UNI_NON_BOUNDARY: | 80 | 0 | thatp = ((void*) ptr > state->beginning) ? | 81 | 0 | SRE_UNI_IS_WORD((int) ptr[-1]) : 0; | 82 | 0 | thisp = ((void*) ptr < state->end) ? | 83 | 0 | SRE_UNI_IS_WORD((int) ptr[0]) : 0; | 84 | 0 | return thisp == thatp; | 85 | | | 86 | 1.70M | } | 87 | | | 88 | 0 | return 0; | 89 | 1.70M | } |
Line | Count | Source | 17 | 1.72M | { | 18 | | /* check if pointer is at given position */ | 19 | | | 20 | 1.72M | Py_ssize_t thisp, thatp; | 21 | | | 22 | 1.72M | switch (at) { | 23 | | | 24 | 3.43k | case SRE_AT_BEGINNING: | 25 | 3.43k | case SRE_AT_BEGINNING_STRING: | 26 | 3.43k | return ((void*) ptr == state->beginning); | 27 | | | 28 | 0 | case SRE_AT_BEGINNING_LINE: | 29 | 0 | return ((void*) ptr == state->beginning || | 30 | 0 | SRE_IS_LINEBREAK((int) ptr[-1])); | 31 | | | 32 | 34.7k | case SRE_AT_END: | 33 | 34.7k | return (((SRE_CHAR *)state->end - ptr == 1 && | 34 | 102 | SRE_IS_LINEBREAK((int) ptr[0])) || | 35 | 34.7k | ((void*) ptr == state->end)); | 36 | | | 37 | 0 | case SRE_AT_END_LINE: | 38 | 0 | return ((void*) ptr == state->end || | 39 | 0 | SRE_IS_LINEBREAK((int) ptr[0])); | 40 | | | 41 | 1.68M | case SRE_AT_END_STRING: | 42 | 1.68M | return ((void*) ptr == state->end); | 43 | | | 44 | 0 | case SRE_AT_BOUNDARY: | 45 | 0 | thatp = ((void*) ptr > state->beginning) ? | 46 | 0 | SRE_IS_WORD((int) ptr[-1]) : 0; | 47 | 0 | thisp = ((void*) ptr < state->end) ? | 48 | 0 | SRE_IS_WORD((int) ptr[0]) : 0; | 49 | 0 | return thisp != thatp; | 50 | | | 51 | 0 | case SRE_AT_NON_BOUNDARY: | 52 | 0 | thatp = ((void*) ptr > state->beginning) ? | 53 | 0 | SRE_IS_WORD((int) ptr[-1]) : 0; | 54 | 0 | thisp = ((void*) ptr < state->end) ? | 55 | 0 | SRE_IS_WORD((int) ptr[0]) : 0; | 56 | 0 | return thisp == thatp; | 57 | | | 58 | 0 | case SRE_AT_LOC_BOUNDARY: | 59 | 0 | thatp = ((void*) ptr > state->beginning) ? | 60 | 0 | SRE_LOC_IS_WORD((int) ptr[-1]) : 0; | 61 | 0 | thisp = ((void*) ptr < state->end) ? | 62 | 0 | SRE_LOC_IS_WORD((int) ptr[0]) : 0; | 63 | 0 | return thisp != thatp; | 64 | | | 65 | 0 | case SRE_AT_LOC_NON_BOUNDARY: | 66 | 0 | thatp = ((void*) ptr > state->beginning) ? | 67 | 0 | SRE_LOC_IS_WORD((int) ptr[-1]) : 0; | 68 | 0 | thisp = ((void*) ptr < state->end) ? | 69 | 0 | SRE_LOC_IS_WORD((int) ptr[0]) : 0; | 70 | 0 | return thisp == thatp; | 71 | | | 72 | 0 | case SRE_AT_UNI_BOUNDARY: | 73 | 0 | thatp = ((void*) ptr > state->beginning) ? | 74 | 0 | SRE_UNI_IS_WORD((int) ptr[-1]) : 0; | 75 | 0 | thisp = ((void*) ptr < state->end) ? | 76 | 0 | SRE_UNI_IS_WORD((int) ptr[0]) : 0; | 77 | 0 | return thisp != thatp; | 78 | | | 79 | 0 | case SRE_AT_UNI_NON_BOUNDARY: | 80 | 0 | thatp = ((void*) ptr > state->beginning) ? | 81 | 0 | SRE_UNI_IS_WORD((int) ptr[-1]) : 0; | 82 | 0 | thisp = ((void*) ptr < state->end) ? | 83 | 0 | SRE_UNI_IS_WORD((int) ptr[0]) : 0; | 84 | 0 | return thisp == thatp; | 85 | | | 86 | 1.72M | } | 87 | | | 88 | 0 | return 0; | 89 | 1.72M | } |
|
90 | | |
91 | | LOCAL(int) |
92 | | SRE(charset)(SRE_STATE* state, const SRE_CODE* set, SRE_CODE ch) |
93 | 1.45G | { |
94 | | /* check if character is a member of the given set */ |
95 | | |
96 | 1.45G | int ok = 1; |
97 | | |
98 | 3.37G | for (;;) { |
99 | 3.37G | switch (*set++) { |
100 | | |
101 | 976M | case SRE_OP_FAILURE: |
102 | 976M | return !ok; |
103 | | |
104 | 1.08G | case SRE_OP_LITERAL: |
105 | | /* <LITERAL> <code> */ |
106 | 1.08G | if (ch == set[0]) |
107 | 7.65M | return ok; |
108 | 1.08G | set++; |
109 | 1.08G | break; |
110 | | |
111 | 532 | case SRE_OP_CATEGORY: |
112 | | /* <CATEGORY> <code> */ |
113 | 532 | if (sre_category(set[0], (int) ch)) |
114 | 452 | return ok; |
115 | 80 | set++; |
116 | 80 | break; |
117 | | |
118 | 549M | case SRE_OP_CHARSET: |
119 | | /* <CHARSET> <bitmap> */ |
120 | 549M | if (ch < 256 && |
121 | 523M | (set[ch/SRE_CODE_BITS] & (1u << (ch & (SRE_CODE_BITS-1))))) |
122 | 195M | return ok; |
123 | 353M | set += 256/SRE_CODE_BITS; |
124 | 353M | break; |
125 | | |
126 | 448M | case SRE_OP_RANGE: |
127 | | /* <RANGE> <lower> <upper> */ |
128 | 448M | if (set[0] <= ch && ch <= set[1]) |
129 | 279M | return ok; |
130 | 168M | set += 2; |
131 | 168M | break; |
132 | | |
133 | 0 | case SRE_OP_RANGE_UNI_IGNORE: |
134 | | /* <RANGE_UNI_IGNORE> <lower> <upper> */ |
135 | 0 | { |
136 | 0 | SRE_CODE uch; |
137 | | /* ch is already lower cased */ |
138 | 0 | if (set[0] <= ch && ch <= set[1]) |
139 | 0 | return ok; |
140 | 0 | uch = sre_upper_unicode(ch); |
141 | 0 | if (set[0] <= uch && uch <= set[1]) |
142 | 0 | return ok; |
143 | 0 | set += 2; |
144 | 0 | break; |
145 | 0 | } |
146 | | |
147 | 316M | case SRE_OP_NEGATE: |
148 | 316M | ok = !ok; |
149 | 316M | break; |
150 | | |
151 | 0 | case SRE_OP_BIGCHARSET: |
152 | | /* <BIGCHARSET> <blockcount> <256 blockindices> <blocks> */ |
153 | 0 | { |
154 | 0 | Py_ssize_t count, block; |
155 | 0 | count = *(set++); |
156 | |
|
157 | 0 | if (ch < 0x10000u) |
158 | 0 | block = ((unsigned char*)set)[ch >> 8]; |
159 | 0 | else |
160 | 0 | block = -1; |
161 | 0 | set += 256/sizeof(SRE_CODE); |
162 | 0 | if (block >=0 && |
163 | 0 | (set[(block * 256 + (ch & 255))/SRE_CODE_BITS] & |
164 | 0 | (1u << (ch & (SRE_CODE_BITS-1))))) |
165 | 0 | return ok; |
166 | 0 | set += count * (256/SRE_CODE_BITS); |
167 | 0 | break; |
168 | 0 | } |
169 | | |
170 | 0 | default: |
171 | | /* internal error -- there's not much we can do about it |
172 | | here, so let's just pretend it didn't match... */ |
173 | 0 | return 0; |
174 | 3.37G | } |
175 | 3.37G | } |
176 | 1.45G | } Line | Count | Source | 93 | 403M | { | 94 | | /* check if character is a member of the given set */ | 95 | | | 96 | 403M | int ok = 1; | 97 | | | 98 | 824M | for (;;) { | 99 | 824M | switch (*set++) { | 100 | | | 101 | 214M | case SRE_OP_FAILURE: | 102 | 214M | return !ok; | 103 | | | 104 | 192M | case SRE_OP_LITERAL: | 105 | | /* <LITERAL> <code> */ | 106 | 192M | if (ch == set[0]) | 107 | 2.80M | return ok; | 108 | 190M | set++; | 109 | 190M | break; | 110 | | | 111 | 532 | case SRE_OP_CATEGORY: | 112 | | /* <CATEGORY> <code> */ | 113 | 532 | if (sre_category(set[0], (int) ch)) | 114 | 452 | return ok; | 115 | 80 | set++; | 116 | 80 | break; | 117 | | | 118 | 133M | case SRE_OP_CHARSET: | 119 | | /* <CHARSET> <bitmap> */ | 120 | 133M | if (ch < 256 && | 121 | 133M | (set[ch/SRE_CODE_BITS] & (1u << (ch & (SRE_CODE_BITS-1))))) | 122 | 53.9M | return ok; | 123 | 79.2M | set += 256/SRE_CODE_BITS; | 124 | 79.2M | break; | 125 | | | 126 | 212M | case SRE_OP_RANGE: | 127 | | /* <RANGE> <lower> <upper> */ | 128 | 212M | if (set[0] <= ch && ch <= set[1]) | 129 | 132M | return ok; | 130 | 79.6M | set += 2; | 131 | 79.6M | break; | 132 | | | 133 | 0 | case SRE_OP_RANGE_UNI_IGNORE: | 134 | | /* <RANGE_UNI_IGNORE> <lower> <upper> */ | 135 | 0 | { | 136 | 0 | SRE_CODE uch; | 137 | | /* ch is already lower cased */ | 138 | 0 | if (set[0] <= ch && ch <= set[1]) | 139 | 0 | return ok; | 140 | 0 | uch = sre_upper_unicode(ch); | 141 | 0 | if (set[0] <= uch && uch <= set[1]) | 142 | 0 | return ok; | 143 | 0 | set += 2; | 144 | 0 | break; | 145 | 0 | } | 146 | | | 147 | 71.3M | case SRE_OP_NEGATE: | 148 | 71.3M | ok = !ok; | 149 | 71.3M | break; | 150 | | | 151 | 0 | case SRE_OP_BIGCHARSET: | 152 | | /* <BIGCHARSET> <blockcount> <256 blockindices> <blocks> */ | 153 | 0 | { | 154 | 0 | Py_ssize_t count, block; | 155 | 0 | count = *(set++); | 156 | |
| 157 | 0 | if (ch < 0x10000u) | 158 | 0 | block = ((unsigned char*)set)[ch >> 8]; | 159 | 0 | else | 160 | 0 | block = -1; | 161 | 0 | set += 256/sizeof(SRE_CODE); | 162 | 0 | if (block >=0 && | 163 | 0 | (set[(block * 256 + (ch & 255))/SRE_CODE_BITS] & | 164 | 0 | (1u << (ch & (SRE_CODE_BITS-1))))) | 165 | 0 | return ok; | 166 | 0 | set += count * (256/SRE_CODE_BITS); | 167 | 0 | break; | 168 | 0 | } | 169 | | | 170 | 0 | default: | 171 | | /* internal error -- there's not much we can do about it | 172 | | here, so let's just pretend it didn't match... */ | 173 | 0 | return 0; | 174 | 824M | } | 175 | 824M | } | 176 | 403M | } |
Line | Count | Source | 93 | 701M | { | 94 | | /* check if character is a member of the given set */ | 95 | | | 96 | 701M | int ok = 1; | 97 | | | 98 | 1.71G | for (;;) { | 99 | 1.71G | switch (*set++) { | 100 | | | 101 | 510M | case SRE_OP_FAILURE: | 102 | 510M | return !ok; | 103 | | | 104 | 661M | case SRE_OP_LITERAL: | 105 | | /* <LITERAL> <code> */ | 106 | 661M | if (ch == set[0]) | 107 | 4.08M | return ok; | 108 | 657M | set++; | 109 | 657M | break; | 110 | | | 111 | 0 | case SRE_OP_CATEGORY: | 112 | | /* <CATEGORY> <code> */ | 113 | 0 | if (sre_category(set[0], (int) ch)) | 114 | 0 | return ok; | 115 | 0 | set++; | 116 | 0 | break; | 117 | | | 118 | 203M | case SRE_OP_CHARSET: | 119 | | /* <CHARSET> <bitmap> */ | 120 | 203M | if (ch < 256 && | 121 | 190M | (set[ch/SRE_CODE_BITS] & (1u << (ch & (SRE_CODE_BITS-1))))) | 122 | 58.6M | return ok; | 123 | 144M | set += 256/SRE_CODE_BITS; | 124 | 144M | break; | 125 | | | 126 | 205M | case SRE_OP_RANGE: | 127 | | /* <RANGE> <lower> <upper> */ | 128 | 205M | if (set[0] <= ch && ch <= set[1]) | 129 | 127M | return ok; | 130 | 77.1M | set += 2; | 131 | 77.1M | break; | 132 | | | 133 | 0 | case SRE_OP_RANGE_UNI_IGNORE: | 134 | | /* <RANGE_UNI_IGNORE> <lower> <upper> */ | 135 | 0 | { | 136 | 0 | SRE_CODE uch; | 137 | | /* ch is already lower cased */ | 138 | 0 | if (set[0] <= ch && ch <= set[1]) | 139 | 0 | return ok; | 140 | 0 | uch = sre_upper_unicode(ch); | 141 | 0 | if (set[0] <= uch && uch <= set[1]) | 142 | 0 | return ok; | 143 | 0 | set += 2; | 144 | 0 | break; | 145 | 0 | } | 146 | | | 147 | 132M | case SRE_OP_NEGATE: | 148 | 132M | ok = !ok; | 149 | 132M | break; | 150 | | | 151 | 0 | case SRE_OP_BIGCHARSET: | 152 | | /* <BIGCHARSET> <blockcount> <256 blockindices> <blocks> */ | 153 | 0 | { | 154 | 0 | Py_ssize_t count, block; | 155 | 0 | count = *(set++); | 156 | |
| 157 | 0 | if (ch < 0x10000u) | 158 | 0 | block = ((unsigned char*)set)[ch >> 8]; | 159 | 0 | else | 160 | 0 | block = -1; | 161 | 0 | set += 256/sizeof(SRE_CODE); | 162 | 0 | if (block >=0 && | 163 | 0 | (set[(block * 256 + (ch & 255))/SRE_CODE_BITS] & | 164 | 0 | (1u << (ch & (SRE_CODE_BITS-1))))) | 165 | 0 | return ok; | 166 | 0 | set += count * (256/SRE_CODE_BITS); | 167 | 0 | break; | 168 | 0 | } | 169 | | | 170 | 0 | default: | 171 | | /* internal error -- there's not much we can do about it | 172 | | here, so let's just pretend it didn't match... */ | 173 | 0 | return 0; | 174 | 1.71G | } | 175 | 1.71G | } | 176 | 701M | } |
Line | Count | Source | 93 | 354M | { | 94 | | /* check if character is a member of the given set */ | 95 | | | 96 | 354M | int ok = 1; | 97 | | | 98 | 842M | for (;;) { | 99 | 842M | switch (*set++) { | 100 | | | 101 | 252M | case SRE_OP_FAILURE: | 102 | 252M | return !ok; | 103 | | | 104 | 234M | case SRE_OP_LITERAL: | 105 | | /* <LITERAL> <code> */ | 106 | 234M | if (ch == set[0]) | 107 | 763k | return ok; | 108 | 233M | set++; | 109 | 233M | break; | 110 | | | 111 | 0 | case SRE_OP_CATEGORY: | 112 | | /* <CATEGORY> <code> */ | 113 | 0 | if (sre_category(set[0], (int) ch)) | 114 | 0 | return ok; | 115 | 0 | set++; | 116 | 0 | break; | 117 | | | 118 | 212M | case SRE_OP_CHARSET: | 119 | | /* <CHARSET> <bitmap> */ | 120 | 212M | if (ch < 256 && | 121 | 199M | (set[ch/SRE_CODE_BITS] & (1u << (ch & (SRE_CODE_BITS-1))))) | 122 | 82.6M | return ok; | 123 | 129M | set += 256/SRE_CODE_BITS; | 124 | 129M | break; | 125 | | | 126 | 30.5M | case SRE_OP_RANGE: | 127 | | /* <RANGE> <lower> <upper> */ | 128 | 30.5M | if (set[0] <= ch && ch <= set[1]) | 129 | 18.9M | return ok; | 130 | 11.5M | set += 2; | 131 | 11.5M | break; | 132 | | | 133 | 0 | case SRE_OP_RANGE_UNI_IGNORE: | 134 | | /* <RANGE_UNI_IGNORE> <lower> <upper> */ | 135 | 0 | { | 136 | 0 | SRE_CODE uch; | 137 | | /* ch is already lower cased */ | 138 | 0 | if (set[0] <= ch && ch <= set[1]) | 139 | 0 | return ok; | 140 | 0 | uch = sre_upper_unicode(ch); | 141 | 0 | if (set[0] <= uch && uch <= set[1]) | 142 | 0 | return ok; | 143 | 0 | set += 2; | 144 | 0 | break; | 145 | 0 | } | 146 | | | 147 | 112M | case SRE_OP_NEGATE: | 148 | 112M | ok = !ok; | 149 | 112M | break; | 150 | | | 151 | 0 | case SRE_OP_BIGCHARSET: | 152 | | /* <BIGCHARSET> <blockcount> <256 blockindices> <blocks> */ | 153 | 0 | { | 154 | 0 | Py_ssize_t count, block; | 155 | 0 | count = *(set++); | 156 | |
| 157 | 0 | if (ch < 0x10000u) | 158 | 0 | block = ((unsigned char*)set)[ch >> 8]; | 159 | 0 | else | 160 | 0 | block = -1; | 161 | 0 | set += 256/sizeof(SRE_CODE); | 162 | 0 | if (block >=0 && | 163 | 0 | (set[(block * 256 + (ch & 255))/SRE_CODE_BITS] & | 164 | 0 | (1u << (ch & (SRE_CODE_BITS-1))))) | 165 | 0 | return ok; | 166 | 0 | set += count * (256/SRE_CODE_BITS); | 167 | 0 | break; | 168 | 0 | } | 169 | | | 170 | 0 | default: | 171 | | /* internal error -- there's not much we can do about it | 172 | | here, so let's just pretend it didn't match... */ | 173 | 0 | return 0; | 174 | 842M | } | 175 | 842M | } | 176 | 354M | } |
|
177 | | |
178 | | LOCAL(int) |
179 | | SRE(charset_loc_ignore)(SRE_STATE* state, const SRE_CODE* set, SRE_CODE ch) |
180 | 0 | { |
181 | 0 | SRE_CODE lo, up; |
182 | 0 | lo = sre_lower_locale(ch); |
183 | 0 | if (SRE(charset)(state, set, lo)) |
184 | 0 | return 1; |
185 | | |
186 | 0 | up = sre_upper_locale(ch); |
187 | 0 | return up != lo && SRE(charset)(state, set, up); |
188 | 0 | } Unexecuted instantiation: sre.c:sre_ucs1_charset_loc_ignore Unexecuted instantiation: sre.c:sre_ucs2_charset_loc_ignore Unexecuted instantiation: sre.c:sre_ucs4_charset_loc_ignore |
189 | | |
190 | | LOCAL(Py_ssize_t) SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel); |
191 | | |
192 | | LOCAL(Py_ssize_t) |
193 | | SRE(count)(SRE_STATE* state, const SRE_CODE* pattern, Py_ssize_t maxcount) |
194 | 374M | { |
195 | 374M | SRE_CODE chr; |
196 | 374M | SRE_CODE arg; |
197 | 374M | SRE_CHAR c; |
198 | 374M | const SRE_CHAR* ptr = (const SRE_CHAR *)state->ptr; |
199 | 374M | const SRE_CHAR* end = (const SRE_CHAR *)state->end; |
200 | 374M | Py_ssize_t i; |
201 | 374M | INIT_TRACE(state); |
202 | | |
203 | | /* adjust end */ |
204 | 374M | if (maxcount < end - ptr && maxcount != SRE_MAXREPEAT) |
205 | 13.3M | end = ptr + maxcount; |
206 | | |
207 | 374M | switch (pattern[0]) { |
208 | | |
209 | 355M | case SRE_OP_IN: |
210 | | /* repeated set */ |
211 | 355M | TRACE(("|%p|%p|COUNT IN\n", pattern, ptr)); |
212 | 757M | while (ptr < end && SRE(charset)(state, pattern + 2, *ptr)) |
213 | 402M | ptr++; |
214 | 355M | break; |
215 | | |
216 | 872 | case SRE_OP_ANY: |
217 | | /* repeated dot wildcard. */ |
218 | 872 | TRACE(("|%p|%p|COUNT ANY\n", pattern, ptr)); |
219 | 1.72k | while (ptr < end && !SRE_IS_LINEBREAK(*ptr)) |
220 | 855 | ptr++; |
221 | 872 | break; |
222 | | |
223 | 0 | case SRE_OP_ANY_ALL: |
224 | | /* repeated dot wildcard. skip to the end of the target |
225 | | string, and backtrack from there */ |
226 | 0 | TRACE(("|%p|%p|COUNT ANY_ALL\n", pattern, ptr)); |
227 | 0 | ptr = end; |
228 | 0 | break; |
229 | | |
230 | 15.1M | case SRE_OP_LITERAL: |
231 | | /* repeated literal */ |
232 | 15.1M | chr = pattern[1]; |
233 | 15.1M | TRACE(("|%p|%p|COUNT LITERAL %d\n", pattern, ptr, chr)); |
234 | 15.1M | c = (SRE_CHAR) chr; |
235 | | #if SIZEOF_SRE_CHAR < 4 |
236 | 12.1M | if ((SRE_CODE) c != chr) |
237 | 0 | ; /* literal can't match: doesn't fit in char width */ |
238 | 12.1M | else |
239 | 12.1M | #endif |
240 | 18.0M | while (ptr < end && *ptr == c) |
241 | 2.88M | ptr++; |
242 | 15.1M | break; |
243 | | |
244 | 0 | case SRE_OP_LITERAL_IGNORE: |
245 | | /* repeated literal */ |
246 | 0 | chr = pattern[1]; |
247 | 0 | TRACE(("|%p|%p|COUNT LITERAL_IGNORE %d\n", pattern, ptr, chr)); |
248 | 0 | while (ptr < end && (SRE_CODE) sre_lower_ascii(*ptr) == chr) |
249 | 0 | ptr++; |
250 | 0 | break; |
251 | | |
252 | 0 | case SRE_OP_LITERAL_UNI_IGNORE: |
253 | | /* repeated literal */ |
254 | 0 | chr = pattern[1]; |
255 | 0 | TRACE(("|%p|%p|COUNT LITERAL_UNI_IGNORE %d\n", pattern, ptr, chr)); |
256 | 0 | while (ptr < end && (SRE_CODE) sre_lower_unicode(*ptr) == chr) |
257 | 0 | ptr++; |
258 | 0 | break; |
259 | | |
260 | 0 | case SRE_OP_LITERAL_LOC_IGNORE: |
261 | | /* repeated literal */ |
262 | 0 | chr = pattern[1]; |
263 | 0 | TRACE(("|%p|%p|COUNT LITERAL_LOC_IGNORE %d\n", pattern, ptr, chr)); |
264 | 0 | while (ptr < end && char_loc_ignore(chr, *ptr)) |
265 | 0 | ptr++; |
266 | 0 | break; |
267 | | |
268 | 724k | case SRE_OP_NOT_LITERAL: |
269 | | /* repeated non-literal */ |
270 | 724k | chr = pattern[1]; |
271 | 724k | TRACE(("|%p|%p|COUNT NOT_LITERAL %d\n", pattern, ptr, chr)); |
272 | 724k | c = (SRE_CHAR) chr; |
273 | | #if SIZEOF_SRE_CHAR < 4 |
274 | 389k | if ((SRE_CODE) c != chr) |
275 | 0 | ptr = end; /* literal can't match: doesn't fit in char width */ |
276 | 389k | else |
277 | 389k | #endif |
278 | 54.6M | while (ptr < end && *ptr != c) |
279 | 53.9M | ptr++; |
280 | 724k | break; |
281 | | |
282 | 0 | case SRE_OP_NOT_LITERAL_IGNORE: |
283 | | /* repeated non-literal */ |
284 | 0 | chr = pattern[1]; |
285 | 0 | TRACE(("|%p|%p|COUNT NOT_LITERAL_IGNORE %d\n", pattern, ptr, chr)); |
286 | 0 | while (ptr < end && (SRE_CODE) sre_lower_ascii(*ptr) != chr) |
287 | 0 | ptr++; |
288 | 0 | break; |
289 | | |
290 | 0 | case SRE_OP_NOT_LITERAL_UNI_IGNORE: |
291 | | /* repeated non-literal */ |
292 | 0 | chr = pattern[1]; |
293 | 0 | TRACE(("|%p|%p|COUNT NOT_LITERAL_UNI_IGNORE %d\n", pattern, ptr, chr)); |
294 | 0 | while (ptr < end && (SRE_CODE) sre_lower_unicode(*ptr) != chr) |
295 | 0 | ptr++; |
296 | 0 | break; |
297 | | |
298 | 0 | case SRE_OP_NOT_LITERAL_LOC_IGNORE: |
299 | | /* repeated non-literal */ |
300 | 0 | chr = pattern[1]; |
301 | 0 | TRACE(("|%p|%p|COUNT NOT_LITERAL_LOC_IGNORE %d\n", pattern, ptr, chr)); |
302 | 0 | while (ptr < end && !char_loc_ignore(chr, *ptr)) |
303 | 0 | ptr++; |
304 | 0 | break; |
305 | | |
306 | 3.06M | case SRE_OP_CATEGORY: |
307 | 3.06M | arg = pattern[1]; |
308 | 3.06M | TRACE(("|%p|%p|COUNT CATEGORY %d\n", pattern, ptr, arg)); |
309 | 11.3M | while (ptr < end && sre_category(arg, *ptr)) |
310 | 8.30M | ptr++; |
311 | 3.06M | break; |
312 | | |
313 | 0 | default: |
314 | | /* repeated single character pattern */ |
315 | 0 | TRACE(("|%p|%p|COUNT SUBPATTERN\n", pattern, ptr)); |
316 | 0 | while ((SRE_CHAR*) state->ptr < end) { |
317 | 0 | i = SRE(match)(state, pattern, 0); |
318 | 0 | if (i < 0) |
319 | 0 | return i; |
320 | 0 | if (!i) |
321 | 0 | break; |
322 | 0 | } |
323 | 0 | TRACE(("|%p|%p|COUNT %zd\n", pattern, ptr, |
324 | 0 | (SRE_CHAR*) state->ptr - ptr)); |
325 | 0 | return (SRE_CHAR*) state->ptr - ptr; |
326 | 374M | } |
327 | | |
328 | 374M | TRACE(("|%p|%p|COUNT %zd\n", pattern, ptr, |
329 | 374M | ptr - (SRE_CHAR*) state->ptr)); |
330 | 374M | return ptr - (SRE_CHAR*) state->ptr; |
331 | 374M | } Line | Count | Source | 194 | 92.6M | { | 195 | 92.6M | SRE_CODE chr; | 196 | 92.6M | SRE_CODE arg; | 197 | 92.6M | SRE_CHAR c; | 198 | 92.6M | const SRE_CHAR* ptr = (const SRE_CHAR *)state->ptr; | 199 | 92.6M | const SRE_CHAR* end = (const SRE_CHAR *)state->end; | 200 | 92.6M | Py_ssize_t i; | 201 | 92.6M | INIT_TRACE(state); | 202 | | | 203 | | /* adjust end */ | 204 | 92.6M | if (maxcount < end - ptr && maxcount != SRE_MAXREPEAT) | 205 | 2.09M | end = ptr + maxcount; | 206 | | | 207 | 92.6M | switch (pattern[0]) { | 208 | | | 209 | 81.9M | case SRE_OP_IN: | 210 | | /* repeated set */ | 211 | 81.9M | TRACE(("|%p|%p|COUNT IN\n", pattern, ptr)); | 212 | 228M | while (ptr < end && SRE(charset)(state, pattern + 2, *ptr)) | 213 | 146M | ptr++; | 214 | 81.9M | break; | 215 | | | 216 | 872 | case SRE_OP_ANY: | 217 | | /* repeated dot wildcard. */ | 218 | 872 | TRACE(("|%p|%p|COUNT ANY\n", pattern, ptr)); | 219 | 1.72k | while (ptr < end && !SRE_IS_LINEBREAK(*ptr)) | 220 | 855 | ptr++; | 221 | 872 | break; | 222 | | | 223 | 0 | case SRE_OP_ANY_ALL: | 224 | | /* repeated dot wildcard. skip to the end of the target | 225 | | string, and backtrack from there */ | 226 | 0 | TRACE(("|%p|%p|COUNT ANY_ALL\n", pattern, ptr)); | 227 | 0 | ptr = end; | 228 | 0 | break; | 229 | | | 230 | 7.47M | case SRE_OP_LITERAL: | 231 | | /* repeated literal */ | 232 | 7.47M | chr = pattern[1]; | 233 | 7.47M | TRACE(("|%p|%p|COUNT LITERAL %d\n", pattern, ptr, chr)); | 234 | 7.47M | c = (SRE_CHAR) chr; | 235 | 7.47M | #if SIZEOF_SRE_CHAR < 4 | 236 | 7.47M | if ((SRE_CODE) c != chr) | 237 | 0 | ; /* literal can't match: doesn't fit in char width */ | 238 | 7.47M | else | 239 | 7.47M | #endif | 240 | 7.88M | while (ptr < end && *ptr == c) | 241 | 401k | ptr++; | 242 | 7.47M | break; | 243 | | | 244 | 0 | case SRE_OP_LITERAL_IGNORE: | 245 | | /* repeated literal */ | 246 | 0 | chr = pattern[1]; | 247 | 0 | TRACE(("|%p|%p|COUNT LITERAL_IGNORE %d\n", pattern, ptr, chr)); | 248 | 0 | while (ptr < end && (SRE_CODE) sre_lower_ascii(*ptr) == chr) | 249 | 0 | ptr++; | 250 | 0 | break; | 251 | | | 252 | 0 | case SRE_OP_LITERAL_UNI_IGNORE: | 253 | | /* repeated literal */ | 254 | 0 | chr = pattern[1]; | 255 | 0 | TRACE(("|%p|%p|COUNT LITERAL_UNI_IGNORE %d\n", pattern, ptr, chr)); | 256 | 0 | while (ptr < end && (SRE_CODE) sre_lower_unicode(*ptr) == chr) | 257 | 0 | ptr++; | 258 | 0 | break; | 259 | | | 260 | 0 | case SRE_OP_LITERAL_LOC_IGNORE: | 261 | | /* repeated literal */ | 262 | 0 | chr = pattern[1]; | 263 | 0 | TRACE(("|%p|%p|COUNT LITERAL_LOC_IGNORE %d\n", pattern, ptr, chr)); | 264 | 0 | while (ptr < end && char_loc_ignore(chr, *ptr)) | 265 | 0 | ptr++; | 266 | 0 | break; | 267 | | | 268 | 135k | case SRE_OP_NOT_LITERAL: | 269 | | /* repeated non-literal */ | 270 | 135k | chr = pattern[1]; | 271 | 135k | TRACE(("|%p|%p|COUNT NOT_LITERAL %d\n", pattern, ptr, chr)); | 272 | 135k | c = (SRE_CHAR) chr; | 273 | 135k | #if SIZEOF_SRE_CHAR < 4 | 274 | 135k | if ((SRE_CODE) c != chr) | 275 | 0 | ptr = end; /* literal can't match: doesn't fit in char width */ | 276 | 135k | else | 277 | 135k | #endif | 278 | 11.0M | while (ptr < end && *ptr != c) | 279 | 10.8M | ptr++; | 280 | 135k | break; | 281 | | | 282 | 0 | case SRE_OP_NOT_LITERAL_IGNORE: | 283 | | /* repeated non-literal */ | 284 | 0 | chr = pattern[1]; | 285 | 0 | TRACE(("|%p|%p|COUNT NOT_LITERAL_IGNORE %d\n", pattern, ptr, chr)); | 286 | 0 | while (ptr < end && (SRE_CODE) sre_lower_ascii(*ptr) != chr) | 287 | 0 | ptr++; | 288 | 0 | break; | 289 | | | 290 | 0 | case SRE_OP_NOT_LITERAL_UNI_IGNORE: | 291 | | /* repeated non-literal */ | 292 | 0 | chr = pattern[1]; | 293 | 0 | TRACE(("|%p|%p|COUNT NOT_LITERAL_UNI_IGNORE %d\n", pattern, ptr, chr)); | 294 | 0 | while (ptr < end && (SRE_CODE) sre_lower_unicode(*ptr) != chr) | 295 | 0 | ptr++; | 296 | 0 | break; | 297 | | | 298 | 0 | case SRE_OP_NOT_LITERAL_LOC_IGNORE: | 299 | | /* repeated non-literal */ | 300 | 0 | chr = pattern[1]; | 301 | 0 | TRACE(("|%p|%p|COUNT NOT_LITERAL_LOC_IGNORE %d\n", pattern, ptr, chr)); | 302 | 0 | while (ptr < end && !char_loc_ignore(chr, *ptr)) | 303 | 0 | ptr++; | 304 | 0 | break; | 305 | | | 306 | 3.05M | case SRE_OP_CATEGORY: | 307 | 3.05M | arg = pattern[1]; | 308 | 3.05M | TRACE(("|%p|%p|COUNT CATEGORY %d\n", pattern, ptr, arg)); | 309 | 10.1M | while (ptr < end && sre_category(arg, *ptr)) | 310 | 7.04M | ptr++; | 311 | 3.05M | break; | 312 | | | 313 | 0 | default: | 314 | | /* repeated single character pattern */ | 315 | 0 | TRACE(("|%p|%p|COUNT SUBPATTERN\n", pattern, ptr)); | 316 | 0 | while ((SRE_CHAR*) state->ptr < end) { | 317 | 0 | i = SRE(match)(state, pattern, 0); | 318 | 0 | if (i < 0) | 319 | 0 | return i; | 320 | 0 | if (!i) | 321 | 0 | break; | 322 | 0 | } | 323 | 0 | TRACE(("|%p|%p|COUNT %zd\n", pattern, ptr, | 324 | 0 | (SRE_CHAR*) state->ptr - ptr)); | 325 | 0 | return (SRE_CHAR*) state->ptr - ptr; | 326 | 92.6M | } | 327 | | | 328 | 92.6M | TRACE(("|%p|%p|COUNT %zd\n", pattern, ptr, | 329 | 92.6M | ptr - (SRE_CHAR*) state->ptr)); | 330 | 92.6M | return ptr - (SRE_CHAR*) state->ptr; | 331 | 92.6M | } |
Line | Count | Source | 194 | 194M | { | 195 | 194M | SRE_CODE chr; | 196 | 194M | SRE_CODE arg; | 197 | 194M | SRE_CHAR c; | 198 | 194M | const SRE_CHAR* ptr = (const SRE_CHAR *)state->ptr; | 199 | 194M | const SRE_CHAR* end = (const SRE_CHAR *)state->end; | 200 | 194M | Py_ssize_t i; | 201 | 194M | INIT_TRACE(state); | 202 | | | 203 | | /* adjust end */ | 204 | 194M | if (maxcount < end - ptr && maxcount != SRE_MAXREPEAT) | 205 | 5.93M | end = ptr + maxcount; | 206 | | | 207 | 194M | switch (pattern[0]) { | 208 | | | 209 | 189M | case SRE_OP_IN: | 210 | | /* repeated set */ | 211 | 189M | TRACE(("|%p|%p|COUNT IN\n", pattern, ptr)); | 212 | 331M | while (ptr < end && SRE(charset)(state, pattern + 2, *ptr)) | 213 | 141M | ptr++; | 214 | 189M | break; | 215 | | | 216 | 0 | case SRE_OP_ANY: | 217 | | /* repeated dot wildcard. */ | 218 | 0 | TRACE(("|%p|%p|COUNT ANY\n", pattern, ptr)); | 219 | 0 | while (ptr < end && !SRE_IS_LINEBREAK(*ptr)) | 220 | 0 | ptr++; | 221 | 0 | break; | 222 | | | 223 | 0 | case SRE_OP_ANY_ALL: | 224 | | /* repeated dot wildcard. skip to the end of the target | 225 | | string, and backtrack from there */ | 226 | 0 | TRACE(("|%p|%p|COUNT ANY_ALL\n", pattern, ptr)); | 227 | 0 | ptr = end; | 228 | 0 | break; | 229 | | | 230 | 4.62M | case SRE_OP_LITERAL: | 231 | | /* repeated literal */ | 232 | 4.62M | chr = pattern[1]; | 233 | 4.62M | TRACE(("|%p|%p|COUNT LITERAL %d\n", pattern, ptr, chr)); | 234 | 4.62M | c = (SRE_CHAR) chr; | 235 | 4.62M | #if SIZEOF_SRE_CHAR < 4 | 236 | 4.62M | if ((SRE_CODE) c != chr) | 237 | 0 | ; /* literal can't match: doesn't fit in char width */ | 238 | 4.62M | else | 239 | 4.62M | #endif | 240 | 6.25M | while (ptr < end && *ptr == c) | 241 | 1.62M | ptr++; | 242 | 4.62M | break; | 243 | | | 244 | 0 | case SRE_OP_LITERAL_IGNORE: | 245 | | /* repeated literal */ | 246 | 0 | chr = pattern[1]; | 247 | 0 | TRACE(("|%p|%p|COUNT LITERAL_IGNORE %d\n", pattern, ptr, chr)); | 248 | 0 | while (ptr < end && (SRE_CODE) sre_lower_ascii(*ptr) == chr) | 249 | 0 | ptr++; | 250 | 0 | break; | 251 | | | 252 | 0 | case SRE_OP_LITERAL_UNI_IGNORE: | 253 | | /* repeated literal */ | 254 | 0 | chr = pattern[1]; | 255 | 0 | TRACE(("|%p|%p|COUNT LITERAL_UNI_IGNORE %d\n", pattern, ptr, chr)); | 256 | 0 | while (ptr < end && (SRE_CODE) sre_lower_unicode(*ptr) == chr) | 257 | 0 | ptr++; | 258 | 0 | break; | 259 | | | 260 | 0 | case SRE_OP_LITERAL_LOC_IGNORE: | 261 | | /* repeated literal */ | 262 | 0 | chr = pattern[1]; | 263 | 0 | TRACE(("|%p|%p|COUNT LITERAL_LOC_IGNORE %d\n", pattern, ptr, chr)); | 264 | 0 | while (ptr < end && char_loc_ignore(chr, *ptr)) | 265 | 0 | ptr++; | 266 | 0 | break; | 267 | | | 268 | 253k | case SRE_OP_NOT_LITERAL: | 269 | | /* repeated non-literal */ | 270 | 253k | chr = pattern[1]; | 271 | 253k | TRACE(("|%p|%p|COUNT NOT_LITERAL %d\n", pattern, ptr, chr)); | 272 | 253k | c = (SRE_CHAR) chr; | 273 | 253k | #if SIZEOF_SRE_CHAR < 4 | 274 | 253k | if ((SRE_CODE) c != chr) | 275 | 0 | ptr = end; /* literal can't match: doesn't fit in char width */ | 276 | 253k | else | 277 | 253k | #endif | 278 | 12.4M | while (ptr < end && *ptr != c) | 279 | 12.2M | ptr++; | 280 | 253k | break; | 281 | | | 282 | 0 | case SRE_OP_NOT_LITERAL_IGNORE: | 283 | | /* repeated non-literal */ | 284 | 0 | chr = pattern[1]; | 285 | 0 | TRACE(("|%p|%p|COUNT NOT_LITERAL_IGNORE %d\n", pattern, ptr, chr)); | 286 | 0 | while (ptr < end && (SRE_CODE) sre_lower_ascii(*ptr) != chr) | 287 | 0 | ptr++; | 288 | 0 | break; | 289 | | | 290 | 0 | case SRE_OP_NOT_LITERAL_UNI_IGNORE: | 291 | | /* repeated non-literal */ | 292 | 0 | chr = pattern[1]; | 293 | 0 | TRACE(("|%p|%p|COUNT NOT_LITERAL_UNI_IGNORE %d\n", pattern, ptr, chr)); | 294 | 0 | while (ptr < end && (SRE_CODE) sre_lower_unicode(*ptr) != chr) | 295 | 0 | ptr++; | 296 | 0 | break; | 297 | | | 298 | 0 | case SRE_OP_NOT_LITERAL_LOC_IGNORE: | 299 | | /* repeated non-literal */ | 300 | 0 | chr = pattern[1]; | 301 | 0 | TRACE(("|%p|%p|COUNT NOT_LITERAL_LOC_IGNORE %d\n", pattern, ptr, chr)); | 302 | 0 | while (ptr < end && !char_loc_ignore(chr, *ptr)) | 303 | 0 | ptr++; | 304 | 0 | break; | 305 | | | 306 | 7.06k | case SRE_OP_CATEGORY: | 307 | 7.06k | arg = pattern[1]; | 308 | 7.06k | TRACE(("|%p|%p|COUNT CATEGORY %d\n", pattern, ptr, arg)); | 309 | 532k | while (ptr < end && sre_category(arg, *ptr)) | 310 | 525k | ptr++; | 311 | 7.06k | break; | 312 | | | 313 | 0 | default: | 314 | | /* repeated single character pattern */ | 315 | 0 | TRACE(("|%p|%p|COUNT SUBPATTERN\n", pattern, ptr)); | 316 | 0 | while ((SRE_CHAR*) state->ptr < end) { | 317 | 0 | i = SRE(match)(state, pattern, 0); | 318 | 0 | if (i < 0) | 319 | 0 | return i; | 320 | 0 | if (!i) | 321 | 0 | break; | 322 | 0 | } | 323 | 0 | TRACE(("|%p|%p|COUNT %zd\n", pattern, ptr, | 324 | 0 | (SRE_CHAR*) state->ptr - ptr)); | 325 | 0 | return (SRE_CHAR*) state->ptr - ptr; | 326 | 194M | } | 327 | | | 328 | 194M | TRACE(("|%p|%p|COUNT %zd\n", pattern, ptr, | 329 | 194M | ptr - (SRE_CHAR*) state->ptr)); | 330 | 194M | return ptr - (SRE_CHAR*) state->ptr; | 331 | 194M | } |
Line | Count | Source | 194 | 87.1M | { | 195 | 87.1M | SRE_CODE chr; | 196 | 87.1M | SRE_CODE arg; | 197 | 87.1M | SRE_CHAR c; | 198 | 87.1M | const SRE_CHAR* ptr = (const SRE_CHAR *)state->ptr; | 199 | 87.1M | const SRE_CHAR* end = (const SRE_CHAR *)state->end; | 200 | 87.1M | Py_ssize_t i; | 201 | 87.1M | INIT_TRACE(state); | 202 | | | 203 | | /* adjust end */ | 204 | 87.1M | if (maxcount < end - ptr && maxcount != SRE_MAXREPEAT) | 205 | 5.33M | end = ptr + maxcount; | 206 | | | 207 | 87.1M | switch (pattern[0]) { | 208 | | | 209 | 83.7M | case SRE_OP_IN: | 210 | | /* repeated set */ | 211 | 83.7M | TRACE(("|%p|%p|COUNT IN\n", pattern, ptr)); | 212 | 198M | while (ptr < end && SRE(charset)(state, pattern + 2, *ptr)) | 213 | 114M | ptr++; | 214 | 83.7M | break; | 215 | | | 216 | 0 | case SRE_OP_ANY: | 217 | | /* repeated dot wildcard. */ | 218 | 0 | TRACE(("|%p|%p|COUNT ANY\n", pattern, ptr)); | 219 | 0 | while (ptr < end && !SRE_IS_LINEBREAK(*ptr)) | 220 | 0 | ptr++; | 221 | 0 | break; | 222 | | | 223 | 0 | case SRE_OP_ANY_ALL: | 224 | | /* repeated dot wildcard. skip to the end of the target | 225 | | string, and backtrack from there */ | 226 | 0 | TRACE(("|%p|%p|COUNT ANY_ALL\n", pattern, ptr)); | 227 | 0 | ptr = end; | 228 | 0 | break; | 229 | | | 230 | 3.06M | case SRE_OP_LITERAL: | 231 | | /* repeated literal */ | 232 | 3.06M | chr = pattern[1]; | 233 | 3.06M | TRACE(("|%p|%p|COUNT LITERAL %d\n", pattern, ptr, chr)); | 234 | 3.06M | c = (SRE_CHAR) chr; | 235 | | #if SIZEOF_SRE_CHAR < 4 | 236 | | if ((SRE_CODE) c != chr) | 237 | | ; /* literal can't match: doesn't fit in char width */ | 238 | | else | 239 | | #endif | 240 | 3.91M | while (ptr < end && *ptr == c) | 241 | 854k | ptr++; | 242 | 3.06M | break; | 243 | | | 244 | 0 | case SRE_OP_LITERAL_IGNORE: | 245 | | /* repeated literal */ | 246 | 0 | chr = pattern[1]; | 247 | 0 | TRACE(("|%p|%p|COUNT LITERAL_IGNORE %d\n", pattern, ptr, chr)); | 248 | 0 | while (ptr < end && (SRE_CODE) sre_lower_ascii(*ptr) == chr) | 249 | 0 | ptr++; | 250 | 0 | break; | 251 | | | 252 | 0 | case SRE_OP_LITERAL_UNI_IGNORE: | 253 | | /* repeated literal */ | 254 | 0 | chr = pattern[1]; | 255 | 0 | TRACE(("|%p|%p|COUNT LITERAL_UNI_IGNORE %d\n", pattern, ptr, chr)); | 256 | 0 | while (ptr < end && (SRE_CODE) sre_lower_unicode(*ptr) == chr) | 257 | 0 | ptr++; | 258 | 0 | break; | 259 | | | 260 | 0 | case SRE_OP_LITERAL_LOC_IGNORE: | 261 | | /* repeated literal */ | 262 | 0 | chr = pattern[1]; | 263 | 0 | TRACE(("|%p|%p|COUNT LITERAL_LOC_IGNORE %d\n", pattern, ptr, chr)); | 264 | 0 | while (ptr < end && char_loc_ignore(chr, *ptr)) | 265 | 0 | ptr++; | 266 | 0 | break; | 267 | | | 268 | 335k | case SRE_OP_NOT_LITERAL: | 269 | | /* repeated non-literal */ | 270 | 335k | chr = pattern[1]; | 271 | 335k | TRACE(("|%p|%p|COUNT NOT_LITERAL %d\n", pattern, ptr, chr)); | 272 | 335k | c = (SRE_CHAR) chr; | 273 | | #if SIZEOF_SRE_CHAR < 4 | 274 | | if ((SRE_CODE) c != chr) | 275 | | ptr = end; /* literal can't match: doesn't fit in char width */ | 276 | | else | 277 | | #endif | 278 | 31.1M | while (ptr < end && *ptr != c) | 279 | 30.8M | ptr++; | 280 | 335k | break; | 281 | | | 282 | 0 | case SRE_OP_NOT_LITERAL_IGNORE: | 283 | | /* repeated non-literal */ | 284 | 0 | chr = pattern[1]; | 285 | 0 | TRACE(("|%p|%p|COUNT NOT_LITERAL_IGNORE %d\n", pattern, ptr, chr)); | 286 | 0 | while (ptr < end && (SRE_CODE) sre_lower_ascii(*ptr) != chr) | 287 | 0 | ptr++; | 288 | 0 | break; | 289 | | | 290 | 0 | case SRE_OP_NOT_LITERAL_UNI_IGNORE: | 291 | | /* repeated non-literal */ | 292 | 0 | chr = pattern[1]; | 293 | 0 | TRACE(("|%p|%p|COUNT NOT_LITERAL_UNI_IGNORE %d\n", pattern, ptr, chr)); | 294 | 0 | while (ptr < end && (SRE_CODE) sre_lower_unicode(*ptr) != chr) | 295 | 0 | ptr++; | 296 | 0 | break; | 297 | | | 298 | 0 | case SRE_OP_NOT_LITERAL_LOC_IGNORE: | 299 | | /* repeated non-literal */ | 300 | 0 | chr = pattern[1]; | 301 | 0 | TRACE(("|%p|%p|COUNT NOT_LITERAL_LOC_IGNORE %d\n", pattern, ptr, chr)); | 302 | 0 | while (ptr < end && !char_loc_ignore(chr, *ptr)) | 303 | 0 | ptr++; | 304 | 0 | break; | 305 | | | 306 | 378 | case SRE_OP_CATEGORY: | 307 | 378 | arg = pattern[1]; | 308 | 378 | TRACE(("|%p|%p|COUNT CATEGORY %d\n", pattern, ptr, arg)); | 309 | 735k | while (ptr < end && sre_category(arg, *ptr)) | 310 | 734k | ptr++; | 311 | 378 | break; | 312 | | | 313 | 0 | default: | 314 | | /* repeated single character pattern */ | 315 | 0 | TRACE(("|%p|%p|COUNT SUBPATTERN\n", pattern, ptr)); | 316 | 0 | while ((SRE_CHAR*) state->ptr < end) { | 317 | 0 | i = SRE(match)(state, pattern, 0); | 318 | 0 | if (i < 0) | 319 | 0 | return i; | 320 | 0 | if (!i) | 321 | 0 | break; | 322 | 0 | } | 323 | 0 | TRACE(("|%p|%p|COUNT %zd\n", pattern, ptr, | 324 | 0 | (SRE_CHAR*) state->ptr - ptr)); | 325 | 0 | return (SRE_CHAR*) state->ptr - ptr; | 326 | 87.1M | } | 327 | | | 328 | 87.1M | TRACE(("|%p|%p|COUNT %zd\n", pattern, ptr, | 329 | 87.1M | ptr - (SRE_CHAR*) state->ptr)); | 330 | 87.1M | return ptr - (SRE_CHAR*) state->ptr; | 331 | 87.1M | } |
|
332 | | |
333 | | /* The macros below should be used to protect recursive SRE(match)() |
334 | | * calls that *failed* and do *not* return immediately (IOW, those |
335 | | * that will backtrack). Explaining: |
336 | | * |
337 | | * - Recursive SRE(match)() returned true: that's usually a success |
338 | | * (besides atypical cases like ASSERT_NOT), therefore there's no |
339 | | * reason to restore lastmark; |
340 | | * |
341 | | * - Recursive SRE(match)() returned false but the current SRE(match)() |
342 | | * is returning to the caller: If the current SRE(match)() is the |
343 | | * top function of the recursion, returning false will be a matching |
344 | | * failure, and it doesn't matter where lastmark is pointing to. |
345 | | * If it's *not* the top function, it will be a recursive SRE(match)() |
346 | | * failure by itself, and the calling SRE(match)() will have to deal |
347 | | * with the failure by the same rules explained here (it will restore |
348 | | * lastmark by itself if necessary); |
349 | | * |
350 | | * - Recursive SRE(match)() returned false, and will continue the |
351 | | * outside 'for' loop: must be protected when breaking, since the next |
352 | | * OP could potentially depend on lastmark; |
353 | | * |
354 | | * - Recursive SRE(match)() returned false, and will be called again |
355 | | * inside a local for/while loop: must be protected between each |
356 | | * loop iteration, since the recursive SRE(match)() could do anything, |
357 | | * and could potentially depend on lastmark. |
358 | | * |
359 | | * For more information, check the discussion at SF patch #712900. |
360 | | */ |
361 | | #define LASTMARK_SAVE() \ |
362 | 335M | do { \ |
363 | 335M | ctx->lastmark = state->lastmark; \ |
364 | 335M | ctx->lastindex = state->lastindex; \ |
365 | 335M | } while (0) |
366 | | #define LASTMARK_RESTORE() \ |
367 | 78.8M | do { \ |
368 | 78.8M | state->lastmark = ctx->lastmark; \ |
369 | 78.8M | state->lastindex = ctx->lastindex; \ |
370 | 78.8M | } while (0) |
371 | | |
372 | | #define LAST_PTR_PUSH() \ |
373 | 89.3M | do { \ |
374 | 89.3M | TRACE(("push last_ptr: %zd", \ |
375 | 89.3M | PTR_TO_INDEX(ctx->u.rep->last_ptr))); \ |
376 | 89.3M | DATA_PUSH(&ctx->u.rep->last_ptr); \ |
377 | 89.3M | } while (0) |
378 | | #define LAST_PTR_POP() \ |
379 | 89.3M | do { \ |
380 | 89.3M | DATA_POP(&ctx->u.rep->last_ptr); \ |
381 | 89.3M | TRACE(("pop last_ptr: %zd", \ |
382 | 89.3M | PTR_TO_INDEX(ctx->u.rep->last_ptr))); \ |
383 | 89.3M | } while (0) |
384 | | |
385 | 0 | #define RETURN_ERROR(i) do { return i; } while(0) |
386 | 356M | #define RETURN_FAILURE do { ret = 0; goto exit; } while(0) |
387 | 499M | #define RETURN_SUCCESS do { ret = 1; goto exit; } while(0) |
388 | | |
389 | | #define RETURN_ON_ERROR(i) \ |
390 | 725M | do { if (i < 0) RETURN_ERROR(i); } while (0) |
391 | | #define RETURN_ON_SUCCESS(i) \ |
392 | 35.1M | do { RETURN_ON_ERROR(i); if (i > 0) RETURN_SUCCESS; } while (0) |
393 | | #define RETURN_ON_FAILURE(i) \ |
394 | 26.0M | do { RETURN_ON_ERROR(i); if (i == 0) RETURN_FAILURE; } while (0) |
395 | | |
396 | 855M | #define DATA_STACK_ALLOC(state, type, ptr) \ |
397 | 855M | do { \ |
398 | 855M | alloc_pos = state->data_stack_base; \ |
399 | 855M | TRACE(("allocating %s in %zd (%zd)\n", \ |
400 | 855M | Py_STRINGIFY(type), alloc_pos, sizeof(type))); \ |
401 | 855M | if (sizeof(type) > state->data_stack_size - alloc_pos) { \ |
402 | 167M | int j = data_stack_grow(state, sizeof(type)); \ |
403 | 167M | if (j < 0) return j; \ |
404 | 167M | if (ctx_pos != -1) \ |
405 | 167M | DATA_STACK_LOOKUP_AT(state, SRE(match_context), ctx, ctx_pos); \ |
406 | 167M | } \ |
407 | 855M | ptr = (type*)(state->data_stack+alloc_pos); \ |
408 | 855M | state->data_stack_base += sizeof(type); \ |
409 | 855M | } while (0) |
410 | | |
411 | 804M | #define DATA_STACK_LOOKUP_AT(state, type, ptr, pos) \ |
412 | 804M | do { \ |
413 | 804M | TRACE(("looking up %s at %zd\n", Py_STRINGIFY(type), pos)); \ |
414 | 804M | ptr = (type*)(state->data_stack+pos); \ |
415 | 804M | } while (0) |
416 | | |
417 | 239M | #define DATA_STACK_PUSH(state, data, size) \ |
418 | 239M | do { \ |
419 | 239M | TRACE(("copy data in %p to %zd (%zd)\n", \ |
420 | 239M | data, state->data_stack_base, size)); \ |
421 | 239M | if (size > state->data_stack_size - state->data_stack_base) { \ |
422 | 48.3k | int j = data_stack_grow(state, size); \ |
423 | 48.3k | if (j < 0) return j; \ |
424 | 48.3k | if (ctx_pos != -1) \ |
425 | 48.3k | DATA_STACK_LOOKUP_AT(state, SRE(match_context), ctx, ctx_pos); \ |
426 | 48.3k | } \ |
427 | 239M | memcpy(state->data_stack+state->data_stack_base, data, size); \ |
428 | 239M | state->data_stack_base += size; \ |
429 | 239M | } while (0) |
430 | | |
431 | | /* We add an explicit cast to memcpy here because MSVC has a bug when |
432 | | compiling C code where it believes that `const void**` cannot be |
433 | | safely casted to `void*`, see bpo-39943 for details. */ |
434 | 123M | #define DATA_STACK_POP(state, data, size, discard) \ |
435 | 123M | do { \ |
436 | 123M | TRACE(("copy data to %p from %zd (%zd)\n", \ |
437 | 123M | data, state->data_stack_base-size, size)); \ |
438 | 123M | memcpy((void*) data, state->data_stack+state->data_stack_base-size, size); \ |
439 | 123M | if (discard) \ |
440 | 123M | state->data_stack_base -= size; \ |
441 | 123M | } while (0) |
442 | | |
443 | 972M | #define DATA_STACK_POP_DISCARD(state, size) \ |
444 | 972M | do { \ |
445 | 972M | TRACE(("discard data from %zd (%zd)\n", \ |
446 | 972M | state->data_stack_base-size, size)); \ |
447 | 972M | state->data_stack_base -= size; \ |
448 | 972M | } while(0) |
449 | | |
450 | | #define DATA_PUSH(x) \ |
451 | 89.3M | DATA_STACK_PUSH(state, (x), sizeof(*(x))) |
452 | | #define DATA_POP(x) \ |
453 | 89.3M | DATA_STACK_POP(state, (x), sizeof(*(x)), 1) |
454 | | #define DATA_POP_DISCARD(x) \ |
455 | 855M | DATA_STACK_POP_DISCARD(state, sizeof(*(x))) |
456 | | #define DATA_ALLOC(t,p) \ |
457 | 855M | DATA_STACK_ALLOC(state, t, p) |
458 | | #define DATA_LOOKUP_AT(t,p,pos) \ |
459 | 804M | DATA_STACK_LOOKUP_AT(state,t,p,pos) |
460 | | |
461 | | #define PTR_TO_INDEX(ptr) \ |
462 | | ((ptr) ? ((char*)(ptr) - (char*)state->beginning) / state->charsize : -1) |
463 | | |
464 | | #if VERBOSE |
465 | | # define MARK_TRACE(label, lastmark) \ |
466 | | do if (DO_TRACE) { \ |
467 | | TRACE(("%s %d marks:", (label), (lastmark)+1)); \ |
468 | | for (int j = 0; j <= (lastmark); j++) { \ |
469 | | if (j && (j & 1) == 0) { \ |
470 | | TRACE((" ")); \ |
471 | | } \ |
472 | | TRACE((" %zd", PTR_TO_INDEX(state->mark[j]))); \ |
473 | | } \ |
474 | | TRACE(("\n")); \ |
475 | | } while (0) |
476 | | #else |
477 | | # define MARK_TRACE(label, lastmark) |
478 | | #endif |
479 | | #define MARK_PUSH(lastmark) \ |
480 | 257M | do if (lastmark >= 0) { \ |
481 | 150M | MARK_TRACE("push", (lastmark)); \ |
482 | 150M | size_t _marks_size = (lastmark+1) * sizeof(void*); \ |
483 | 150M | DATA_STACK_PUSH(state, state->mark, _marks_size); \ |
484 | 257M | } while (0) |
485 | | #define MARK_POP(lastmark) \ |
486 | 49.5M | do if (lastmark >= 0) { \ |
487 | 33.5M | size_t _marks_size = (lastmark+1) * sizeof(void*); \ |
488 | 33.5M | DATA_STACK_POP(state, state->mark, _marks_size, 1); \ |
489 | 33.5M | MARK_TRACE("pop", (lastmark)); \ |
490 | 49.5M | } while (0) |
491 | | #define MARK_POP_KEEP(lastmark) \ |
492 | 621k | do if (lastmark >= 0) { \ |
493 | 619k | size_t _marks_size = (lastmark+1) * sizeof(void*); \ |
494 | 619k | DATA_STACK_POP(state, state->mark, _marks_size, 0); \ |
495 | 619k | MARK_TRACE("pop keep", (lastmark)); \ |
496 | 621k | } while (0) |
497 | | #define MARK_POP_DISCARD(lastmark) \ |
498 | 208M | do if (lastmark >= 0) { \ |
499 | 116M | size_t _marks_size = (lastmark+1) * sizeof(void*); \ |
500 | 116M | DATA_STACK_POP_DISCARD(state, _marks_size); \ |
501 | 116M | MARK_TRACE("pop discard", (lastmark)); \ |
502 | 208M | } while (0) |
503 | | |
504 | 425M | #define JUMP_NONE 0 |
505 | 0 | #define JUMP_MAX_UNTIL_1 1 |
506 | 89.3M | #define JUMP_MAX_UNTIL_2 2 |
507 | 35.1M | #define JUMP_MAX_UNTIL_3 3 |
508 | 0 | #define JUMP_MIN_UNTIL_1 4 |
509 | 0 | #define JUMP_MIN_UNTIL_2 5 |
510 | 0 | #define JUMP_MIN_UNTIL_3 6 |
511 | 34.8M | #define JUMP_REPEAT 7 |
512 | 14.8M | #define JUMP_REPEAT_ONE_1 8 |
513 | 98.7M | #define JUMP_REPEAT_ONE_2 9 |
514 | 872 | #define JUMP_MIN_REPEAT_ONE 10 |
515 | 102M | #define JUMP_BRANCH 11 |
516 | 26.0M | #define JUMP_ASSERT 12 |
517 | 29.2M | #define JUMP_ASSERT_NOT 13 |
518 | 0 | #define JUMP_POSS_REPEAT_1 14 |
519 | 0 | #define JUMP_POSS_REPEAT_2 15 |
520 | 0 | #define JUMP_ATOMIC_GROUP 16 |
521 | | |
522 | | #define DO_JUMPX(jumpvalue, jumplabel, nextpattern, toplevel_) \ |
523 | 430M | ctx->pattern = pattern; \ |
524 | 430M | ctx->ptr = ptr; \ |
525 | 430M | DATA_ALLOC(SRE(match_context), nextctx); \ |
526 | 430M | nextctx->pattern = nextpattern; \ |
527 | 430M | nextctx->toplevel = toplevel_; \ |
528 | 430M | nextctx->jump = jumpvalue; \ |
529 | 430M | nextctx->last_ctx_pos = ctx_pos; \ |
530 | 430M | pattern = nextpattern; \ |
531 | 430M | ctx_pos = alloc_pos; \ |
532 | 430M | ctx = nextctx; \ |
533 | 430M | goto entrance; \ |
534 | 430M | jumplabel: \ |
535 | 430M | pattern = ctx->pattern; \ |
536 | 430M | ptr = ctx->ptr; |
537 | | |
538 | | #define DO_JUMP(jumpvalue, jumplabel, nextpattern) \ |
539 | 375M | DO_JUMPX(jumpvalue, jumplabel, nextpattern, ctx->toplevel) |
540 | | |
541 | | #define DO_JUMP0(jumpvalue, jumplabel, nextpattern) \ |
542 | 55.3M | DO_JUMPX(jumpvalue, jumplabel, nextpattern, 0) |
543 | | |
544 | | typedef struct { |
545 | | Py_ssize_t count; |
546 | | union { |
547 | | SRE_CODE chr; |
548 | | SRE_REPEAT* rep; |
549 | | } u; |
550 | | int lastmark; |
551 | | int lastindex; |
552 | | const SRE_CODE* pattern; |
553 | | const SRE_CHAR* ptr; |
554 | | int toplevel; |
555 | | int jump; |
556 | | Py_ssize_t last_ctx_pos; |
557 | | } SRE(match_context); |
558 | | |
559 | | #define _MAYBE_CHECK_SIGNALS \ |
560 | 1.59G | do { \ |
561 | 1.59G | if ((0 == (++sigcount & 0xfff)) && PyErr_CheckSignals()) { \ |
562 | 0 | RETURN_ERROR(SRE_ERROR_INTERRUPTED); \ |
563 | 0 | } \ |
564 | 1.59G | } while (0) |
565 | | |
566 | | #ifdef Py_DEBUG |
567 | | # define MAYBE_CHECK_SIGNALS \ |
568 | | do { \ |
569 | | _MAYBE_CHECK_SIGNALS; \ |
570 | | if (state->fail_after_count >= 0) { \ |
571 | | if (state->fail_after_count-- == 0) { \ |
572 | | PyErr_SetNone(state->fail_after_exc); \ |
573 | | RETURN_ERROR(SRE_ERROR_INTERRUPTED); \ |
574 | | } \ |
575 | | } \ |
576 | | } while (0) |
577 | | #else |
578 | 1.59G | # define MAYBE_CHECK_SIGNALS _MAYBE_CHECK_SIGNALS |
579 | | #endif /* Py_DEBUG */ |
580 | | |
581 | | #ifdef HAVE_COMPUTED_GOTOS |
582 | | #ifndef USE_COMPUTED_GOTOS |
583 | | #define USE_COMPUTED_GOTOS 1 |
584 | | #endif |
585 | | #elif defined(USE_COMPUTED_GOTOS) && USE_COMPUTED_GOTOS |
586 | | #error "Computed gotos are not supported on this compiler." |
587 | | #else |
588 | | #undef USE_COMPUTED_GOTOS |
589 | | #define USE_COMPUTED_GOTOS 0 |
590 | | #endif |
591 | | |
592 | | #if USE_COMPUTED_GOTOS |
593 | 1.67G | #define TARGET(OP) TARGET_ ## OP |
594 | | #define DISPATCH \ |
595 | 1.59G | do { \ |
596 | 1.59G | MAYBE_CHECK_SIGNALS; \ |
597 | 1.59G | goto *sre_targets[*pattern++]; \ |
598 | 1.59G | } while (0) |
599 | | #else |
600 | | #define TARGET(OP) case OP |
601 | | #define DISPATCH goto dispatch |
602 | | #endif |
603 | | |
604 | | /* check if string matches the given pattern. returns <0 for |
605 | | error, 0 for failure, and 1 for success */ |
606 | | LOCAL(Py_ssize_t) |
607 | | SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel) |
608 | 425M | { |
609 | 425M | const SRE_CHAR* end = (const SRE_CHAR *)state->end; |
610 | 425M | Py_ssize_t alloc_pos, ctx_pos = -1; |
611 | 425M | Py_ssize_t ret = 0; |
612 | 425M | int jump; |
613 | 425M | unsigned int sigcount = state->sigcount; |
614 | | |
615 | 425M | SRE(match_context)* ctx; |
616 | 425M | SRE(match_context)* nextctx; |
617 | 425M | INIT_TRACE(state); |
618 | | |
619 | 425M | TRACE(("|%p|%p|ENTER\n", pattern, state->ptr)); |
620 | | |
621 | 425M | DATA_ALLOC(SRE(match_context), ctx); |
622 | 425M | ctx->last_ctx_pos = -1; |
623 | 425M | ctx->jump = JUMP_NONE; |
624 | 425M | ctx->toplevel = toplevel; |
625 | 425M | ctx_pos = alloc_pos; |
626 | | |
627 | 425M | #if USE_COMPUTED_GOTOS |
628 | 425M | #include "sre_targets.h" |
629 | 425M | #endif |
630 | | |
631 | 855M | entrance: |
632 | | |
633 | 855M | ; // Fashion statement. |
634 | 855M | const SRE_CHAR *ptr = (SRE_CHAR *)state->ptr; |
635 | | |
636 | 855M | if (pattern[0] == SRE_OP_INFO) { |
637 | | /* optimization info block */ |
638 | | /* <INFO> <1=skip> <2=flags> <3=min> ... */ |
639 | 51.2M | if (pattern[3] && (uintptr_t)(end - ptr) < pattern[3]) { |
640 | 2.02M | TRACE(("reject (got %tu chars, need %zu)\n", |
641 | 2.02M | end - ptr, (size_t) pattern[3])); |
642 | 2.02M | RETURN_FAILURE; |
643 | 2.02M | } |
644 | 49.2M | pattern += pattern[1] + 1; |
645 | 49.2M | } |
646 | | |
647 | 853M | #if USE_COMPUTED_GOTOS |
648 | 853M | DISPATCH; |
649 | | #else |
650 | | dispatch: |
651 | | MAYBE_CHECK_SIGNALS; |
652 | | switch (*pattern++) |
653 | | #endif |
654 | 853M | { |
655 | | |
656 | 853M | TARGET(SRE_OP_MARK): |
657 | | /* set mark */ |
658 | | /* <MARK> <gid> */ |
659 | 339M | TRACE(("|%p|%p|MARK %d\n", pattern, |
660 | 339M | ptr, pattern[0])); |
661 | 339M | { |
662 | 339M | int i = pattern[0]; |
663 | 339M | if (i & 1) |
664 | 42.0M | state->lastindex = i/2 + 1; |
665 | 339M | if (i > state->lastmark) { |
666 | | /* state->lastmark is the highest valid index in the |
667 | | state->mark array. If it is increased by more than 1, |
668 | | the intervening marks must be set to NULL to signal |
669 | | that these marks have not been encountered. */ |
670 | 333M | int j = state->lastmark + 1; |
671 | 339M | while (j < i) |
672 | 6.22M | state->mark[j++] = NULL; |
673 | 333M | state->lastmark = i; |
674 | 333M | } |
675 | 339M | state->mark[i] = ptr; |
676 | 339M | } |
677 | 339M | pattern++; |
678 | 339M | DISPATCH; |
679 | | |
680 | 339M | TARGET(SRE_OP_LITERAL): |
681 | | /* match literal string */ |
682 | | /* <LITERAL> <code> */ |
683 | 118M | TRACE(("|%p|%p|LITERAL %d\n", pattern, |
684 | 118M | ptr, *pattern)); |
685 | 118M | if (ptr >= end || (SRE_CODE) ptr[0] != pattern[0]) |
686 | 37.2M | RETURN_FAILURE; |
687 | 81.5M | pattern++; |
688 | 81.5M | ptr++; |
689 | 81.5M | DISPATCH; |
690 | | |
691 | 81.5M | TARGET(SRE_OP_NOT_LITERAL): |
692 | | /* match anything that is not literal character */ |
693 | | /* <NOT_LITERAL> <code> */ |
694 | 0 | TRACE(("|%p|%p|NOT_LITERAL %d\n", pattern, |
695 | 0 | ptr, *pattern)); |
696 | 0 | if (ptr >= end || (SRE_CODE) ptr[0] == pattern[0]) |
697 | 0 | RETURN_FAILURE; |
698 | 0 | pattern++; |
699 | 0 | ptr++; |
700 | 0 | DISPATCH; |
701 | | |
702 | 173M | TARGET(SRE_OP_SUCCESS): |
703 | | /* end of pattern */ |
704 | 173M | TRACE(("|%p|%p|SUCCESS\n", pattern, ptr)); |
705 | 173M | if (ctx->toplevel && |
706 | 37.1M | ((state->match_all && ptr != state->end) || |
707 | 37.1M | (state->must_advance && ptr == state->start))) |
708 | 0 | { |
709 | 0 | RETURN_FAILURE; |
710 | 0 | } |
711 | 173M | state->ptr = ptr; |
712 | 173M | RETURN_SUCCESS; |
713 | | |
714 | 15.7M | TARGET(SRE_OP_AT): |
715 | | /* match at given position */ |
716 | | /* <AT> <code> */ |
717 | 15.7M | TRACE(("|%p|%p|AT %d\n", pattern, ptr, *pattern)); |
718 | 15.7M | if (!SRE(at)(state, ptr, *pattern)) |
719 | 6.63M | RETURN_FAILURE; |
720 | 9.11M | pattern++; |
721 | 9.11M | DISPATCH; |
722 | | |
723 | 9.11M | TARGET(SRE_OP_CATEGORY): |
724 | | /* match at given category */ |
725 | | /* <CATEGORY> <code> */ |
726 | 1.74k | TRACE(("|%p|%p|CATEGORY %d\n", pattern, |
727 | 1.74k | ptr, *pattern)); |
728 | 1.74k | if (ptr >= end || !sre_category(pattern[0], ptr[0])) |
729 | 12 | RETURN_FAILURE; |
730 | 1.73k | pattern++; |
731 | 1.73k | ptr++; |
732 | 1.73k | DISPATCH; |
733 | | |
734 | 1.73k | TARGET(SRE_OP_ANY): |
735 | | /* match anything (except a newline) */ |
736 | | /* <ANY> */ |
737 | 0 | TRACE(("|%p|%p|ANY\n", pattern, ptr)); |
738 | 0 | if (ptr >= end || SRE_IS_LINEBREAK(ptr[0])) |
739 | 0 | RETURN_FAILURE; |
740 | 0 | ptr++; |
741 | 0 | DISPATCH; |
742 | | |
743 | 0 | TARGET(SRE_OP_ANY_ALL): |
744 | | /* match anything */ |
745 | | /* <ANY_ALL> */ |
746 | 0 | TRACE(("|%p|%p|ANY_ALL\n", pattern, ptr)); |
747 | 0 | if (ptr >= end) |
748 | 0 | RETURN_FAILURE; |
749 | 0 | ptr++; |
750 | 0 | DISPATCH; |
751 | | |
752 | 198M | TARGET(SRE_OP_IN): |
753 | | /* match set member (or non_member) */ |
754 | | /* <IN> <skip> <set> */ |
755 | 198M | TRACE(("|%p|%p|IN\n", pattern, ptr)); |
756 | 198M | if (ptr >= end || |
757 | 198M | !SRE(charset)(state, pattern + 1, *ptr)) |
758 | 20.8M | RETURN_FAILURE; |
759 | 177M | pattern += pattern[0]; |
760 | 177M | ptr++; |
761 | 177M | DISPATCH; |
762 | | |
763 | 177M | TARGET(SRE_OP_LITERAL_IGNORE): |
764 | 7.87M | TRACE(("|%p|%p|LITERAL_IGNORE %d\n", |
765 | 7.87M | pattern, ptr, pattern[0])); |
766 | 7.87M | if (ptr >= end || |
767 | 7.87M | sre_lower_ascii(*ptr) != *pattern) |
768 | 68.0k | RETURN_FAILURE; |
769 | 7.80M | pattern++; |
770 | 7.80M | ptr++; |
771 | 7.80M | DISPATCH; |
772 | | |
773 | 7.80M | TARGET(SRE_OP_LITERAL_UNI_IGNORE): |
774 | 28 | TRACE(("|%p|%p|LITERAL_UNI_IGNORE %d\n", |
775 | 28 | pattern, ptr, pattern[0])); |
776 | 28 | if (ptr >= end || |
777 | 28 | sre_lower_unicode(*ptr) != *pattern) |
778 | 0 | RETURN_FAILURE; |
779 | 28 | pattern++; |
780 | 28 | ptr++; |
781 | 28 | DISPATCH; |
782 | | |
783 | 28 | TARGET(SRE_OP_LITERAL_LOC_IGNORE): |
784 | 0 | TRACE(("|%p|%p|LITERAL_LOC_IGNORE %d\n", |
785 | 0 | pattern, ptr, pattern[0])); |
786 | 0 | if (ptr >= end |
787 | 0 | || !char_loc_ignore(*pattern, *ptr)) |
788 | 0 | RETURN_FAILURE; |
789 | 0 | pattern++; |
790 | 0 | ptr++; |
791 | 0 | DISPATCH; |
792 | | |
793 | 0 | TARGET(SRE_OP_NOT_LITERAL_IGNORE): |
794 | 0 | TRACE(("|%p|%p|NOT_LITERAL_IGNORE %d\n", |
795 | 0 | pattern, ptr, *pattern)); |
796 | 0 | if (ptr >= end || |
797 | 0 | sre_lower_ascii(*ptr) == *pattern) |
798 | 0 | RETURN_FAILURE; |
799 | 0 | pattern++; |
800 | 0 | ptr++; |
801 | 0 | DISPATCH; |
802 | | |
803 | 0 | TARGET(SRE_OP_NOT_LITERAL_UNI_IGNORE): |
804 | 0 | TRACE(("|%p|%p|NOT_LITERAL_UNI_IGNORE %d\n", |
805 | 0 | pattern, ptr, *pattern)); |
806 | 0 | if (ptr >= end || |
807 | 0 | sre_lower_unicode(*ptr) == *pattern) |
808 | 0 | RETURN_FAILURE; |
809 | 0 | pattern++; |
810 | 0 | ptr++; |
811 | 0 | DISPATCH; |
812 | | |
813 | 0 | TARGET(SRE_OP_NOT_LITERAL_LOC_IGNORE): |
814 | 0 | TRACE(("|%p|%p|NOT_LITERAL_LOC_IGNORE %d\n", |
815 | 0 | pattern, ptr, *pattern)); |
816 | 0 | if (ptr >= end |
817 | 0 | || char_loc_ignore(*pattern, *ptr)) |
818 | 0 | RETURN_FAILURE; |
819 | 0 | pattern++; |
820 | 0 | ptr++; |
821 | 0 | DISPATCH; |
822 | | |
823 | 0 | TARGET(SRE_OP_IN_IGNORE): |
824 | 0 | TRACE(("|%p|%p|IN_IGNORE\n", pattern, ptr)); |
825 | 0 | if (ptr >= end |
826 | 0 | || !SRE(charset)(state, pattern+1, |
827 | 0 | (SRE_CODE)sre_lower_ascii(*ptr))) |
828 | 0 | RETURN_FAILURE; |
829 | 0 | pattern += pattern[0]; |
830 | 0 | ptr++; |
831 | 0 | DISPATCH; |
832 | | |
833 | 24 | TARGET(SRE_OP_IN_UNI_IGNORE): |
834 | 24 | TRACE(("|%p|%p|IN_UNI_IGNORE\n", pattern, ptr)); |
835 | 24 | if (ptr >= end |
836 | 16 | || !SRE(charset)(state, pattern+1, |
837 | 16 | (SRE_CODE)sre_lower_unicode(*ptr))) |
838 | 16 | RETURN_FAILURE; |
839 | 8 | pattern += pattern[0]; |
840 | 8 | ptr++; |
841 | 8 | DISPATCH; |
842 | | |
843 | 8 | TARGET(SRE_OP_IN_LOC_IGNORE): |
844 | 0 | TRACE(("|%p|%p|IN_LOC_IGNORE\n", pattern, ptr)); |
845 | 0 | if (ptr >= end |
846 | 0 | || !SRE(charset_loc_ignore)(state, pattern+1, *ptr)) |
847 | 0 | RETURN_FAILURE; |
848 | 0 | pattern += pattern[0]; |
849 | 0 | ptr++; |
850 | 0 | DISPATCH; |
851 | | |
852 | 79.1M | TARGET(SRE_OP_JUMP): |
853 | 79.1M | TARGET(SRE_OP_INFO): |
854 | | /* jump forward */ |
855 | | /* <JUMP> <offset> */ |
856 | 79.1M | TRACE(("|%p|%p|JUMP %d\n", pattern, |
857 | 79.1M | ptr, pattern[0])); |
858 | 79.1M | pattern += pattern[0]; |
859 | 79.1M | DISPATCH; |
860 | | |
861 | 96.2M | TARGET(SRE_OP_BRANCH): |
862 | | /* alternation */ |
863 | | /* <BRANCH> <0=skip> code <JUMP> ... <NULL> */ |
864 | 96.2M | TRACE(("|%p|%p|BRANCH\n", pattern, ptr)); |
865 | 96.2M | LASTMARK_SAVE(); |
866 | 96.2M | if (state->save_marks) |
867 | 61.6M | MARK_PUSH(ctx->lastmark); |
868 | 215M | for (; pattern[0]; pattern += pattern[0]) { |
869 | 195M | if (pattern[1] == SRE_OP_LITERAL && |
870 | 120M | (ptr >= end || |
871 | 120M | (SRE_CODE) *ptr != pattern[2])) |
872 | 65.0M | continue; |
873 | 130M | if (pattern[1] == SRE_OP_IN && |
874 | 51.4M | (ptr >= end || |
875 | 51.3M | !SRE(charset)(state, pattern + 3, |
876 | 51.3M | (SRE_CODE) *ptr))) |
877 | 27.9M | continue; |
878 | 102M | state->ptr = ptr; |
879 | 102M | DO_JUMP(JUMP_BRANCH, jump_branch, pattern+1); |
880 | 102M | if (ret) { |
881 | 76.2M | if (state->save_marks) |
882 | 52.7M | MARK_POP_DISCARD(ctx->lastmark); |
883 | 76.2M | RETURN_ON_ERROR(ret); |
884 | 76.2M | RETURN_SUCCESS; |
885 | 76.2M | } |
886 | 26.0M | if (state->save_marks) |
887 | 16.2k | MARK_POP_KEEP(ctx->lastmark); |
888 | 26.0M | LASTMARK_RESTORE(); |
889 | 26.0M | } |
890 | 19.9M | if (state->save_marks) |
891 | 8.93M | MARK_POP_DISCARD(ctx->lastmark); |
892 | 19.9M | RETURN_FAILURE; |
893 | | |
894 | 375M | TARGET(SRE_OP_REPEAT_ONE): |
895 | | /* match repeated sequence (maximizing regexp) */ |
896 | | |
897 | | /* this operator only works if the repeated item is |
898 | | exactly one character wide, and we're not already |
899 | | collecting backtracking points. for other cases, |
900 | | use the MAX_REPEAT operator */ |
901 | | |
902 | | /* <REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> tail */ |
903 | | |
904 | 375M | TRACE(("|%p|%p|REPEAT_ONE %d %d\n", pattern, ptr, |
905 | 375M | pattern[1], pattern[2])); |
906 | | |
907 | 375M | if ((Py_ssize_t) pattern[1] > end - ptr) |
908 | 869k | RETURN_FAILURE; /* cannot match */ |
909 | | |
910 | 374M | state->ptr = ptr; |
911 | | |
912 | 374M | ret = SRE(count)(state, pattern+3, pattern[2]); |
913 | 374M | RETURN_ON_ERROR(ret); |
914 | 374M | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); |
915 | 374M | ctx->count = ret; |
916 | 374M | ptr += ctx->count; |
917 | | |
918 | | /* when we arrive here, count contains the number of |
919 | | matches, and ptr points to the tail of the target |
920 | | string. check if the rest of the pattern matches, |
921 | | and backtrack if not. */ |
922 | | |
923 | 374M | if (ctx->count < (Py_ssize_t) pattern[1]) |
924 | 253M | RETURN_FAILURE; |
925 | | |
926 | 120M | if (pattern[pattern[0]] == SRE_OP_SUCCESS && |
927 | 6.14M | ptr == state->end && |
928 | 90.5k | !(ctx->toplevel && state->must_advance && ptr == state->start)) |
929 | 90.5k | { |
930 | | /* tail is empty. we're finished */ |
931 | 90.5k | state->ptr = ptr; |
932 | 90.5k | RETURN_SUCCESS; |
933 | 90.5k | } |
934 | | |
935 | 120M | LASTMARK_SAVE(); |
936 | 120M | if (state->save_marks) |
937 | 77.6M | MARK_PUSH(ctx->lastmark); |
938 | | |
939 | 120M | if (pattern[pattern[0]] == SRE_OP_LITERAL) { |
940 | | /* tail starts with a literal. skip positions where |
941 | | the rest of the pattern cannot possibly match */ |
942 | 24.3M | ctx->u.chr = pattern[pattern[0]+1]; |
943 | 24.3M | for (;;) { |
944 | 61.6M | while (ctx->count >= (Py_ssize_t) pattern[1] && |
945 | 52.2M | (ptr >= end || *ptr != ctx->u.chr)) { |
946 | 37.3M | ptr--; |
947 | 37.3M | ctx->count--; |
948 | 37.3M | } |
949 | 24.3M | if (ctx->count < (Py_ssize_t) pattern[1]) |
950 | 9.45M | break; |
951 | 14.8M | state->ptr = ptr; |
952 | 14.8M | DO_JUMP(JUMP_REPEAT_ONE_1, jump_repeat_one_1, |
953 | 14.8M | pattern+pattern[0]); |
954 | 14.8M | if (ret) { |
955 | 14.8M | if (state->save_marks) |
956 | 12.8M | MARK_POP_DISCARD(ctx->lastmark); |
957 | 14.8M | RETURN_ON_ERROR(ret); |
958 | 14.8M | RETURN_SUCCESS; |
959 | 14.8M | } |
960 | 852 | if (state->save_marks) |
961 | 835 | MARK_POP_KEEP(ctx->lastmark); |
962 | 852 | LASTMARK_RESTORE(); |
963 | | |
964 | 852 | ptr--; |
965 | 852 | ctx->count--; |
966 | 852 | } |
967 | 9.45M | if (state->save_marks) |
968 | 8.21M | MARK_POP_DISCARD(ctx->lastmark); |
969 | 96.0M | } else { |
970 | | /* general case */ |
971 | 99.2M | while (ctx->count >= (Py_ssize_t) pattern[1]) { |
972 | 98.7M | state->ptr = ptr; |
973 | 98.7M | DO_JUMP(JUMP_REPEAT_ONE_2, jump_repeat_one_2, |
974 | 98.7M | pattern+pattern[0]); |
975 | 98.7M | if (ret) { |
976 | 95.4M | if (state->save_marks) |
977 | 56.1M | MARK_POP_DISCARD(ctx->lastmark); |
978 | 95.4M | RETURN_ON_ERROR(ret); |
979 | 95.4M | RETURN_SUCCESS; |
980 | 95.4M | } |
981 | 3.25M | if (state->save_marks) |
982 | 604k | MARK_POP_KEEP(ctx->lastmark); |
983 | 3.25M | LASTMARK_RESTORE(); |
984 | | |
985 | 3.25M | ptr--; |
986 | 3.25M | ctx->count--; |
987 | 3.25M | } |
988 | 544k | if (state->save_marks) |
989 | 346k | MARK_POP_DISCARD(ctx->lastmark); |
990 | 544k | } |
991 | 10.0M | RETURN_FAILURE; |
992 | | |
993 | 17 | TARGET(SRE_OP_MIN_REPEAT_ONE): |
994 | | /* match repeated sequence (minimizing regexp) */ |
995 | | |
996 | | /* this operator only works if the repeated item is |
997 | | exactly one character wide, and we're not already |
998 | | collecting backtracking points. for other cases, |
999 | | use the MIN_REPEAT operator */ |
1000 | | |
1001 | | /* <MIN_REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> tail */ |
1002 | | |
1003 | 17 | TRACE(("|%p|%p|MIN_REPEAT_ONE %d %d\n", pattern, ptr, |
1004 | 17 | pattern[1], pattern[2])); |
1005 | | |
1006 | 17 | if ((Py_ssize_t) pattern[1] > end - ptr) |
1007 | 0 | RETURN_FAILURE; /* cannot match */ |
1008 | | |
1009 | 17 | state->ptr = ptr; |
1010 | | |
1011 | 17 | if (pattern[1] == 0) |
1012 | 17 | ctx->count = 0; |
1013 | 0 | else { |
1014 | | /* count using pattern min as the maximum */ |
1015 | 0 | ret = SRE(count)(state, pattern+3, pattern[1]); |
1016 | 0 | RETURN_ON_ERROR(ret); |
1017 | 0 | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); |
1018 | 0 | if (ret < (Py_ssize_t) pattern[1]) |
1019 | | /* didn't match minimum number of times */ |
1020 | 0 | RETURN_FAILURE; |
1021 | | /* advance past minimum matches of repeat */ |
1022 | 0 | ctx->count = ret; |
1023 | 0 | ptr += ctx->count; |
1024 | 0 | } |
1025 | | |
1026 | 17 | if (pattern[pattern[0]] == SRE_OP_SUCCESS && |
1027 | 0 | !(ctx->toplevel && |
1028 | 0 | ((state->match_all && ptr != state->end) || |
1029 | 0 | (state->must_advance && ptr == state->start)))) |
1030 | 0 | { |
1031 | | /* tail is empty. we're finished */ |
1032 | 0 | state->ptr = ptr; |
1033 | 0 | RETURN_SUCCESS; |
1034 | |
|
1035 | 17 | } else { |
1036 | | /* general case */ |
1037 | 17 | LASTMARK_SAVE(); |
1038 | 17 | if (state->save_marks) |
1039 | 0 | MARK_PUSH(ctx->lastmark); |
1040 | | |
1041 | 872 | while ((Py_ssize_t)pattern[2] == SRE_MAXREPEAT |
1042 | 872 | || ctx->count <= (Py_ssize_t)pattern[2]) { |
1043 | 872 | state->ptr = ptr; |
1044 | 872 | DO_JUMP(JUMP_MIN_REPEAT_ONE,jump_min_repeat_one, |
1045 | 872 | pattern+pattern[0]); |
1046 | 872 | if (ret) { |
1047 | 0 | if (state->save_marks) |
1048 | 0 | MARK_POP_DISCARD(ctx->lastmark); |
1049 | 0 | RETURN_ON_ERROR(ret); |
1050 | 0 | RETURN_SUCCESS; |
1051 | 0 | } |
1052 | 872 | if (state->save_marks) |
1053 | 0 | MARK_POP_KEEP(ctx->lastmark); |
1054 | 872 | LASTMARK_RESTORE(); |
1055 | | |
1056 | 872 | state->ptr = ptr; |
1057 | 872 | ret = SRE(count)(state, pattern+3, 1); |
1058 | 872 | RETURN_ON_ERROR(ret); |
1059 | 872 | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); |
1060 | 872 | if (ret == 0) |
1061 | 17 | break; |
1062 | 872 | assert(ret == 1); |
1063 | 855 | ptr++; |
1064 | 855 | ctx->count++; |
1065 | 855 | } |
1066 | 17 | if (state->save_marks) |
1067 | 0 | MARK_POP_DISCARD(ctx->lastmark); |
1068 | 17 | } |
1069 | 17 | RETURN_FAILURE; |
1070 | | |
1071 | 0 | TARGET(SRE_OP_POSSESSIVE_REPEAT_ONE): |
1072 | | /* match repeated sequence (maximizing regexp) without |
1073 | | backtracking */ |
1074 | | |
1075 | | /* this operator only works if the repeated item is |
1076 | | exactly one character wide, and we're not already |
1077 | | collecting backtracking points. for other cases, |
1078 | | use the MAX_REPEAT operator */ |
1079 | | |
1080 | | /* <POSSESSIVE_REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> |
1081 | | tail */ |
1082 | |
|
1083 | 0 | TRACE(("|%p|%p|POSSESSIVE_REPEAT_ONE %d %d\n", pattern, |
1084 | 0 | ptr, pattern[1], pattern[2])); |
1085 | |
|
1086 | 0 | if (ptr + pattern[1] > end) { |
1087 | 0 | RETURN_FAILURE; /* cannot match */ |
1088 | 0 | } |
1089 | | |
1090 | 0 | state->ptr = ptr; |
1091 | |
|
1092 | 0 | ret = SRE(count)(state, pattern + 3, pattern[2]); |
1093 | 0 | RETURN_ON_ERROR(ret); |
1094 | 0 | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); |
1095 | 0 | ctx->count = ret; |
1096 | 0 | ptr += ctx->count; |
1097 | | |
1098 | | /* when we arrive here, count contains the number of |
1099 | | matches, and ptr points to the tail of the target |
1100 | | string. check if the rest of the pattern matches, |
1101 | | and fail if not. */ |
1102 | | |
1103 | | /* Test for not enough repetitions in match */ |
1104 | 0 | if (ctx->count < (Py_ssize_t) pattern[1]) { |
1105 | 0 | RETURN_FAILURE; |
1106 | 0 | } |
1107 | | |
1108 | | /* Update the pattern to point to the next op code */ |
1109 | 0 | pattern += pattern[0]; |
1110 | | |
1111 | | /* Let the tail be evaluated separately and consider this |
1112 | | match successful. */ |
1113 | 0 | if (*pattern == SRE_OP_SUCCESS && |
1114 | 0 | ptr == state->end && |
1115 | 0 | !(ctx->toplevel && state->must_advance && ptr == state->start)) |
1116 | 0 | { |
1117 | | /* tail is empty. we're finished */ |
1118 | 0 | state->ptr = ptr; |
1119 | 0 | RETURN_SUCCESS; |
1120 | 0 | } |
1121 | | |
1122 | | /* Attempt to match the rest of the string */ |
1123 | 0 | DISPATCH; |
1124 | | |
1125 | 34.8M | TARGET(SRE_OP_REPEAT): |
1126 | | /* create repeat context. all the hard work is done |
1127 | | by the UNTIL operator (MAX_UNTIL, MIN_UNTIL) */ |
1128 | | /* <REPEAT> <skip> <1=min> <2=max> |
1129 | | <3=repeat_index> item <UNTIL> tail */ |
1130 | 34.8M | TRACE(("|%p|%p|REPEAT %d %d\n", pattern, ptr, |
1131 | 34.8M | pattern[1], pattern[2])); |
1132 | | |
1133 | | /* install new repeat context */ |
1134 | 34.8M | ctx->u.rep = repeat_pool_malloc(state); |
1135 | 34.8M | if (!ctx->u.rep) { |
1136 | 0 | RETURN_ERROR(SRE_ERROR_MEMORY); |
1137 | 0 | } |
1138 | 34.8M | ctx->u.rep->count = -1; |
1139 | 34.8M | ctx->u.rep->pattern = pattern; |
1140 | 34.8M | ctx->u.rep->prev = state->repeat; |
1141 | 34.8M | ctx->u.rep->last_ptr = NULL; |
1142 | 34.8M | state->repeat = ctx->u.rep; |
1143 | 34.8M | state->save_marks++; |
1144 | | |
1145 | 34.8M | state->ptr = ptr; |
1146 | 34.8M | DO_JUMP(JUMP_REPEAT, jump_repeat, pattern+pattern[0]); |
1147 | 34.8M | state->repeat = ctx->u.rep->prev; |
1148 | 34.8M | state->save_marks--; |
1149 | 34.8M | repeat_pool_free(state, ctx->u.rep); |
1150 | | |
1151 | 34.8M | if (ret) { |
1152 | 34.7M | RETURN_ON_ERROR(ret); |
1153 | 34.7M | RETURN_SUCCESS; |
1154 | 34.7M | } |
1155 | 93.1k | RETURN_FAILURE; |
1156 | | |
1157 | 104M | TARGET(SRE_OP_MAX_UNTIL): |
1158 | | /* maximizing repeat */ |
1159 | | /* <REPEAT> <skip> <1=min> <2=max> item <MAX_UNTIL> tail */ |
1160 | | |
1161 | | /* FIXME: we probably need to deal with zero-width |
1162 | | matches in here... */ |
1163 | | |
1164 | 104M | ctx->u.rep = state->repeat; |
1165 | 104M | if (!ctx->u.rep) |
1166 | 0 | RETURN_ERROR(SRE_ERROR_STATE); |
1167 | | |
1168 | 104M | state->ptr = ptr; |
1169 | | |
1170 | 104M | ctx->count = ctx->u.rep->count+1; |
1171 | | |
1172 | 104M | TRACE(("|%p|%p|MAX_UNTIL %zd\n", pattern, |
1173 | 104M | ptr, ctx->count)); |
1174 | | |
1175 | 104M | if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) { |
1176 | | /* not enough matches */ |
1177 | 0 | ctx->u.rep->count = ctx->count; |
1178 | 0 | DO_JUMP(JUMP_MAX_UNTIL_1, jump_max_until_1, |
1179 | 0 | ctx->u.rep->pattern+3); |
1180 | 0 | if (ret) { |
1181 | 0 | RETURN_ON_ERROR(ret); |
1182 | 0 | RETURN_SUCCESS; |
1183 | 0 | } |
1184 | 0 | ctx->u.rep->count = ctx->count-1; |
1185 | 0 | state->ptr = ptr; |
1186 | 0 | RETURN_FAILURE; |
1187 | 0 | } |
1188 | | |
1189 | 104M | if ((ctx->count < (Py_ssize_t) ctx->u.rep->pattern[2] || |
1190 | 14.8M | ctx->u.rep->pattern[2] == SRE_MAXREPEAT) && |
1191 | 89.3M | state->ptr != ctx->u.rep->last_ptr) { |
1192 | | /* we may have enough matches, but if we can |
1193 | | match another item, do so */ |
1194 | 89.3M | ctx->u.rep->count = ctx->count; |
1195 | 89.3M | LASTMARK_SAVE(); |
1196 | 89.3M | MARK_PUSH(ctx->lastmark); |
1197 | | /* zero-width match protection */ |
1198 | 89.3M | LAST_PTR_PUSH(); |
1199 | 89.3M | ctx->u.rep->last_ptr = state->ptr; |
1200 | 89.3M | DO_JUMP(JUMP_MAX_UNTIL_2, jump_max_until_2, |
1201 | 89.3M | ctx->u.rep->pattern+3); |
1202 | 89.3M | LAST_PTR_POP(); |
1203 | 89.3M | if (ret) { |
1204 | 69.0M | MARK_POP_DISCARD(ctx->lastmark); |
1205 | 69.0M | RETURN_ON_ERROR(ret); |
1206 | 69.0M | RETURN_SUCCESS; |
1207 | 69.0M | } |
1208 | 20.3M | MARK_POP(ctx->lastmark); |
1209 | 20.3M | LASTMARK_RESTORE(); |
1210 | 20.3M | ctx->u.rep->count = ctx->count-1; |
1211 | 20.3M | state->ptr = ptr; |
1212 | 20.3M | } |
1213 | | |
1214 | | /* cannot match more repeated items here. make sure the |
1215 | | tail matches */ |
1216 | 35.1M | state->repeat = ctx->u.rep->prev; |
1217 | 35.1M | state->save_marks--; |
1218 | 35.1M | DO_JUMP(JUMP_MAX_UNTIL_3, jump_max_until_3, pattern); |
1219 | 35.1M | state->repeat = ctx->u.rep; // restore repeat before return |
1220 | 35.1M | state->save_marks++; |
1221 | | |
1222 | 35.1M | RETURN_ON_SUCCESS(ret); |
1223 | 400k | state->ptr = ptr; |
1224 | 400k | RETURN_FAILURE; |
1225 | | |
1226 | 0 | TARGET(SRE_OP_MIN_UNTIL): |
1227 | | /* minimizing repeat */ |
1228 | | /* <REPEAT> <skip> <1=min> <2=max> item <MIN_UNTIL> tail */ |
1229 | |
|
1230 | 0 | ctx->u.rep = state->repeat; |
1231 | 0 | if (!ctx->u.rep) |
1232 | 0 | RETURN_ERROR(SRE_ERROR_STATE); |
1233 | | |
1234 | 0 | state->ptr = ptr; |
1235 | |
|
1236 | 0 | ctx->count = ctx->u.rep->count+1; |
1237 | |
|
1238 | 0 | TRACE(("|%p|%p|MIN_UNTIL %zd %p\n", pattern, |
1239 | 0 | ptr, ctx->count, ctx->u.rep->pattern)); |
1240 | |
|
1241 | 0 | if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) { |
1242 | | /* not enough matches */ |
1243 | 0 | ctx->u.rep->count = ctx->count; |
1244 | 0 | DO_JUMP(JUMP_MIN_UNTIL_1, jump_min_until_1, |
1245 | 0 | ctx->u.rep->pattern+3); |
1246 | 0 | if (ret) { |
1247 | 0 | RETURN_ON_ERROR(ret); |
1248 | 0 | RETURN_SUCCESS; |
1249 | 0 | } |
1250 | 0 | ctx->u.rep->count = ctx->count-1; |
1251 | 0 | state->ptr = ptr; |
1252 | 0 | RETURN_FAILURE; |
1253 | 0 | } |
1254 | | |
1255 | | /* see if the tail matches */ |
1256 | 0 | state->repeat = ctx->u.rep->prev; |
1257 | 0 | state->save_marks--; |
1258 | |
|
1259 | 0 | LASTMARK_SAVE(); |
1260 | 0 | if (state->save_marks) |
1261 | 0 | MARK_PUSH(ctx->lastmark); |
1262 | | |
1263 | 0 | DO_JUMP(JUMP_MIN_UNTIL_2, jump_min_until_2, pattern); |
1264 | | /* save_marks is balanced across the jump, so this equals the |
1265 | | value tested for MARK_PUSH above */ |
1266 | 0 | int pushed = state->save_marks != 0; |
1267 | 0 | state->repeat = ctx->u.rep; // restore repeat before return |
1268 | 0 | state->save_marks++; |
1269 | |
|
1270 | 0 | if (ret) { |
1271 | 0 | if (pushed) |
1272 | 0 | MARK_POP_DISCARD(ctx->lastmark); |
1273 | 0 | RETURN_ON_ERROR(ret); |
1274 | 0 | RETURN_SUCCESS; |
1275 | 0 | } |
1276 | 0 | if (pushed) |
1277 | 0 | MARK_POP(ctx->lastmark); |
1278 | 0 | LASTMARK_RESTORE(); |
1279 | |
|
1280 | 0 | state->ptr = ptr; |
1281 | |
|
1282 | 0 | if ((ctx->count >= (Py_ssize_t) ctx->u.rep->pattern[2] |
1283 | 0 | && ctx->u.rep->pattern[2] != SRE_MAXREPEAT) || |
1284 | 0 | state->ptr == ctx->u.rep->last_ptr) |
1285 | 0 | RETURN_FAILURE; |
1286 | | |
1287 | 0 | ctx->u.rep->count = ctx->count; |
1288 | | /* zero-width match protection */ |
1289 | 0 | LAST_PTR_PUSH(); |
1290 | 0 | ctx->u.rep->last_ptr = state->ptr; |
1291 | 0 | DO_JUMP(JUMP_MIN_UNTIL_3,jump_min_until_3, |
1292 | 0 | ctx->u.rep->pattern+3); |
1293 | 0 | LAST_PTR_POP(); |
1294 | 0 | if (ret) { |
1295 | 0 | RETURN_ON_ERROR(ret); |
1296 | 0 | RETURN_SUCCESS; |
1297 | 0 | } |
1298 | 0 | ctx->u.rep->count = ctx->count-1; |
1299 | 0 | state->ptr = ptr; |
1300 | 0 | RETURN_FAILURE; |
1301 | | |
1302 | 0 | TARGET(SRE_OP_POSSESSIVE_REPEAT): |
1303 | | /* create possessive repeat contexts. */ |
1304 | | /* <POSSESSIVE_REPEAT> <skip> <1=min> <2=max> pattern |
1305 | | <SUCCESS> tail */ |
1306 | 0 | TRACE(("|%p|%p|POSSESSIVE_REPEAT %d %d\n", pattern, |
1307 | 0 | ptr, pattern[1], pattern[2])); |
1308 | | |
1309 | | /* Set the global Input pointer to this context's Input |
1310 | | pointer */ |
1311 | 0 | state->ptr = ptr; |
1312 | | |
1313 | | /* Capture groups in the body can be revisited on backtracking |
1314 | | between iterations, so their marks must be saved and restored, |
1315 | | as is done inside a repeat. */ |
1316 | 0 | state->save_marks++; |
1317 | | |
1318 | | /* Initialize Count to 0 */ |
1319 | 0 | ctx->count = 0; |
1320 | | |
1321 | | /* Check for minimum required matches. */ |
1322 | 0 | while (ctx->count < (Py_ssize_t)pattern[1]) { |
1323 | | /* not enough matches */ |
1324 | 0 | DO_JUMP0(JUMP_POSS_REPEAT_1, jump_poss_repeat_1, |
1325 | 0 | &pattern[3]); |
1326 | 0 | if (ret) { |
1327 | 0 | RETURN_ON_ERROR(ret); |
1328 | 0 | ctx->count++; |
1329 | 0 | } |
1330 | 0 | else { |
1331 | 0 | state->ptr = ptr; |
1332 | 0 | state->save_marks--; |
1333 | 0 | RETURN_FAILURE; |
1334 | 0 | } |
1335 | 0 | } |
1336 | | |
1337 | | /* Clear the context's Input stream pointer so that it |
1338 | | doesn't match the global state so that the while loop can |
1339 | | be entered. */ |
1340 | 0 | ptr = NULL; |
1341 | | |
1342 | | /* Keep trying to parse the <pattern> sub-pattern until the |
1343 | | end is reached, creating a new context each time. */ |
1344 | 0 | while ((ctx->count < (Py_ssize_t)pattern[2] || |
1345 | 0 | (Py_ssize_t)pattern[2] == SRE_MAXREPEAT) && |
1346 | 0 | state->ptr != ptr) { |
1347 | | /* Save the Capture Group Marker state into the current |
1348 | | Context and back up the current highest number |
1349 | | Capture Group marker. */ |
1350 | 0 | LASTMARK_SAVE(); |
1351 | 0 | MARK_PUSH(ctx->lastmark); |
1352 | | |
1353 | | /* zero-width match protection */ |
1354 | | /* Set the context's Input Stream pointer to be the |
1355 | | current Input Stream pointer from the global |
1356 | | state. When the loop reaches the next iteration, |
1357 | | the context will then store the last known good |
1358 | | position with the global state holding the Input |
1359 | | Input Stream position that has been updated with |
1360 | | the most recent match. Thus, if state's Input |
1361 | | stream remains the same as the one stored in the |
1362 | | current Context, we know we have successfully |
1363 | | matched an empty string and that all subsequent |
1364 | | matches will also be the empty string until the |
1365 | | maximum number of matches are counted, and because |
1366 | | of this, we could immediately stop at that point and |
1367 | | consider this match successful. */ |
1368 | 0 | ptr = state->ptr; |
1369 | | |
1370 | | /* We have not reached the maximin matches, so try to |
1371 | | match once more. */ |
1372 | 0 | DO_JUMP0(JUMP_POSS_REPEAT_2, jump_poss_repeat_2, |
1373 | 0 | &pattern[3]); |
1374 | | |
1375 | | /* Check to see if the last attempted match |
1376 | | succeeded. */ |
1377 | 0 | if (ret) { |
1378 | | /* Drop the saved highest number Capture Group |
1379 | | marker saved above and use the newly updated |
1380 | | value. */ |
1381 | 0 | MARK_POP_DISCARD(ctx->lastmark); |
1382 | 0 | RETURN_ON_ERROR(ret); |
1383 | | |
1384 | | /* Success, increment the count. */ |
1385 | 0 | ctx->count++; |
1386 | 0 | } |
1387 | | /* Last attempted match failed. */ |
1388 | 0 | else { |
1389 | | /* Restore the previously saved highest number |
1390 | | Capture Group marker since the last iteration |
1391 | | did not match, then restore that to the global |
1392 | | state. */ |
1393 | 0 | MARK_POP(ctx->lastmark); |
1394 | 0 | LASTMARK_RESTORE(); |
1395 | | |
1396 | | /* Restore the global Input Stream pointer |
1397 | | since it can change after jumps. */ |
1398 | 0 | state->ptr = ptr; |
1399 | | |
1400 | | /* We have sufficient matches, so exit loop. */ |
1401 | 0 | break; |
1402 | 0 | } |
1403 | 0 | } |
1404 | | |
1405 | 0 | state->save_marks--; |
1406 | | |
1407 | | /* Evaluate Tail */ |
1408 | | /* Jump to end of pattern indicated by skip, and then skip |
1409 | | the SUCCESS op code that follows it. */ |
1410 | 0 | pattern += pattern[0] + 1; |
1411 | 0 | ptr = state->ptr; |
1412 | 0 | DISPATCH; |
1413 | | |
1414 | 0 | TARGET(SRE_OP_ATOMIC_GROUP): |
1415 | | /* Atomic Group Sub Pattern */ |
1416 | | /* <ATOMIC_GROUP> <skip> pattern <SUCCESS> tail */ |
1417 | 0 | TRACE(("|%p|%p|ATOMIC_GROUP\n", pattern, ptr)); |
1418 | | |
1419 | | /* Set the global Input pointer to this context's Input |
1420 | | pointer */ |
1421 | 0 | state->ptr = ptr; |
1422 | | |
1423 | | /* Evaluate the Atomic Group in a new context, terminating |
1424 | | when the end of the group, represented by a SUCCESS op |
1425 | | code, is reached. */ |
1426 | | /* Group Pattern begins at an offset of 1 code. */ |
1427 | 0 | DO_JUMP0(JUMP_ATOMIC_GROUP, jump_atomic_group, |
1428 | 0 | &pattern[1]); |
1429 | | |
1430 | | /* Test Exit Condition */ |
1431 | 0 | RETURN_ON_ERROR(ret); |
1432 | | |
1433 | 0 | if (ret == 0) { |
1434 | | /* Atomic Group failed to Match. */ |
1435 | 0 | state->ptr = ptr; |
1436 | 0 | RETURN_FAILURE; |
1437 | 0 | } |
1438 | | |
1439 | | /* Evaluate Tail */ |
1440 | | /* Jump to end of pattern indicated by skip, and then skip |
1441 | | the SUCCESS op code that follows it. */ |
1442 | 0 | pattern += pattern[0]; |
1443 | 0 | ptr = state->ptr; |
1444 | 0 | DISPATCH; |
1445 | | |
1446 | 0 | TARGET(SRE_OP_GROUPREF): |
1447 | | /* match backreference */ |
1448 | 0 | TRACE(("|%p|%p|GROUPREF %d\n", pattern, |
1449 | 0 | ptr, pattern[0])); |
1450 | 0 | { |
1451 | 0 | int groupref = pattern[0] * 2; |
1452 | 0 | if (groupref >= state->lastmark) { |
1453 | 0 | RETURN_FAILURE; |
1454 | 0 | } else { |
1455 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; |
1456 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; |
1457 | 0 | if (!p || !e || e < p) |
1458 | 0 | RETURN_FAILURE; |
1459 | 0 | while (p < e) { |
1460 | 0 | if (ptr >= end || *ptr != *p) |
1461 | 0 | RETURN_FAILURE; |
1462 | 0 | p++; |
1463 | 0 | ptr++; |
1464 | 0 | } |
1465 | 0 | } |
1466 | 0 | } |
1467 | 0 | pattern++; |
1468 | 0 | DISPATCH; |
1469 | | |
1470 | 0 | TARGET(SRE_OP_GROUPREF_IGNORE): |
1471 | | /* match backreference */ |
1472 | 0 | TRACE(("|%p|%p|GROUPREF_IGNORE %d\n", pattern, |
1473 | 0 | ptr, pattern[0])); |
1474 | 0 | { |
1475 | 0 | int groupref = pattern[0] * 2; |
1476 | 0 | if (groupref >= state->lastmark) { |
1477 | 0 | RETURN_FAILURE; |
1478 | 0 | } else { |
1479 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; |
1480 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; |
1481 | 0 | if (!p || !e || e < p) |
1482 | 0 | RETURN_FAILURE; |
1483 | 0 | while (p < e) { |
1484 | 0 | if (ptr >= end || |
1485 | 0 | sre_lower_ascii(*ptr) != sre_lower_ascii(*p)) |
1486 | 0 | RETURN_FAILURE; |
1487 | 0 | p++; |
1488 | 0 | ptr++; |
1489 | 0 | } |
1490 | 0 | } |
1491 | 0 | } |
1492 | 0 | pattern++; |
1493 | 0 | DISPATCH; |
1494 | | |
1495 | 0 | TARGET(SRE_OP_GROUPREF_UNI_IGNORE): |
1496 | | /* match backreference */ |
1497 | 0 | TRACE(("|%p|%p|GROUPREF_UNI_IGNORE %d\n", pattern, |
1498 | 0 | ptr, pattern[0])); |
1499 | 0 | { |
1500 | 0 | int groupref = pattern[0] * 2; |
1501 | 0 | if (groupref >= state->lastmark) { |
1502 | 0 | RETURN_FAILURE; |
1503 | 0 | } else { |
1504 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; |
1505 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; |
1506 | 0 | if (!p || !e || e < p) |
1507 | 0 | RETURN_FAILURE; |
1508 | 0 | while (p < e) { |
1509 | 0 | if (ptr >= end || |
1510 | 0 | sre_lower_unicode(*ptr) != sre_lower_unicode(*p)) |
1511 | 0 | RETURN_FAILURE; |
1512 | 0 | p++; |
1513 | 0 | ptr++; |
1514 | 0 | } |
1515 | 0 | } |
1516 | 0 | } |
1517 | 0 | pattern++; |
1518 | 0 | DISPATCH; |
1519 | | |
1520 | 0 | TARGET(SRE_OP_GROUPREF_LOC_IGNORE): |
1521 | | /* match backreference */ |
1522 | 0 | TRACE(("|%p|%p|GROUPREF_LOC_IGNORE %d\n", pattern, |
1523 | 0 | ptr, pattern[0])); |
1524 | 0 | { |
1525 | 0 | int groupref = pattern[0] * 2; |
1526 | 0 | if (groupref >= state->lastmark) { |
1527 | 0 | RETURN_FAILURE; |
1528 | 0 | } else { |
1529 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; |
1530 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; |
1531 | 0 | if (!p || !e || e < p) |
1532 | 0 | RETURN_FAILURE; |
1533 | 0 | while (p < e) { |
1534 | 0 | if (ptr >= end || |
1535 | 0 | sre_lower_locale(*ptr) != sre_lower_locale(*p)) |
1536 | 0 | RETURN_FAILURE; |
1537 | 0 | p++; |
1538 | 0 | ptr++; |
1539 | 0 | } |
1540 | 0 | } |
1541 | 0 | } |
1542 | 0 | pattern++; |
1543 | 0 | DISPATCH; |
1544 | | |
1545 | 0 | TARGET(SRE_OP_GROUPREF_EXISTS): |
1546 | 0 | TRACE(("|%p|%p|GROUPREF_EXISTS %d\n", pattern, |
1547 | 0 | ptr, pattern[0])); |
1548 | | /* <GROUPREF_EXISTS> <group> <skip> codeyes <JUMP> codeno ... */ |
1549 | 0 | { |
1550 | 0 | int groupref = pattern[0] * 2; |
1551 | 0 | if (groupref >= state->lastmark) { |
1552 | 0 | pattern += pattern[1]; |
1553 | 0 | DISPATCH; |
1554 | 0 | } else { |
1555 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; |
1556 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; |
1557 | 0 | if (!p || !e || e < p) { |
1558 | 0 | pattern += pattern[1]; |
1559 | 0 | DISPATCH; |
1560 | 0 | } |
1561 | 0 | } |
1562 | 0 | } |
1563 | 0 | pattern += 2; |
1564 | 0 | DISPATCH; |
1565 | | |
1566 | 26.0M | TARGET(SRE_OP_ASSERT): |
1567 | | /* assert subpattern */ |
1568 | | /* <ASSERT> <skip> <back> <pattern> */ |
1569 | 26.0M | TRACE(("|%p|%p|ASSERT %d\n", pattern, |
1570 | 26.0M | ptr, pattern[1])); |
1571 | 26.0M | if ((uintptr_t)(ptr - (SRE_CHAR *)state->beginning) < pattern[1]) |
1572 | 0 | RETURN_FAILURE; |
1573 | 26.0M | state->ptr = ptr - pattern[1]; |
1574 | 26.0M | DO_JUMP0(JUMP_ASSERT, jump_assert, pattern+2); |
1575 | 26.0M | RETURN_ON_FAILURE(ret); |
1576 | 21.2M | pattern += pattern[0]; |
1577 | 21.2M | DISPATCH; |
1578 | | |
1579 | 29.2M | TARGET(SRE_OP_ASSERT_NOT): |
1580 | | /* assert not subpattern */ |
1581 | | /* <ASSERT_NOT> <skip> <back> <pattern> */ |
1582 | 29.2M | TRACE(("|%p|%p|ASSERT_NOT %d\n", pattern, |
1583 | 29.2M | ptr, pattern[1])); |
1584 | 29.2M | if ((uintptr_t)(ptr - (SRE_CHAR *)state->beginning) >= pattern[1]) { |
1585 | 29.2M | state->ptr = ptr - pattern[1]; |
1586 | 29.2M | LASTMARK_SAVE(); |
1587 | 29.2M | if (state->save_marks) |
1588 | 29.2M | MARK_PUSH(ctx->lastmark); |
1589 | | |
1590 | 58.4M | DO_JUMP0(JUMP_ASSERT_NOT, jump_assert_not, pattern+2); |
1591 | 58.4M | if (ret) { |
1592 | 10.9k | if (state->save_marks) |
1593 | 10.9k | MARK_POP_DISCARD(ctx->lastmark); |
1594 | 10.9k | RETURN_ON_ERROR(ret); |
1595 | 10.9k | RETURN_FAILURE; |
1596 | 10.9k | } |
1597 | 29.2M | if (state->save_marks) |
1598 | 29.2M | MARK_POP(ctx->lastmark); |
1599 | 29.2M | LASTMARK_RESTORE(); |
1600 | 29.2M | } |
1601 | 29.2M | pattern += pattern[0]; |
1602 | 29.2M | DISPATCH; |
1603 | | |
1604 | 29.2M | TARGET(SRE_OP_FAILURE): |
1605 | | /* immediate failure */ |
1606 | 0 | TRACE(("|%p|%p|FAILURE\n", pattern, ptr)); |
1607 | 0 | RETURN_FAILURE; |
1608 | | |
1609 | | #if !USE_COMPUTED_GOTOS |
1610 | | default: |
1611 | | #endif |
1612 | | // Also any unused opcodes: |
1613 | 0 | TARGET(SRE_OP_RANGE_UNI_IGNORE): |
1614 | 0 | TARGET(SRE_OP_SUBPATTERN): |
1615 | 0 | TARGET(SRE_OP_RANGE): |
1616 | 0 | TARGET(SRE_OP_NEGATE): |
1617 | 0 | TARGET(SRE_OP_BIGCHARSET): |
1618 | 0 | TARGET(SRE_OP_CHARSET): |
1619 | 0 | TRACE(("|%p|%p|UNKNOWN %d\n", pattern, ptr, |
1620 | 0 | pattern[-1])); |
1621 | 0 | RETURN_ERROR(SRE_ERROR_ILLEGAL); |
1622 | |
|
1623 | 0 | } |
1624 | | |
1625 | 855M | exit: |
1626 | 855M | ctx_pos = ctx->last_ctx_pos; |
1627 | 855M | jump = ctx->jump; |
1628 | 855M | DATA_POP_DISCARD(ctx); |
1629 | 855M | if (ctx_pos == -1) { |
1630 | 425M | state->sigcount = sigcount; |
1631 | 425M | return ret; |
1632 | 425M | } |
1633 | 430M | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); |
1634 | | |
1635 | 430M | switch (jump) { |
1636 | 89.3M | case JUMP_MAX_UNTIL_2: |
1637 | 89.3M | TRACE(("|%p|%p|JUMP_MAX_UNTIL_2\n", pattern, ptr)); |
1638 | 89.3M | goto jump_max_until_2; |
1639 | 35.1M | case JUMP_MAX_UNTIL_3: |
1640 | 35.1M | TRACE(("|%p|%p|JUMP_MAX_UNTIL_3\n", pattern, ptr)); |
1641 | 35.1M | goto jump_max_until_3; |
1642 | 0 | case JUMP_MIN_UNTIL_2: |
1643 | 0 | TRACE(("|%p|%p|JUMP_MIN_UNTIL_2\n", pattern, ptr)); |
1644 | 0 | goto jump_min_until_2; |
1645 | 0 | case JUMP_MIN_UNTIL_3: |
1646 | 0 | TRACE(("|%p|%p|JUMP_MIN_UNTIL_3\n", pattern, ptr)); |
1647 | 0 | goto jump_min_until_3; |
1648 | 102M | case JUMP_BRANCH: |
1649 | 102M | TRACE(("|%p|%p|JUMP_BRANCH\n", pattern, ptr)); |
1650 | 102M | goto jump_branch; |
1651 | 0 | case JUMP_MAX_UNTIL_1: |
1652 | 0 | TRACE(("|%p|%p|JUMP_MAX_UNTIL_1\n", pattern, ptr)); |
1653 | 0 | goto jump_max_until_1; |
1654 | 0 | case JUMP_MIN_UNTIL_1: |
1655 | 0 | TRACE(("|%p|%p|JUMP_MIN_UNTIL_1\n", pattern, ptr)); |
1656 | 0 | goto jump_min_until_1; |
1657 | 0 | case JUMP_POSS_REPEAT_1: |
1658 | 0 | TRACE(("|%p|%p|JUMP_POSS_REPEAT_1\n", pattern, ptr)); |
1659 | 0 | goto jump_poss_repeat_1; |
1660 | 0 | case JUMP_POSS_REPEAT_2: |
1661 | 0 | TRACE(("|%p|%p|JUMP_POSS_REPEAT_2\n", pattern, ptr)); |
1662 | 0 | goto jump_poss_repeat_2; |
1663 | 34.8M | case JUMP_REPEAT: |
1664 | 34.8M | TRACE(("|%p|%p|JUMP_REPEAT\n", pattern, ptr)); |
1665 | 34.8M | goto jump_repeat; |
1666 | 14.8M | case JUMP_REPEAT_ONE_1: |
1667 | 14.8M | TRACE(("|%p|%p|JUMP_REPEAT_ONE_1\n", pattern, ptr)); |
1668 | 14.8M | goto jump_repeat_one_1; |
1669 | 98.7M | case JUMP_REPEAT_ONE_2: |
1670 | 98.7M | TRACE(("|%p|%p|JUMP_REPEAT_ONE_2\n", pattern, ptr)); |
1671 | 98.7M | goto jump_repeat_one_2; |
1672 | 872 | case JUMP_MIN_REPEAT_ONE: |
1673 | 872 | TRACE(("|%p|%p|JUMP_MIN_REPEAT_ONE\n", pattern, ptr)); |
1674 | 872 | goto jump_min_repeat_one; |
1675 | 0 | case JUMP_ATOMIC_GROUP: |
1676 | 0 | TRACE(("|%p|%p|JUMP_ATOMIC_GROUP\n", pattern, ptr)); |
1677 | 0 | goto jump_atomic_group; |
1678 | 26.0M | case JUMP_ASSERT: |
1679 | 26.0M | TRACE(("|%p|%p|JUMP_ASSERT\n", pattern, ptr)); |
1680 | 26.0M | goto jump_assert; |
1681 | 29.2M | case JUMP_ASSERT_NOT: |
1682 | 29.2M | TRACE(("|%p|%p|JUMP_ASSERT_NOT\n", pattern, ptr)); |
1683 | 29.2M | goto jump_assert_not; |
1684 | 0 | case JUMP_NONE: |
1685 | 0 | TRACE(("|%p|%p|RETURN %zd\n", pattern, |
1686 | 0 | ptr, ret)); |
1687 | 0 | break; |
1688 | 430M | } |
1689 | | |
1690 | 0 | return ret; /* should never get here */ |
1691 | 430M | } Line | Count | Source | 608 | 133M | { | 609 | 133M | const SRE_CHAR* end = (const SRE_CHAR *)state->end; | 610 | 133M | Py_ssize_t alloc_pos, ctx_pos = -1; | 611 | 133M | Py_ssize_t ret = 0; | 612 | 133M | int jump; | 613 | 133M | unsigned int sigcount = state->sigcount; | 614 | | | 615 | 133M | SRE(match_context)* ctx; | 616 | 133M | SRE(match_context)* nextctx; | 617 | 133M | INIT_TRACE(state); | 618 | | | 619 | 133M | TRACE(("|%p|%p|ENTER\n", pattern, state->ptr)); | 620 | | | 621 | 133M | DATA_ALLOC(SRE(match_context), ctx); | 622 | 133M | ctx->last_ctx_pos = -1; | 623 | 133M | ctx->jump = JUMP_NONE; | 624 | 133M | ctx->toplevel = toplevel; | 625 | 133M | ctx_pos = alloc_pos; | 626 | | | 627 | 133M | #if USE_COMPUTED_GOTOS | 628 | 133M | #include "sre_targets.h" | 629 | 133M | #endif | 630 | | | 631 | 269M | entrance: | 632 | | | 633 | 269M | ; // Fashion statement. | 634 | 269M | const SRE_CHAR *ptr = (SRE_CHAR *)state->ptr; | 635 | | | 636 | 269M | if (pattern[0] == SRE_OP_INFO) { | 637 | | /* optimization info block */ | 638 | | /* <INFO> <1=skip> <2=flags> <3=min> ... */ | 639 | 30.3M | if (pattern[3] && (uintptr_t)(end - ptr) < pattern[3]) { | 640 | 2.02M | TRACE(("reject (got %tu chars, need %zu)\n", | 641 | 2.02M | end - ptr, (size_t) pattern[3])); | 642 | 2.02M | RETURN_FAILURE; | 643 | 2.02M | } | 644 | 28.3M | pattern += pattern[1] + 1; | 645 | 28.3M | } | 646 | | | 647 | 267M | #if USE_COMPUTED_GOTOS | 648 | 267M | DISPATCH; | 649 | | #else | 650 | | dispatch: | 651 | | MAYBE_CHECK_SIGNALS; | 652 | | switch (*pattern++) | 653 | | #endif | 654 | 267M | { | 655 | | | 656 | 267M | TARGET(SRE_OP_MARK): | 657 | | /* set mark */ | 658 | | /* <MARK> <gid> */ | 659 | 95.9M | TRACE(("|%p|%p|MARK %d\n", pattern, | 660 | 95.9M | ptr, pattern[0])); | 661 | 95.9M | { | 662 | 95.9M | int i = pattern[0]; | 663 | 95.9M | if (i & 1) | 664 | 19.0M | state->lastindex = i/2 + 1; | 665 | 95.9M | if (i > state->lastmark) { | 666 | | /* state->lastmark is the highest valid index in the | 667 | | state->mark array. If it is increased by more than 1, | 668 | | the intervening marks must be set to NULL to signal | 669 | | that these marks have not been encountered. */ | 670 | 93.0M | int j = state->lastmark + 1; | 671 | 96.3M | while (j < i) | 672 | 3.26M | state->mark[j++] = NULL; | 673 | 93.0M | state->lastmark = i; | 674 | 93.0M | } | 675 | 95.9M | state->mark[i] = ptr; | 676 | 95.9M | } | 677 | 95.9M | pattern++; | 678 | 95.9M | DISPATCH; | 679 | | | 680 | 95.9M | TARGET(SRE_OP_LITERAL): | 681 | | /* match literal string */ | 682 | | /* <LITERAL> <code> */ | 683 | 71.0M | TRACE(("|%p|%p|LITERAL %d\n", pattern, | 684 | 71.0M | ptr, *pattern)); | 685 | 71.0M | if (ptr >= end || (SRE_CODE) ptr[0] != pattern[0]) | 686 | 22.8M | RETURN_FAILURE; | 687 | 48.1M | pattern++; | 688 | 48.1M | ptr++; | 689 | 48.1M | DISPATCH; | 690 | | | 691 | 48.1M | TARGET(SRE_OP_NOT_LITERAL): | 692 | | /* match anything that is not literal character */ | 693 | | /* <NOT_LITERAL> <code> */ | 694 | 0 | TRACE(("|%p|%p|NOT_LITERAL %d\n", pattern, | 695 | 0 | ptr, *pattern)); | 696 | 0 | if (ptr >= end || (SRE_CODE) ptr[0] == pattern[0]) | 697 | 0 | RETURN_FAILURE; | 698 | 0 | pattern++; | 699 | 0 | ptr++; | 700 | 0 | DISPATCH; | 701 | | | 702 | 68.0M | TARGET(SRE_OP_SUCCESS): | 703 | | /* end of pattern */ | 704 | 68.0M | TRACE(("|%p|%p|SUCCESS\n", pattern, ptr)); | 705 | 68.0M | if (ctx->toplevel && | 706 | 21.6M | ((state->match_all && ptr != state->end) || | 707 | 21.6M | (state->must_advance && ptr == state->start))) | 708 | 0 | { | 709 | 0 | RETURN_FAILURE; | 710 | 0 | } | 711 | 68.0M | state->ptr = ptr; | 712 | 68.0M | RETURN_SUCCESS; | 713 | | | 714 | 12.3M | TARGET(SRE_OP_AT): | 715 | | /* match at given position */ | 716 | | /* <AT> <code> */ | 717 | 12.3M | TRACE(("|%p|%p|AT %d\n", pattern, ptr, *pattern)); | 718 | 12.3M | if (!SRE(at)(state, ptr, *pattern)) | 719 | 3.24M | RETURN_FAILURE; | 720 | 9.07M | pattern++; | 721 | 9.07M | DISPATCH; | 722 | | | 723 | 9.07M | TARGET(SRE_OP_CATEGORY): | 724 | | /* match at given category */ | 725 | | /* <CATEGORY> <code> */ | 726 | 1.74k | TRACE(("|%p|%p|CATEGORY %d\n", pattern, | 727 | 1.74k | ptr, *pattern)); | 728 | 1.74k | if (ptr >= end || !sre_category(pattern[0], ptr[0])) | 729 | 12 | RETURN_FAILURE; | 730 | 1.73k | pattern++; | 731 | 1.73k | ptr++; | 732 | 1.73k | DISPATCH; | 733 | | | 734 | 1.73k | TARGET(SRE_OP_ANY): | 735 | | /* match anything (except a newline) */ | 736 | | /* <ANY> */ | 737 | 0 | TRACE(("|%p|%p|ANY\n", pattern, ptr)); | 738 | 0 | if (ptr >= end || SRE_IS_LINEBREAK(ptr[0])) | 739 | 0 | RETURN_FAILURE; | 740 | 0 | ptr++; | 741 | 0 | DISPATCH; | 742 | | | 743 | 0 | TARGET(SRE_OP_ANY_ALL): | 744 | | /* match anything */ | 745 | | /* <ANY_ALL> */ | 746 | 0 | TRACE(("|%p|%p|ANY_ALL\n", pattern, ptr)); | 747 | 0 | if (ptr >= end) | 748 | 0 | RETURN_FAILURE; | 749 | 0 | ptr++; | 750 | 0 | DISPATCH; | 751 | | | 752 | 56.5M | TARGET(SRE_OP_IN): | 753 | | /* match set member (or non_member) */ | 754 | | /* <IN> <skip> <set> */ | 755 | 56.5M | TRACE(("|%p|%p|IN\n", pattern, ptr)); | 756 | 56.5M | if (ptr >= end || | 757 | 56.5M | !SRE(charset)(state, pattern + 1, *ptr)) | 758 | 3.78M | RETURN_FAILURE; | 759 | 52.7M | pattern += pattern[0]; | 760 | 52.7M | ptr++; | 761 | 52.7M | DISPATCH; | 762 | | | 763 | 52.7M | TARGET(SRE_OP_LITERAL_IGNORE): | 764 | 659k | TRACE(("|%p|%p|LITERAL_IGNORE %d\n", | 765 | 659k | pattern, ptr, pattern[0])); | 766 | 659k | if (ptr >= end || | 767 | 659k | sre_lower_ascii(*ptr) != *pattern) | 768 | 3.73k | RETURN_FAILURE; | 769 | 656k | pattern++; | 770 | 656k | ptr++; | 771 | 656k | DISPATCH; | 772 | | | 773 | 656k | TARGET(SRE_OP_LITERAL_UNI_IGNORE): | 774 | 28 | TRACE(("|%p|%p|LITERAL_UNI_IGNORE %d\n", | 775 | 28 | pattern, ptr, pattern[0])); | 776 | 28 | if (ptr >= end || | 777 | 28 | sre_lower_unicode(*ptr) != *pattern) | 778 | 0 | RETURN_FAILURE; | 779 | 28 | pattern++; | 780 | 28 | ptr++; | 781 | 28 | DISPATCH; | 782 | | | 783 | 28 | TARGET(SRE_OP_LITERAL_LOC_IGNORE): | 784 | 0 | TRACE(("|%p|%p|LITERAL_LOC_IGNORE %d\n", | 785 | 0 | pattern, ptr, pattern[0])); | 786 | 0 | if (ptr >= end | 787 | 0 | || !char_loc_ignore(*pattern, *ptr)) | 788 | 0 | RETURN_FAILURE; | 789 | 0 | pattern++; | 790 | 0 | ptr++; | 791 | 0 | DISPATCH; | 792 | | | 793 | 0 | TARGET(SRE_OP_NOT_LITERAL_IGNORE): | 794 | 0 | TRACE(("|%p|%p|NOT_LITERAL_IGNORE %d\n", | 795 | 0 | pattern, ptr, *pattern)); | 796 | 0 | if (ptr >= end || | 797 | 0 | sre_lower_ascii(*ptr) == *pattern) | 798 | 0 | RETURN_FAILURE; | 799 | 0 | pattern++; | 800 | 0 | ptr++; | 801 | 0 | DISPATCH; | 802 | | | 803 | 0 | TARGET(SRE_OP_NOT_LITERAL_UNI_IGNORE): | 804 | 0 | TRACE(("|%p|%p|NOT_LITERAL_UNI_IGNORE %d\n", | 805 | 0 | pattern, ptr, *pattern)); | 806 | 0 | if (ptr >= end || | 807 | 0 | sre_lower_unicode(*ptr) == *pattern) | 808 | 0 | RETURN_FAILURE; | 809 | 0 | pattern++; | 810 | 0 | ptr++; | 811 | 0 | DISPATCH; | 812 | | | 813 | 0 | TARGET(SRE_OP_NOT_LITERAL_LOC_IGNORE): | 814 | 0 | TRACE(("|%p|%p|NOT_LITERAL_LOC_IGNORE %d\n", | 815 | 0 | pattern, ptr, *pattern)); | 816 | 0 | if (ptr >= end | 817 | 0 | || char_loc_ignore(*pattern, *ptr)) | 818 | 0 | RETURN_FAILURE; | 819 | 0 | pattern++; | 820 | 0 | ptr++; | 821 | 0 | DISPATCH; | 822 | | | 823 | 0 | TARGET(SRE_OP_IN_IGNORE): | 824 | 0 | TRACE(("|%p|%p|IN_IGNORE\n", pattern, ptr)); | 825 | 0 | if (ptr >= end | 826 | 0 | || !SRE(charset)(state, pattern+1, | 827 | 0 | (SRE_CODE)sre_lower_ascii(*ptr))) | 828 | 0 | RETURN_FAILURE; | 829 | 0 | pattern += pattern[0]; | 830 | 0 | ptr++; | 831 | 0 | DISPATCH; | 832 | | | 833 | 24 | TARGET(SRE_OP_IN_UNI_IGNORE): | 834 | 24 | TRACE(("|%p|%p|IN_UNI_IGNORE\n", pattern, ptr)); | 835 | 24 | if (ptr >= end | 836 | 16 | || !SRE(charset)(state, pattern+1, | 837 | 16 | (SRE_CODE)sre_lower_unicode(*ptr))) | 838 | 16 | RETURN_FAILURE; | 839 | 8 | pattern += pattern[0]; | 840 | 8 | ptr++; | 841 | 8 | DISPATCH; | 842 | | | 843 | 8 | TARGET(SRE_OP_IN_LOC_IGNORE): | 844 | 0 | TRACE(("|%p|%p|IN_LOC_IGNORE\n", pattern, ptr)); | 845 | 0 | if (ptr >= end | 846 | 0 | || !SRE(charset_loc_ignore)(state, pattern+1, *ptr)) | 847 | 0 | RETURN_FAILURE; | 848 | 0 | pattern += pattern[0]; | 849 | 0 | ptr++; | 850 | 0 | DISPATCH; | 851 | | | 852 | 34.3M | TARGET(SRE_OP_JUMP): | 853 | 34.3M | TARGET(SRE_OP_INFO): | 854 | | /* jump forward */ | 855 | | /* <JUMP> <offset> */ | 856 | 34.3M | TRACE(("|%p|%p|JUMP %d\n", pattern, | 857 | 34.3M | ptr, pattern[0])); | 858 | 34.3M | pattern += pattern[0]; | 859 | 34.3M | DISPATCH; | 860 | | | 861 | 42.2M | TARGET(SRE_OP_BRANCH): | 862 | | /* alternation */ | 863 | | /* <BRANCH> <0=skip> code <JUMP> ... <NULL> */ | 864 | 42.2M | TRACE(("|%p|%p|BRANCH\n", pattern, ptr)); | 865 | 42.2M | LASTMARK_SAVE(); | 866 | 42.2M | if (state->save_marks) | 867 | 14.6M | MARK_PUSH(ctx->lastmark); | 868 | 101M | for (; pattern[0]; pattern += pattern[0]) { | 869 | 91.2M | if (pattern[1] == SRE_OP_LITERAL && | 870 | 67.7M | (ptr >= end || | 871 | 67.4M | (SRE_CODE) *ptr != pattern[2])) | 872 | 28.7M | continue; | 873 | 62.5M | if (pattern[1] == SRE_OP_IN && | 874 | 13.2M | (ptr >= end || | 875 | 13.0M | !SRE(charset)(state, pattern + 3, | 876 | 13.0M | (SRE_CODE) *ptr))) | 877 | 6.78M | continue; | 878 | 55.7M | state->ptr = ptr; | 879 | 55.7M | DO_JUMP(JUMP_BRANCH, jump_branch, pattern+1); | 880 | 55.7M | if (ret) { | 881 | 32.4M | if (state->save_marks) | 882 | 14.1M | MARK_POP_DISCARD(ctx->lastmark); | 883 | 32.4M | RETURN_ON_ERROR(ret); | 884 | 32.4M | RETURN_SUCCESS; | 885 | 32.4M | } | 886 | 23.2M | if (state->save_marks) | 887 | 5.76k | MARK_POP_KEEP(ctx->lastmark); | 888 | 23.2M | LASTMARK_RESTORE(); | 889 | 23.2M | } | 890 | 9.80M | if (state->save_marks) | 891 | 486k | MARK_POP_DISCARD(ctx->lastmark); | 892 | 9.80M | RETURN_FAILURE; | 893 | | | 894 | 93.3M | TARGET(SRE_OP_REPEAT_ONE): | 895 | | /* match repeated sequence (maximizing regexp) */ | 896 | | | 897 | | /* this operator only works if the repeated item is | 898 | | exactly one character wide, and we're not already | 899 | | collecting backtracking points. for other cases, | 900 | | use the MAX_REPEAT operator */ | 901 | | | 902 | | /* <REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> tail */ | 903 | | | 904 | 93.3M | TRACE(("|%p|%p|REPEAT_ONE %d %d\n", pattern, ptr, | 905 | 93.3M | pattern[1], pattern[2])); | 906 | | | 907 | 93.3M | if ((Py_ssize_t) pattern[1] > end - ptr) | 908 | 710k | RETURN_FAILURE; /* cannot match */ | 909 | | | 910 | 92.6M | state->ptr = ptr; | 911 | | | 912 | 92.6M | ret = SRE(count)(state, pattern+3, pattern[2]); | 913 | 92.6M | RETURN_ON_ERROR(ret); | 914 | 92.6M | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); | 915 | 92.6M | ctx->count = ret; | 916 | 92.6M | ptr += ctx->count; | 917 | | | 918 | | /* when we arrive here, count contains the number of | 919 | | matches, and ptr points to the tail of the target | 920 | | string. check if the rest of the pattern matches, | 921 | | and backtrack if not. */ | 922 | | | 923 | 92.6M | if (ctx->count < (Py_ssize_t) pattern[1]) | 924 | 59.2M | RETURN_FAILURE; | 925 | | | 926 | 33.4M | if (pattern[pattern[0]] == SRE_OP_SUCCESS && | 927 | 685k | ptr == state->end && | 928 | 61.4k | !(ctx->toplevel && state->must_advance && ptr == state->start)) | 929 | 61.4k | { | 930 | | /* tail is empty. we're finished */ | 931 | 61.4k | state->ptr = ptr; | 932 | 61.4k | RETURN_SUCCESS; | 933 | 61.4k | } | 934 | | | 935 | 33.3M | LASTMARK_SAVE(); | 936 | 33.3M | if (state->save_marks) | 937 | 19.8M | MARK_PUSH(ctx->lastmark); | 938 | | | 939 | 33.3M | if (pattern[pattern[0]] == SRE_OP_LITERAL) { | 940 | | /* tail starts with a literal. skip positions where | 941 | | the rest of the pattern cannot possibly match */ | 942 | 6.57M | ctx->u.chr = pattern[pattern[0]+1]; | 943 | 6.57M | for (;;) { | 944 | 16.6M | while (ctx->count >= (Py_ssize_t) pattern[1] && | 945 | 15.0M | (ptr >= end || *ptr != ctx->u.chr)) { | 946 | 10.0M | ptr--; | 947 | 10.0M | ctx->count--; | 948 | 10.0M | } | 949 | 6.57M | if (ctx->count < (Py_ssize_t) pattern[1]) | 950 | 1.60M | break; | 951 | 4.96M | state->ptr = ptr; | 952 | 4.96M | DO_JUMP(JUMP_REPEAT_ONE_1, jump_repeat_one_1, | 953 | 4.96M | pattern+pattern[0]); | 954 | 4.96M | if (ret) { | 955 | 4.96M | if (state->save_marks) | 956 | 3.01M | MARK_POP_DISCARD(ctx->lastmark); | 957 | 4.96M | RETURN_ON_ERROR(ret); | 958 | 4.96M | RETURN_SUCCESS; | 959 | 4.96M | } | 960 | 238 | if (state->save_marks) | 961 | 221 | MARK_POP_KEEP(ctx->lastmark); | 962 | 238 | LASTMARK_RESTORE(); | 963 | | | 964 | 238 | ptr--; | 965 | 238 | ctx->count--; | 966 | 238 | } | 967 | 1.60M | if (state->save_marks) | 968 | 405k | MARK_POP_DISCARD(ctx->lastmark); | 969 | 26.7M | } else { | 970 | | /* general case */ | 971 | 28.6M | while (ctx->count >= (Py_ssize_t) pattern[1]) { | 972 | 28.1M | state->ptr = ptr; | 973 | 28.1M | DO_JUMP(JUMP_REPEAT_ONE_2, jump_repeat_one_2, | 974 | 28.1M | pattern+pattern[0]); | 975 | 28.1M | if (ret) { | 976 | 26.3M | if (state->save_marks) | 977 | 16.2M | MARK_POP_DISCARD(ctx->lastmark); | 978 | 26.3M | RETURN_ON_ERROR(ret); | 979 | 26.3M | RETURN_SUCCESS; | 980 | 26.3M | } | 981 | 1.81M | if (state->save_marks) | 982 | 433k | MARK_POP_KEEP(ctx->lastmark); | 983 | 1.81M | LASTMARK_RESTORE(); | 984 | | | 985 | 1.81M | ptr--; | 986 | 1.81M | ctx->count--; | 987 | 1.81M | } | 988 | 455k | if (state->save_marks) | 989 | 260k | MARK_POP_DISCARD(ctx->lastmark); | 990 | 455k | } | 991 | 2.06M | RETURN_FAILURE; | 992 | | | 993 | 17 | TARGET(SRE_OP_MIN_REPEAT_ONE): | 994 | | /* match repeated sequence (minimizing regexp) */ | 995 | | | 996 | | /* this operator only works if the repeated item is | 997 | | exactly one character wide, and we're not already | 998 | | collecting backtracking points. for other cases, | 999 | | use the MIN_REPEAT operator */ | 1000 | | | 1001 | | /* <MIN_REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> tail */ | 1002 | | | 1003 | 17 | TRACE(("|%p|%p|MIN_REPEAT_ONE %d %d\n", pattern, ptr, | 1004 | 17 | pattern[1], pattern[2])); | 1005 | | | 1006 | 17 | if ((Py_ssize_t) pattern[1] > end - ptr) | 1007 | 0 | RETURN_FAILURE; /* cannot match */ | 1008 | | | 1009 | 17 | state->ptr = ptr; | 1010 | | | 1011 | 17 | if (pattern[1] == 0) | 1012 | 17 | ctx->count = 0; | 1013 | 0 | else { | 1014 | | /* count using pattern min as the maximum */ | 1015 | 0 | ret = SRE(count)(state, pattern+3, pattern[1]); | 1016 | 0 | RETURN_ON_ERROR(ret); | 1017 | 0 | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); | 1018 | 0 | if (ret < (Py_ssize_t) pattern[1]) | 1019 | | /* didn't match minimum number of times */ | 1020 | 0 | RETURN_FAILURE; | 1021 | | /* advance past minimum matches of repeat */ | 1022 | 0 | ctx->count = ret; | 1023 | 0 | ptr += ctx->count; | 1024 | 0 | } | 1025 | | | 1026 | 17 | if (pattern[pattern[0]] == SRE_OP_SUCCESS && | 1027 | 0 | !(ctx->toplevel && | 1028 | 0 | ((state->match_all && ptr != state->end) || | 1029 | 0 | (state->must_advance && ptr == state->start)))) | 1030 | 0 | { | 1031 | | /* tail is empty. we're finished */ | 1032 | 0 | state->ptr = ptr; | 1033 | 0 | RETURN_SUCCESS; | 1034 | |
| 1035 | 17 | } else { | 1036 | | /* general case */ | 1037 | 17 | LASTMARK_SAVE(); | 1038 | 17 | if (state->save_marks) | 1039 | 0 | MARK_PUSH(ctx->lastmark); | 1040 | | | 1041 | 872 | while ((Py_ssize_t)pattern[2] == SRE_MAXREPEAT | 1042 | 872 | || ctx->count <= (Py_ssize_t)pattern[2]) { | 1043 | 872 | state->ptr = ptr; | 1044 | 872 | DO_JUMP(JUMP_MIN_REPEAT_ONE,jump_min_repeat_one, | 1045 | 872 | pattern+pattern[0]); | 1046 | 872 | if (ret) { | 1047 | 0 | if (state->save_marks) | 1048 | 0 | MARK_POP_DISCARD(ctx->lastmark); | 1049 | 0 | RETURN_ON_ERROR(ret); | 1050 | 0 | RETURN_SUCCESS; | 1051 | 0 | } | 1052 | 872 | if (state->save_marks) | 1053 | 0 | MARK_POP_KEEP(ctx->lastmark); | 1054 | 872 | LASTMARK_RESTORE(); | 1055 | | | 1056 | 872 | state->ptr = ptr; | 1057 | 872 | ret = SRE(count)(state, pattern+3, 1); | 1058 | 872 | RETURN_ON_ERROR(ret); | 1059 | 872 | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); | 1060 | 872 | if (ret == 0) | 1061 | 17 | break; | 1062 | 872 | assert(ret == 1); | 1063 | 855 | ptr++; | 1064 | 855 | ctx->count++; | 1065 | 855 | } | 1066 | 17 | if (state->save_marks) | 1067 | 0 | MARK_POP_DISCARD(ctx->lastmark); | 1068 | 17 | } | 1069 | 17 | RETURN_FAILURE; | 1070 | | | 1071 | 0 | TARGET(SRE_OP_POSSESSIVE_REPEAT_ONE): | 1072 | | /* match repeated sequence (maximizing regexp) without | 1073 | | backtracking */ | 1074 | | | 1075 | | /* this operator only works if the repeated item is | 1076 | | exactly one character wide, and we're not already | 1077 | | collecting backtracking points. for other cases, | 1078 | | use the MAX_REPEAT operator */ | 1079 | | | 1080 | | /* <POSSESSIVE_REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> | 1081 | | tail */ | 1082 | |
| 1083 | 0 | TRACE(("|%p|%p|POSSESSIVE_REPEAT_ONE %d %d\n", pattern, | 1084 | 0 | ptr, pattern[1], pattern[2])); | 1085 | |
| 1086 | 0 | if (ptr + pattern[1] > end) { | 1087 | 0 | RETURN_FAILURE; /* cannot match */ | 1088 | 0 | } | 1089 | | | 1090 | 0 | state->ptr = ptr; | 1091 | |
| 1092 | 0 | ret = SRE(count)(state, pattern + 3, pattern[2]); | 1093 | 0 | RETURN_ON_ERROR(ret); | 1094 | 0 | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); | 1095 | 0 | ctx->count = ret; | 1096 | 0 | ptr += ctx->count; | 1097 | | | 1098 | | /* when we arrive here, count contains the number of | 1099 | | matches, and ptr points to the tail of the target | 1100 | | string. check if the rest of the pattern matches, | 1101 | | and fail if not. */ | 1102 | | | 1103 | | /* Test for not enough repetitions in match */ | 1104 | 0 | if (ctx->count < (Py_ssize_t) pattern[1]) { | 1105 | 0 | RETURN_FAILURE; | 1106 | 0 | } | 1107 | | | 1108 | | /* Update the pattern to point to the next op code */ | 1109 | 0 | pattern += pattern[0]; | 1110 | | | 1111 | | /* Let the tail be evaluated separately and consider this | 1112 | | match successful. */ | 1113 | 0 | if (*pattern == SRE_OP_SUCCESS && | 1114 | 0 | ptr == state->end && | 1115 | 0 | !(ctx->toplevel && state->must_advance && ptr == state->start)) | 1116 | 0 | { | 1117 | | /* tail is empty. we're finished */ | 1118 | 0 | state->ptr = ptr; | 1119 | 0 | RETURN_SUCCESS; | 1120 | 0 | } | 1121 | | | 1122 | | /* Attempt to match the rest of the string */ | 1123 | 0 | DISPATCH; | 1124 | | | 1125 | 6.91M | TARGET(SRE_OP_REPEAT): | 1126 | | /* create repeat context. all the hard work is done | 1127 | | by the UNTIL operator (MAX_UNTIL, MIN_UNTIL) */ | 1128 | | /* <REPEAT> <skip> <1=min> <2=max> | 1129 | | <3=repeat_index> item <UNTIL> tail */ | 1130 | 6.91M | TRACE(("|%p|%p|REPEAT %d %d\n", pattern, ptr, | 1131 | 6.91M | pattern[1], pattern[2])); | 1132 | | | 1133 | | /* install new repeat context */ | 1134 | 6.91M | ctx->u.rep = repeat_pool_malloc(state); | 1135 | 6.91M | if (!ctx->u.rep) { | 1136 | 0 | RETURN_ERROR(SRE_ERROR_MEMORY); | 1137 | 0 | } | 1138 | 6.91M | ctx->u.rep->count = -1; | 1139 | 6.91M | ctx->u.rep->pattern = pattern; | 1140 | 6.91M | ctx->u.rep->prev = state->repeat; | 1141 | 6.91M | ctx->u.rep->last_ptr = NULL; | 1142 | 6.91M | state->repeat = ctx->u.rep; | 1143 | 6.91M | state->save_marks++; | 1144 | | | 1145 | 6.91M | state->ptr = ptr; | 1146 | 6.91M | DO_JUMP(JUMP_REPEAT, jump_repeat, pattern+pattern[0]); | 1147 | 6.91M | state->repeat = ctx->u.rep->prev; | 1148 | 6.91M | state->save_marks--; | 1149 | 6.91M | repeat_pool_free(state, ctx->u.rep); | 1150 | | | 1151 | 6.91M | if (ret) { | 1152 | 6.81M | RETURN_ON_ERROR(ret); | 1153 | 6.81M | RETURN_SUCCESS; | 1154 | 6.81M | } | 1155 | 91.7k | RETURN_FAILURE; | 1156 | | | 1157 | 26.6M | TARGET(SRE_OP_MAX_UNTIL): | 1158 | | /* maximizing repeat */ | 1159 | | /* <REPEAT> <skip> <1=min> <2=max> item <MAX_UNTIL> tail */ | 1160 | | | 1161 | | /* FIXME: we probably need to deal with zero-width | 1162 | | matches in here... */ | 1163 | | | 1164 | 26.6M | ctx->u.rep = state->repeat; | 1165 | 26.6M | if (!ctx->u.rep) | 1166 | 0 | RETURN_ERROR(SRE_ERROR_STATE); | 1167 | | | 1168 | 26.6M | state->ptr = ptr; | 1169 | | | 1170 | 26.6M | ctx->count = ctx->u.rep->count+1; | 1171 | | | 1172 | 26.6M | TRACE(("|%p|%p|MAX_UNTIL %zd\n", pattern, | 1173 | 26.6M | ptr, ctx->count)); | 1174 | | | 1175 | 26.6M | if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) { | 1176 | | /* not enough matches */ | 1177 | 0 | ctx->u.rep->count = ctx->count; | 1178 | 0 | DO_JUMP(JUMP_MAX_UNTIL_1, jump_max_until_1, | 1179 | 0 | ctx->u.rep->pattern+3); | 1180 | 0 | if (ret) { | 1181 | 0 | RETURN_ON_ERROR(ret); | 1182 | 0 | RETURN_SUCCESS; | 1183 | 0 | } | 1184 | 0 | ctx->u.rep->count = ctx->count-1; | 1185 | 0 | state->ptr = ptr; | 1186 | 0 | RETURN_FAILURE; | 1187 | 0 | } | 1188 | | | 1189 | 26.6M | if ((ctx->count < (Py_ssize_t) ctx->u.rep->pattern[2] || | 1190 | 5.45M | ctx->u.rep->pattern[2] == SRE_MAXREPEAT) && | 1191 | 21.1M | state->ptr != ctx->u.rep->last_ptr) { | 1192 | | /* we may have enough matches, but if we can | 1193 | | match another item, do so */ | 1194 | 21.1M | ctx->u.rep->count = ctx->count; | 1195 | 21.1M | LASTMARK_SAVE(); | 1196 | 21.1M | MARK_PUSH(ctx->lastmark); | 1197 | | /* zero-width match protection */ | 1198 | 21.1M | LAST_PTR_PUSH(); | 1199 | 21.1M | ctx->u.rep->last_ptr = state->ptr; | 1200 | 21.1M | DO_JUMP(JUMP_MAX_UNTIL_2, jump_max_until_2, | 1201 | 21.1M | ctx->u.rep->pattern+3); | 1202 | 21.1M | LAST_PTR_POP(); | 1203 | 21.1M | if (ret) { | 1204 | 19.4M | MARK_POP_DISCARD(ctx->lastmark); | 1205 | 19.4M | RETURN_ON_ERROR(ret); | 1206 | 19.4M | RETURN_SUCCESS; | 1207 | 19.4M | } | 1208 | 1.67M | MARK_POP(ctx->lastmark); | 1209 | 1.67M | LASTMARK_RESTORE(); | 1210 | 1.67M | ctx->u.rep->count = ctx->count-1; | 1211 | 1.67M | state->ptr = ptr; | 1212 | 1.67M | } | 1213 | | | 1214 | | /* cannot match more repeated items here. make sure the | 1215 | | tail matches */ | 1216 | 7.13M | state->repeat = ctx->u.rep->prev; | 1217 | 7.13M | state->save_marks--; | 1218 | 7.13M | DO_JUMP(JUMP_MAX_UNTIL_3, jump_max_until_3, pattern); | 1219 | 7.13M | state->repeat = ctx->u.rep; // restore repeat before return | 1220 | 7.13M | state->save_marks++; | 1221 | | | 1222 | 7.13M | RETURN_ON_SUCCESS(ret); | 1223 | 313k | state->ptr = ptr; | 1224 | 313k | RETURN_FAILURE; | 1225 | | | 1226 | 0 | TARGET(SRE_OP_MIN_UNTIL): | 1227 | | /* minimizing repeat */ | 1228 | | /* <REPEAT> <skip> <1=min> <2=max> item <MIN_UNTIL> tail */ | 1229 | |
| 1230 | 0 | ctx->u.rep = state->repeat; | 1231 | 0 | if (!ctx->u.rep) | 1232 | 0 | RETURN_ERROR(SRE_ERROR_STATE); | 1233 | | | 1234 | 0 | state->ptr = ptr; | 1235 | |
| 1236 | 0 | ctx->count = ctx->u.rep->count+1; | 1237 | |
| 1238 | 0 | TRACE(("|%p|%p|MIN_UNTIL %zd %p\n", pattern, | 1239 | 0 | ptr, ctx->count, ctx->u.rep->pattern)); | 1240 | |
| 1241 | 0 | if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) { | 1242 | | /* not enough matches */ | 1243 | 0 | ctx->u.rep->count = ctx->count; | 1244 | 0 | DO_JUMP(JUMP_MIN_UNTIL_1, jump_min_until_1, | 1245 | 0 | ctx->u.rep->pattern+3); | 1246 | 0 | if (ret) { | 1247 | 0 | RETURN_ON_ERROR(ret); | 1248 | 0 | RETURN_SUCCESS; | 1249 | 0 | } | 1250 | 0 | ctx->u.rep->count = ctx->count-1; | 1251 | 0 | state->ptr = ptr; | 1252 | 0 | RETURN_FAILURE; | 1253 | 0 | } | 1254 | | | 1255 | | /* see if the tail matches */ | 1256 | 0 | state->repeat = ctx->u.rep->prev; | 1257 | 0 | state->save_marks--; | 1258 | |
| 1259 | 0 | LASTMARK_SAVE(); | 1260 | 0 | if (state->save_marks) | 1261 | 0 | MARK_PUSH(ctx->lastmark); | 1262 | | | 1263 | 0 | DO_JUMP(JUMP_MIN_UNTIL_2, jump_min_until_2, pattern); | 1264 | | /* save_marks is balanced across the jump, so this equals the | 1265 | | value tested for MARK_PUSH above */ | 1266 | 0 | int pushed = state->save_marks != 0; | 1267 | 0 | state->repeat = ctx->u.rep; // restore repeat before return | 1268 | 0 | state->save_marks++; | 1269 | |
| 1270 | 0 | if (ret) { | 1271 | 0 | if (pushed) | 1272 | 0 | MARK_POP_DISCARD(ctx->lastmark); | 1273 | 0 | RETURN_ON_ERROR(ret); | 1274 | 0 | RETURN_SUCCESS; | 1275 | 0 | } | 1276 | 0 | if (pushed) | 1277 | 0 | MARK_POP(ctx->lastmark); | 1278 | 0 | LASTMARK_RESTORE(); | 1279 | |
| 1280 | 0 | state->ptr = ptr; | 1281 | |
| 1282 | 0 | if ((ctx->count >= (Py_ssize_t) ctx->u.rep->pattern[2] | 1283 | 0 | && ctx->u.rep->pattern[2] != SRE_MAXREPEAT) || | 1284 | 0 | state->ptr == ctx->u.rep->last_ptr) | 1285 | 0 | RETURN_FAILURE; | 1286 | | | 1287 | 0 | ctx->u.rep->count = ctx->count; | 1288 | | /* zero-width match protection */ | 1289 | 0 | LAST_PTR_PUSH(); | 1290 | 0 | ctx->u.rep->last_ptr = state->ptr; | 1291 | 0 | DO_JUMP(JUMP_MIN_UNTIL_3,jump_min_until_3, | 1292 | 0 | ctx->u.rep->pattern+3); | 1293 | 0 | LAST_PTR_POP(); | 1294 | 0 | if (ret) { | 1295 | 0 | RETURN_ON_ERROR(ret); | 1296 | 0 | RETURN_SUCCESS; | 1297 | 0 | } | 1298 | 0 | ctx->u.rep->count = ctx->count-1; | 1299 | 0 | state->ptr = ptr; | 1300 | 0 | RETURN_FAILURE; | 1301 | | | 1302 | 0 | TARGET(SRE_OP_POSSESSIVE_REPEAT): | 1303 | | /* create possessive repeat contexts. */ | 1304 | | /* <POSSESSIVE_REPEAT> <skip> <1=min> <2=max> pattern | 1305 | | <SUCCESS> tail */ | 1306 | 0 | TRACE(("|%p|%p|POSSESSIVE_REPEAT %d %d\n", pattern, | 1307 | 0 | ptr, pattern[1], pattern[2])); | 1308 | | | 1309 | | /* Set the global Input pointer to this context's Input | 1310 | | pointer */ | 1311 | 0 | state->ptr = ptr; | 1312 | | | 1313 | | /* Capture groups in the body can be revisited on backtracking | 1314 | | between iterations, so their marks must be saved and restored, | 1315 | | as is done inside a repeat. */ | 1316 | 0 | state->save_marks++; | 1317 | | | 1318 | | /* Initialize Count to 0 */ | 1319 | 0 | ctx->count = 0; | 1320 | | | 1321 | | /* Check for minimum required matches. */ | 1322 | 0 | while (ctx->count < (Py_ssize_t)pattern[1]) { | 1323 | | /* not enough matches */ | 1324 | 0 | DO_JUMP0(JUMP_POSS_REPEAT_1, jump_poss_repeat_1, | 1325 | 0 | &pattern[3]); | 1326 | 0 | if (ret) { | 1327 | 0 | RETURN_ON_ERROR(ret); | 1328 | 0 | ctx->count++; | 1329 | 0 | } | 1330 | 0 | else { | 1331 | 0 | state->ptr = ptr; | 1332 | 0 | state->save_marks--; | 1333 | 0 | RETURN_FAILURE; | 1334 | 0 | } | 1335 | 0 | } | 1336 | | | 1337 | | /* Clear the context's Input stream pointer so that it | 1338 | | doesn't match the global state so that the while loop can | 1339 | | be entered. */ | 1340 | 0 | ptr = NULL; | 1341 | | | 1342 | | /* Keep trying to parse the <pattern> sub-pattern until the | 1343 | | end is reached, creating a new context each time. */ | 1344 | 0 | while ((ctx->count < (Py_ssize_t)pattern[2] || | 1345 | 0 | (Py_ssize_t)pattern[2] == SRE_MAXREPEAT) && | 1346 | 0 | state->ptr != ptr) { | 1347 | | /* Save the Capture Group Marker state into the current | 1348 | | Context and back up the current highest number | 1349 | | Capture Group marker. */ | 1350 | 0 | LASTMARK_SAVE(); | 1351 | 0 | MARK_PUSH(ctx->lastmark); | 1352 | | | 1353 | | /* zero-width match protection */ | 1354 | | /* Set the context's Input Stream pointer to be the | 1355 | | current Input Stream pointer from the global | 1356 | | state. When the loop reaches the next iteration, | 1357 | | the context will then store the last known good | 1358 | | position with the global state holding the Input | 1359 | | Input Stream position that has been updated with | 1360 | | the most recent match. Thus, if state's Input | 1361 | | stream remains the same as the one stored in the | 1362 | | current Context, we know we have successfully | 1363 | | matched an empty string and that all subsequent | 1364 | | matches will also be the empty string until the | 1365 | | maximum number of matches are counted, and because | 1366 | | of this, we could immediately stop at that point and | 1367 | | consider this match successful. */ | 1368 | 0 | ptr = state->ptr; | 1369 | | | 1370 | | /* We have not reached the maximin matches, so try to | 1371 | | match once more. */ | 1372 | 0 | DO_JUMP0(JUMP_POSS_REPEAT_2, jump_poss_repeat_2, | 1373 | 0 | &pattern[3]); | 1374 | | | 1375 | | /* Check to see if the last attempted match | 1376 | | succeeded. */ | 1377 | 0 | if (ret) { | 1378 | | /* Drop the saved highest number Capture Group | 1379 | | marker saved above and use the newly updated | 1380 | | value. */ | 1381 | 0 | MARK_POP_DISCARD(ctx->lastmark); | 1382 | 0 | RETURN_ON_ERROR(ret); | 1383 | | | 1384 | | /* Success, increment the count. */ | 1385 | 0 | ctx->count++; | 1386 | 0 | } | 1387 | | /* Last attempted match failed. */ | 1388 | 0 | else { | 1389 | | /* Restore the previously saved highest number | 1390 | | Capture Group marker since the last iteration | 1391 | | did not match, then restore that to the global | 1392 | | state. */ | 1393 | 0 | MARK_POP(ctx->lastmark); | 1394 | 0 | LASTMARK_RESTORE(); | 1395 | | | 1396 | | /* Restore the global Input Stream pointer | 1397 | | since it can change after jumps. */ | 1398 | 0 | state->ptr = ptr; | 1399 | | | 1400 | | /* We have sufficient matches, so exit loop. */ | 1401 | 0 | break; | 1402 | 0 | } | 1403 | 0 | } | 1404 | | | 1405 | 0 | state->save_marks--; | 1406 | | | 1407 | | /* Evaluate Tail */ | 1408 | | /* Jump to end of pattern indicated by skip, and then skip | 1409 | | the SUCCESS op code that follows it. */ | 1410 | 0 | pattern += pattern[0] + 1; | 1411 | 0 | ptr = state->ptr; | 1412 | 0 | DISPATCH; | 1413 | | | 1414 | 0 | TARGET(SRE_OP_ATOMIC_GROUP): | 1415 | | /* Atomic Group Sub Pattern */ | 1416 | | /* <ATOMIC_GROUP> <skip> pattern <SUCCESS> tail */ | 1417 | 0 | TRACE(("|%p|%p|ATOMIC_GROUP\n", pattern, ptr)); | 1418 | | | 1419 | | /* Set the global Input pointer to this context's Input | 1420 | | pointer */ | 1421 | 0 | state->ptr = ptr; | 1422 | | | 1423 | | /* Evaluate the Atomic Group in a new context, terminating | 1424 | | when the end of the group, represented by a SUCCESS op | 1425 | | code, is reached. */ | 1426 | | /* Group Pattern begins at an offset of 1 code. */ | 1427 | 0 | DO_JUMP0(JUMP_ATOMIC_GROUP, jump_atomic_group, | 1428 | 0 | &pattern[1]); | 1429 | | | 1430 | | /* Test Exit Condition */ | 1431 | 0 | RETURN_ON_ERROR(ret); | 1432 | | | 1433 | 0 | if (ret == 0) { | 1434 | | /* Atomic Group failed to Match. */ | 1435 | 0 | state->ptr = ptr; | 1436 | 0 | RETURN_FAILURE; | 1437 | 0 | } | 1438 | | | 1439 | | /* Evaluate Tail */ | 1440 | | /* Jump to end of pattern indicated by skip, and then skip | 1441 | | the SUCCESS op code that follows it. */ | 1442 | 0 | pattern += pattern[0]; | 1443 | 0 | ptr = state->ptr; | 1444 | 0 | DISPATCH; | 1445 | | | 1446 | 0 | TARGET(SRE_OP_GROUPREF): | 1447 | | /* match backreference */ | 1448 | 0 | TRACE(("|%p|%p|GROUPREF %d\n", pattern, | 1449 | 0 | ptr, pattern[0])); | 1450 | 0 | { | 1451 | 0 | int groupref = pattern[0] * 2; | 1452 | 0 | if (groupref >= state->lastmark) { | 1453 | 0 | RETURN_FAILURE; | 1454 | 0 | } else { | 1455 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; | 1456 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; | 1457 | 0 | if (!p || !e || e < p) | 1458 | 0 | RETURN_FAILURE; | 1459 | 0 | while (p < e) { | 1460 | 0 | if (ptr >= end || *ptr != *p) | 1461 | 0 | RETURN_FAILURE; | 1462 | 0 | p++; | 1463 | 0 | ptr++; | 1464 | 0 | } | 1465 | 0 | } | 1466 | 0 | } | 1467 | 0 | pattern++; | 1468 | 0 | DISPATCH; | 1469 | | | 1470 | 0 | TARGET(SRE_OP_GROUPREF_IGNORE): | 1471 | | /* match backreference */ | 1472 | 0 | TRACE(("|%p|%p|GROUPREF_IGNORE %d\n", pattern, | 1473 | 0 | ptr, pattern[0])); | 1474 | 0 | { | 1475 | 0 | int groupref = pattern[0] * 2; | 1476 | 0 | if (groupref >= state->lastmark) { | 1477 | 0 | RETURN_FAILURE; | 1478 | 0 | } else { | 1479 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; | 1480 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; | 1481 | 0 | if (!p || !e || e < p) | 1482 | 0 | RETURN_FAILURE; | 1483 | 0 | while (p < e) { | 1484 | 0 | if (ptr >= end || | 1485 | 0 | sre_lower_ascii(*ptr) != sre_lower_ascii(*p)) | 1486 | 0 | RETURN_FAILURE; | 1487 | 0 | p++; | 1488 | 0 | ptr++; | 1489 | 0 | } | 1490 | 0 | } | 1491 | 0 | } | 1492 | 0 | pattern++; | 1493 | 0 | DISPATCH; | 1494 | | | 1495 | 0 | TARGET(SRE_OP_GROUPREF_UNI_IGNORE): | 1496 | | /* match backreference */ | 1497 | 0 | TRACE(("|%p|%p|GROUPREF_UNI_IGNORE %d\n", pattern, | 1498 | 0 | ptr, pattern[0])); | 1499 | 0 | { | 1500 | 0 | int groupref = pattern[0] * 2; | 1501 | 0 | if (groupref >= state->lastmark) { | 1502 | 0 | RETURN_FAILURE; | 1503 | 0 | } else { | 1504 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; | 1505 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; | 1506 | 0 | if (!p || !e || e < p) | 1507 | 0 | RETURN_FAILURE; | 1508 | 0 | while (p < e) { | 1509 | 0 | if (ptr >= end || | 1510 | 0 | sre_lower_unicode(*ptr) != sre_lower_unicode(*p)) | 1511 | 0 | RETURN_FAILURE; | 1512 | 0 | p++; | 1513 | 0 | ptr++; | 1514 | 0 | } | 1515 | 0 | } | 1516 | 0 | } | 1517 | 0 | pattern++; | 1518 | 0 | DISPATCH; | 1519 | | | 1520 | 0 | TARGET(SRE_OP_GROUPREF_LOC_IGNORE): | 1521 | | /* match backreference */ | 1522 | 0 | TRACE(("|%p|%p|GROUPREF_LOC_IGNORE %d\n", pattern, | 1523 | 0 | ptr, pattern[0])); | 1524 | 0 | { | 1525 | 0 | int groupref = pattern[0] * 2; | 1526 | 0 | if (groupref >= state->lastmark) { | 1527 | 0 | RETURN_FAILURE; | 1528 | 0 | } else { | 1529 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; | 1530 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; | 1531 | 0 | if (!p || !e || e < p) | 1532 | 0 | RETURN_FAILURE; | 1533 | 0 | while (p < e) { | 1534 | 0 | if (ptr >= end || | 1535 | 0 | sre_lower_locale(*ptr) != sre_lower_locale(*p)) | 1536 | 0 | RETURN_FAILURE; | 1537 | 0 | p++; | 1538 | 0 | ptr++; | 1539 | 0 | } | 1540 | 0 | } | 1541 | 0 | } | 1542 | 0 | pattern++; | 1543 | 0 | DISPATCH; | 1544 | | | 1545 | 0 | TARGET(SRE_OP_GROUPREF_EXISTS): | 1546 | 0 | TRACE(("|%p|%p|GROUPREF_EXISTS %d\n", pattern, | 1547 | 0 | ptr, pattern[0])); | 1548 | | /* <GROUPREF_EXISTS> <group> <skip> codeyes <JUMP> codeno ... */ | 1549 | 0 | { | 1550 | 0 | int groupref = pattern[0] * 2; | 1551 | 0 | if (groupref >= state->lastmark) { | 1552 | 0 | pattern += pattern[1]; | 1553 | 0 | DISPATCH; | 1554 | 0 | } else { | 1555 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; | 1556 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; | 1557 | 0 | if (!p || !e || e < p) { | 1558 | 0 | pattern += pattern[1]; | 1559 | 0 | DISPATCH; | 1560 | 0 | } | 1561 | 0 | } | 1562 | 0 | } | 1563 | 0 | pattern += 2; | 1564 | 0 | DISPATCH; | 1565 | | | 1566 | 3.66M | TARGET(SRE_OP_ASSERT): | 1567 | | /* assert subpattern */ | 1568 | | /* <ASSERT> <skip> <back> <pattern> */ | 1569 | 3.66M | TRACE(("|%p|%p|ASSERT %d\n", pattern, | 1570 | 3.66M | ptr, pattern[1])); | 1571 | 3.66M | if ((uintptr_t)(ptr - (SRE_CHAR *)state->beginning) < pattern[1]) | 1572 | 0 | RETURN_FAILURE; | 1573 | 3.66M | state->ptr = ptr - pattern[1]; | 1574 | 3.66M | DO_JUMP0(JUMP_ASSERT, jump_assert, pattern+2); | 1575 | 3.66M | RETURN_ON_FAILURE(ret); | 1576 | 3.36M | pattern += pattern[0]; | 1577 | 3.36M | DISPATCH; | 1578 | | | 1579 | 7.88M | TARGET(SRE_OP_ASSERT_NOT): | 1580 | | /* assert not subpattern */ | 1581 | | /* <ASSERT_NOT> <skip> <back> <pattern> */ | 1582 | 7.88M | TRACE(("|%p|%p|ASSERT_NOT %d\n", pattern, | 1583 | 7.88M | ptr, pattern[1])); | 1584 | 7.88M | if ((uintptr_t)(ptr - (SRE_CHAR *)state->beginning) >= pattern[1]) { | 1585 | 7.88M | state->ptr = ptr - pattern[1]; | 1586 | 7.88M | LASTMARK_SAVE(); | 1587 | 7.88M | if (state->save_marks) | 1588 | 7.88M | MARK_PUSH(ctx->lastmark); | 1589 | | | 1590 | 15.7M | DO_JUMP0(JUMP_ASSERT_NOT, jump_assert_not, pattern+2); | 1591 | 15.7M | if (ret) { | 1592 | 1.10k | if (state->save_marks) | 1593 | 1.10k | MARK_POP_DISCARD(ctx->lastmark); | 1594 | 1.10k | RETURN_ON_ERROR(ret); | 1595 | 1.10k | RETURN_FAILURE; | 1596 | 1.10k | } | 1597 | 7.88M | if (state->save_marks) | 1598 | 7.88M | MARK_POP(ctx->lastmark); | 1599 | 7.88M | LASTMARK_RESTORE(); | 1600 | 7.88M | } | 1601 | 7.88M | pattern += pattern[0]; | 1602 | 7.88M | DISPATCH; | 1603 | | | 1604 | 7.88M | TARGET(SRE_OP_FAILURE): | 1605 | | /* immediate failure */ | 1606 | 0 | TRACE(("|%p|%p|FAILURE\n", pattern, ptr)); | 1607 | 0 | RETURN_FAILURE; | 1608 | | | 1609 | | #if !USE_COMPUTED_GOTOS | 1610 | | default: | 1611 | | #endif | 1612 | | // Also any unused opcodes: | 1613 | 0 | TARGET(SRE_OP_RANGE_UNI_IGNORE): | 1614 | 0 | TARGET(SRE_OP_SUBPATTERN): | 1615 | 0 | TARGET(SRE_OP_RANGE): | 1616 | 0 | TARGET(SRE_OP_NEGATE): | 1617 | 0 | TARGET(SRE_OP_BIGCHARSET): | 1618 | 0 | TARGET(SRE_OP_CHARSET): | 1619 | 0 | TRACE(("|%p|%p|UNKNOWN %d\n", pattern, ptr, | 1620 | 0 | pattern[-1])); | 1621 | 0 | RETURN_ERROR(SRE_ERROR_ILLEGAL); | 1622 | |
| 1623 | 0 | } | 1624 | | | 1625 | 269M | exit: | 1626 | 269M | ctx_pos = ctx->last_ctx_pos; | 1627 | 269M | jump = ctx->jump; | 1628 | 269M | DATA_POP_DISCARD(ctx); | 1629 | 269M | if (ctx_pos == -1) { | 1630 | 133M | state->sigcount = sigcount; | 1631 | 133M | return ret; | 1632 | 133M | } | 1633 | 135M | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); | 1634 | | | 1635 | 135M | switch (jump) { | 1636 | 21.1M | case JUMP_MAX_UNTIL_2: | 1637 | 21.1M | TRACE(("|%p|%p|JUMP_MAX_UNTIL_2\n", pattern, ptr)); | 1638 | 21.1M | goto jump_max_until_2; | 1639 | 7.13M | case JUMP_MAX_UNTIL_3: | 1640 | 7.13M | TRACE(("|%p|%p|JUMP_MAX_UNTIL_3\n", pattern, ptr)); | 1641 | 7.13M | goto jump_max_until_3; | 1642 | 0 | case JUMP_MIN_UNTIL_2: | 1643 | 0 | TRACE(("|%p|%p|JUMP_MIN_UNTIL_2\n", pattern, ptr)); | 1644 | 0 | goto jump_min_until_2; | 1645 | 0 | case JUMP_MIN_UNTIL_3: | 1646 | 0 | TRACE(("|%p|%p|JUMP_MIN_UNTIL_3\n", pattern, ptr)); | 1647 | 0 | goto jump_min_until_3; | 1648 | 55.7M | case JUMP_BRANCH: | 1649 | 55.7M | TRACE(("|%p|%p|JUMP_BRANCH\n", pattern, ptr)); | 1650 | 55.7M | goto jump_branch; | 1651 | 0 | case JUMP_MAX_UNTIL_1: | 1652 | 0 | TRACE(("|%p|%p|JUMP_MAX_UNTIL_1\n", pattern, ptr)); | 1653 | 0 | goto jump_max_until_1; | 1654 | 0 | case JUMP_MIN_UNTIL_1: | 1655 | 0 | TRACE(("|%p|%p|JUMP_MIN_UNTIL_1\n", pattern, ptr)); | 1656 | 0 | goto jump_min_until_1; | 1657 | 0 | case JUMP_POSS_REPEAT_1: | 1658 | 0 | TRACE(("|%p|%p|JUMP_POSS_REPEAT_1\n", pattern, ptr)); | 1659 | 0 | goto jump_poss_repeat_1; | 1660 | 0 | case JUMP_POSS_REPEAT_2: | 1661 | 0 | TRACE(("|%p|%p|JUMP_POSS_REPEAT_2\n", pattern, ptr)); | 1662 | 0 | goto jump_poss_repeat_2; | 1663 | 6.91M | case JUMP_REPEAT: | 1664 | 6.91M | TRACE(("|%p|%p|JUMP_REPEAT\n", pattern, ptr)); | 1665 | 6.91M | goto jump_repeat; | 1666 | 4.96M | case JUMP_REPEAT_ONE_1: | 1667 | 4.96M | TRACE(("|%p|%p|JUMP_REPEAT_ONE_1\n", pattern, ptr)); | 1668 | 4.96M | goto jump_repeat_one_1; | 1669 | 28.1M | case JUMP_REPEAT_ONE_2: | 1670 | 28.1M | TRACE(("|%p|%p|JUMP_REPEAT_ONE_2\n", pattern, ptr)); | 1671 | 28.1M | goto jump_repeat_one_2; | 1672 | 872 | case JUMP_MIN_REPEAT_ONE: | 1673 | 872 | TRACE(("|%p|%p|JUMP_MIN_REPEAT_ONE\n", pattern, ptr)); | 1674 | 872 | goto jump_min_repeat_one; | 1675 | 0 | case JUMP_ATOMIC_GROUP: | 1676 | 0 | TRACE(("|%p|%p|JUMP_ATOMIC_GROUP\n", pattern, ptr)); | 1677 | 0 | goto jump_atomic_group; | 1678 | 3.66M | case JUMP_ASSERT: | 1679 | 3.66M | TRACE(("|%p|%p|JUMP_ASSERT\n", pattern, ptr)); | 1680 | 3.66M | goto jump_assert; | 1681 | 7.88M | case JUMP_ASSERT_NOT: | 1682 | 7.88M | TRACE(("|%p|%p|JUMP_ASSERT_NOT\n", pattern, ptr)); | 1683 | 7.88M | goto jump_assert_not; | 1684 | 0 | case JUMP_NONE: | 1685 | 0 | TRACE(("|%p|%p|RETURN %zd\n", pattern, | 1686 | 0 | ptr, ret)); | 1687 | 0 | break; | 1688 | 135M | } | 1689 | | | 1690 | 0 | return ret; /* should never get here */ | 1691 | 135M | } |
Line | Count | Source | 608 | 232M | { | 609 | 232M | const SRE_CHAR* end = (const SRE_CHAR *)state->end; | 610 | 232M | Py_ssize_t alloc_pos, ctx_pos = -1; | 611 | 232M | Py_ssize_t ret = 0; | 612 | 232M | int jump; | 613 | 232M | unsigned int sigcount = state->sigcount; | 614 | | | 615 | 232M | SRE(match_context)* ctx; | 616 | 232M | SRE(match_context)* nextctx; | 617 | 232M | INIT_TRACE(state); | 618 | | | 619 | 232M | TRACE(("|%p|%p|ENTER\n", pattern, state->ptr)); | 620 | | | 621 | 232M | DATA_ALLOC(SRE(match_context), ctx); | 622 | 232M | ctx->last_ctx_pos = -1; | 623 | 232M | ctx->jump = JUMP_NONE; | 624 | 232M | ctx->toplevel = toplevel; | 625 | 232M | ctx_pos = alloc_pos; | 626 | | | 627 | 232M | #if USE_COMPUTED_GOTOS | 628 | 232M | #include "sre_targets.h" | 629 | 232M | #endif | 630 | | | 631 | 358M | entrance: | 632 | | | 633 | 358M | ; // Fashion statement. | 634 | 358M | const SRE_CHAR *ptr = (SRE_CHAR *)state->ptr; | 635 | | | 636 | 358M | if (pattern[0] == SRE_OP_INFO) { | 637 | | /* optimization info block */ | 638 | | /* <INFO> <1=skip> <2=flags> <3=min> ... */ | 639 | 11.7M | if (pattern[3] && (uintptr_t)(end - ptr) < pattern[3]) { | 640 | 867 | TRACE(("reject (got %tu chars, need %zu)\n", | 641 | 867 | end - ptr, (size_t) pattern[3])); | 642 | 867 | RETURN_FAILURE; | 643 | 867 | } | 644 | 11.7M | pattern += pattern[1] + 1; | 645 | 11.7M | } | 646 | | | 647 | 358M | #if USE_COMPUTED_GOTOS | 648 | 358M | DISPATCH; | 649 | | #else | 650 | | dispatch: | 651 | | MAYBE_CHECK_SIGNALS; | 652 | | switch (*pattern++) | 653 | | #endif | 654 | 358M | { | 655 | | | 656 | 358M | TARGET(SRE_OP_MARK): | 657 | | /* set mark */ | 658 | | /* <MARK> <gid> */ | 659 | 176M | TRACE(("|%p|%p|MARK %d\n", pattern, | 660 | 176M | ptr, pattern[0])); | 661 | 176M | { | 662 | 176M | int i = pattern[0]; | 663 | 176M | if (i & 1) | 664 | 9.54M | state->lastindex = i/2 + 1; | 665 | 176M | if (i > state->lastmark) { | 666 | | /* state->lastmark is the highest valid index in the | 667 | | state->mark array. If it is increased by more than 1, | 668 | | the intervening marks must be set to NULL to signal | 669 | | that these marks have not been encountered. */ | 670 | 175M | int j = state->lastmark + 1; | 671 | 176M | while (j < i) | 672 | 682k | state->mark[j++] = NULL; | 673 | 175M | state->lastmark = i; | 674 | 175M | } | 675 | 176M | state->mark[i] = ptr; | 676 | 176M | } | 677 | 176M | pattern++; | 678 | 176M | DISPATCH; | 679 | | | 680 | 176M | TARGET(SRE_OP_LITERAL): | 681 | | /* match literal string */ | 682 | | /* <LITERAL> <code> */ | 683 | 23.2M | TRACE(("|%p|%p|LITERAL %d\n", pattern, | 684 | 23.2M | ptr, *pattern)); | 685 | 23.2M | if (ptr >= end || (SRE_CODE) ptr[0] != pattern[0]) | 686 | 6.90M | RETURN_FAILURE; | 687 | 16.2M | pattern++; | 688 | 16.2M | ptr++; | 689 | 16.2M | DISPATCH; | 690 | | | 691 | 16.2M | TARGET(SRE_OP_NOT_LITERAL): | 692 | | /* match anything that is not literal character */ | 693 | | /* <NOT_LITERAL> <code> */ | 694 | 0 | TRACE(("|%p|%p|NOT_LITERAL %d\n", pattern, | 695 | 0 | ptr, *pattern)); | 696 | 0 | if (ptr >= end || (SRE_CODE) ptr[0] == pattern[0]) | 697 | 0 | RETURN_FAILURE; | 698 | 0 | pattern++; | 699 | 0 | ptr++; | 700 | 0 | DISPATCH; | 701 | | | 702 | 77.7M | TARGET(SRE_OP_SUCCESS): | 703 | | /* end of pattern */ | 704 | 77.7M | TRACE(("|%p|%p|SUCCESS\n", pattern, ptr)); | 705 | 77.7M | if (ctx->toplevel && | 706 | 8.47M | ((state->match_all && ptr != state->end) || | 707 | 8.47M | (state->must_advance && ptr == state->start))) | 708 | 0 | { | 709 | 0 | RETURN_FAILURE; | 710 | 0 | } | 711 | 77.7M | state->ptr = ptr; | 712 | 77.7M | RETURN_SUCCESS; | 713 | | | 714 | 1.70M | TARGET(SRE_OP_AT): | 715 | | /* match at given position */ | 716 | | /* <AT> <code> */ | 717 | 1.70M | TRACE(("|%p|%p|AT %d\n", pattern, ptr, *pattern)); | 718 | 1.70M | if (!SRE(at)(state, ptr, *pattern)) | 719 | 1.67M | RETURN_FAILURE; | 720 | 30.2k | pattern++; | 721 | 30.2k | DISPATCH; | 722 | | | 723 | 30.2k | TARGET(SRE_OP_CATEGORY): | 724 | | /* match at given category */ | 725 | | /* <CATEGORY> <code> */ | 726 | 0 | TRACE(("|%p|%p|CATEGORY %d\n", pattern, | 727 | 0 | ptr, *pattern)); | 728 | 0 | if (ptr >= end || !sre_category(pattern[0], ptr[0])) | 729 | 0 | RETURN_FAILURE; | 730 | 0 | pattern++; | 731 | 0 | ptr++; | 732 | 0 | DISPATCH; | 733 | | | 734 | 0 | TARGET(SRE_OP_ANY): | 735 | | /* match anything (except a newline) */ | 736 | | /* <ANY> */ | 737 | 0 | TRACE(("|%p|%p|ANY\n", pattern, ptr)); | 738 | 0 | if (ptr >= end || SRE_IS_LINEBREAK(ptr[0])) | 739 | 0 | RETURN_FAILURE; | 740 | 0 | ptr++; | 741 | 0 | DISPATCH; | 742 | | | 743 | 0 | TARGET(SRE_OP_ANY_ALL): | 744 | | /* match anything */ | 745 | | /* <ANY_ALL> */ | 746 | 0 | TRACE(("|%p|%p|ANY_ALL\n", pattern, ptr)); | 747 | 0 | if (ptr >= end) | 748 | 0 | RETURN_FAILURE; | 749 | 0 | ptr++; | 750 | 0 | DISPATCH; | 751 | | | 752 | 91.6M | TARGET(SRE_OP_IN): | 753 | | /* match set member (or non_member) */ | 754 | | /* <IN> <skip> <set> */ | 755 | 91.6M | TRACE(("|%p|%p|IN\n", pattern, ptr)); | 756 | 91.6M | if (ptr >= end || | 757 | 91.6M | !SRE(charset)(state, pattern + 1, *ptr)) | 758 | 8.15M | RETURN_FAILURE; | 759 | 83.5M | pattern += pattern[0]; | 760 | 83.5M | ptr++; | 761 | 83.5M | DISPATCH; | 762 | | | 763 | 83.5M | TARGET(SRE_OP_LITERAL_IGNORE): | 764 | 4.34M | TRACE(("|%p|%p|LITERAL_IGNORE %d\n", | 765 | 4.34M | pattern, ptr, pattern[0])); | 766 | 4.34M | if (ptr >= end || | 767 | 4.34M | sre_lower_ascii(*ptr) != *pattern) | 768 | 29.8k | RETURN_FAILURE; | 769 | 4.31M | pattern++; | 770 | 4.31M | ptr++; | 771 | 4.31M | DISPATCH; | 772 | | | 773 | 4.31M | TARGET(SRE_OP_LITERAL_UNI_IGNORE): | 774 | 0 | TRACE(("|%p|%p|LITERAL_UNI_IGNORE %d\n", | 775 | 0 | pattern, ptr, pattern[0])); | 776 | 0 | if (ptr >= end || | 777 | 0 | sre_lower_unicode(*ptr) != *pattern) | 778 | 0 | RETURN_FAILURE; | 779 | 0 | pattern++; | 780 | 0 | ptr++; | 781 | 0 | DISPATCH; | 782 | | | 783 | 0 | TARGET(SRE_OP_LITERAL_LOC_IGNORE): | 784 | 0 | TRACE(("|%p|%p|LITERAL_LOC_IGNORE %d\n", | 785 | 0 | pattern, ptr, pattern[0])); | 786 | 0 | if (ptr >= end | 787 | 0 | || !char_loc_ignore(*pattern, *ptr)) | 788 | 0 | RETURN_FAILURE; | 789 | 0 | pattern++; | 790 | 0 | ptr++; | 791 | 0 | DISPATCH; | 792 | | | 793 | 0 | TARGET(SRE_OP_NOT_LITERAL_IGNORE): | 794 | 0 | TRACE(("|%p|%p|NOT_LITERAL_IGNORE %d\n", | 795 | 0 | pattern, ptr, *pattern)); | 796 | 0 | if (ptr >= end || | 797 | 0 | sre_lower_ascii(*ptr) == *pattern) | 798 | 0 | RETURN_FAILURE; | 799 | 0 | pattern++; | 800 | 0 | ptr++; | 801 | 0 | DISPATCH; | 802 | | | 803 | 0 | TARGET(SRE_OP_NOT_LITERAL_UNI_IGNORE): | 804 | 0 | TRACE(("|%p|%p|NOT_LITERAL_UNI_IGNORE %d\n", | 805 | 0 | pattern, ptr, *pattern)); | 806 | 0 | if (ptr >= end || | 807 | 0 | sre_lower_unicode(*ptr) == *pattern) | 808 | 0 | RETURN_FAILURE; | 809 | 0 | pattern++; | 810 | 0 | ptr++; | 811 | 0 | DISPATCH; | 812 | | | 813 | 0 | TARGET(SRE_OP_NOT_LITERAL_LOC_IGNORE): | 814 | 0 | TRACE(("|%p|%p|NOT_LITERAL_LOC_IGNORE %d\n", | 815 | 0 | pattern, ptr, *pattern)); | 816 | 0 | if (ptr >= end | 817 | 0 | || char_loc_ignore(*pattern, *ptr)) | 818 | 0 | RETURN_FAILURE; | 819 | 0 | pattern++; | 820 | 0 | ptr++; | 821 | 0 | DISPATCH; | 822 | | | 823 | 0 | TARGET(SRE_OP_IN_IGNORE): | 824 | 0 | TRACE(("|%p|%p|IN_IGNORE\n", pattern, ptr)); | 825 | 0 | if (ptr >= end | 826 | 0 | || !SRE(charset)(state, pattern+1, | 827 | 0 | (SRE_CODE)sre_lower_ascii(*ptr))) | 828 | 0 | RETURN_FAILURE; | 829 | 0 | pattern += pattern[0]; | 830 | 0 | ptr++; | 831 | 0 | DISPATCH; | 832 | | | 833 | 0 | TARGET(SRE_OP_IN_UNI_IGNORE): | 834 | 0 | TRACE(("|%p|%p|IN_UNI_IGNORE\n", pattern, ptr)); | 835 | 0 | if (ptr >= end | 836 | 0 | || !SRE(charset)(state, pattern+1, | 837 | 0 | (SRE_CODE)sre_lower_unicode(*ptr))) | 838 | 0 | RETURN_FAILURE; | 839 | 0 | pattern += pattern[0]; | 840 | 0 | ptr++; | 841 | 0 | DISPATCH; | 842 | | | 843 | 0 | TARGET(SRE_OP_IN_LOC_IGNORE): | 844 | 0 | TRACE(("|%p|%p|IN_LOC_IGNORE\n", pattern, ptr)); | 845 | 0 | if (ptr >= end | 846 | 0 | || !SRE(charset_loc_ignore)(state, pattern+1, *ptr)) | 847 | 0 | RETURN_FAILURE; | 848 | 0 | pattern += pattern[0]; | 849 | 0 | ptr++; | 850 | 0 | DISPATCH; | 851 | | | 852 | 19.7M | TARGET(SRE_OP_JUMP): | 853 | 19.7M | TARGET(SRE_OP_INFO): | 854 | | /* jump forward */ | 855 | | /* <JUMP> <offset> */ | 856 | 19.7M | TRACE(("|%p|%p|JUMP %d\n", pattern, | 857 | 19.7M | ptr, pattern[0])); | 858 | 19.7M | pattern += pattern[0]; | 859 | 19.7M | DISPATCH; | 860 | | | 861 | 23.7M | TARGET(SRE_OP_BRANCH): | 862 | | /* alternation */ | 863 | | /* <BRANCH> <0=skip> code <JUMP> ... <NULL> */ | 864 | 23.7M | TRACE(("|%p|%p|BRANCH\n", pattern, ptr)); | 865 | 23.7M | LASTMARK_SAVE(); | 866 | 23.7M | if (state->save_marks) | 867 | 19.7M | MARK_PUSH(ctx->lastmark); | 868 | 49.5M | for (; pattern[0]; pattern += pattern[0]) { | 869 | 44.9M | if (pattern[1] == SRE_OP_LITERAL && | 870 | 22.7M | (ptr >= end || | 871 | 22.7M | (SRE_CODE) *ptr != pattern[2])) | 872 | 14.2M | continue; | 873 | 30.7M | if (pattern[1] == SRE_OP_IN && | 874 | 17.0M | (ptr >= end || | 875 | 16.9M | !SRE(charset)(state, pattern + 3, | 876 | 16.9M | (SRE_CODE) *ptr))) | 877 | 9.50M | continue; | 878 | 21.2M | state->ptr = ptr; | 879 | 21.2M | DO_JUMP(JUMP_BRANCH, jump_branch, pattern+1); | 880 | 21.2M | if (ret) { | 881 | 19.2M | if (state->save_marks) | 882 | 16.3M | MARK_POP_DISCARD(ctx->lastmark); | 883 | 19.2M | RETURN_ON_ERROR(ret); | 884 | 19.2M | RETURN_SUCCESS; | 885 | 19.2M | } | 886 | 1.99M | if (state->save_marks) | 887 | 2.69k | MARK_POP_KEEP(ctx->lastmark); | 888 | 1.99M | LASTMARK_RESTORE(); | 889 | 1.99M | } | 890 | 4.55M | if (state->save_marks) | 891 | 3.38M | MARK_POP_DISCARD(ctx->lastmark); | 892 | 4.55M | RETURN_FAILURE; | 893 | | | 894 | 194M | TARGET(SRE_OP_REPEAT_ONE): | 895 | | /* match repeated sequence (maximizing regexp) */ | 896 | | | 897 | | /* this operator only works if the repeated item is | 898 | | exactly one character wide, and we're not already | 899 | | collecting backtracking points. for other cases, | 900 | | use the MAX_REPEAT operator */ | 901 | | | 902 | | /* <REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> tail */ | 903 | | | 904 | 194M | TRACE(("|%p|%p|REPEAT_ONE %d %d\n", pattern, ptr, | 905 | 194M | pattern[1], pattern[2])); | 906 | | | 907 | 194M | if ((Py_ssize_t) pattern[1] > end - ptr) | 908 | 148k | RETURN_FAILURE; /* cannot match */ | 909 | | | 910 | 194M | state->ptr = ptr; | 911 | | | 912 | 194M | ret = SRE(count)(state, pattern+3, pattern[2]); | 913 | 194M | RETURN_ON_ERROR(ret); | 914 | 194M | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); | 915 | 194M | ctx->count = ret; | 916 | 194M | ptr += ctx->count; | 917 | | | 918 | | /* when we arrive here, count contains the number of | 919 | | matches, and ptr points to the tail of the target | 920 | | string. check if the rest of the pattern matches, | 921 | | and backtrack if not. */ | 922 | | | 923 | 194M | if (ctx->count < (Py_ssize_t) pattern[1]) | 924 | 156M | RETURN_FAILURE; | 925 | | | 926 | 38.0M | if (pattern[pattern[0]] == SRE_OP_SUCCESS && | 927 | 4.14M | ptr == state->end && | 928 | 22.6k | !(ctx->toplevel && state->must_advance && ptr == state->start)) | 929 | 22.6k | { | 930 | | /* tail is empty. we're finished */ | 931 | 22.6k | state->ptr = ptr; | 932 | 22.6k | RETURN_SUCCESS; | 933 | 22.6k | } | 934 | | | 935 | 38.0M | LASTMARK_SAVE(); | 936 | 38.0M | if (state->save_marks) | 937 | 21.4M | MARK_PUSH(ctx->lastmark); | 938 | | | 939 | 38.0M | if (pattern[pattern[0]] == SRE_OP_LITERAL) { | 940 | | /* tail starts with a literal. skip positions where | 941 | | the rest of the pattern cannot possibly match */ | 942 | 6.57M | ctx->u.chr = pattern[pattern[0]+1]; | 943 | 6.57M | for (;;) { | 944 | 14.5M | while (ctx->count >= (Py_ssize_t) pattern[1] && | 945 | 11.4M | (ptr >= end || *ptr != ctx->u.chr)) { | 946 | 7.93M | ptr--; | 947 | 7.93M | ctx->count--; | 948 | 7.93M | } | 949 | 6.57M | if (ctx->count < (Py_ssize_t) pattern[1]) | 950 | 3.06M | break; | 951 | 3.50M | state->ptr = ptr; | 952 | 3.50M | DO_JUMP(JUMP_REPEAT_ONE_1, jump_repeat_one_1, | 953 | 3.50M | pattern+pattern[0]); | 954 | 3.50M | if (ret) { | 955 | 3.50M | if (state->save_marks) | 956 | 3.46M | MARK_POP_DISCARD(ctx->lastmark); | 957 | 3.50M | RETURN_ON_ERROR(ret); | 958 | 3.50M | RETURN_SUCCESS; | 959 | 3.50M | } | 960 | 310 | if (state->save_marks) | 961 | 310 | MARK_POP_KEEP(ctx->lastmark); | 962 | 310 | LASTMARK_RESTORE(); | 963 | | | 964 | 310 | ptr--; | 965 | 310 | ctx->count--; | 966 | 310 | } | 967 | 3.06M | if (state->save_marks) | 968 | 3.02M | MARK_POP_DISCARD(ctx->lastmark); | 969 | 31.4M | } else { | 970 | | /* general case */ | 971 | 32.0M | while (ctx->count >= (Py_ssize_t) pattern[1]) { | 972 | 32.0M | state->ptr = ptr; | 973 | 32.0M | DO_JUMP(JUMP_REPEAT_ONE_2, jump_repeat_one_2, | 974 | 32.0M | pattern+pattern[0]); | 975 | 32.0M | if (ret) { | 976 | 31.4M | if (state->save_marks) | 977 | 14.9M | MARK_POP_DISCARD(ctx->lastmark); | 978 | 31.4M | RETURN_ON_ERROR(ret); | 979 | 31.4M | RETURN_SUCCESS; | 980 | 31.4M | } | 981 | 627k | if (state->save_marks) | 982 | 101k | MARK_POP_KEEP(ctx->lastmark); | 983 | 627k | LASTMARK_RESTORE(); | 984 | | | 985 | 627k | ptr--; | 986 | 627k | ctx->count--; | 987 | 627k | } | 988 | 53.1k | if (state->save_marks) | 989 | 51.1k | MARK_POP_DISCARD(ctx->lastmark); | 990 | 53.1k | } | 991 | 3.11M | RETURN_FAILURE; | 992 | | | 993 | 0 | TARGET(SRE_OP_MIN_REPEAT_ONE): | 994 | | /* match repeated sequence (minimizing regexp) */ | 995 | | | 996 | | /* this operator only works if the repeated item is | 997 | | exactly one character wide, and we're not already | 998 | | collecting backtracking points. for other cases, | 999 | | use the MIN_REPEAT operator */ | 1000 | | | 1001 | | /* <MIN_REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> tail */ | 1002 | |
| 1003 | 0 | TRACE(("|%p|%p|MIN_REPEAT_ONE %d %d\n", pattern, ptr, | 1004 | 0 | pattern[1], pattern[2])); | 1005 | |
| 1006 | 0 | if ((Py_ssize_t) pattern[1] > end - ptr) | 1007 | 0 | RETURN_FAILURE; /* cannot match */ | 1008 | | | 1009 | 0 | state->ptr = ptr; | 1010 | |
| 1011 | 0 | if (pattern[1] == 0) | 1012 | 0 | ctx->count = 0; | 1013 | 0 | else { | 1014 | | /* count using pattern min as the maximum */ | 1015 | 0 | ret = SRE(count)(state, pattern+3, pattern[1]); | 1016 | 0 | RETURN_ON_ERROR(ret); | 1017 | 0 | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); | 1018 | 0 | if (ret < (Py_ssize_t) pattern[1]) | 1019 | | /* didn't match minimum number of times */ | 1020 | 0 | RETURN_FAILURE; | 1021 | | /* advance past minimum matches of repeat */ | 1022 | 0 | ctx->count = ret; | 1023 | 0 | ptr += ctx->count; | 1024 | 0 | } | 1025 | | | 1026 | 0 | if (pattern[pattern[0]] == SRE_OP_SUCCESS && | 1027 | 0 | !(ctx->toplevel && | 1028 | 0 | ((state->match_all && ptr != state->end) || | 1029 | 0 | (state->must_advance && ptr == state->start)))) | 1030 | 0 | { | 1031 | | /* tail is empty. we're finished */ | 1032 | 0 | state->ptr = ptr; | 1033 | 0 | RETURN_SUCCESS; | 1034 | |
| 1035 | 0 | } else { | 1036 | | /* general case */ | 1037 | 0 | LASTMARK_SAVE(); | 1038 | 0 | if (state->save_marks) | 1039 | 0 | MARK_PUSH(ctx->lastmark); | 1040 | | | 1041 | 0 | while ((Py_ssize_t)pattern[2] == SRE_MAXREPEAT | 1042 | 0 | || ctx->count <= (Py_ssize_t)pattern[2]) { | 1043 | 0 | state->ptr = ptr; | 1044 | 0 | DO_JUMP(JUMP_MIN_REPEAT_ONE,jump_min_repeat_one, | 1045 | 0 | pattern+pattern[0]); | 1046 | 0 | if (ret) { | 1047 | 0 | if (state->save_marks) | 1048 | 0 | MARK_POP_DISCARD(ctx->lastmark); | 1049 | 0 | RETURN_ON_ERROR(ret); | 1050 | 0 | RETURN_SUCCESS; | 1051 | 0 | } | 1052 | 0 | if (state->save_marks) | 1053 | 0 | MARK_POP_KEEP(ctx->lastmark); | 1054 | 0 | LASTMARK_RESTORE(); | 1055 | |
| 1056 | 0 | state->ptr = ptr; | 1057 | 0 | ret = SRE(count)(state, pattern+3, 1); | 1058 | 0 | RETURN_ON_ERROR(ret); | 1059 | 0 | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); | 1060 | 0 | if (ret == 0) | 1061 | 0 | break; | 1062 | 0 | assert(ret == 1); | 1063 | 0 | ptr++; | 1064 | 0 | ctx->count++; | 1065 | 0 | } | 1066 | 0 | if (state->save_marks) | 1067 | 0 | MARK_POP_DISCARD(ctx->lastmark); | 1068 | 0 | } | 1069 | 0 | RETURN_FAILURE; | 1070 | | | 1071 | 0 | TARGET(SRE_OP_POSSESSIVE_REPEAT_ONE): | 1072 | | /* match repeated sequence (maximizing regexp) without | 1073 | | backtracking */ | 1074 | | | 1075 | | /* this operator only works if the repeated item is | 1076 | | exactly one character wide, and we're not already | 1077 | | collecting backtracking points. for other cases, | 1078 | | use the MAX_REPEAT operator */ | 1079 | | | 1080 | | /* <POSSESSIVE_REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> | 1081 | | tail */ | 1082 | |
| 1083 | 0 | TRACE(("|%p|%p|POSSESSIVE_REPEAT_ONE %d %d\n", pattern, | 1084 | 0 | ptr, pattern[1], pattern[2])); | 1085 | |
| 1086 | 0 | if (ptr + pattern[1] > end) { | 1087 | 0 | RETURN_FAILURE; /* cannot match */ | 1088 | 0 | } | 1089 | | | 1090 | 0 | state->ptr = ptr; | 1091 | |
| 1092 | 0 | ret = SRE(count)(state, pattern + 3, pattern[2]); | 1093 | 0 | RETURN_ON_ERROR(ret); | 1094 | 0 | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); | 1095 | 0 | ctx->count = ret; | 1096 | 0 | ptr += ctx->count; | 1097 | | | 1098 | | /* when we arrive here, count contains the number of | 1099 | | matches, and ptr points to the tail of the target | 1100 | | string. check if the rest of the pattern matches, | 1101 | | and fail if not. */ | 1102 | | | 1103 | | /* Test for not enough repetitions in match */ | 1104 | 0 | if (ctx->count < (Py_ssize_t) pattern[1]) { | 1105 | 0 | RETURN_FAILURE; | 1106 | 0 | } | 1107 | | | 1108 | | /* Update the pattern to point to the next op code */ | 1109 | 0 | pattern += pattern[0]; | 1110 | | | 1111 | | /* Let the tail be evaluated separately and consider this | 1112 | | match successful. */ | 1113 | 0 | if (*pattern == SRE_OP_SUCCESS && | 1114 | 0 | ptr == state->end && | 1115 | 0 | !(ctx->toplevel && state->must_advance && ptr == state->start)) | 1116 | 0 | { | 1117 | | /* tail is empty. we're finished */ | 1118 | 0 | state->ptr = ptr; | 1119 | 0 | RETURN_SUCCESS; | 1120 | 0 | } | 1121 | | | 1122 | | /* Attempt to match the rest of the string */ | 1123 | 0 | DISPATCH; | 1124 | | | 1125 | 11.1M | TARGET(SRE_OP_REPEAT): | 1126 | | /* create repeat context. all the hard work is done | 1127 | | by the UNTIL operator (MAX_UNTIL, MIN_UNTIL) */ | 1128 | | /* <REPEAT> <skip> <1=min> <2=max> | 1129 | | <3=repeat_index> item <UNTIL> tail */ | 1130 | 11.1M | TRACE(("|%p|%p|REPEAT %d %d\n", pattern, ptr, | 1131 | 11.1M | pattern[1], pattern[2])); | 1132 | | | 1133 | | /* install new repeat context */ | 1134 | 11.1M | ctx->u.rep = repeat_pool_malloc(state); | 1135 | 11.1M | if (!ctx->u.rep) { | 1136 | 0 | RETURN_ERROR(SRE_ERROR_MEMORY); | 1137 | 0 | } | 1138 | 11.1M | ctx->u.rep->count = -1; | 1139 | 11.1M | ctx->u.rep->pattern = pattern; | 1140 | 11.1M | ctx->u.rep->prev = state->repeat; | 1141 | 11.1M | ctx->u.rep->last_ptr = NULL; | 1142 | 11.1M | state->repeat = ctx->u.rep; | 1143 | 11.1M | state->save_marks++; | 1144 | | | 1145 | 11.1M | state->ptr = ptr; | 1146 | 11.1M | DO_JUMP(JUMP_REPEAT, jump_repeat, pattern+pattern[0]); | 1147 | 11.1M | state->repeat = ctx->u.rep->prev; | 1148 | 11.1M | state->save_marks--; | 1149 | 11.1M | repeat_pool_free(state, ctx->u.rep); | 1150 | | | 1151 | 11.1M | if (ret) { | 1152 | 11.1M | RETURN_ON_ERROR(ret); | 1153 | 11.1M | RETURN_SUCCESS; | 1154 | 11.1M | } | 1155 | 978 | RETURN_FAILURE; | 1156 | | | 1157 | 31.9M | TARGET(SRE_OP_MAX_UNTIL): | 1158 | | /* maximizing repeat */ | 1159 | | /* <REPEAT> <skip> <1=min> <2=max> item <MAX_UNTIL> tail */ | 1160 | | | 1161 | | /* FIXME: we probably need to deal with zero-width | 1162 | | matches in here... */ | 1163 | | | 1164 | 31.9M | ctx->u.rep = state->repeat; | 1165 | 31.9M | if (!ctx->u.rep) | 1166 | 0 | RETURN_ERROR(SRE_ERROR_STATE); | 1167 | | | 1168 | 31.9M | state->ptr = ptr; | 1169 | | | 1170 | 31.9M | ctx->count = ctx->u.rep->count+1; | 1171 | | | 1172 | 31.9M | TRACE(("|%p|%p|MAX_UNTIL %zd\n", pattern, | 1173 | 31.9M | ptr, ctx->count)); | 1174 | | | 1175 | 31.9M | if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) { | 1176 | | /* not enough matches */ | 1177 | 0 | ctx->u.rep->count = ctx->count; | 1178 | 0 | DO_JUMP(JUMP_MAX_UNTIL_1, jump_max_until_1, | 1179 | 0 | ctx->u.rep->pattern+3); | 1180 | 0 | if (ret) { | 1181 | 0 | RETURN_ON_ERROR(ret); | 1182 | 0 | RETURN_SUCCESS; | 1183 | 0 | } | 1184 | 0 | ctx->u.rep->count = ctx->count-1; | 1185 | 0 | state->ptr = ptr; | 1186 | 0 | RETURN_FAILURE; | 1187 | 0 | } | 1188 | | | 1189 | 31.9M | if ((ctx->count < (Py_ssize_t) ctx->u.rep->pattern[2] || | 1190 | 3.26M | ctx->u.rep->pattern[2] == SRE_MAXREPEAT) && | 1191 | 28.6M | state->ptr != ctx->u.rep->last_ptr) { | 1192 | | /* we may have enough matches, but if we can | 1193 | | match another item, do so */ | 1194 | 28.6M | ctx->u.rep->count = ctx->count; | 1195 | 28.6M | LASTMARK_SAVE(); | 1196 | 28.6M | MARK_PUSH(ctx->lastmark); | 1197 | | /* zero-width match protection */ | 1198 | 28.6M | LAST_PTR_PUSH(); | 1199 | 28.6M | ctx->u.rep->last_ptr = state->ptr; | 1200 | 28.6M | DO_JUMP(JUMP_MAX_UNTIL_2, jump_max_until_2, | 1201 | 28.6M | ctx->u.rep->pattern+3); | 1202 | 28.6M | LAST_PTR_POP(); | 1203 | 28.6M | if (ret) { | 1204 | 20.7M | MARK_POP_DISCARD(ctx->lastmark); | 1205 | 20.7M | RETURN_ON_ERROR(ret); | 1206 | 20.7M | RETURN_SUCCESS; | 1207 | 20.7M | } | 1208 | 7.94M | MARK_POP(ctx->lastmark); | 1209 | 7.94M | LASTMARK_RESTORE(); | 1210 | 7.94M | ctx->u.rep->count = ctx->count-1; | 1211 | 7.94M | state->ptr = ptr; | 1212 | 7.94M | } | 1213 | | | 1214 | | /* cannot match more repeated items here. make sure the | 1215 | | tail matches */ | 1216 | 11.2M | state->repeat = ctx->u.rep->prev; | 1217 | 11.2M | state->save_marks--; | 1218 | 11.2M | DO_JUMP(JUMP_MAX_UNTIL_3, jump_max_until_3, pattern); | 1219 | 11.2M | state->repeat = ctx->u.rep; // restore repeat before return | 1220 | 11.2M | state->save_marks++; | 1221 | | | 1222 | 11.2M | RETURN_ON_SUCCESS(ret); | 1223 | 51.7k | state->ptr = ptr; | 1224 | 51.7k | RETURN_FAILURE; | 1225 | | | 1226 | 0 | TARGET(SRE_OP_MIN_UNTIL): | 1227 | | /* minimizing repeat */ | 1228 | | /* <REPEAT> <skip> <1=min> <2=max> item <MIN_UNTIL> tail */ | 1229 | |
| 1230 | 0 | ctx->u.rep = state->repeat; | 1231 | 0 | if (!ctx->u.rep) | 1232 | 0 | RETURN_ERROR(SRE_ERROR_STATE); | 1233 | | | 1234 | 0 | state->ptr = ptr; | 1235 | |
| 1236 | 0 | ctx->count = ctx->u.rep->count+1; | 1237 | |
| 1238 | 0 | TRACE(("|%p|%p|MIN_UNTIL %zd %p\n", pattern, | 1239 | 0 | ptr, ctx->count, ctx->u.rep->pattern)); | 1240 | |
| 1241 | 0 | if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) { | 1242 | | /* not enough matches */ | 1243 | 0 | ctx->u.rep->count = ctx->count; | 1244 | 0 | DO_JUMP(JUMP_MIN_UNTIL_1, jump_min_until_1, | 1245 | 0 | ctx->u.rep->pattern+3); | 1246 | 0 | if (ret) { | 1247 | 0 | RETURN_ON_ERROR(ret); | 1248 | 0 | RETURN_SUCCESS; | 1249 | 0 | } | 1250 | 0 | ctx->u.rep->count = ctx->count-1; | 1251 | 0 | state->ptr = ptr; | 1252 | 0 | RETURN_FAILURE; | 1253 | 0 | } | 1254 | | | 1255 | | /* see if the tail matches */ | 1256 | 0 | state->repeat = ctx->u.rep->prev; | 1257 | 0 | state->save_marks--; | 1258 | |
| 1259 | 0 | LASTMARK_SAVE(); | 1260 | 0 | if (state->save_marks) | 1261 | 0 | MARK_PUSH(ctx->lastmark); | 1262 | | | 1263 | 0 | DO_JUMP(JUMP_MIN_UNTIL_2, jump_min_until_2, pattern); | 1264 | | /* save_marks is balanced across the jump, so this equals the | 1265 | | value tested for MARK_PUSH above */ | 1266 | 0 | int pushed = state->save_marks != 0; | 1267 | 0 | state->repeat = ctx->u.rep; // restore repeat before return | 1268 | 0 | state->save_marks++; | 1269 | |
| 1270 | 0 | if (ret) { | 1271 | 0 | if (pushed) | 1272 | 0 | MARK_POP_DISCARD(ctx->lastmark); | 1273 | 0 | RETURN_ON_ERROR(ret); | 1274 | 0 | RETURN_SUCCESS; | 1275 | 0 | } | 1276 | 0 | if (pushed) | 1277 | 0 | MARK_POP(ctx->lastmark); | 1278 | 0 | LASTMARK_RESTORE(); | 1279 | |
| 1280 | 0 | state->ptr = ptr; | 1281 | |
| 1282 | 0 | if ((ctx->count >= (Py_ssize_t) ctx->u.rep->pattern[2] | 1283 | 0 | && ctx->u.rep->pattern[2] != SRE_MAXREPEAT) || | 1284 | 0 | state->ptr == ctx->u.rep->last_ptr) | 1285 | 0 | RETURN_FAILURE; | 1286 | | | 1287 | 0 | ctx->u.rep->count = ctx->count; | 1288 | | /* zero-width match protection */ | 1289 | 0 | LAST_PTR_PUSH(); | 1290 | 0 | ctx->u.rep->last_ptr = state->ptr; | 1291 | 0 | DO_JUMP(JUMP_MIN_UNTIL_3,jump_min_until_3, | 1292 | 0 | ctx->u.rep->pattern+3); | 1293 | 0 | LAST_PTR_POP(); | 1294 | 0 | if (ret) { | 1295 | 0 | RETURN_ON_ERROR(ret); | 1296 | 0 | RETURN_SUCCESS; | 1297 | 0 | } | 1298 | 0 | ctx->u.rep->count = ctx->count-1; | 1299 | 0 | state->ptr = ptr; | 1300 | 0 | RETURN_FAILURE; | 1301 | | | 1302 | 0 | TARGET(SRE_OP_POSSESSIVE_REPEAT): | 1303 | | /* create possessive repeat contexts. */ | 1304 | | /* <POSSESSIVE_REPEAT> <skip> <1=min> <2=max> pattern | 1305 | | <SUCCESS> tail */ | 1306 | 0 | TRACE(("|%p|%p|POSSESSIVE_REPEAT %d %d\n", pattern, | 1307 | 0 | ptr, pattern[1], pattern[2])); | 1308 | | | 1309 | | /* Set the global Input pointer to this context's Input | 1310 | | pointer */ | 1311 | 0 | state->ptr = ptr; | 1312 | | | 1313 | | /* Capture groups in the body can be revisited on backtracking | 1314 | | between iterations, so their marks must be saved and restored, | 1315 | | as is done inside a repeat. */ | 1316 | 0 | state->save_marks++; | 1317 | | | 1318 | | /* Initialize Count to 0 */ | 1319 | 0 | ctx->count = 0; | 1320 | | | 1321 | | /* Check for minimum required matches. */ | 1322 | 0 | while (ctx->count < (Py_ssize_t)pattern[1]) { | 1323 | | /* not enough matches */ | 1324 | 0 | DO_JUMP0(JUMP_POSS_REPEAT_1, jump_poss_repeat_1, | 1325 | 0 | &pattern[3]); | 1326 | 0 | if (ret) { | 1327 | 0 | RETURN_ON_ERROR(ret); | 1328 | 0 | ctx->count++; | 1329 | 0 | } | 1330 | 0 | else { | 1331 | 0 | state->ptr = ptr; | 1332 | 0 | state->save_marks--; | 1333 | 0 | RETURN_FAILURE; | 1334 | 0 | } | 1335 | 0 | } | 1336 | | | 1337 | | /* Clear the context's Input stream pointer so that it | 1338 | | doesn't match the global state so that the while loop can | 1339 | | be entered. */ | 1340 | 0 | ptr = NULL; | 1341 | | | 1342 | | /* Keep trying to parse the <pattern> sub-pattern until the | 1343 | | end is reached, creating a new context each time. */ | 1344 | 0 | while ((ctx->count < (Py_ssize_t)pattern[2] || | 1345 | 0 | (Py_ssize_t)pattern[2] == SRE_MAXREPEAT) && | 1346 | 0 | state->ptr != ptr) { | 1347 | | /* Save the Capture Group Marker state into the current | 1348 | | Context and back up the current highest number | 1349 | | Capture Group marker. */ | 1350 | 0 | LASTMARK_SAVE(); | 1351 | 0 | MARK_PUSH(ctx->lastmark); | 1352 | | | 1353 | | /* zero-width match protection */ | 1354 | | /* Set the context's Input Stream pointer to be the | 1355 | | current Input Stream pointer from the global | 1356 | | state. When the loop reaches the next iteration, | 1357 | | the context will then store the last known good | 1358 | | position with the global state holding the Input | 1359 | | Input Stream position that has been updated with | 1360 | | the most recent match. Thus, if state's Input | 1361 | | stream remains the same as the one stored in the | 1362 | | current Context, we know we have successfully | 1363 | | matched an empty string and that all subsequent | 1364 | | matches will also be the empty string until the | 1365 | | maximum number of matches are counted, and because | 1366 | | of this, we could immediately stop at that point and | 1367 | | consider this match successful. */ | 1368 | 0 | ptr = state->ptr; | 1369 | | | 1370 | | /* We have not reached the maximin matches, so try to | 1371 | | match once more. */ | 1372 | 0 | DO_JUMP0(JUMP_POSS_REPEAT_2, jump_poss_repeat_2, | 1373 | 0 | &pattern[3]); | 1374 | | | 1375 | | /* Check to see if the last attempted match | 1376 | | succeeded. */ | 1377 | 0 | if (ret) { | 1378 | | /* Drop the saved highest number Capture Group | 1379 | | marker saved above and use the newly updated | 1380 | | value. */ | 1381 | 0 | MARK_POP_DISCARD(ctx->lastmark); | 1382 | 0 | RETURN_ON_ERROR(ret); | 1383 | | | 1384 | | /* Success, increment the count. */ | 1385 | 0 | ctx->count++; | 1386 | 0 | } | 1387 | | /* Last attempted match failed. */ | 1388 | 0 | else { | 1389 | | /* Restore the previously saved highest number | 1390 | | Capture Group marker since the last iteration | 1391 | | did not match, then restore that to the global | 1392 | | state. */ | 1393 | 0 | MARK_POP(ctx->lastmark); | 1394 | 0 | LASTMARK_RESTORE(); | 1395 | | | 1396 | | /* Restore the global Input Stream pointer | 1397 | | since it can change after jumps. */ | 1398 | 0 | state->ptr = ptr; | 1399 | | | 1400 | | /* We have sufficient matches, so exit loop. */ | 1401 | 0 | break; | 1402 | 0 | } | 1403 | 0 | } | 1404 | | | 1405 | 0 | state->save_marks--; | 1406 | | | 1407 | | /* Evaluate Tail */ | 1408 | | /* Jump to end of pattern indicated by skip, and then skip | 1409 | | the SUCCESS op code that follows it. */ | 1410 | 0 | pattern += pattern[0] + 1; | 1411 | 0 | ptr = state->ptr; | 1412 | 0 | DISPATCH; | 1413 | | | 1414 | 0 | TARGET(SRE_OP_ATOMIC_GROUP): | 1415 | | /* Atomic Group Sub Pattern */ | 1416 | | /* <ATOMIC_GROUP> <skip> pattern <SUCCESS> tail */ | 1417 | 0 | TRACE(("|%p|%p|ATOMIC_GROUP\n", pattern, ptr)); | 1418 | | | 1419 | | /* Set the global Input pointer to this context's Input | 1420 | | pointer */ | 1421 | 0 | state->ptr = ptr; | 1422 | | | 1423 | | /* Evaluate the Atomic Group in a new context, terminating | 1424 | | when the end of the group, represented by a SUCCESS op | 1425 | | code, is reached. */ | 1426 | | /* Group Pattern begins at an offset of 1 code. */ | 1427 | 0 | DO_JUMP0(JUMP_ATOMIC_GROUP, jump_atomic_group, | 1428 | 0 | &pattern[1]); | 1429 | | | 1430 | | /* Test Exit Condition */ | 1431 | 0 | RETURN_ON_ERROR(ret); | 1432 | | | 1433 | 0 | if (ret == 0) { | 1434 | | /* Atomic Group failed to Match. */ | 1435 | 0 | state->ptr = ptr; | 1436 | 0 | RETURN_FAILURE; | 1437 | 0 | } | 1438 | | | 1439 | | /* Evaluate Tail */ | 1440 | | /* Jump to end of pattern indicated by skip, and then skip | 1441 | | the SUCCESS op code that follows it. */ | 1442 | 0 | pattern += pattern[0]; | 1443 | 0 | ptr = state->ptr; | 1444 | 0 | DISPATCH; | 1445 | | | 1446 | 0 | TARGET(SRE_OP_GROUPREF): | 1447 | | /* match backreference */ | 1448 | 0 | TRACE(("|%p|%p|GROUPREF %d\n", pattern, | 1449 | 0 | ptr, pattern[0])); | 1450 | 0 | { | 1451 | 0 | int groupref = pattern[0] * 2; | 1452 | 0 | if (groupref >= state->lastmark) { | 1453 | 0 | RETURN_FAILURE; | 1454 | 0 | } else { | 1455 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; | 1456 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; | 1457 | 0 | if (!p || !e || e < p) | 1458 | 0 | RETURN_FAILURE; | 1459 | 0 | while (p < e) { | 1460 | 0 | if (ptr >= end || *ptr != *p) | 1461 | 0 | RETURN_FAILURE; | 1462 | 0 | p++; | 1463 | 0 | ptr++; | 1464 | 0 | } | 1465 | 0 | } | 1466 | 0 | } | 1467 | 0 | pattern++; | 1468 | 0 | DISPATCH; | 1469 | | | 1470 | 0 | TARGET(SRE_OP_GROUPREF_IGNORE): | 1471 | | /* match backreference */ | 1472 | 0 | TRACE(("|%p|%p|GROUPREF_IGNORE %d\n", pattern, | 1473 | 0 | ptr, pattern[0])); | 1474 | 0 | { | 1475 | 0 | int groupref = pattern[0] * 2; | 1476 | 0 | if (groupref >= state->lastmark) { | 1477 | 0 | RETURN_FAILURE; | 1478 | 0 | } else { | 1479 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; | 1480 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; | 1481 | 0 | if (!p || !e || e < p) | 1482 | 0 | RETURN_FAILURE; | 1483 | 0 | while (p < e) { | 1484 | 0 | if (ptr >= end || | 1485 | 0 | sre_lower_ascii(*ptr) != sre_lower_ascii(*p)) | 1486 | 0 | RETURN_FAILURE; | 1487 | 0 | p++; | 1488 | 0 | ptr++; | 1489 | 0 | } | 1490 | 0 | } | 1491 | 0 | } | 1492 | 0 | pattern++; | 1493 | 0 | DISPATCH; | 1494 | | | 1495 | 0 | TARGET(SRE_OP_GROUPREF_UNI_IGNORE): | 1496 | | /* match backreference */ | 1497 | 0 | TRACE(("|%p|%p|GROUPREF_UNI_IGNORE %d\n", pattern, | 1498 | 0 | ptr, pattern[0])); | 1499 | 0 | { | 1500 | 0 | int groupref = pattern[0] * 2; | 1501 | 0 | if (groupref >= state->lastmark) { | 1502 | 0 | RETURN_FAILURE; | 1503 | 0 | } else { | 1504 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; | 1505 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; | 1506 | 0 | if (!p || !e || e < p) | 1507 | 0 | RETURN_FAILURE; | 1508 | 0 | while (p < e) { | 1509 | 0 | if (ptr >= end || | 1510 | 0 | sre_lower_unicode(*ptr) != sre_lower_unicode(*p)) | 1511 | 0 | RETURN_FAILURE; | 1512 | 0 | p++; | 1513 | 0 | ptr++; | 1514 | 0 | } | 1515 | 0 | } | 1516 | 0 | } | 1517 | 0 | pattern++; | 1518 | 0 | DISPATCH; | 1519 | | | 1520 | 0 | TARGET(SRE_OP_GROUPREF_LOC_IGNORE): | 1521 | | /* match backreference */ | 1522 | 0 | TRACE(("|%p|%p|GROUPREF_LOC_IGNORE %d\n", pattern, | 1523 | 0 | ptr, pattern[0])); | 1524 | 0 | { | 1525 | 0 | int groupref = pattern[0] * 2; | 1526 | 0 | if (groupref >= state->lastmark) { | 1527 | 0 | RETURN_FAILURE; | 1528 | 0 | } else { | 1529 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; | 1530 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; | 1531 | 0 | if (!p || !e || e < p) | 1532 | 0 | RETURN_FAILURE; | 1533 | 0 | while (p < e) { | 1534 | 0 | if (ptr >= end || | 1535 | 0 | sre_lower_locale(*ptr) != sre_lower_locale(*p)) | 1536 | 0 | RETURN_FAILURE; | 1537 | 0 | p++; | 1538 | 0 | ptr++; | 1539 | 0 | } | 1540 | 0 | } | 1541 | 0 | } | 1542 | 0 | pattern++; | 1543 | 0 | DISPATCH; | 1544 | | | 1545 | 0 | TARGET(SRE_OP_GROUPREF_EXISTS): | 1546 | 0 | TRACE(("|%p|%p|GROUPREF_EXISTS %d\n", pattern, | 1547 | 0 | ptr, pattern[0])); | 1548 | | /* <GROUPREF_EXISTS> <group> <skip> codeyes <JUMP> codeno ... */ | 1549 | 0 | { | 1550 | 0 | int groupref = pattern[0] * 2; | 1551 | 0 | if (groupref >= state->lastmark) { | 1552 | 0 | pattern += pattern[1]; | 1553 | 0 | DISPATCH; | 1554 | 0 | } else { | 1555 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; | 1556 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; | 1557 | 0 | if (!p || !e || e < p) { | 1558 | 0 | pattern += pattern[1]; | 1559 | 0 | DISPATCH; | 1560 | 0 | } | 1561 | 0 | } | 1562 | 0 | } | 1563 | 0 | pattern += 2; | 1564 | 0 | DISPATCH; | 1565 | | | 1566 | 9.63M | TARGET(SRE_OP_ASSERT): | 1567 | | /* assert subpattern */ | 1568 | | /* <ASSERT> <skip> <back> <pattern> */ | 1569 | 9.63M | TRACE(("|%p|%p|ASSERT %d\n", pattern, | 1570 | 9.63M | ptr, pattern[1])); | 1571 | 9.63M | if ((uintptr_t)(ptr - (SRE_CHAR *)state->beginning) < pattern[1]) | 1572 | 0 | RETURN_FAILURE; | 1573 | 9.63M | state->ptr = ptr - pattern[1]; | 1574 | 9.63M | DO_JUMP0(JUMP_ASSERT, jump_assert, pattern+2); | 1575 | 9.63M | RETURN_ON_FAILURE(ret); | 1576 | 6.69M | pattern += pattern[0]; | 1577 | 6.69M | DISPATCH; | 1578 | | | 1579 | 9.03M | TARGET(SRE_OP_ASSERT_NOT): | 1580 | | /* assert not subpattern */ | 1581 | | /* <ASSERT_NOT> <skip> <back> <pattern> */ | 1582 | 9.03M | TRACE(("|%p|%p|ASSERT_NOT %d\n", pattern, | 1583 | 9.03M | ptr, pattern[1])); | 1584 | 9.03M | if ((uintptr_t)(ptr - (SRE_CHAR *)state->beginning) >= pattern[1]) { | 1585 | 9.03M | state->ptr = ptr - pattern[1]; | 1586 | 9.03M | LASTMARK_SAVE(); | 1587 | 9.03M | if (state->save_marks) | 1588 | 9.03M | MARK_PUSH(ctx->lastmark); | 1589 | | | 1590 | 18.0M | DO_JUMP0(JUMP_ASSERT_NOT, jump_assert_not, pattern+2); | 1591 | 18.0M | if (ret) { | 1592 | 2.34k | if (state->save_marks) | 1593 | 2.34k | MARK_POP_DISCARD(ctx->lastmark); | 1594 | 2.34k | RETURN_ON_ERROR(ret); | 1595 | 2.34k | RETURN_FAILURE; | 1596 | 2.34k | } | 1597 | 9.03M | if (state->save_marks) | 1598 | 9.03M | MARK_POP(ctx->lastmark); | 1599 | 9.03M | LASTMARK_RESTORE(); | 1600 | 9.03M | } | 1601 | 9.03M | pattern += pattern[0]; | 1602 | 9.03M | DISPATCH; | 1603 | | | 1604 | 9.03M | TARGET(SRE_OP_FAILURE): | 1605 | | /* immediate failure */ | 1606 | 0 | TRACE(("|%p|%p|FAILURE\n", pattern, ptr)); | 1607 | 0 | RETURN_FAILURE; | 1608 | | | 1609 | | #if !USE_COMPUTED_GOTOS | 1610 | | default: | 1611 | | #endif | 1612 | | // Also any unused opcodes: | 1613 | 0 | TARGET(SRE_OP_RANGE_UNI_IGNORE): | 1614 | 0 | TARGET(SRE_OP_SUBPATTERN): | 1615 | 0 | TARGET(SRE_OP_RANGE): | 1616 | 0 | TARGET(SRE_OP_NEGATE): | 1617 | 0 | TARGET(SRE_OP_BIGCHARSET): | 1618 | 0 | TARGET(SRE_OP_CHARSET): | 1619 | 0 | TRACE(("|%p|%p|UNKNOWN %d\n", pattern, ptr, | 1620 | 0 | pattern[-1])); | 1621 | 0 | RETURN_ERROR(SRE_ERROR_ILLEGAL); | 1622 | |
| 1623 | 0 | } | 1624 | | | 1625 | 358M | exit: | 1626 | 358M | ctx_pos = ctx->last_ctx_pos; | 1627 | 358M | jump = ctx->jump; | 1628 | 358M | DATA_POP_DISCARD(ctx); | 1629 | 358M | if (ctx_pos == -1) { | 1630 | 232M | state->sigcount = sigcount; | 1631 | 232M | return ret; | 1632 | 232M | } | 1633 | 126M | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); | 1634 | | | 1635 | 126M | switch (jump) { | 1636 | 28.6M | case JUMP_MAX_UNTIL_2: | 1637 | 28.6M | TRACE(("|%p|%p|JUMP_MAX_UNTIL_2\n", pattern, ptr)); | 1638 | 28.6M | goto jump_max_until_2; | 1639 | 11.2M | case JUMP_MAX_UNTIL_3: | 1640 | 11.2M | TRACE(("|%p|%p|JUMP_MAX_UNTIL_3\n", pattern, ptr)); | 1641 | 11.2M | goto jump_max_until_3; | 1642 | 0 | case JUMP_MIN_UNTIL_2: | 1643 | 0 | TRACE(("|%p|%p|JUMP_MIN_UNTIL_2\n", pattern, ptr)); | 1644 | 0 | goto jump_min_until_2; | 1645 | 0 | case JUMP_MIN_UNTIL_3: | 1646 | 0 | TRACE(("|%p|%p|JUMP_MIN_UNTIL_3\n", pattern, ptr)); | 1647 | 0 | goto jump_min_until_3; | 1648 | 21.2M | case JUMP_BRANCH: | 1649 | 21.2M | TRACE(("|%p|%p|JUMP_BRANCH\n", pattern, ptr)); | 1650 | 21.2M | goto jump_branch; | 1651 | 0 | case JUMP_MAX_UNTIL_1: | 1652 | 0 | TRACE(("|%p|%p|JUMP_MAX_UNTIL_1\n", pattern, ptr)); | 1653 | 0 | goto jump_max_until_1; | 1654 | 0 | case JUMP_MIN_UNTIL_1: | 1655 | 0 | TRACE(("|%p|%p|JUMP_MIN_UNTIL_1\n", pattern, ptr)); | 1656 | 0 | goto jump_min_until_1; | 1657 | 0 | case JUMP_POSS_REPEAT_1: | 1658 | 0 | TRACE(("|%p|%p|JUMP_POSS_REPEAT_1\n", pattern, ptr)); | 1659 | 0 | goto jump_poss_repeat_1; | 1660 | 0 | case JUMP_POSS_REPEAT_2: | 1661 | 0 | TRACE(("|%p|%p|JUMP_POSS_REPEAT_2\n", pattern, ptr)); | 1662 | 0 | goto jump_poss_repeat_2; | 1663 | 11.1M | case JUMP_REPEAT: | 1664 | 11.1M | TRACE(("|%p|%p|JUMP_REPEAT\n", pattern, ptr)); | 1665 | 11.1M | goto jump_repeat; | 1666 | 3.50M | case JUMP_REPEAT_ONE_1: | 1667 | 3.50M | TRACE(("|%p|%p|JUMP_REPEAT_ONE_1\n", pattern, ptr)); | 1668 | 3.50M | goto jump_repeat_one_1; | 1669 | 32.0M | case JUMP_REPEAT_ONE_2: | 1670 | 32.0M | TRACE(("|%p|%p|JUMP_REPEAT_ONE_2\n", pattern, ptr)); | 1671 | 32.0M | goto jump_repeat_one_2; | 1672 | 0 | case JUMP_MIN_REPEAT_ONE: | 1673 | 0 | TRACE(("|%p|%p|JUMP_MIN_REPEAT_ONE\n", pattern, ptr)); | 1674 | 0 | goto jump_min_repeat_one; | 1675 | 0 | case JUMP_ATOMIC_GROUP: | 1676 | 0 | TRACE(("|%p|%p|JUMP_ATOMIC_GROUP\n", pattern, ptr)); | 1677 | 0 | goto jump_atomic_group; | 1678 | 9.63M | case JUMP_ASSERT: | 1679 | 9.63M | TRACE(("|%p|%p|JUMP_ASSERT\n", pattern, ptr)); | 1680 | 9.63M | goto jump_assert; | 1681 | 9.03M | case JUMP_ASSERT_NOT: | 1682 | 9.03M | TRACE(("|%p|%p|JUMP_ASSERT_NOT\n", pattern, ptr)); | 1683 | 9.03M | goto jump_assert_not; | 1684 | 0 | case JUMP_NONE: | 1685 | 0 | TRACE(("|%p|%p|RETURN %zd\n", pattern, | 1686 | 0 | ptr, ret)); | 1687 | 0 | break; | 1688 | 126M | } | 1689 | | | 1690 | 0 | return ret; /* should never get here */ | 1691 | 126M | } |
Line | Count | Source | 608 | 59.1M | { | 609 | 59.1M | const SRE_CHAR* end = (const SRE_CHAR *)state->end; | 610 | 59.1M | Py_ssize_t alloc_pos, ctx_pos = -1; | 611 | 59.1M | Py_ssize_t ret = 0; | 612 | 59.1M | int jump; | 613 | 59.1M | unsigned int sigcount = state->sigcount; | 614 | | | 615 | 59.1M | SRE(match_context)* ctx; | 616 | 59.1M | SRE(match_context)* nextctx; | 617 | 59.1M | INIT_TRACE(state); | 618 | | | 619 | 59.1M | TRACE(("|%p|%p|ENTER\n", pattern, state->ptr)); | 620 | | | 621 | 59.1M | DATA_ALLOC(SRE(match_context), ctx); | 622 | 59.1M | ctx->last_ctx_pos = -1; | 623 | 59.1M | ctx->jump = JUMP_NONE; | 624 | 59.1M | ctx->toplevel = toplevel; | 625 | 59.1M | ctx_pos = alloc_pos; | 626 | | | 627 | 59.1M | #if USE_COMPUTED_GOTOS | 628 | 59.1M | #include "sre_targets.h" | 629 | 59.1M | #endif | 630 | | | 631 | 227M | entrance: | 632 | | | 633 | 227M | ; // Fashion statement. | 634 | 227M | const SRE_CHAR *ptr = (SRE_CHAR *)state->ptr; | 635 | | | 636 | 227M | if (pattern[0] == SRE_OP_INFO) { | 637 | | /* optimization info block */ | 638 | | /* <INFO> <1=skip> <2=flags> <3=min> ... */ | 639 | 9.11M | if (pattern[3] && (uintptr_t)(end - ptr) < pattern[3]) { | 640 | 452 | TRACE(("reject (got %tu chars, need %zu)\n", | 641 | 452 | end - ptr, (size_t) pattern[3])); | 642 | 452 | RETURN_FAILURE; | 643 | 452 | } | 644 | 9.11M | pattern += pattern[1] + 1; | 645 | 9.11M | } | 646 | | | 647 | 227M | #if USE_COMPUTED_GOTOS | 648 | 227M | DISPATCH; | 649 | | #else | 650 | | dispatch: | 651 | | MAYBE_CHECK_SIGNALS; | 652 | | switch (*pattern++) | 653 | | #endif | 654 | 227M | { | 655 | | | 656 | 227M | TARGET(SRE_OP_MARK): | 657 | | /* set mark */ | 658 | | /* <MARK> <gid> */ | 659 | 66.5M | TRACE(("|%p|%p|MARK %d\n", pattern, | 660 | 66.5M | ptr, pattern[0])); | 661 | 66.5M | { | 662 | 66.5M | int i = pattern[0]; | 663 | 66.5M | if (i & 1) | 664 | 13.4M | state->lastindex = i/2 + 1; | 665 | 66.5M | if (i > state->lastmark) { | 666 | | /* state->lastmark is the highest valid index in the | 667 | | state->mark array. If it is increased by more than 1, | 668 | | the intervening marks must be set to NULL to signal | 669 | | that these marks have not been encountered. */ | 670 | 64.2M | int j = state->lastmark + 1; | 671 | 66.5M | while (j < i) | 672 | 2.28M | state->mark[j++] = NULL; | 673 | 64.2M | state->lastmark = i; | 674 | 64.2M | } | 675 | 66.5M | state->mark[i] = ptr; | 676 | 66.5M | } | 677 | 66.5M | pattern++; | 678 | 66.5M | DISPATCH; | 679 | | | 680 | 66.5M | TARGET(SRE_OP_LITERAL): | 681 | | /* match literal string */ | 682 | | /* <LITERAL> <code> */ | 683 | 24.4M | TRACE(("|%p|%p|LITERAL %d\n", pattern, | 684 | 24.4M | ptr, *pattern)); | 685 | 24.4M | if (ptr >= end || (SRE_CODE) ptr[0] != pattern[0]) | 686 | 7.40M | RETURN_FAILURE; | 687 | 17.0M | pattern++; | 688 | 17.0M | ptr++; | 689 | 17.0M | DISPATCH; | 690 | | | 691 | 17.0M | TARGET(SRE_OP_NOT_LITERAL): | 692 | | /* match anything that is not literal character */ | 693 | | /* <NOT_LITERAL> <code> */ | 694 | 0 | TRACE(("|%p|%p|NOT_LITERAL %d\n", pattern, | 695 | 0 | ptr, *pattern)); | 696 | 0 | if (ptr >= end || (SRE_CODE) ptr[0] == pattern[0]) | 697 | 0 | RETURN_FAILURE; | 698 | 0 | pattern++; | 699 | 0 | ptr++; | 700 | 0 | DISPATCH; | 701 | | | 702 | 28.1M | TARGET(SRE_OP_SUCCESS): | 703 | | /* end of pattern */ | 704 | 28.1M | TRACE(("|%p|%p|SUCCESS\n", pattern, ptr)); | 705 | 28.1M | if (ctx->toplevel && | 706 | 7.03M | ((state->match_all && ptr != state->end) || | 707 | 7.03M | (state->must_advance && ptr == state->start))) | 708 | 0 | { | 709 | 0 | RETURN_FAILURE; | 710 | 0 | } | 711 | 28.1M | state->ptr = ptr; | 712 | 28.1M | RETURN_SUCCESS; | 713 | | | 714 | 1.72M | TARGET(SRE_OP_AT): | 715 | | /* match at given position */ | 716 | | /* <AT> <code> */ | 717 | 1.72M | TRACE(("|%p|%p|AT %d\n", pattern, ptr, *pattern)); | 718 | 1.72M | if (!SRE(at)(state, ptr, *pattern)) | 719 | 1.71M | RETURN_FAILURE; | 720 | 3.89k | pattern++; | 721 | 3.89k | DISPATCH; | 722 | | | 723 | 3.89k | TARGET(SRE_OP_CATEGORY): | 724 | | /* match at given category */ | 725 | | /* <CATEGORY> <code> */ | 726 | 0 | TRACE(("|%p|%p|CATEGORY %d\n", pattern, | 727 | 0 | ptr, *pattern)); | 728 | 0 | if (ptr >= end || !sre_category(pattern[0], ptr[0])) | 729 | 0 | RETURN_FAILURE; | 730 | 0 | pattern++; | 731 | 0 | ptr++; | 732 | 0 | DISPATCH; | 733 | | | 734 | 0 | TARGET(SRE_OP_ANY): | 735 | | /* match anything (except a newline) */ | 736 | | /* <ANY> */ | 737 | 0 | TRACE(("|%p|%p|ANY\n", pattern, ptr)); | 738 | 0 | if (ptr >= end || SRE_IS_LINEBREAK(ptr[0])) | 739 | 0 | RETURN_FAILURE; | 740 | 0 | ptr++; | 741 | 0 | DISPATCH; | 742 | | | 743 | 0 | TARGET(SRE_OP_ANY_ALL): | 744 | | /* match anything */ | 745 | | /* <ANY_ALL> */ | 746 | 0 | TRACE(("|%p|%p|ANY_ALL\n", pattern, ptr)); | 747 | 0 | if (ptr >= end) | 748 | 0 | RETURN_FAILURE; | 749 | 0 | ptr++; | 750 | 0 | DISPATCH; | 751 | | | 752 | 50.3M | TARGET(SRE_OP_IN): | 753 | | /* match set member (or non_member) */ | 754 | | /* <IN> <skip> <set> */ | 755 | 50.3M | TRACE(("|%p|%p|IN\n", pattern, ptr)); | 756 | 50.3M | if (ptr >= end || | 757 | 50.3M | !SRE(charset)(state, pattern + 1, *ptr)) | 758 | 8.92M | RETURN_FAILURE; | 759 | 41.4M | pattern += pattern[0]; | 760 | 41.4M | ptr++; | 761 | 41.4M | DISPATCH; | 762 | | | 763 | 41.4M | TARGET(SRE_OP_LITERAL_IGNORE): | 764 | 2.86M | TRACE(("|%p|%p|LITERAL_IGNORE %d\n", | 765 | 2.86M | pattern, ptr, pattern[0])); | 766 | 2.86M | if (ptr >= end || | 767 | 2.86M | sre_lower_ascii(*ptr) != *pattern) | 768 | 34.5k | RETURN_FAILURE; | 769 | 2.82M | pattern++; | 770 | 2.82M | ptr++; | 771 | 2.82M | DISPATCH; | 772 | | | 773 | 2.82M | TARGET(SRE_OP_LITERAL_UNI_IGNORE): | 774 | 0 | TRACE(("|%p|%p|LITERAL_UNI_IGNORE %d\n", | 775 | 0 | pattern, ptr, pattern[0])); | 776 | 0 | if (ptr >= end || | 777 | 0 | sre_lower_unicode(*ptr) != *pattern) | 778 | 0 | RETURN_FAILURE; | 779 | 0 | pattern++; | 780 | 0 | ptr++; | 781 | 0 | DISPATCH; | 782 | | | 783 | 0 | TARGET(SRE_OP_LITERAL_LOC_IGNORE): | 784 | 0 | TRACE(("|%p|%p|LITERAL_LOC_IGNORE %d\n", | 785 | 0 | pattern, ptr, pattern[0])); | 786 | 0 | if (ptr >= end | 787 | 0 | || !char_loc_ignore(*pattern, *ptr)) | 788 | 0 | RETURN_FAILURE; | 789 | 0 | pattern++; | 790 | 0 | ptr++; | 791 | 0 | DISPATCH; | 792 | | | 793 | 0 | TARGET(SRE_OP_NOT_LITERAL_IGNORE): | 794 | 0 | TRACE(("|%p|%p|NOT_LITERAL_IGNORE %d\n", | 795 | 0 | pattern, ptr, *pattern)); | 796 | 0 | if (ptr >= end || | 797 | 0 | sre_lower_ascii(*ptr) == *pattern) | 798 | 0 | RETURN_FAILURE; | 799 | 0 | pattern++; | 800 | 0 | ptr++; | 801 | 0 | DISPATCH; | 802 | | | 803 | 0 | TARGET(SRE_OP_NOT_LITERAL_UNI_IGNORE): | 804 | 0 | TRACE(("|%p|%p|NOT_LITERAL_UNI_IGNORE %d\n", | 805 | 0 | pattern, ptr, *pattern)); | 806 | 0 | if (ptr >= end || | 807 | 0 | sre_lower_unicode(*ptr) == *pattern) | 808 | 0 | RETURN_FAILURE; | 809 | 0 | pattern++; | 810 | 0 | ptr++; | 811 | 0 | DISPATCH; | 812 | | | 813 | 0 | TARGET(SRE_OP_NOT_LITERAL_LOC_IGNORE): | 814 | 0 | TRACE(("|%p|%p|NOT_LITERAL_LOC_IGNORE %d\n", | 815 | 0 | pattern, ptr, *pattern)); | 816 | 0 | if (ptr >= end | 817 | 0 | || char_loc_ignore(*pattern, *ptr)) | 818 | 0 | RETURN_FAILURE; | 819 | 0 | pattern++; | 820 | 0 | ptr++; | 821 | 0 | DISPATCH; | 822 | | | 823 | 0 | TARGET(SRE_OP_IN_IGNORE): | 824 | 0 | TRACE(("|%p|%p|IN_IGNORE\n", pattern, ptr)); | 825 | 0 | if (ptr >= end | 826 | 0 | || !SRE(charset)(state, pattern+1, | 827 | 0 | (SRE_CODE)sre_lower_ascii(*ptr))) | 828 | 0 | RETURN_FAILURE; | 829 | 0 | pattern += pattern[0]; | 830 | 0 | ptr++; | 831 | 0 | DISPATCH; | 832 | | | 833 | 0 | TARGET(SRE_OP_IN_UNI_IGNORE): | 834 | 0 | TRACE(("|%p|%p|IN_UNI_IGNORE\n", pattern, ptr)); | 835 | 0 | if (ptr >= end | 836 | 0 | || !SRE(charset)(state, pattern+1, | 837 | 0 | (SRE_CODE)sre_lower_unicode(*ptr))) | 838 | 0 | RETURN_FAILURE; | 839 | 0 | pattern += pattern[0]; | 840 | 0 | ptr++; | 841 | 0 | DISPATCH; | 842 | | | 843 | 0 | TARGET(SRE_OP_IN_LOC_IGNORE): | 844 | 0 | TRACE(("|%p|%p|IN_LOC_IGNORE\n", pattern, ptr)); | 845 | 0 | if (ptr >= end | 846 | 0 | || !SRE(charset_loc_ignore)(state, pattern+1, *ptr)) | 847 | 0 | RETURN_FAILURE; | 848 | 0 | pattern += pattern[0]; | 849 | 0 | ptr++; | 850 | 0 | DISPATCH; | 851 | | | 852 | 25.1M | TARGET(SRE_OP_JUMP): | 853 | 25.1M | TARGET(SRE_OP_INFO): | 854 | | /* jump forward */ | 855 | | /* <JUMP> <offset> */ | 856 | 25.1M | TRACE(("|%p|%p|JUMP %d\n", pattern, | 857 | 25.1M | ptr, pattern[0])); | 858 | 25.1M | pattern += pattern[0]; | 859 | 25.1M | DISPATCH; | 860 | | | 861 | 30.2M | TARGET(SRE_OP_BRANCH): | 862 | | /* alternation */ | 863 | | /* <BRANCH> <0=skip> code <JUMP> ... <NULL> */ | 864 | 30.2M | TRACE(("|%p|%p|BRANCH\n", pattern, ptr)); | 865 | 30.2M | LASTMARK_SAVE(); | 866 | 30.2M | if (state->save_marks) | 867 | 27.2M | MARK_PUSH(ctx->lastmark); | 868 | 64.6M | for (; pattern[0]; pattern += pattern[0]) { | 869 | 59.0M | if (pattern[1] == SRE_OP_LITERAL && | 870 | 30.0M | (ptr >= end || | 871 | 30.0M | (SRE_CODE) *ptr != pattern[2])) | 872 | 22.0M | continue; | 873 | 37.0M | if (pattern[1] == SRE_OP_IN && | 874 | 21.2M | (ptr >= end || | 875 | 21.2M | !SRE(charset)(state, pattern + 3, | 876 | 21.2M | (SRE_CODE) *ptr))) | 877 | 11.6M | continue; | 878 | 25.3M | state->ptr = ptr; | 879 | 25.3M | DO_JUMP(JUMP_BRANCH, jump_branch, pattern+1); | 880 | 25.3M | if (ret) { | 881 | 24.5M | if (state->save_marks) | 882 | 22.2M | MARK_POP_DISCARD(ctx->lastmark); | 883 | 24.5M | RETURN_ON_ERROR(ret); | 884 | 24.5M | RETURN_SUCCESS; | 885 | 24.5M | } | 886 | 771k | if (state->save_marks) | 887 | 7.82k | MARK_POP_KEEP(ctx->lastmark); | 888 | 771k | LASTMARK_RESTORE(); | 889 | 771k | } | 890 | 5.63M | if (state->save_marks) | 891 | 5.06M | MARK_POP_DISCARD(ctx->lastmark); | 892 | 5.63M | RETURN_FAILURE; | 893 | | | 894 | 87.1M | TARGET(SRE_OP_REPEAT_ONE): | 895 | | /* match repeated sequence (maximizing regexp) */ | 896 | | | 897 | | /* this operator only works if the repeated item is | 898 | | exactly one character wide, and we're not already | 899 | | collecting backtracking points. for other cases, | 900 | | use the MAX_REPEAT operator */ | 901 | | | 902 | | /* <REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> tail */ | 903 | | | 904 | 87.1M | TRACE(("|%p|%p|REPEAT_ONE %d %d\n", pattern, ptr, | 905 | 87.1M | pattern[1], pattern[2])); | 906 | | | 907 | 87.1M | if ((Py_ssize_t) pattern[1] > end - ptr) | 908 | 10.1k | RETURN_FAILURE; /* cannot match */ | 909 | | | 910 | 87.1M | state->ptr = ptr; | 911 | | | 912 | 87.1M | ret = SRE(count)(state, pattern+3, pattern[2]); | 913 | 87.1M | RETURN_ON_ERROR(ret); | 914 | 87.1M | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); | 915 | 87.1M | ctx->count = ret; | 916 | 87.1M | ptr += ctx->count; | 917 | | | 918 | | /* when we arrive here, count contains the number of | 919 | | matches, and ptr points to the tail of the target | 920 | | string. check if the rest of the pattern matches, | 921 | | and backtrack if not. */ | 922 | | | 923 | 87.1M | if (ctx->count < (Py_ssize_t) pattern[1]) | 924 | 38.1M | RETURN_FAILURE; | 925 | | | 926 | 48.9M | if (pattern[pattern[0]] == SRE_OP_SUCCESS && | 927 | 1.30M | ptr == state->end && | 928 | 6.48k | !(ctx->toplevel && state->must_advance && ptr == state->start)) | 929 | 6.48k | { | 930 | | /* tail is empty. we're finished */ | 931 | 6.48k | state->ptr = ptr; | 932 | 6.48k | RETURN_SUCCESS; | 933 | 6.48k | } | 934 | | | 935 | 48.9M | LASTMARK_SAVE(); | 936 | 48.9M | if (state->save_marks) | 937 | 36.2M | MARK_PUSH(ctx->lastmark); | 938 | | | 939 | 48.9M | if (pattern[pattern[0]] == SRE_OP_LITERAL) { | 940 | | /* tail starts with a literal. skip positions where | 941 | | the rest of the pattern cannot possibly match */ | 942 | 11.1M | ctx->u.chr = pattern[pattern[0]+1]; | 943 | 11.1M | for (;;) { | 944 | 30.4M | while (ctx->count >= (Py_ssize_t) pattern[1] && | 945 | 25.7M | (ptr >= end || *ptr != ctx->u.chr)) { | 946 | 19.3M | ptr--; | 947 | 19.3M | ctx->count--; | 948 | 19.3M | } | 949 | 11.1M | if (ctx->count < (Py_ssize_t) pattern[1]) | 950 | 4.78M | break; | 951 | 6.39M | state->ptr = ptr; | 952 | 6.39M | DO_JUMP(JUMP_REPEAT_ONE_1, jump_repeat_one_1, | 953 | 6.39M | pattern+pattern[0]); | 954 | 6.39M | if (ret) { | 955 | 6.39M | if (state->save_marks) | 956 | 6.39M | MARK_POP_DISCARD(ctx->lastmark); | 957 | 6.39M | RETURN_ON_ERROR(ret); | 958 | 6.39M | RETURN_SUCCESS; | 959 | 6.39M | } | 960 | 304 | if (state->save_marks) | 961 | 304 | MARK_POP_KEEP(ctx->lastmark); | 962 | 304 | LASTMARK_RESTORE(); | 963 | | | 964 | 304 | ptr--; | 965 | 304 | ctx->count--; | 966 | 304 | } | 967 | 4.78M | if (state->save_marks) | 968 | 4.78M | MARK_POP_DISCARD(ctx->lastmark); | 969 | 37.7M | } else { | 970 | | /* general case */ | 971 | 38.5M | while (ctx->count >= (Py_ssize_t) pattern[1]) { | 972 | 38.5M | state->ptr = ptr; | 973 | 38.5M | DO_JUMP(JUMP_REPEAT_ONE_2, jump_repeat_one_2, | 974 | 38.5M | pattern+pattern[0]); | 975 | 38.5M | if (ret) { | 976 | 37.7M | if (state->save_marks) | 977 | 25.0M | MARK_POP_DISCARD(ctx->lastmark); | 978 | 37.7M | RETURN_ON_ERROR(ret); | 979 | 37.7M | RETURN_SUCCESS; | 980 | 37.7M | } | 981 | 804k | if (state->save_marks) | 982 | 69.3k | MARK_POP_KEEP(ctx->lastmark); | 983 | 804k | LASTMARK_RESTORE(); | 984 | | | 985 | 804k | ptr--; | 986 | 804k | ctx->count--; | 987 | 804k | } | 988 | 35.2k | if (state->save_marks) | 989 | 34.8k | MARK_POP_DISCARD(ctx->lastmark); | 990 | 35.2k | } | 991 | 4.81M | RETURN_FAILURE; | 992 | | | 993 | 0 | TARGET(SRE_OP_MIN_REPEAT_ONE): | 994 | | /* match repeated sequence (minimizing regexp) */ | 995 | | | 996 | | /* this operator only works if the repeated item is | 997 | | exactly one character wide, and we're not already | 998 | | collecting backtracking points. for other cases, | 999 | | use the MIN_REPEAT operator */ | 1000 | | | 1001 | | /* <MIN_REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> tail */ | 1002 | |
| 1003 | 0 | TRACE(("|%p|%p|MIN_REPEAT_ONE %d %d\n", pattern, ptr, | 1004 | 0 | pattern[1], pattern[2])); | 1005 | |
| 1006 | 0 | if ((Py_ssize_t) pattern[1] > end - ptr) | 1007 | 0 | RETURN_FAILURE; /* cannot match */ | 1008 | | | 1009 | 0 | state->ptr = ptr; | 1010 | |
| 1011 | 0 | if (pattern[1] == 0) | 1012 | 0 | ctx->count = 0; | 1013 | 0 | else { | 1014 | | /* count using pattern min as the maximum */ | 1015 | 0 | ret = SRE(count)(state, pattern+3, pattern[1]); | 1016 | 0 | RETURN_ON_ERROR(ret); | 1017 | 0 | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); | 1018 | 0 | if (ret < (Py_ssize_t) pattern[1]) | 1019 | | /* didn't match minimum number of times */ | 1020 | 0 | RETURN_FAILURE; | 1021 | | /* advance past minimum matches of repeat */ | 1022 | 0 | ctx->count = ret; | 1023 | 0 | ptr += ctx->count; | 1024 | 0 | } | 1025 | | | 1026 | 0 | if (pattern[pattern[0]] == SRE_OP_SUCCESS && | 1027 | 0 | !(ctx->toplevel && | 1028 | 0 | ((state->match_all && ptr != state->end) || | 1029 | 0 | (state->must_advance && ptr == state->start)))) | 1030 | 0 | { | 1031 | | /* tail is empty. we're finished */ | 1032 | 0 | state->ptr = ptr; | 1033 | 0 | RETURN_SUCCESS; | 1034 | |
| 1035 | 0 | } else { | 1036 | | /* general case */ | 1037 | 0 | LASTMARK_SAVE(); | 1038 | 0 | if (state->save_marks) | 1039 | 0 | MARK_PUSH(ctx->lastmark); | 1040 | | | 1041 | 0 | while ((Py_ssize_t)pattern[2] == SRE_MAXREPEAT | 1042 | 0 | || ctx->count <= (Py_ssize_t)pattern[2]) { | 1043 | 0 | state->ptr = ptr; | 1044 | 0 | DO_JUMP(JUMP_MIN_REPEAT_ONE,jump_min_repeat_one, | 1045 | 0 | pattern+pattern[0]); | 1046 | 0 | if (ret) { | 1047 | 0 | if (state->save_marks) | 1048 | 0 | MARK_POP_DISCARD(ctx->lastmark); | 1049 | 0 | RETURN_ON_ERROR(ret); | 1050 | 0 | RETURN_SUCCESS; | 1051 | 0 | } | 1052 | 0 | if (state->save_marks) | 1053 | 0 | MARK_POP_KEEP(ctx->lastmark); | 1054 | 0 | LASTMARK_RESTORE(); | 1055 | |
| 1056 | 0 | state->ptr = ptr; | 1057 | 0 | ret = SRE(count)(state, pattern+3, 1); | 1058 | 0 | RETURN_ON_ERROR(ret); | 1059 | 0 | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); | 1060 | 0 | if (ret == 0) | 1061 | 0 | break; | 1062 | 0 | assert(ret == 1); | 1063 | 0 | ptr++; | 1064 | 0 | ctx->count++; | 1065 | 0 | } | 1066 | 0 | if (state->save_marks) | 1067 | 0 | MARK_POP_DISCARD(ctx->lastmark); | 1068 | 0 | } | 1069 | 0 | RETURN_FAILURE; | 1070 | | | 1071 | 0 | TARGET(SRE_OP_POSSESSIVE_REPEAT_ONE): | 1072 | | /* match repeated sequence (maximizing regexp) without | 1073 | | backtracking */ | 1074 | | | 1075 | | /* this operator only works if the repeated item is | 1076 | | exactly one character wide, and we're not already | 1077 | | collecting backtracking points. for other cases, | 1078 | | use the MAX_REPEAT operator */ | 1079 | | | 1080 | | /* <POSSESSIVE_REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> | 1081 | | tail */ | 1082 | |
| 1083 | 0 | TRACE(("|%p|%p|POSSESSIVE_REPEAT_ONE %d %d\n", pattern, | 1084 | 0 | ptr, pattern[1], pattern[2])); | 1085 | |
| 1086 | 0 | if (ptr + pattern[1] > end) { | 1087 | 0 | RETURN_FAILURE; /* cannot match */ | 1088 | 0 | } | 1089 | | | 1090 | 0 | state->ptr = ptr; | 1091 | |
| 1092 | 0 | ret = SRE(count)(state, pattern + 3, pattern[2]); | 1093 | 0 | RETURN_ON_ERROR(ret); | 1094 | 0 | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); | 1095 | 0 | ctx->count = ret; | 1096 | 0 | ptr += ctx->count; | 1097 | | | 1098 | | /* when we arrive here, count contains the number of | 1099 | | matches, and ptr points to the tail of the target | 1100 | | string. check if the rest of the pattern matches, | 1101 | | and fail if not. */ | 1102 | | | 1103 | | /* Test for not enough repetitions in match */ | 1104 | 0 | if (ctx->count < (Py_ssize_t) pattern[1]) { | 1105 | 0 | RETURN_FAILURE; | 1106 | 0 | } | 1107 | | | 1108 | | /* Update the pattern to point to the next op code */ | 1109 | 0 | pattern += pattern[0]; | 1110 | | | 1111 | | /* Let the tail be evaluated separately and consider this | 1112 | | match successful. */ | 1113 | 0 | if (*pattern == SRE_OP_SUCCESS && | 1114 | 0 | ptr == state->end && | 1115 | 0 | !(ctx->toplevel && state->must_advance && ptr == state->start)) | 1116 | 0 | { | 1117 | | /* tail is empty. we're finished */ | 1118 | 0 | state->ptr = ptr; | 1119 | 0 | RETURN_SUCCESS; | 1120 | 0 | } | 1121 | | | 1122 | | /* Attempt to match the rest of the string */ | 1123 | 0 | DISPATCH; | 1124 | | | 1125 | 16.7M | TARGET(SRE_OP_REPEAT): | 1126 | | /* create repeat context. all the hard work is done | 1127 | | by the UNTIL operator (MAX_UNTIL, MIN_UNTIL) */ | 1128 | | /* <REPEAT> <skip> <1=min> <2=max> | 1129 | | <3=repeat_index> item <UNTIL> tail */ | 1130 | 16.7M | TRACE(("|%p|%p|REPEAT %d %d\n", pattern, ptr, | 1131 | 16.7M | pattern[1], pattern[2])); | 1132 | | | 1133 | | /* install new repeat context */ | 1134 | 16.7M | ctx->u.rep = repeat_pool_malloc(state); | 1135 | 16.7M | if (!ctx->u.rep) { | 1136 | 0 | RETURN_ERROR(SRE_ERROR_MEMORY); | 1137 | 0 | } | 1138 | 16.7M | ctx->u.rep->count = -1; | 1139 | 16.7M | ctx->u.rep->pattern = pattern; | 1140 | 16.7M | ctx->u.rep->prev = state->repeat; | 1141 | 16.7M | ctx->u.rep->last_ptr = NULL; | 1142 | 16.7M | state->repeat = ctx->u.rep; | 1143 | 16.7M | state->save_marks++; | 1144 | | | 1145 | 16.7M | state->ptr = ptr; | 1146 | 16.7M | DO_JUMP(JUMP_REPEAT, jump_repeat, pattern+pattern[0]); | 1147 | 16.7M | state->repeat = ctx->u.rep->prev; | 1148 | 16.7M | state->save_marks--; | 1149 | 16.7M | repeat_pool_free(state, ctx->u.rep); | 1150 | | | 1151 | 16.7M | if (ret) { | 1152 | 16.7M | RETURN_ON_ERROR(ret); | 1153 | 16.7M | RETURN_SUCCESS; | 1154 | 16.7M | } | 1155 | 421 | RETURN_FAILURE; | 1156 | | | 1157 | 45.6M | TARGET(SRE_OP_MAX_UNTIL): | 1158 | | /* maximizing repeat */ | 1159 | | /* <REPEAT> <skip> <1=min> <2=max> item <MAX_UNTIL> tail */ | 1160 | | | 1161 | | /* FIXME: we probably need to deal with zero-width | 1162 | | matches in here... */ | 1163 | | | 1164 | 45.6M | ctx->u.rep = state->repeat; | 1165 | 45.6M | if (!ctx->u.rep) | 1166 | 0 | RETURN_ERROR(SRE_ERROR_STATE); | 1167 | | | 1168 | 45.6M | state->ptr = ptr; | 1169 | | | 1170 | 45.6M | ctx->count = ctx->u.rep->count+1; | 1171 | | | 1172 | 45.6M | TRACE(("|%p|%p|MAX_UNTIL %zd\n", pattern, | 1173 | 45.6M | ptr, ctx->count)); | 1174 | | | 1175 | 45.6M | if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) { | 1176 | | /* not enough matches */ | 1177 | 0 | ctx->u.rep->count = ctx->count; | 1178 | 0 | DO_JUMP(JUMP_MAX_UNTIL_1, jump_max_until_1, | 1179 | 0 | ctx->u.rep->pattern+3); | 1180 | 0 | if (ret) { | 1181 | 0 | RETURN_ON_ERROR(ret); | 1182 | 0 | RETURN_SUCCESS; | 1183 | 0 | } | 1184 | 0 | ctx->u.rep->count = ctx->count-1; | 1185 | 0 | state->ptr = ptr; | 1186 | 0 | RETURN_FAILURE; | 1187 | 0 | } | 1188 | | | 1189 | 45.6M | if ((ctx->count < (Py_ssize_t) ctx->u.rep->pattern[2] || | 1190 | 6.09M | ctx->u.rep->pattern[2] == SRE_MAXREPEAT) && | 1191 | 39.5M | state->ptr != ctx->u.rep->last_ptr) { | 1192 | | /* we may have enough matches, but if we can | 1193 | | match another item, do so */ | 1194 | 39.5M | ctx->u.rep->count = ctx->count; | 1195 | 39.5M | LASTMARK_SAVE(); | 1196 | 39.5M | MARK_PUSH(ctx->lastmark); | 1197 | | /* zero-width match protection */ | 1198 | 39.5M | LAST_PTR_PUSH(); | 1199 | 39.5M | ctx->u.rep->last_ptr = state->ptr; | 1200 | 39.5M | DO_JUMP(JUMP_MAX_UNTIL_2, jump_max_until_2, | 1201 | 39.5M | ctx->u.rep->pattern+3); | 1202 | 39.5M | LAST_PTR_POP(); | 1203 | 39.5M | if (ret) { | 1204 | 28.8M | MARK_POP_DISCARD(ctx->lastmark); | 1205 | 28.8M | RETURN_ON_ERROR(ret); | 1206 | 28.8M | RETURN_SUCCESS; | 1207 | 28.8M | } | 1208 | 10.6M | MARK_POP(ctx->lastmark); | 1209 | 10.6M | LASTMARK_RESTORE(); | 1210 | 10.6M | ctx->u.rep->count = ctx->count-1; | 1211 | 10.6M | state->ptr = ptr; | 1212 | 10.6M | } | 1213 | | | 1214 | | /* cannot match more repeated items here. make sure the | 1215 | | tail matches */ | 1216 | 16.7M | state->repeat = ctx->u.rep->prev; | 1217 | 16.7M | state->save_marks--; | 1218 | 16.7M | DO_JUMP(JUMP_MAX_UNTIL_3, jump_max_until_3, pattern); | 1219 | 16.7M | state->repeat = ctx->u.rep; // restore repeat before return | 1220 | 16.7M | state->save_marks++; | 1221 | | | 1222 | 16.7M | RETURN_ON_SUCCESS(ret); | 1223 | 34.9k | state->ptr = ptr; | 1224 | 34.9k | RETURN_FAILURE; | 1225 | | | 1226 | 0 | TARGET(SRE_OP_MIN_UNTIL): | 1227 | | /* minimizing repeat */ | 1228 | | /* <REPEAT> <skip> <1=min> <2=max> item <MIN_UNTIL> tail */ | 1229 | |
| 1230 | 0 | ctx->u.rep = state->repeat; | 1231 | 0 | if (!ctx->u.rep) | 1232 | 0 | RETURN_ERROR(SRE_ERROR_STATE); | 1233 | | | 1234 | 0 | state->ptr = ptr; | 1235 | |
| 1236 | 0 | ctx->count = ctx->u.rep->count+1; | 1237 | |
| 1238 | 0 | TRACE(("|%p|%p|MIN_UNTIL %zd %p\n", pattern, | 1239 | 0 | ptr, ctx->count, ctx->u.rep->pattern)); | 1240 | |
| 1241 | 0 | if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) { | 1242 | | /* not enough matches */ | 1243 | 0 | ctx->u.rep->count = ctx->count; | 1244 | 0 | DO_JUMP(JUMP_MIN_UNTIL_1, jump_min_until_1, | 1245 | 0 | ctx->u.rep->pattern+3); | 1246 | 0 | if (ret) { | 1247 | 0 | RETURN_ON_ERROR(ret); | 1248 | 0 | RETURN_SUCCESS; | 1249 | 0 | } | 1250 | 0 | ctx->u.rep->count = ctx->count-1; | 1251 | 0 | state->ptr = ptr; | 1252 | 0 | RETURN_FAILURE; | 1253 | 0 | } | 1254 | | | 1255 | | /* see if the tail matches */ | 1256 | 0 | state->repeat = ctx->u.rep->prev; | 1257 | 0 | state->save_marks--; | 1258 | |
| 1259 | 0 | LASTMARK_SAVE(); | 1260 | 0 | if (state->save_marks) | 1261 | 0 | MARK_PUSH(ctx->lastmark); | 1262 | | | 1263 | 0 | DO_JUMP(JUMP_MIN_UNTIL_2, jump_min_until_2, pattern); | 1264 | | /* save_marks is balanced across the jump, so this equals the | 1265 | | value tested for MARK_PUSH above */ | 1266 | 0 | int pushed = state->save_marks != 0; | 1267 | 0 | state->repeat = ctx->u.rep; // restore repeat before return | 1268 | 0 | state->save_marks++; | 1269 | |
| 1270 | 0 | if (ret) { | 1271 | 0 | if (pushed) | 1272 | 0 | MARK_POP_DISCARD(ctx->lastmark); | 1273 | 0 | RETURN_ON_ERROR(ret); | 1274 | 0 | RETURN_SUCCESS; | 1275 | 0 | } | 1276 | 0 | if (pushed) | 1277 | 0 | MARK_POP(ctx->lastmark); | 1278 | 0 | LASTMARK_RESTORE(); | 1279 | |
| 1280 | 0 | state->ptr = ptr; | 1281 | |
| 1282 | 0 | if ((ctx->count >= (Py_ssize_t) ctx->u.rep->pattern[2] | 1283 | 0 | && ctx->u.rep->pattern[2] != SRE_MAXREPEAT) || | 1284 | 0 | state->ptr == ctx->u.rep->last_ptr) | 1285 | 0 | RETURN_FAILURE; | 1286 | | | 1287 | 0 | ctx->u.rep->count = ctx->count; | 1288 | | /* zero-width match protection */ | 1289 | 0 | LAST_PTR_PUSH(); | 1290 | 0 | ctx->u.rep->last_ptr = state->ptr; | 1291 | 0 | DO_JUMP(JUMP_MIN_UNTIL_3,jump_min_until_3, | 1292 | 0 | ctx->u.rep->pattern+3); | 1293 | 0 | LAST_PTR_POP(); | 1294 | 0 | if (ret) { | 1295 | 0 | RETURN_ON_ERROR(ret); | 1296 | 0 | RETURN_SUCCESS; | 1297 | 0 | } | 1298 | 0 | ctx->u.rep->count = ctx->count-1; | 1299 | 0 | state->ptr = ptr; | 1300 | 0 | RETURN_FAILURE; | 1301 | | | 1302 | 0 | TARGET(SRE_OP_POSSESSIVE_REPEAT): | 1303 | | /* create possessive repeat contexts. */ | 1304 | | /* <POSSESSIVE_REPEAT> <skip> <1=min> <2=max> pattern | 1305 | | <SUCCESS> tail */ | 1306 | 0 | TRACE(("|%p|%p|POSSESSIVE_REPEAT %d %d\n", pattern, | 1307 | 0 | ptr, pattern[1], pattern[2])); | 1308 | | | 1309 | | /* Set the global Input pointer to this context's Input | 1310 | | pointer */ | 1311 | 0 | state->ptr = ptr; | 1312 | | | 1313 | | /* Capture groups in the body can be revisited on backtracking | 1314 | | between iterations, so their marks must be saved and restored, | 1315 | | as is done inside a repeat. */ | 1316 | 0 | state->save_marks++; | 1317 | | | 1318 | | /* Initialize Count to 0 */ | 1319 | 0 | ctx->count = 0; | 1320 | | | 1321 | | /* Check for minimum required matches. */ | 1322 | 0 | while (ctx->count < (Py_ssize_t)pattern[1]) { | 1323 | | /* not enough matches */ | 1324 | 0 | DO_JUMP0(JUMP_POSS_REPEAT_1, jump_poss_repeat_1, | 1325 | 0 | &pattern[3]); | 1326 | 0 | if (ret) { | 1327 | 0 | RETURN_ON_ERROR(ret); | 1328 | 0 | ctx->count++; | 1329 | 0 | } | 1330 | 0 | else { | 1331 | 0 | state->ptr = ptr; | 1332 | 0 | state->save_marks--; | 1333 | 0 | RETURN_FAILURE; | 1334 | 0 | } | 1335 | 0 | } | 1336 | | | 1337 | | /* Clear the context's Input stream pointer so that it | 1338 | | doesn't match the global state so that the while loop can | 1339 | | be entered. */ | 1340 | 0 | ptr = NULL; | 1341 | | | 1342 | | /* Keep trying to parse the <pattern> sub-pattern until the | 1343 | | end is reached, creating a new context each time. */ | 1344 | 0 | while ((ctx->count < (Py_ssize_t)pattern[2] || | 1345 | 0 | (Py_ssize_t)pattern[2] == SRE_MAXREPEAT) && | 1346 | 0 | state->ptr != ptr) { | 1347 | | /* Save the Capture Group Marker state into the current | 1348 | | Context and back up the current highest number | 1349 | | Capture Group marker. */ | 1350 | 0 | LASTMARK_SAVE(); | 1351 | 0 | MARK_PUSH(ctx->lastmark); | 1352 | | | 1353 | | /* zero-width match protection */ | 1354 | | /* Set the context's Input Stream pointer to be the | 1355 | | current Input Stream pointer from the global | 1356 | | state. When the loop reaches the next iteration, | 1357 | | the context will then store the last known good | 1358 | | position with the global state holding the Input | 1359 | | Input Stream position that has been updated with | 1360 | | the most recent match. Thus, if state's Input | 1361 | | stream remains the same as the one stored in the | 1362 | | current Context, we know we have successfully | 1363 | | matched an empty string and that all subsequent | 1364 | | matches will also be the empty string until the | 1365 | | maximum number of matches are counted, and because | 1366 | | of this, we could immediately stop at that point and | 1367 | | consider this match successful. */ | 1368 | 0 | ptr = state->ptr; | 1369 | | | 1370 | | /* We have not reached the maximin matches, so try to | 1371 | | match once more. */ | 1372 | 0 | DO_JUMP0(JUMP_POSS_REPEAT_2, jump_poss_repeat_2, | 1373 | 0 | &pattern[3]); | 1374 | | | 1375 | | /* Check to see if the last attempted match | 1376 | | succeeded. */ | 1377 | 0 | if (ret) { | 1378 | | /* Drop the saved highest number Capture Group | 1379 | | marker saved above and use the newly updated | 1380 | | value. */ | 1381 | 0 | MARK_POP_DISCARD(ctx->lastmark); | 1382 | 0 | RETURN_ON_ERROR(ret); | 1383 | | | 1384 | | /* Success, increment the count. */ | 1385 | 0 | ctx->count++; | 1386 | 0 | } | 1387 | | /* Last attempted match failed. */ | 1388 | 0 | else { | 1389 | | /* Restore the previously saved highest number | 1390 | | Capture Group marker since the last iteration | 1391 | | did not match, then restore that to the global | 1392 | | state. */ | 1393 | 0 | MARK_POP(ctx->lastmark); | 1394 | 0 | LASTMARK_RESTORE(); | 1395 | | | 1396 | | /* Restore the global Input Stream pointer | 1397 | | since it can change after jumps. */ | 1398 | 0 | state->ptr = ptr; | 1399 | | | 1400 | | /* We have sufficient matches, so exit loop. */ | 1401 | 0 | break; | 1402 | 0 | } | 1403 | 0 | } | 1404 | | | 1405 | 0 | state->save_marks--; | 1406 | | | 1407 | | /* Evaluate Tail */ | 1408 | | /* Jump to end of pattern indicated by skip, and then skip | 1409 | | the SUCCESS op code that follows it. */ | 1410 | 0 | pattern += pattern[0] + 1; | 1411 | 0 | ptr = state->ptr; | 1412 | 0 | DISPATCH; | 1413 | | | 1414 | 0 | TARGET(SRE_OP_ATOMIC_GROUP): | 1415 | | /* Atomic Group Sub Pattern */ | 1416 | | /* <ATOMIC_GROUP> <skip> pattern <SUCCESS> tail */ | 1417 | 0 | TRACE(("|%p|%p|ATOMIC_GROUP\n", pattern, ptr)); | 1418 | | | 1419 | | /* Set the global Input pointer to this context's Input | 1420 | | pointer */ | 1421 | 0 | state->ptr = ptr; | 1422 | | | 1423 | | /* Evaluate the Atomic Group in a new context, terminating | 1424 | | when the end of the group, represented by a SUCCESS op | 1425 | | code, is reached. */ | 1426 | | /* Group Pattern begins at an offset of 1 code. */ | 1427 | 0 | DO_JUMP0(JUMP_ATOMIC_GROUP, jump_atomic_group, | 1428 | 0 | &pattern[1]); | 1429 | | | 1430 | | /* Test Exit Condition */ | 1431 | 0 | RETURN_ON_ERROR(ret); | 1432 | | | 1433 | 0 | if (ret == 0) { | 1434 | | /* Atomic Group failed to Match. */ | 1435 | 0 | state->ptr = ptr; | 1436 | 0 | RETURN_FAILURE; | 1437 | 0 | } | 1438 | | | 1439 | | /* Evaluate Tail */ | 1440 | | /* Jump to end of pattern indicated by skip, and then skip | 1441 | | the SUCCESS op code that follows it. */ | 1442 | 0 | pattern += pattern[0]; | 1443 | 0 | ptr = state->ptr; | 1444 | 0 | DISPATCH; | 1445 | | | 1446 | 0 | TARGET(SRE_OP_GROUPREF): | 1447 | | /* match backreference */ | 1448 | 0 | TRACE(("|%p|%p|GROUPREF %d\n", pattern, | 1449 | 0 | ptr, pattern[0])); | 1450 | 0 | { | 1451 | 0 | int groupref = pattern[0] * 2; | 1452 | 0 | if (groupref >= state->lastmark) { | 1453 | 0 | RETURN_FAILURE; | 1454 | 0 | } else { | 1455 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; | 1456 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; | 1457 | 0 | if (!p || !e || e < p) | 1458 | 0 | RETURN_FAILURE; | 1459 | 0 | while (p < e) { | 1460 | 0 | if (ptr >= end || *ptr != *p) | 1461 | 0 | RETURN_FAILURE; | 1462 | 0 | p++; | 1463 | 0 | ptr++; | 1464 | 0 | } | 1465 | 0 | } | 1466 | 0 | } | 1467 | 0 | pattern++; | 1468 | 0 | DISPATCH; | 1469 | | | 1470 | 0 | TARGET(SRE_OP_GROUPREF_IGNORE): | 1471 | | /* match backreference */ | 1472 | 0 | TRACE(("|%p|%p|GROUPREF_IGNORE %d\n", pattern, | 1473 | 0 | ptr, pattern[0])); | 1474 | 0 | { | 1475 | 0 | int groupref = pattern[0] * 2; | 1476 | 0 | if (groupref >= state->lastmark) { | 1477 | 0 | RETURN_FAILURE; | 1478 | 0 | } else { | 1479 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; | 1480 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; | 1481 | 0 | if (!p || !e || e < p) | 1482 | 0 | RETURN_FAILURE; | 1483 | 0 | while (p < e) { | 1484 | 0 | if (ptr >= end || | 1485 | 0 | sre_lower_ascii(*ptr) != sre_lower_ascii(*p)) | 1486 | 0 | RETURN_FAILURE; | 1487 | 0 | p++; | 1488 | 0 | ptr++; | 1489 | 0 | } | 1490 | 0 | } | 1491 | 0 | } | 1492 | 0 | pattern++; | 1493 | 0 | DISPATCH; | 1494 | | | 1495 | 0 | TARGET(SRE_OP_GROUPREF_UNI_IGNORE): | 1496 | | /* match backreference */ | 1497 | 0 | TRACE(("|%p|%p|GROUPREF_UNI_IGNORE %d\n", pattern, | 1498 | 0 | ptr, pattern[0])); | 1499 | 0 | { | 1500 | 0 | int groupref = pattern[0] * 2; | 1501 | 0 | if (groupref >= state->lastmark) { | 1502 | 0 | RETURN_FAILURE; | 1503 | 0 | } else { | 1504 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; | 1505 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; | 1506 | 0 | if (!p || !e || e < p) | 1507 | 0 | RETURN_FAILURE; | 1508 | 0 | while (p < e) { | 1509 | 0 | if (ptr >= end || | 1510 | 0 | sre_lower_unicode(*ptr) != sre_lower_unicode(*p)) | 1511 | 0 | RETURN_FAILURE; | 1512 | 0 | p++; | 1513 | 0 | ptr++; | 1514 | 0 | } | 1515 | 0 | } | 1516 | 0 | } | 1517 | 0 | pattern++; | 1518 | 0 | DISPATCH; | 1519 | | | 1520 | 0 | TARGET(SRE_OP_GROUPREF_LOC_IGNORE): | 1521 | | /* match backreference */ | 1522 | 0 | TRACE(("|%p|%p|GROUPREF_LOC_IGNORE %d\n", pattern, | 1523 | 0 | ptr, pattern[0])); | 1524 | 0 | { | 1525 | 0 | int groupref = pattern[0] * 2; | 1526 | 0 | if (groupref >= state->lastmark) { | 1527 | 0 | RETURN_FAILURE; | 1528 | 0 | } else { | 1529 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; | 1530 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; | 1531 | 0 | if (!p || !e || e < p) | 1532 | 0 | RETURN_FAILURE; | 1533 | 0 | while (p < e) { | 1534 | 0 | if (ptr >= end || | 1535 | 0 | sre_lower_locale(*ptr) != sre_lower_locale(*p)) | 1536 | 0 | RETURN_FAILURE; | 1537 | 0 | p++; | 1538 | 0 | ptr++; | 1539 | 0 | } | 1540 | 0 | } | 1541 | 0 | } | 1542 | 0 | pattern++; | 1543 | 0 | DISPATCH; | 1544 | | | 1545 | 0 | TARGET(SRE_OP_GROUPREF_EXISTS): | 1546 | 0 | TRACE(("|%p|%p|GROUPREF_EXISTS %d\n", pattern, | 1547 | 0 | ptr, pattern[0])); | 1548 | | /* <GROUPREF_EXISTS> <group> <skip> codeyes <JUMP> codeno ... */ | 1549 | 0 | { | 1550 | 0 | int groupref = pattern[0] * 2; | 1551 | 0 | if (groupref >= state->lastmark) { | 1552 | 0 | pattern += pattern[1]; | 1553 | 0 | DISPATCH; | 1554 | 0 | } else { | 1555 | 0 | SRE_CHAR* p = (SRE_CHAR*) state->mark[groupref]; | 1556 | 0 | SRE_CHAR* e = (SRE_CHAR*) state->mark[groupref+1]; | 1557 | 0 | if (!p || !e || e < p) { | 1558 | 0 | pattern += pattern[1]; | 1559 | 0 | DISPATCH; | 1560 | 0 | } | 1561 | 0 | } | 1562 | 0 | } | 1563 | 0 | pattern += 2; | 1564 | 0 | DISPATCH; | 1565 | | | 1566 | 12.7M | TARGET(SRE_OP_ASSERT): | 1567 | | /* assert subpattern */ | 1568 | | /* <ASSERT> <skip> <back> <pattern> */ | 1569 | 12.7M | TRACE(("|%p|%p|ASSERT %d\n", pattern, | 1570 | 12.7M | ptr, pattern[1])); | 1571 | 12.7M | if ((uintptr_t)(ptr - (SRE_CHAR *)state->beginning) < pattern[1]) | 1572 | 0 | RETURN_FAILURE; | 1573 | 12.7M | state->ptr = ptr - pattern[1]; | 1574 | 12.7M | DO_JUMP0(JUMP_ASSERT, jump_assert, pattern+2); | 1575 | 12.7M | RETURN_ON_FAILURE(ret); | 1576 | 11.1M | pattern += pattern[0]; | 1577 | 11.1M | DISPATCH; | 1578 | | | 1579 | 12.3M | TARGET(SRE_OP_ASSERT_NOT): | 1580 | | /* assert not subpattern */ | 1581 | | /* <ASSERT_NOT> <skip> <back> <pattern> */ | 1582 | 12.3M | TRACE(("|%p|%p|ASSERT_NOT %d\n", pattern, | 1583 | 12.3M | ptr, pattern[1])); | 1584 | 12.3M | if ((uintptr_t)(ptr - (SRE_CHAR *)state->beginning) >= pattern[1]) { | 1585 | 12.3M | state->ptr = ptr - pattern[1]; | 1586 | 12.3M | LASTMARK_SAVE(); | 1587 | 12.3M | if (state->save_marks) | 1588 | 12.3M | MARK_PUSH(ctx->lastmark); | 1589 | | | 1590 | 24.6M | DO_JUMP0(JUMP_ASSERT_NOT, jump_assert_not, pattern+2); | 1591 | 24.6M | if (ret) { | 1592 | 7.49k | if (state->save_marks) | 1593 | 7.49k | MARK_POP_DISCARD(ctx->lastmark); | 1594 | 7.49k | RETURN_ON_ERROR(ret); | 1595 | 7.49k | RETURN_FAILURE; | 1596 | 7.49k | } | 1597 | 12.3M | if (state->save_marks) | 1598 | 12.3M | MARK_POP(ctx->lastmark); | 1599 | 12.3M | LASTMARK_RESTORE(); | 1600 | 12.3M | } | 1601 | 12.3M | pattern += pattern[0]; | 1602 | 12.3M | DISPATCH; | 1603 | | | 1604 | 12.3M | TARGET(SRE_OP_FAILURE): | 1605 | | /* immediate failure */ | 1606 | 0 | TRACE(("|%p|%p|FAILURE\n", pattern, ptr)); | 1607 | 0 | RETURN_FAILURE; | 1608 | | | 1609 | | #if !USE_COMPUTED_GOTOS | 1610 | | default: | 1611 | | #endif | 1612 | | // Also any unused opcodes: | 1613 | 0 | TARGET(SRE_OP_RANGE_UNI_IGNORE): | 1614 | 0 | TARGET(SRE_OP_SUBPATTERN): | 1615 | 0 | TARGET(SRE_OP_RANGE): | 1616 | 0 | TARGET(SRE_OP_NEGATE): | 1617 | 0 | TARGET(SRE_OP_BIGCHARSET): | 1618 | 0 | TARGET(SRE_OP_CHARSET): | 1619 | 0 | TRACE(("|%p|%p|UNKNOWN %d\n", pattern, ptr, | 1620 | 0 | pattern[-1])); | 1621 | 0 | RETURN_ERROR(SRE_ERROR_ILLEGAL); | 1622 | |
| 1623 | 0 | } | 1624 | | | 1625 | 227M | exit: | 1626 | 227M | ctx_pos = ctx->last_ctx_pos; | 1627 | 227M | jump = ctx->jump; | 1628 | 227M | DATA_POP_DISCARD(ctx); | 1629 | 227M | if (ctx_pos == -1) { | 1630 | 59.1M | state->sigcount = sigcount; | 1631 | 59.1M | return ret; | 1632 | 59.1M | } | 1633 | 168M | DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos); | 1634 | | | 1635 | 168M | switch (jump) { | 1636 | 39.5M | case JUMP_MAX_UNTIL_2: | 1637 | 39.5M | TRACE(("|%p|%p|JUMP_MAX_UNTIL_2\n", pattern, ptr)); | 1638 | 39.5M | goto jump_max_until_2; | 1639 | 16.7M | case JUMP_MAX_UNTIL_3: | 1640 | 16.7M | TRACE(("|%p|%p|JUMP_MAX_UNTIL_3\n", pattern, ptr)); | 1641 | 16.7M | goto jump_max_until_3; | 1642 | 0 | case JUMP_MIN_UNTIL_2: | 1643 | 0 | TRACE(("|%p|%p|JUMP_MIN_UNTIL_2\n", pattern, ptr)); | 1644 | 0 | goto jump_min_until_2; | 1645 | 0 | case JUMP_MIN_UNTIL_3: | 1646 | 0 | TRACE(("|%p|%p|JUMP_MIN_UNTIL_3\n", pattern, ptr)); | 1647 | 0 | goto jump_min_until_3; | 1648 | 25.3M | case JUMP_BRANCH: | 1649 | 25.3M | TRACE(("|%p|%p|JUMP_BRANCH\n", pattern, ptr)); | 1650 | 25.3M | goto jump_branch; | 1651 | 0 | case JUMP_MAX_UNTIL_1: | 1652 | 0 | TRACE(("|%p|%p|JUMP_MAX_UNTIL_1\n", pattern, ptr)); | 1653 | 0 | goto jump_max_until_1; | 1654 | 0 | case JUMP_MIN_UNTIL_1: | 1655 | 0 | TRACE(("|%p|%p|JUMP_MIN_UNTIL_1\n", pattern, ptr)); | 1656 | 0 | goto jump_min_until_1; | 1657 | 0 | case JUMP_POSS_REPEAT_1: | 1658 | 0 | TRACE(("|%p|%p|JUMP_POSS_REPEAT_1\n", pattern, ptr)); | 1659 | 0 | goto jump_poss_repeat_1; | 1660 | 0 | case JUMP_POSS_REPEAT_2: | 1661 | 0 | TRACE(("|%p|%p|JUMP_POSS_REPEAT_2\n", pattern, ptr)); | 1662 | 0 | goto jump_poss_repeat_2; | 1663 | 16.7M | case JUMP_REPEAT: | 1664 | 16.7M | TRACE(("|%p|%p|JUMP_REPEAT\n", pattern, ptr)); | 1665 | 16.7M | goto jump_repeat; | 1666 | 6.39M | case JUMP_REPEAT_ONE_1: | 1667 | 6.39M | TRACE(("|%p|%p|JUMP_REPEAT_ONE_1\n", pattern, ptr)); | 1668 | 6.39M | goto jump_repeat_one_1; | 1669 | 38.5M | case JUMP_REPEAT_ONE_2: | 1670 | 38.5M | TRACE(("|%p|%p|JUMP_REPEAT_ONE_2\n", pattern, ptr)); | 1671 | 38.5M | goto jump_repeat_one_2; | 1672 | 0 | case JUMP_MIN_REPEAT_ONE: | 1673 | 0 | TRACE(("|%p|%p|JUMP_MIN_REPEAT_ONE\n", pattern, ptr)); | 1674 | 0 | goto jump_min_repeat_one; | 1675 | 0 | case JUMP_ATOMIC_GROUP: | 1676 | 0 | TRACE(("|%p|%p|JUMP_ATOMIC_GROUP\n", pattern, ptr)); | 1677 | 0 | goto jump_atomic_group; | 1678 | 12.7M | case JUMP_ASSERT: | 1679 | 12.7M | TRACE(("|%p|%p|JUMP_ASSERT\n", pattern, ptr)); | 1680 | 12.7M | goto jump_assert; | 1681 | 12.3M | case JUMP_ASSERT_NOT: | 1682 | 12.3M | TRACE(("|%p|%p|JUMP_ASSERT_NOT\n", pattern, ptr)); | 1683 | 12.3M | goto jump_assert_not; | 1684 | 0 | case JUMP_NONE: | 1685 | 0 | TRACE(("|%p|%p|RETURN %zd\n", pattern, | 1686 | 0 | ptr, ret)); | 1687 | 0 | break; | 1688 | 168M | } | 1689 | | | 1690 | 0 | return ret; /* should never get here */ | 1691 | 168M | } |
|
1692 | | |
1693 | | /* need to reset capturing groups between two SRE(match) callings in loops */ |
1694 | | #define RESET_CAPTURE_GROUP() \ |
1695 | 257M | do { state->lastmark = state->lastindex = -1; } while (0) |
1696 | | |
1697 | | LOCAL(Py_ssize_t) |
1698 | | SRE(search)(SRE_STATE* state, SRE_CODE* pattern) |
1699 | 124M | { |
1700 | 124M | SRE_CHAR* ptr = (SRE_CHAR *)state->start; |
1701 | 124M | SRE_CHAR* end = (SRE_CHAR *)state->end; |
1702 | 124M | Py_ssize_t status = 0; |
1703 | 124M | Py_ssize_t prefix_len = 0; |
1704 | 124M | Py_ssize_t prefix_skip = 0; |
1705 | 124M | SRE_CODE* prefix = NULL; |
1706 | 124M | SRE_CODE* charset = NULL; |
1707 | 124M | SRE_CODE* overlap = NULL; |
1708 | 124M | int flags = 0; |
1709 | 124M | INIT_TRACE(state); |
1710 | | |
1711 | 124M | if (ptr > end) |
1712 | 0 | return 0; |
1713 | | |
1714 | 124M | if (pattern[0] == SRE_OP_INFO) { |
1715 | | /* optimization info block */ |
1716 | | /* <INFO> <1=skip> <2=flags> <3=min> <4=max> <5=prefix info> */ |
1717 | | |
1718 | 124M | flags = pattern[2]; |
1719 | | |
1720 | 124M | if (pattern[3] && (uintptr_t)(end - ptr) < pattern[3]) { |
1721 | 3.76M | TRACE(("reject (got %tu chars, need %zu)\n", |
1722 | 3.76M | end - ptr, (size_t) pattern[3])); |
1723 | 3.76M | return 0; |
1724 | 3.76M | } |
1725 | 120M | if (pattern[3] > 1) { |
1726 | | /* adjust end point (but make sure we leave at least one |
1727 | | character in there, so literal search will work) */ |
1728 | 8.01M | end -= pattern[3] - 1; |
1729 | 8.01M | if (end <= ptr) |
1730 | 0 | end = ptr; |
1731 | 8.01M | } |
1732 | | |
1733 | 120M | if (flags & SRE_INFO_PREFIX) { |
1734 | | /* pattern starts with a known prefix */ |
1735 | | /* <length> <skip> <prefix data> <overlap data> */ |
1736 | 8.02M | prefix_len = pattern[5]; |
1737 | 8.02M | prefix_skip = pattern[6]; |
1738 | 8.02M | prefix = pattern + 7; |
1739 | 8.02M | overlap = prefix + prefix_len - 1; |
1740 | 112M | } else if (flags & SRE_INFO_CHARSET) |
1741 | | /* pattern starts with a character from a known set */ |
1742 | | /* <charset> */ |
1743 | 108M | charset = pattern + 5; |
1744 | | |
1745 | 120M | pattern += 1 + pattern[1]; |
1746 | 120M | } |
1747 | | |
1748 | 120M | TRACE(("prefix = %p %zd %zd\n", |
1749 | 120M | prefix, prefix_len, prefix_skip)); |
1750 | 120M | TRACE(("charset = %p\n", charset)); |
1751 | | |
1752 | 120M | if (prefix_len == 1) { |
1753 | | /* pattern starts with a literal character */ |
1754 | 7.17M | SRE_CHAR c = (SRE_CHAR) prefix[0]; |
1755 | | #if SIZEOF_SRE_CHAR < 4 |
1756 | 4.81M | if ((SRE_CODE) c != prefix[0]) |
1757 | 0 | return 0; /* literal can't match: doesn't fit in char width */ |
1758 | 4.81M | #endif |
1759 | 4.81M | end = (SRE_CHAR *)state->end; |
1760 | 4.81M | state->must_advance = 0; |
1761 | 8.02M | while (ptr < end) { |
1762 | 119M | while (*ptr != c) { |
1763 | 112M | if (++ptr >= end) |
1764 | 470k | return 0; |
1765 | 112M | } |
1766 | 7.40M | TRACE(("|%p|%p|SEARCH LITERAL\n", pattern, ptr)); |
1767 | 7.40M | state->start = ptr; |
1768 | 7.40M | state->ptr = ptr + prefix_skip; |
1769 | 7.40M | if (flags & SRE_INFO_LITERAL) |
1770 | 7.11k | return 1; /* we got all of it */ |
1771 | 7.39M | status = SRE(match)(state, pattern + 2*prefix_skip, 0); |
1772 | 7.39M | if (status != 0) |
1773 | 6.55M | return status; |
1774 | 843k | ++ptr; |
1775 | 843k | RESET_CAPTURE_GROUP(); |
1776 | 843k | } |
1777 | 147k | return 0; |
1778 | 4.81M | } |
1779 | | |
1780 | 113M | if (prefix_len > 1) { |
1781 | | /* pattern starts with a known prefix. use the overlap |
1782 | | table to skip forward as fast as we possibly can */ |
1783 | 849k | Py_ssize_t i = 0; |
1784 | | |
1785 | 849k | end = (SRE_CHAR *)state->end; |
1786 | 849k | if (prefix_len > end - ptr) |
1787 | 0 | return 0; |
1788 | | #if SIZEOF_SRE_CHAR < 4 |
1789 | 1.67M | for (i = 0; i < prefix_len; i++) |
1790 | 1.11M | if ((SRE_CODE)(SRE_CHAR) prefix[i] != prefix[i]) |
1791 | 0 | return 0; /* literal can't match: doesn't fit in char width */ |
1792 | 558k | #endif |
1793 | 1.76M | while (ptr < end) { |
1794 | 1.76M | SRE_CHAR c = (SRE_CHAR) prefix[0]; |
1795 | 21.8M | while (*ptr++ != c) { |
1796 | 20.1M | if (ptr >= end) |
1797 | 347 | return 0; |
1798 | 20.1M | } |
1799 | 1.76M | if (ptr >= end) |
1800 | 44 | return 0; |
1801 | | |
1802 | 1.76M | i = 1; |
1803 | 1.76M | state->must_advance = 0; |
1804 | 1.76M | do { |
1805 | 1.76M | if (*ptr == (SRE_CHAR) prefix[i]) { |
1806 | 1.63M | if (++i != prefix_len) { |
1807 | 0 | if (++ptr >= end) |
1808 | 0 | return 0; |
1809 | 0 | continue; |
1810 | 0 | } |
1811 | | /* found a potential match */ |
1812 | 1.63M | TRACE(("|%p|%p|SEARCH SCAN\n", pattern, ptr)); |
1813 | 1.63M | state->start = ptr - (prefix_len - 1); |
1814 | 1.63M | state->ptr = ptr - (prefix_len - prefix_skip - 1); |
1815 | 1.63M | if (flags & SRE_INFO_LITERAL) |
1816 | 0 | return 1; /* we got all of it */ |
1817 | 1.63M | status = SRE(match)(state, pattern + 2*prefix_skip, 0); |
1818 | 1.63M | if (status != 0) |
1819 | 848k | return status; |
1820 | | /* close but no cigar -- try again */ |
1821 | 791k | if (++ptr >= end) |
1822 | 41 | return 0; |
1823 | 791k | RESET_CAPTURE_GROUP(); |
1824 | 791k | } |
1825 | 914k | i = overlap[i]; |
1826 | 914k | } while (i != 0); |
1827 | 1.76M | } |
1828 | 0 | return 0; |
1829 | 849k | } |
1830 | | |
1831 | 112M | if (charset) { |
1832 | | /* pattern starts with a character from a known set */ |
1833 | 108M | end = (SRE_CHAR *)state->end; |
1834 | 108M | state->must_advance = 0; |
1835 | 111M | for (;;) { |
1836 | 459M | while (ptr < end && !SRE(charset)(state, charset, *ptr)) |
1837 | 347M | ptr++; |
1838 | 111M | if (ptr >= end) |
1839 | 3.81M | return 0; |
1840 | 107M | TRACE(("|%p|%p|SEARCH CHARSET\n", pattern, ptr)); |
1841 | 107M | state->start = ptr; |
1842 | 107M | state->ptr = ptr; |
1843 | 107M | status = SRE(match)(state, pattern, 0); |
1844 | 107M | if (status != 0) |
1845 | 104M | break; |
1846 | 2.87M | ptr++; |
1847 | 2.87M | RESET_CAPTURE_GROUP(); |
1848 | 2.87M | } |
1849 | 108M | } else { |
1850 | | /* general case */ |
1851 | 4.20M | assert(ptr <= end); |
1852 | 4.20M | TRACE(("|%p|%p|SEARCH\n", pattern, ptr)); |
1853 | 4.20M | state->start = state->ptr = ptr; |
1854 | 4.20M | status = SRE(match)(state, pattern, 1); |
1855 | 4.20M | state->must_advance = 0; |
1856 | 4.20M | if (status == 0 && pattern[0] == SRE_OP_AT && |
1857 | 75 | (pattern[1] == SRE_AT_BEGINNING || |
1858 | 75 | pattern[1] == SRE_AT_BEGINNING_STRING)) |
1859 | 0 | { |
1860 | 0 | state->start = state->ptr = ptr = end; |
1861 | 0 | return 0; |
1862 | 0 | } |
1863 | 257M | while (status == 0 && ptr < end) { |
1864 | 253M | ptr++; |
1865 | 253M | RESET_CAPTURE_GROUP(); |
1866 | 253M | TRACE(("|%p|%p|SEARCH\n", pattern, ptr)); |
1867 | 253M | state->start = state->ptr = ptr; |
1868 | 253M | status = SRE(match)(state, pattern, 0); |
1869 | 253M | } |
1870 | 4.20M | } |
1871 | | |
1872 | 108M | return status; |
1873 | 112M | } Line | Count | Source | 1699 | 50.3M | { | 1700 | 50.3M | SRE_CHAR* ptr = (SRE_CHAR *)state->start; | 1701 | 50.3M | SRE_CHAR* end = (SRE_CHAR *)state->end; | 1702 | 50.3M | Py_ssize_t status = 0; | 1703 | 50.3M | Py_ssize_t prefix_len = 0; | 1704 | 50.3M | Py_ssize_t prefix_skip = 0; | 1705 | 50.3M | SRE_CODE* prefix = NULL; | 1706 | 50.3M | SRE_CODE* charset = NULL; | 1707 | 50.3M | SRE_CODE* overlap = NULL; | 1708 | 50.3M | int flags = 0; | 1709 | 50.3M | INIT_TRACE(state); | 1710 | | | 1711 | 50.3M | if (ptr > end) | 1712 | 0 | return 0; | 1713 | | | 1714 | 50.3M | if (pattern[0] == SRE_OP_INFO) { | 1715 | | /* optimization info block */ | 1716 | | /* <INFO> <1=skip> <2=flags> <3=min> <4=max> <5=prefix info> */ | 1717 | | | 1718 | 50.3M | flags = pattern[2]; | 1719 | | | 1720 | 50.3M | if (pattern[3] && (uintptr_t)(end - ptr) < pattern[3]) { | 1721 | 3.63M | TRACE(("reject (got %tu chars, need %zu)\n", | 1722 | 3.63M | end - ptr, (size_t) pattern[3])); | 1723 | 3.63M | return 0; | 1724 | 3.63M | } | 1725 | 46.7M | if (pattern[3] > 1) { | 1726 | | /* adjust end point (but make sure we leave at least one | 1727 | | character in there, so literal search will work) */ | 1728 | 1.95M | end -= pattern[3] - 1; | 1729 | 1.95M | if (end <= ptr) | 1730 | 0 | end = ptr; | 1731 | 1.95M | } | 1732 | | | 1733 | 46.7M | if (flags & SRE_INFO_PREFIX) { | 1734 | | /* pattern starts with a known prefix */ | 1735 | | /* <length> <skip> <prefix data> <overlap data> */ | 1736 | 1.95M | prefix_len = pattern[5]; | 1737 | 1.95M | prefix_skip = pattern[6]; | 1738 | 1.95M | prefix = pattern + 7; | 1739 | 1.95M | overlap = prefix + prefix_len - 1; | 1740 | 44.7M | } else if (flags & SRE_INFO_CHARSET) | 1741 | | /* pattern starts with a character from a known set */ | 1742 | | /* <charset> */ | 1743 | 41.6M | charset = pattern + 5; | 1744 | | | 1745 | 46.7M | pattern += 1 + pattern[1]; | 1746 | 46.7M | } | 1747 | | | 1748 | 46.7M | TRACE(("prefix = %p %zd %zd\n", | 1749 | 46.7M | prefix, prefix_len, prefix_skip)); | 1750 | 46.7M | TRACE(("charset = %p\n", charset)); | 1751 | | | 1752 | 46.7M | if (prefix_len == 1) { | 1753 | | /* pattern starts with a literal character */ | 1754 | 1.88M | SRE_CHAR c = (SRE_CHAR) prefix[0]; | 1755 | 1.88M | #if SIZEOF_SRE_CHAR < 4 | 1756 | 1.88M | if ((SRE_CODE) c != prefix[0]) | 1757 | 0 | return 0; /* literal can't match: doesn't fit in char width */ | 1758 | 1.88M | #endif | 1759 | 1.88M | end = (SRE_CHAR *)state->end; | 1760 | 1.88M | state->must_advance = 0; | 1761 | 2.27M | while (ptr < end) { | 1762 | 31.8M | while (*ptr != c) { | 1763 | 30.0M | if (++ptr >= end) | 1764 | 378k | return 0; | 1765 | 30.0M | } | 1766 | 1.75M | TRACE(("|%p|%p|SEARCH LITERAL\n", pattern, ptr)); | 1767 | 1.75M | state->start = ptr; | 1768 | 1.75M | state->ptr = ptr + prefix_skip; | 1769 | 1.75M | if (flags & SRE_INFO_LITERAL) | 1770 | 582 | return 1; /* we got all of it */ | 1771 | 1.74M | status = SRE(match)(state, pattern + 2*prefix_skip, 0); | 1772 | 1.74M | if (status != 0) | 1773 | 1.36M | return status; | 1774 | 388k | ++ptr; | 1775 | 388k | RESET_CAPTURE_GROUP(); | 1776 | 388k | } | 1777 | 142k | return 0; | 1778 | 1.88M | } | 1779 | | | 1780 | 44.8M | if (prefix_len > 1) { | 1781 | | /* pattern starts with a known prefix. use the overlap | 1782 | | table to skip forward as fast as we possibly can */ | 1783 | 75.7k | Py_ssize_t i = 0; | 1784 | | | 1785 | 75.7k | end = (SRE_CHAR *)state->end; | 1786 | 75.7k | if (prefix_len > end - ptr) | 1787 | 0 | return 0; | 1788 | 75.7k | #if SIZEOF_SRE_CHAR < 4 | 1789 | 227k | for (i = 0; i < prefix_len; i++) | 1790 | 151k | if ((SRE_CODE)(SRE_CHAR) prefix[i] != prefix[i]) | 1791 | 0 | return 0; /* literal can't match: doesn't fit in char width */ | 1792 | 75.7k | #endif | 1793 | 144k | while (ptr < end) { | 1794 | 144k | SRE_CHAR c = (SRE_CHAR) prefix[0]; | 1795 | 2.76M | while (*ptr++ != c) { | 1796 | 2.62M | if (ptr >= end) | 1797 | 75 | return 0; | 1798 | 2.62M | } | 1799 | 144k | if (ptr >= end) | 1800 | 12 | return 0; | 1801 | | | 1802 | 144k | i = 1; | 1803 | 144k | state->must_advance = 0; | 1804 | 144k | do { | 1805 | 144k | if (*ptr == (SRE_CHAR) prefix[i]) { | 1806 | 134k | if (++i != prefix_len) { | 1807 | 0 | if (++ptr >= end) | 1808 | 0 | return 0; | 1809 | 0 | continue; | 1810 | 0 | } | 1811 | | /* found a potential match */ | 1812 | 134k | TRACE(("|%p|%p|SEARCH SCAN\n", pattern, ptr)); | 1813 | 134k | state->start = ptr - (prefix_len - 1); | 1814 | 134k | state->ptr = ptr - (prefix_len - prefix_skip - 1); | 1815 | 134k | if (flags & SRE_INFO_LITERAL) | 1816 | 0 | return 1; /* we got all of it */ | 1817 | 134k | status = SRE(match)(state, pattern + 2*prefix_skip, 0); | 1818 | 134k | if (status != 0) | 1819 | 75.6k | return status; | 1820 | | /* close but no cigar -- try again */ | 1821 | 58.5k | if (++ptr >= end) | 1822 | 19 | return 0; | 1823 | 58.5k | RESET_CAPTURE_GROUP(); | 1824 | 58.5k | } | 1825 | 68.7k | i = overlap[i]; | 1826 | 68.7k | } while (i != 0); | 1827 | 144k | } | 1828 | 0 | return 0; | 1829 | 75.7k | } | 1830 | | | 1831 | 44.7M | if (charset) { | 1832 | | /* pattern starts with a character from a known set */ | 1833 | 41.6M | end = (SRE_CHAR *)state->end; | 1834 | 41.6M | state->must_advance = 0; | 1835 | 43.5M | for (;;) { | 1836 | 112M | while (ptr < end && !SRE(charset)(state, charset, *ptr)) | 1837 | 68.6M | ptr++; | 1838 | 43.5M | if (ptr >= end) | 1839 | 2.61M | return 0; | 1840 | 40.8M | TRACE(("|%p|%p|SEARCH CHARSET\n", pattern, ptr)); | 1841 | 40.8M | state->start = ptr; | 1842 | 40.8M | state->ptr = ptr; | 1843 | 40.8M | status = SRE(match)(state, pattern, 0); | 1844 | 40.8M | if (status != 0) | 1845 | 39.0M | break; | 1846 | 1.86M | ptr++; | 1847 | 1.86M | RESET_CAPTURE_GROUP(); | 1848 | 1.86M | } | 1849 | 41.6M | } else { | 1850 | | /* general case */ | 1851 | 3.11M | assert(ptr <= end); | 1852 | 3.11M | TRACE(("|%p|%p|SEARCH\n", pattern, ptr)); | 1853 | 3.11M | state->start = state->ptr = ptr; | 1854 | 3.11M | status = SRE(match)(state, pattern, 1); | 1855 | 3.11M | state->must_advance = 0; | 1856 | 3.11M | if (status == 0 && pattern[0] == SRE_OP_AT && | 1857 | 21 | (pattern[1] == SRE_AT_BEGINNING || | 1858 | 21 | pattern[1] == SRE_AT_BEGINNING_STRING)) | 1859 | 0 | { | 1860 | 0 | state->start = state->ptr = ptr = end; | 1861 | 0 | return 0; | 1862 | 0 | } | 1863 | 60.6M | while (status == 0 && ptr < end) { | 1864 | 57.5M | ptr++; | 1865 | 57.5M | RESET_CAPTURE_GROUP(); | 1866 | 57.5M | TRACE(("|%p|%p|SEARCH\n", pattern, ptr)); | 1867 | 57.5M | state->start = state->ptr = ptr; | 1868 | 57.5M | status = SRE(match)(state, pattern, 0); | 1869 | 57.5M | } | 1870 | 3.11M | } | 1871 | | | 1872 | 42.1M | return status; | 1873 | 44.7M | } |
Line | Count | Source | 1699 | 64.1M | { | 1700 | 64.1M | SRE_CHAR* ptr = (SRE_CHAR *)state->start; | 1701 | 64.1M | SRE_CHAR* end = (SRE_CHAR *)state->end; | 1702 | 64.1M | Py_ssize_t status = 0; | 1703 | 64.1M | Py_ssize_t prefix_len = 0; | 1704 | 64.1M | Py_ssize_t prefix_skip = 0; | 1705 | 64.1M | SRE_CODE* prefix = NULL; | 1706 | 64.1M | SRE_CODE* charset = NULL; | 1707 | 64.1M | SRE_CODE* overlap = NULL; | 1708 | 64.1M | int flags = 0; | 1709 | 64.1M | INIT_TRACE(state); | 1710 | | | 1711 | 64.1M | if (ptr > end) | 1712 | 0 | return 0; | 1713 | | | 1714 | 64.1M | if (pattern[0] == SRE_OP_INFO) { | 1715 | | /* optimization info block */ | 1716 | | /* <INFO> <1=skip> <2=flags> <3=min> <4=max> <5=prefix info> */ | 1717 | | | 1718 | 64.1M | flags = pattern[2]; | 1719 | | | 1720 | 64.1M | if (pattern[3] && (uintptr_t)(end - ptr) < pattern[3]) { | 1721 | 123k | TRACE(("reject (got %tu chars, need %zu)\n", | 1722 | 123k | end - ptr, (size_t) pattern[3])); | 1723 | 123k | return 0; | 1724 | 123k | } | 1725 | 64.0M | if (pattern[3] > 1) { | 1726 | | /* adjust end point (but make sure we leave at least one | 1727 | | character in there, so literal search will work) */ | 1728 | 3.41M | end -= pattern[3] - 1; | 1729 | 3.41M | if (end <= ptr) | 1730 | 0 | end = ptr; | 1731 | 3.41M | } | 1732 | | | 1733 | 64.0M | if (flags & SRE_INFO_PREFIX) { | 1734 | | /* pattern starts with a known prefix */ | 1735 | | /* <length> <skip> <prefix data> <overlap data> */ | 1736 | 3.41M | prefix_len = pattern[5]; | 1737 | 3.41M | prefix_skip = pattern[6]; | 1738 | 3.41M | prefix = pattern + 7; | 1739 | 3.41M | overlap = prefix + prefix_len - 1; | 1740 | 60.6M | } else if (flags & SRE_INFO_CHARSET) | 1741 | | /* pattern starts with a character from a known set */ | 1742 | | /* <charset> */ | 1743 | 59.6M | charset = pattern + 5; | 1744 | | | 1745 | 64.0M | pattern += 1 + pattern[1]; | 1746 | 64.0M | } | 1747 | | | 1748 | 64.0M | TRACE(("prefix = %p %zd %zd\n", | 1749 | 64.0M | prefix, prefix_len, prefix_skip)); | 1750 | 64.0M | TRACE(("charset = %p\n", charset)); | 1751 | | | 1752 | 64.0M | if (prefix_len == 1) { | 1753 | | /* pattern starts with a literal character */ | 1754 | 2.93M | SRE_CHAR c = (SRE_CHAR) prefix[0]; | 1755 | 2.93M | #if SIZEOF_SRE_CHAR < 4 | 1756 | 2.93M | if ((SRE_CODE) c != prefix[0]) | 1757 | 0 | return 0; /* literal can't match: doesn't fit in char width */ | 1758 | 2.93M | #endif | 1759 | 2.93M | end = (SRE_CHAR *)state->end; | 1760 | 2.93M | state->must_advance = 0; | 1761 | 3.34M | while (ptr < end) { | 1762 | 58.9M | while (*ptr != c) { | 1763 | 55.7M | if (++ptr >= end) | 1764 | 87.0k | return 0; | 1765 | 55.7M | } | 1766 | 3.24M | TRACE(("|%p|%p|SEARCH LITERAL\n", pattern, ptr)); | 1767 | 3.24M | state->start = ptr; | 1768 | 3.24M | state->ptr = ptr + prefix_skip; | 1769 | 3.24M | if (flags & SRE_INFO_LITERAL) | 1770 | 3.73k | return 1; /* we got all of it */ | 1771 | 3.24M | status = SRE(match)(state, pattern + 2*prefix_skip, 0); | 1772 | 3.24M | if (status != 0) | 1773 | 2.83M | return status; | 1774 | 409k | ++ptr; | 1775 | 409k | RESET_CAPTURE_GROUP(); | 1776 | 409k | } | 1777 | 3.46k | return 0; | 1778 | 2.93M | } | 1779 | | | 1780 | 61.1M | if (prefix_len > 1) { | 1781 | | /* pattern starts with a known prefix. use the overlap | 1782 | | table to skip forward as fast as we possibly can */ | 1783 | 483k | Py_ssize_t i = 0; | 1784 | | | 1785 | 483k | end = (SRE_CHAR *)state->end; | 1786 | 483k | if (prefix_len > end - ptr) | 1787 | 0 | return 0; | 1788 | 483k | #if SIZEOF_SRE_CHAR < 4 | 1789 | 1.44M | for (i = 0; i < prefix_len; i++) | 1790 | 966k | if ((SRE_CODE)(SRE_CHAR) prefix[i] != prefix[i]) | 1791 | 0 | return 0; /* literal can't match: doesn't fit in char width */ | 1792 | 483k | #endif | 1793 | 946k | while (ptr < end) { | 1794 | 946k | SRE_CHAR c = (SRE_CHAR) prefix[0]; | 1795 | 7.19M | while (*ptr++ != c) { | 1796 | 6.24M | if (ptr >= end) | 1797 | 126 | return 0; | 1798 | 6.24M | } | 1799 | 946k | if (ptr >= end) | 1800 | 16 | return 0; | 1801 | | | 1802 | 946k | i = 1; | 1803 | 946k | state->must_advance = 0; | 1804 | 947k | do { | 1805 | 947k | if (*ptr == (SRE_CHAR) prefix[i]) { | 1806 | 913k | if (++i != prefix_len) { | 1807 | 0 | if (++ptr >= end) | 1808 | 0 | return 0; | 1809 | 0 | continue; | 1810 | 0 | } | 1811 | | /* found a potential match */ | 1812 | 913k | TRACE(("|%p|%p|SEARCH SCAN\n", pattern, ptr)); | 1813 | 913k | state->start = ptr - (prefix_len - 1); | 1814 | 913k | state->ptr = ptr - (prefix_len - prefix_skip - 1); | 1815 | 913k | if (flags & SRE_INFO_LITERAL) | 1816 | 0 | return 1; /* we got all of it */ | 1817 | 913k | status = SRE(match)(state, pattern + 2*prefix_skip, 0); | 1818 | 913k | if (status != 0) | 1819 | 483k | return status; | 1820 | | /* close but no cigar -- try again */ | 1821 | 430k | if (++ptr >= end) | 1822 | 11 | return 0; | 1823 | 430k | RESET_CAPTURE_GROUP(); | 1824 | 430k | } | 1825 | 464k | i = overlap[i]; | 1826 | 464k | } while (i != 0); | 1827 | 946k | } | 1828 | 0 | return 0; | 1829 | 483k | } | 1830 | | | 1831 | 60.6M | if (charset) { | 1832 | | /* pattern starts with a character from a known set */ | 1833 | 59.6M | end = (SRE_CHAR *)state->end; | 1834 | 59.6M | state->must_advance = 0; | 1835 | 60.1M | for (;;) { | 1836 | 262M | while (ptr < end && !SRE(charset)(state, charset, *ptr)) | 1837 | 202M | ptr++; | 1838 | 60.1M | if (ptr >= end) | 1839 | 1.15M | return 0; | 1840 | 58.9M | TRACE(("|%p|%p|SEARCH CHARSET\n", pattern, ptr)); | 1841 | 58.9M | state->start = ptr; | 1842 | 58.9M | state->ptr = ptr; | 1843 | 58.9M | status = SRE(match)(state, pattern, 0); | 1844 | 58.9M | if (status != 0) | 1845 | 58.4M | break; | 1846 | 480k | ptr++; | 1847 | 480k | RESET_CAPTURE_GROUP(); | 1848 | 480k | } | 1849 | 59.6M | } else { | 1850 | | /* general case */ | 1851 | 980k | assert(ptr <= end); | 1852 | 980k | TRACE(("|%p|%p|SEARCH\n", pattern, ptr)); | 1853 | 980k | state->start = state->ptr = ptr; | 1854 | 980k | status = SRE(match)(state, pattern, 1); | 1855 | 980k | state->must_advance = 0; | 1856 | 980k | if (status == 0 && pattern[0] == SRE_OP_AT && | 1857 | 28 | (pattern[1] == SRE_AT_BEGINNING || | 1858 | 28 | pattern[1] == SRE_AT_BEGINNING_STRING)) | 1859 | 0 | { | 1860 | 0 | state->start = state->ptr = ptr = end; | 1861 | 0 | return 0; | 1862 | 0 | } | 1863 | 157M | while (status == 0 && ptr < end) { | 1864 | 156M | ptr++; | 1865 | 156M | RESET_CAPTURE_GROUP(); | 1866 | 156M | TRACE(("|%p|%p|SEARCH\n", pattern, ptr)); | 1867 | 156M | state->start = state->ptr = ptr; | 1868 | 156M | status = SRE(match)(state, pattern, 0); | 1869 | 156M | } | 1870 | 980k | } | 1871 | | | 1872 | 59.4M | return status; | 1873 | 60.6M | } |
Line | Count | Source | 1699 | 10.0M | { | 1700 | 10.0M | SRE_CHAR* ptr = (SRE_CHAR *)state->start; | 1701 | 10.0M | SRE_CHAR* end = (SRE_CHAR *)state->end; | 1702 | 10.0M | Py_ssize_t status = 0; | 1703 | 10.0M | Py_ssize_t prefix_len = 0; | 1704 | 10.0M | Py_ssize_t prefix_skip = 0; | 1705 | 10.0M | SRE_CODE* prefix = NULL; | 1706 | 10.0M | SRE_CODE* charset = NULL; | 1707 | 10.0M | SRE_CODE* overlap = NULL; | 1708 | 10.0M | int flags = 0; | 1709 | 10.0M | INIT_TRACE(state); | 1710 | | | 1711 | 10.0M | if (ptr > end) | 1712 | 0 | return 0; | 1713 | | | 1714 | 10.0M | if (pattern[0] == SRE_OP_INFO) { | 1715 | | /* optimization info block */ | 1716 | | /* <INFO> <1=skip> <2=flags> <3=min> <4=max> <5=prefix info> */ | 1717 | | | 1718 | 10.0M | flags = pattern[2]; | 1719 | | | 1720 | 10.0M | if (pattern[3] && (uintptr_t)(end - ptr) < pattern[3]) { | 1721 | 4.76k | TRACE(("reject (got %tu chars, need %zu)\n", | 1722 | 4.76k | end - ptr, (size_t) pattern[3])); | 1723 | 4.76k | return 0; | 1724 | 4.76k | } | 1725 | 10.0M | if (pattern[3] > 1) { | 1726 | | /* adjust end point (but make sure we leave at least one | 1727 | | character in there, so literal search will work) */ | 1728 | 2.65M | end -= pattern[3] - 1; | 1729 | 2.65M | if (end <= ptr) | 1730 | 0 | end = ptr; | 1731 | 2.65M | } | 1732 | | | 1733 | 10.0M | if (flags & SRE_INFO_PREFIX) { | 1734 | | /* pattern starts with a known prefix */ | 1735 | | /* <length> <skip> <prefix data> <overlap data> */ | 1736 | 2.65M | prefix_len = pattern[5]; | 1737 | 2.65M | prefix_skip = pattern[6]; | 1738 | 2.65M | prefix = pattern + 7; | 1739 | 2.65M | overlap = prefix + prefix_len - 1; | 1740 | 7.39M | } else if (flags & SRE_INFO_CHARSET) | 1741 | | /* pattern starts with a character from a known set */ | 1742 | | /* <charset> */ | 1743 | 7.28M | charset = pattern + 5; | 1744 | | | 1745 | 10.0M | pattern += 1 + pattern[1]; | 1746 | 10.0M | } | 1747 | | | 1748 | 10.0M | TRACE(("prefix = %p %zd %zd\n", | 1749 | 10.0M | prefix, prefix_len, prefix_skip)); | 1750 | 10.0M | TRACE(("charset = %p\n", charset)); | 1751 | | | 1752 | 10.0M | if (prefix_len == 1) { | 1753 | | /* pattern starts with a literal character */ | 1754 | 2.36M | SRE_CHAR c = (SRE_CHAR) prefix[0]; | 1755 | | #if SIZEOF_SRE_CHAR < 4 | 1756 | | if ((SRE_CODE) c != prefix[0]) | 1757 | | return 0; /* literal can't match: doesn't fit in char width */ | 1758 | | #endif | 1759 | 2.36M | end = (SRE_CHAR *)state->end; | 1760 | 2.36M | state->must_advance = 0; | 1761 | 2.40M | while (ptr < end) { | 1762 | 28.7M | while (*ptr != c) { | 1763 | 26.3M | if (++ptr >= end) | 1764 | 5.45k | return 0; | 1765 | 26.3M | } | 1766 | 2.40M | TRACE(("|%p|%p|SEARCH LITERAL\n", pattern, ptr)); | 1767 | 2.40M | state->start = ptr; | 1768 | 2.40M | state->ptr = ptr + prefix_skip; | 1769 | 2.40M | if (flags & SRE_INFO_LITERAL) | 1770 | 2.80k | return 1; /* we got all of it */ | 1771 | 2.40M | status = SRE(match)(state, pattern + 2*prefix_skip, 0); | 1772 | 2.40M | if (status != 0) | 1773 | 2.35M | return status; | 1774 | 46.2k | ++ptr; | 1775 | 46.2k | RESET_CAPTURE_GROUP(); | 1776 | 46.2k | } | 1777 | 712 | return 0; | 1778 | 2.36M | } | 1779 | | | 1780 | 7.68M | if (prefix_len > 1) { | 1781 | | /* pattern starts with a known prefix. use the overlap | 1782 | | table to skip forward as fast as we possibly can */ | 1783 | 290k | Py_ssize_t i = 0; | 1784 | | | 1785 | 290k | end = (SRE_CHAR *)state->end; | 1786 | 290k | if (prefix_len > end - ptr) | 1787 | 0 | return 0; | 1788 | | #if SIZEOF_SRE_CHAR < 4 | 1789 | | for (i = 0; i < prefix_len; i++) | 1790 | | if ((SRE_CODE)(SRE_CHAR) prefix[i] != prefix[i]) | 1791 | | return 0; /* literal can't match: doesn't fit in char width */ | 1792 | | #endif | 1793 | 671k | while (ptr < end) { | 1794 | 671k | SRE_CHAR c = (SRE_CHAR) prefix[0]; | 1795 | 11.9M | while (*ptr++ != c) { | 1796 | 11.2M | if (ptr >= end) | 1797 | 146 | return 0; | 1798 | 11.2M | } | 1799 | 671k | if (ptr >= end) | 1800 | 16 | return 0; | 1801 | | | 1802 | 671k | i = 1; | 1803 | 671k | state->must_advance = 0; | 1804 | 671k | do { | 1805 | 671k | if (*ptr == (SRE_CHAR) prefix[i]) { | 1806 | 591k | if (++i != prefix_len) { | 1807 | 0 | if (++ptr >= end) | 1808 | 0 | return 0; | 1809 | 0 | continue; | 1810 | 0 | } | 1811 | | /* found a potential match */ | 1812 | 591k | TRACE(("|%p|%p|SEARCH SCAN\n", pattern, ptr)); | 1813 | 591k | state->start = ptr - (prefix_len - 1); | 1814 | 591k | state->ptr = ptr - (prefix_len - prefix_skip - 1); | 1815 | 591k | if (flags & SRE_INFO_LITERAL) | 1816 | 0 | return 1; /* we got all of it */ | 1817 | 591k | status = SRE(match)(state, pattern + 2*prefix_skip, 0); | 1818 | 591k | if (status != 0) | 1819 | 289k | return status; | 1820 | | /* close but no cigar -- try again */ | 1821 | 301k | if (++ptr >= end) | 1822 | 11 | return 0; | 1823 | 301k | RESET_CAPTURE_GROUP(); | 1824 | 301k | } | 1825 | 381k | i = overlap[i]; | 1826 | 381k | } while (i != 0); | 1827 | 671k | } | 1828 | 0 | return 0; | 1829 | 290k | } | 1830 | | | 1831 | 7.39M | if (charset) { | 1832 | | /* pattern starts with a character from a known set */ | 1833 | 7.28M | end = (SRE_CHAR *)state->end; | 1834 | 7.28M | state->must_advance = 0; | 1835 | 7.80M | for (;;) { | 1836 | 84.5M | while (ptr < end && !SRE(charset)(state, charset, *ptr)) | 1837 | 76.7M | ptr++; | 1838 | 7.80M | if (ptr >= end) | 1839 | 53.8k | return 0; | 1840 | 7.75M | TRACE(("|%p|%p|SEARCH CHARSET\n", pattern, ptr)); | 1841 | 7.75M | state->start = ptr; | 1842 | 7.75M | state->ptr = ptr; | 1843 | 7.75M | status = SRE(match)(state, pattern, 0); | 1844 | 7.75M | if (status != 0) | 1845 | 7.23M | break; | 1846 | 524k | ptr++; | 1847 | 524k | RESET_CAPTURE_GROUP(); | 1848 | 524k | } | 1849 | 7.28M | } else { | 1850 | | /* general case */ | 1851 | 113k | assert(ptr <= end); | 1852 | 113k | TRACE(("|%p|%p|SEARCH\n", pattern, ptr)); | 1853 | 113k | state->start = state->ptr = ptr; | 1854 | 113k | status = SRE(match)(state, pattern, 1); | 1855 | 113k | state->must_advance = 0; | 1856 | 113k | if (status == 0 && pattern[0] == SRE_OP_AT && | 1857 | 26 | (pattern[1] == SRE_AT_BEGINNING || | 1858 | 26 | pattern[1] == SRE_AT_BEGINNING_STRING)) | 1859 | 0 | { | 1860 | 0 | state->start = state->ptr = ptr = end; | 1861 | 0 | return 0; | 1862 | 0 | } | 1863 | 39.3M | while (status == 0 && ptr < end) { | 1864 | 39.2M | ptr++; | 1865 | 39.2M | RESET_CAPTURE_GROUP(); | 1866 | 39.2M | TRACE(("|%p|%p|SEARCH\n", pattern, ptr)); | 1867 | 39.2M | state->start = state->ptr = ptr; | 1868 | 39.2M | status = SRE(match)(state, pattern, 0); | 1869 | 39.2M | } | 1870 | 113k | } | 1871 | | | 1872 | 7.34M | return status; | 1873 | 7.39M | } |
|
1874 | | |
1875 | | #undef SRE_CHAR |
1876 | | #undef SIZEOF_SRE_CHAR |
1877 | | #undef SRE |
1878 | | |
1879 | | /* vim:ts=4:sw=4:et |
1880 | | */ |