Mercurial > hg > nginx
annotate src/core/ngx_regex.c @ 7981:0b5f12d5c531
PCRE2 library support.
The PCRE2 library is now used by default if found, instead of the
original PCRE library. If needed for some reason, this can be disabled
with the --without-pcre2 configure option.
To make it possible to specify paths to the library and include files
via --with-cc-opt / --with-ld-opt, the library is first tested without
any additional paths and options. If this fails, the pcre2-config script
is used.
Similarly to the original PCRE library, it is now possible to build PCRE2
from sources with nginx configure, by using the --with-pcre= option.
It automatically detects if PCRE or PCRE2 sources are provided.
Note that compiling PCRE2 10.33 and later requires inttypes.h. When
compiling on Windows with MSVC, inttypes.h is only available starting
with MSVC 2013. In older versions some replacement needs to be provided
("echo '#include <stdint.h>' > pcre2-10.xx/src/inttypes.h" is good enough
for MSVC 2010).
The interface on nginx side remains unchanged.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sat, 25 Dec 2021 01:07:15 +0300 |
parents | 060bf88d2473 |
children | fbbb5ce52995 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
381
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
381
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
381
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
381
diff
changeset
|
6 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
12 typedef struct { |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
13 ngx_flag_t pcre_jit; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
14 ngx_list_t *studies; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
15 } ngx_regex_conf_t; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
16 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
17 |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
18 static ngx_inline void ngx_regex_malloc_init(ngx_pool_t *pool); |
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
19 static ngx_inline void ngx_regex_malloc_done(void); |
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
20 |
7981 | 21 #if (NGX_PCRE2) |
22 static void * ngx_libc_cdecl ngx_regex_malloc(size_t size, void *data); | |
23 static void ngx_libc_cdecl ngx_regex_free(void *p, void *data); | |
24 #else | |
503 | 25 static void * ngx_libc_cdecl ngx_regex_malloc(size_t size); |
26 static void ngx_libc_cdecl ngx_regex_free(void *p); | |
7981 | 27 #endif |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
28 static void ngx_regex_cleanup(void *data); |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
30 static ngx_int_t ngx_regex_module_init(ngx_cycle_t *cycle); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
31 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
32 static void *ngx_regex_create_conf(ngx_cycle_t *cycle); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
33 static char *ngx_regex_init_conf(ngx_cycle_t *cycle, void *conf); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
34 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
35 static char *ngx_regex_pcre_jit(ngx_conf_t *cf, void *post, void *data); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
36 static ngx_conf_post_t ngx_regex_pcre_jit_post = { ngx_regex_pcre_jit }; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
37 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
38 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
39 static ngx_command_t ngx_regex_commands[] = { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
40 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
41 { ngx_string("pcre_jit"), |
6511
640288d0e1bc
Fixed NGX_CONF_TAKE1/NGX_CONF_FLAG misuse (as in e444e8f6538b).
Ruslan Ermilov <ru@nginx.com>
parents:
6109
diff
changeset
|
42 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_FLAG, |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
43 ngx_conf_set_flag_slot, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
44 0, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
45 offsetof(ngx_regex_conf_t, pcre_jit), |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
46 &ngx_regex_pcre_jit_post }, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
47 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
48 ngx_null_command |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
49 }; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
50 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
51 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
52 static ngx_core_module_t ngx_regex_module_ctx = { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
53 ngx_string("regex"), |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
54 ngx_regex_create_conf, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
55 ngx_regex_init_conf |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
56 }; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
57 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
58 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
59 ngx_module_t ngx_regex_module = { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
60 NGX_MODULE_V1, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
61 &ngx_regex_module_ctx, /* module context */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
62 ngx_regex_commands, /* module directives */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
63 NGX_CORE_MODULE, /* module type */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
64 NULL, /* init master */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
65 ngx_regex_module_init, /* init module */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
66 NULL, /* init process */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
67 NULL, /* init thread */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
68 NULL, /* exit thread */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
69 NULL, /* exit process */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
70 NULL, /* exit master */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
71 NGX_MODULE_V1_PADDING |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
72 }; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
73 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
74 |
7981 | 75 static ngx_pool_t *ngx_regex_pool; |
76 static ngx_list_t *ngx_regex_studies; | |
77 static ngx_uint_t ngx_regex_direct_alloc; | |
78 | |
79 #if (NGX_PCRE2) | |
80 static pcre2_compile_context *ngx_regex_compile_context; | |
81 static pcre2_match_data *ngx_regex_match_data; | |
82 static ngx_uint_t ngx_regex_match_data_size; | |
83 #endif | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
84 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
85 |
503 | 86 void |
87 ngx_regex_init(void) | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
88 { |
7981 | 89 #if !(NGX_PCRE2) |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
90 pcre_malloc = ngx_regex_malloc; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
91 pcre_free = ngx_regex_free; |
7981 | 92 #endif |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
93 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
94 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
95 |
3325 | 96 static ngx_inline void |
97 ngx_regex_malloc_init(ngx_pool_t *pool) | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
98 { |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
99 ngx_regex_pool = pool; |
7981 | 100 ngx_regex_direct_alloc = (pool == NULL) ? 1 : 0; |
3325 | 101 } |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
102 |
3325 | 103 |
104 static ngx_inline void | |
105 ngx_regex_malloc_done(void) | |
106 { | |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
107 ngx_regex_pool = NULL; |
7981 | 108 ngx_regex_direct_alloc = 0; |
3325 | 109 } |
110 | |
111 | |
7981 | 112 #if (NGX_PCRE2) |
113 | |
114 ngx_int_t | |
115 ngx_regex_compile(ngx_regex_compile_t *rc) | |
116 { | |
117 int n, errcode; | |
118 char *p; | |
119 u_char errstr[128]; | |
120 size_t erroff; | |
121 pcre2_code *re; | |
122 ngx_regex_elt_t *elt; | |
123 pcre2_general_context *gctx; | |
124 pcre2_compile_context *cctx; | |
125 | |
126 if (ngx_regex_compile_context == NULL) { | |
127 /* | |
128 * Allocate a compile context if not yet allocated. This uses | |
129 * direct allocations from heap, so the result can be cached | |
130 * even at runtime. | |
131 */ | |
132 | |
133 ngx_regex_malloc_init(NULL); | |
134 | |
135 gctx = pcre2_general_context_create(ngx_regex_malloc, ngx_regex_free, | |
136 NULL); | |
137 if (gctx == NULL) { | |
138 ngx_regex_malloc_done(); | |
139 goto nomem; | |
140 } | |
141 | |
142 cctx = pcre2_compile_context_create(gctx); | |
143 if (cctx == NULL) { | |
144 pcre2_general_context_free(gctx); | |
145 ngx_regex_malloc_done(); | |
146 goto nomem; | |
147 } | |
148 | |
149 ngx_regex_compile_context = cctx; | |
150 | |
151 pcre2_general_context_free(gctx); | |
152 ngx_regex_malloc_done(); | |
153 } | |
154 | |
155 ngx_regex_malloc_init(rc->pool); | |
156 | |
157 re = pcre2_compile(rc->pattern.data, rc->pattern.len, | |
158 (uint32_t) rc->options, &errcode, &erroff, | |
159 ngx_regex_compile_context); | |
160 | |
161 /* ensure that there is no current pool */ | |
162 ngx_regex_malloc_done(); | |
163 | |
164 if (re == NULL) { | |
165 pcre2_get_error_message(errcode, errstr, 128); | |
166 | |
167 if ((size_t) erroff == rc->pattern.len) { | |
168 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, | |
169 "pcre2_compile() failed: %s in \"%V\"", | |
170 errstr, &rc->pattern) | |
171 - rc->err.data; | |
172 | |
173 } else { | |
174 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, | |
175 "pcre2_compile() failed: %s in \"%V\" at \"%s\"", | |
176 errstr, &rc->pattern, rc->pattern.data + erroff) | |
177 - rc->err.data; | |
178 } | |
179 | |
180 return NGX_ERROR; | |
181 } | |
182 | |
183 rc->regex = re; | |
184 | |
185 /* do not study at runtime */ | |
186 | |
187 if (ngx_regex_studies != NULL) { | |
188 elt = ngx_list_push(ngx_regex_studies); | |
189 if (elt == NULL) { | |
190 goto nomem; | |
191 } | |
192 | |
193 elt->regex = rc->regex; | |
194 elt->name = rc->pattern.data; | |
195 } | |
196 | |
197 n = pcre2_pattern_info(re, PCRE2_INFO_CAPTURECOUNT, &rc->captures); | |
198 if (n < 0) { | |
199 p = "pcre2_pattern_info(\"%V\", PCRE2_INFO_CAPTURECOUNT) failed: %d"; | |
200 goto failed; | |
201 } | |
202 | |
203 if (rc->captures == 0) { | |
204 return NGX_OK; | |
205 } | |
206 | |
207 n = pcre2_pattern_info(re, PCRE2_INFO_NAMECOUNT, &rc->named_captures); | |
208 if (n < 0) { | |
209 p = "pcre2_pattern_info(\"%V\", PCRE2_INFO_NAMECOUNT) failed: %d"; | |
210 goto failed; | |
211 } | |
212 | |
213 if (rc->named_captures == 0) { | |
214 return NGX_OK; | |
215 } | |
216 | |
217 n = pcre2_pattern_info(re, PCRE2_INFO_NAMEENTRYSIZE, &rc->name_size); | |
218 if (n < 0) { | |
219 p = "pcre2_pattern_info(\"%V\", PCRE2_INFO_NAMEENTRYSIZE) failed: %d"; | |
220 goto failed; | |
221 } | |
222 | |
223 n = pcre2_pattern_info(re, PCRE2_INFO_NAMETABLE, &rc->names); | |
224 if (n < 0) { | |
225 p = "pcre2_pattern_info(\"%V\", PCRE2_INFO_NAMETABLE) failed: %d"; | |
226 goto failed; | |
227 } | |
228 | |
229 return NGX_OK; | |
230 | |
231 failed: | |
232 | |
233 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, p, &rc->pattern, n) | |
234 - rc->err.data; | |
235 return NGX_ERROR; | |
236 | |
237 nomem: | |
238 | |
239 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, | |
240 "regex \"%V\" compilation failed: no memory", | |
241 &rc->pattern) | |
242 - rc->err.data; | |
243 return NGX_ERROR; | |
244 } | |
245 | |
246 #else | |
247 | |
3325 | 248 ngx_int_t |
249 ngx_regex_compile(ngx_regex_compile_t *rc) | |
250 { | |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
251 int n, erroff; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
252 char *p; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
253 pcre *re; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
254 const char *errstr; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
255 ngx_regex_elt_t *elt; |
3325 | 256 |
257 ngx_regex_malloc_init(rc->pool); | |
258 | |
259 re = pcre_compile((const char *) rc->pattern.data, (int) rc->options, | |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
216
diff
changeset
|
260 &errstr, &erroff, NULL); |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
261 |
3325 | 262 /* ensure that there is no current pool */ |
263 ngx_regex_malloc_done(); | |
264 | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
265 if (re == NULL) { |
3325 | 266 if ((size_t) erroff == rc->pattern.len) { |
267 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, | |
268 "pcre_compile() failed: %s in \"%V\"", | |
269 errstr, &rc->pattern) | |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
270 - rc->err.data; |
3325 | 271 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
272 } else { |
3325 | 273 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, |
274 "pcre_compile() failed: %s in \"%V\" at \"%s\"", | |
275 errstr, &rc->pattern, rc->pattern.data + erroff) | |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
276 - rc->err.data; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
277 } |
3325 | 278 |
279 return NGX_ERROR; | |
280 } | |
281 | |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
282 rc->regex = ngx_pcalloc(rc->pool, sizeof(ngx_regex_t)); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
283 if (rc->regex == NULL) { |
5824
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
284 goto nomem; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
285 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
286 |
4638
6e1a48bcf915
Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents:
4423
diff
changeset
|
287 rc->regex->code = re; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
288 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
289 /* do not study at runtime */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
290 |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
291 if (ngx_regex_studies != NULL) { |
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
292 elt = ngx_list_push(ngx_regex_studies); |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
293 if (elt == NULL) { |
5824
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
294 goto nomem; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
295 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
296 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
297 elt->regex = rc->regex; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
298 elt->name = rc->pattern.data; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
299 } |
3325 | 300 |
301 n = pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, &rc->captures); | |
302 if (n < 0) { | |
303 p = "pcre_fullinfo(\"%V\", PCRE_INFO_CAPTURECOUNT) failed: %d"; | |
304 goto failed; | |
305 } | |
306 | |
307 if (rc->captures == 0) { | |
308 return NGX_OK; | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
309 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
310 |
3325 | 311 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMECOUNT, &rc->named_captures); |
312 if (n < 0) { | |
313 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMECOUNT) failed: %d"; | |
314 goto failed; | |
315 } | |
316 | |
317 if (rc->named_captures == 0) { | |
318 return NGX_OK; | |
319 } | |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
320 |
3325 | 321 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &rc->name_size); |
322 if (n < 0) { | |
323 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMEENTRYSIZE) failed: %d"; | |
324 goto failed; | |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
325 } |
3325 | 326 |
327 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMETABLE, &rc->names); | |
328 if (n < 0) { | |
329 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMETABLE) failed: %d"; | |
330 goto failed; | |
331 } | |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
332 |
3325 | 333 return NGX_OK; |
334 | |
335 failed: | |
336 | |
337 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, p, &rc->pattern, n) | |
338 - rc->err.data; | |
5824
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
339 return NGX_ERROR; |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
340 |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
341 nomem: |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
342 |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
343 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
344 "regex \"%V\" compilation failed: no memory", |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
345 &rc->pattern) |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
346 - rc->err.data; |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
347 return NGX_ERROR; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
348 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
349 |
7981 | 350 #endif |
351 | |
352 | |
353 #if (NGX_PCRE2) | |
354 | |
355 ngx_int_t | |
356 ngx_regex_exec(ngx_regex_t *re, ngx_str_t *s, int *captures, ngx_uint_t size) | |
357 { | |
358 size_t *ov; | |
359 ngx_int_t rc; | |
360 ngx_uint_t n, i; | |
361 | |
362 /* | |
363 * The pcre2_match() function might allocate memory for backtracking | |
364 * frames, typical allocations are from 40k and above. So the allocator | |
365 * is configured to do direct allocations from heap during matching. | |
366 */ | |
367 | |
368 ngx_regex_malloc_init(NULL); | |
369 | |
370 if (ngx_regex_match_data == NULL | |
371 || size > ngx_regex_match_data_size) | |
372 { | |
373 /* | |
374 * Allocate a match data if not yet allocated or smaller than | |
375 * needed. | |
376 */ | |
377 | |
378 if (ngx_regex_match_data) { | |
379 pcre2_match_data_free(ngx_regex_match_data); | |
380 } | |
381 | |
382 ngx_regex_match_data_size = size; | |
383 ngx_regex_match_data = pcre2_match_data_create(size / 3, NULL); | |
384 | |
385 if (ngx_regex_match_data == NULL) { | |
386 rc = PCRE2_ERROR_NOMEMORY; | |
387 goto failed; | |
388 } | |
389 } | |
390 | |
391 rc = pcre2_match(re, s->data, s->len, 0, 0, ngx_regex_match_data, NULL); | |
392 | |
393 if (rc < 0) { | |
394 goto failed; | |
395 } | |
396 | |
397 n = pcre2_get_ovector_count(ngx_regex_match_data); | |
398 ov = pcre2_get_ovector_pointer(ngx_regex_match_data); | |
399 | |
400 if (n > size / 3) { | |
401 n = size / 3; | |
402 } | |
403 | |
404 for (i = 0; i < n; i++) { | |
405 captures[i * 2] = ov[i * 2]; | |
406 captures[i * 2 + 1] = ov[i * 2 + 1]; | |
407 } | |
408 | |
409 failed: | |
410 | |
411 ngx_regex_malloc_done(); | |
412 | |
413 return rc; | |
414 } | |
415 | |
416 #endif | |
417 | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
418 |
503 | 419 ngx_int_t |
1784 | 420 ngx_regex_exec_array(ngx_array_t *a, ngx_str_t *s, ngx_log_t *log) |
421 { | |
422 ngx_int_t n; | |
423 ngx_uint_t i; | |
424 ngx_regex_elt_t *re; | |
425 | |
426 re = a->elts; | |
427 | |
428 for (i = 0; i < a->nelts; i++) { | |
429 | |
430 n = ngx_regex_exec(re[i].regex, s, NULL, 0); | |
431 | |
432 if (n == NGX_REGEX_NO_MATCHED) { | |
433 continue; | |
434 } | |
435 | |
436 if (n < 0) { | |
437 ngx_log_error(NGX_LOG_ALERT, log, 0, | |
3325 | 438 ngx_regex_exec_n " failed: %i on \"%V\" using \"%s\"", |
1784 | 439 n, s, re[i].name); |
440 return NGX_ERROR; | |
441 } | |
442 | |
443 /* match */ | |
444 | |
445 return NGX_OK; | |
446 } | |
447 | |
448 return NGX_DECLINED; | |
449 } | |
450 | |
451 | |
7981 | 452 #if (NGX_PCRE2) |
453 | |
454 static void * ngx_libc_cdecl | |
455 ngx_regex_malloc(size_t size, void *data) | |
456 { | |
457 if (ngx_regex_pool) { | |
458 return ngx_palloc(ngx_regex_pool, size); | |
459 } | |
460 | |
461 if (ngx_regex_direct_alloc) { | |
462 return ngx_alloc(size, ngx_cycle->log); | |
463 } | |
464 | |
465 return NULL; | |
466 } | |
467 | |
468 | |
469 static void ngx_libc_cdecl | |
470 ngx_regex_free(void *p, void *data) | |
471 { | |
472 if (ngx_regex_direct_alloc) { | |
473 ngx_free(p); | |
474 } | |
475 | |
476 return; | |
477 } | |
478 | |
479 #else | |
480 | |
503 | 481 static void * ngx_libc_cdecl |
482 ngx_regex_malloc(size_t size) | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
483 { |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
484 if (ngx_regex_pool) { |
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
485 return ngx_palloc(ngx_regex_pool, size); |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
486 } |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
487 |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
488 return NULL; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
489 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
490 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
491 |
503 | 492 static void ngx_libc_cdecl |
493 ngx_regex_free(void *p) | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
494 { |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
495 return; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
496 } |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
497 |
7981 | 498 #endif |
499 | |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
500 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
501 static void |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
502 ngx_regex_cleanup(void *data) |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
503 { |
7981 | 504 #if (NGX_PCRE2 || NGX_HAVE_PCRE_JIT) |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
505 ngx_regex_conf_t *rcf = data; |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
506 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
507 ngx_uint_t i; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
508 ngx_list_part_t *part; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
509 ngx_regex_elt_t *elts; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
510 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
511 part = &rcf->studies->part; |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
512 elts = part->elts; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
513 |
7088 | 514 for (i = 0; /* void */ ; i++) { |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
515 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
516 if (i >= part->nelts) { |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
517 if (part->next == NULL) { |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
518 break; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
519 } |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
520 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
521 part = part->next; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
522 elts = part->elts; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
523 i = 0; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
524 } |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
525 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
526 /* |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
527 * The PCRE JIT compiler uses mmap for its executable codes, so we |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
528 * have to explicitly call the pcre_free_study() function to free |
7981 | 529 * this memory. In PCRE2, we call the pcre2_code_free() function |
530 * for the same reason. | |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
531 */ |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
532 |
7981 | 533 #if (NGX_PCRE2) |
534 pcre2_code_free(elts[i].regex); | |
535 #else | |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
536 if (elts[i].regex->extra != NULL) { |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
537 pcre_free_study(elts[i].regex->extra); |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
538 } |
7981 | 539 #endif |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
540 } |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
541 #endif |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
542 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
543 /* |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
544 * On configuration parsing errors ngx_regex_module_init() will not |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
545 * be called. Make sure ngx_regex_studies is properly cleared anyway. |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
546 */ |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
547 |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
548 ngx_regex_studies = NULL; |
7981 | 549 |
550 #if (NGX_PCRE2) | |
551 | |
552 /* | |
553 * Free compile context and match data. If needed at runtime by | |
554 * the new cycle, these will be re-allocated. | |
555 */ | |
556 | |
557 if (ngx_regex_compile_context) { | |
558 pcre2_compile_context_free(ngx_regex_compile_context); | |
559 ngx_regex_compile_context = NULL; | |
560 } | |
561 | |
562 if (ngx_regex_match_data) { | |
563 pcre2_match_data_free(ngx_regex_match_data); | |
564 ngx_regex_match_data = NULL; | |
565 ngx_regex_match_data_size = 0; | |
566 } | |
567 | |
568 #endif | |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
569 } |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
570 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
571 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
572 static ngx_int_t |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
573 ngx_regex_module_init(ngx_cycle_t *cycle) |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
574 { |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
575 int opt; |
7981 | 576 #if !(NGX_PCRE2) |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
577 const char *errstr; |
7981 | 578 #endif |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
579 ngx_uint_t i; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
580 ngx_list_part_t *part; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
581 ngx_regex_elt_t *elts; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
582 ngx_regex_conf_t *rcf; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
583 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
584 opt = 0; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
585 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
586 rcf = (ngx_regex_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_regex_module); |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
587 |
7981 | 588 #if (NGX_PCRE2 || NGX_HAVE_PCRE_JIT) |
589 | |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
590 if (rcf->pcre_jit) { |
7981 | 591 #if (NGX_PCRE2) |
592 opt = 1; | |
593 #else | |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
594 opt = PCRE_STUDY_JIT_COMPILE; |
7981 | 595 #endif |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
596 } |
7981 | 597 |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
598 #endif |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
599 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
600 ngx_regex_malloc_init(cycle->pool); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
601 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
602 part = &rcf->studies->part; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
603 elts = part->elts; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
604 |
7088 | 605 for (i = 0; /* void */ ; i++) { |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
606 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
607 if (i >= part->nelts) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
608 if (part->next == NULL) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
609 break; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
610 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
611 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
612 part = part->next; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
613 elts = part->elts; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
614 i = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
615 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
616 |
7981 | 617 #if (NGX_PCRE2) |
618 | |
619 if (opt) { | |
620 int n; | |
621 | |
622 n = pcre2_jit_compile(elts[i].regex, PCRE2_JIT_COMPLETE); | |
623 | |
624 if (n != 0) { | |
625 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, | |
626 "pcre2_jit_compile() failed: %d in \"%s\", " | |
627 "ignored", | |
628 n, elts[i].name); | |
629 } | |
630 } | |
631 | |
632 #else | |
633 | |
4638
6e1a48bcf915
Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents:
4423
diff
changeset
|
634 elts[i].regex->extra = pcre_study(elts[i].regex->code, opt, &errstr); |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
635 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
636 if (errstr != NULL) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
637 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
638 "pcre_study() failed: %s in \"%s\"", |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
639 errstr, elts[i].name); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
640 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
641 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
642 #if (NGX_HAVE_PCRE_JIT) |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
643 if (opt & PCRE_STUDY_JIT_COMPILE) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
644 int jit, n; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
645 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
646 jit = 0; |
4638
6e1a48bcf915
Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents:
4423
diff
changeset
|
647 n = pcre_fullinfo(elts[i].regex->code, elts[i].regex->extra, |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
648 PCRE_INFO_JIT, &jit); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
649 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
650 if (n != 0 || jit != 1) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
651 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
652 "JIT compiler does not support pattern: \"%s\"", |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
653 elts[i].name); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
654 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
655 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
656 #endif |
7981 | 657 #endif |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
658 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
659 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
660 ngx_regex_malloc_done(); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
661 |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
662 ngx_regex_studies = NULL; |
7981 | 663 #if (NGX_PCRE2) |
664 ngx_regex_compile_context = NULL; | |
665 #endif | |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
666 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
667 return NGX_OK; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
668 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
669 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
670 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
671 static void * |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
672 ngx_regex_create_conf(ngx_cycle_t *cycle) |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
673 { |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
674 ngx_regex_conf_t *rcf; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
675 ngx_pool_cleanup_t *cln; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
676 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
677 rcf = ngx_pcalloc(cycle->pool, sizeof(ngx_regex_conf_t)); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
678 if (rcf == NULL) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
679 return NULL; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
680 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
681 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
682 rcf->pcre_jit = NGX_CONF_UNSET; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
683 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
684 cln = ngx_pool_cleanup_add(cycle->pool, 0); |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
685 if (cln == NULL) { |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
686 return NULL; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
687 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
688 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
689 cln->handler = ngx_regex_cleanup; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
690 cln->data = rcf; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
691 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
692 rcf->studies = ngx_list_create(cycle->pool, 8, sizeof(ngx_regex_elt_t)); |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
693 if (rcf->studies == NULL) { |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
694 return NULL; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
695 } |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
696 |
7979
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7978
diff
changeset
|
697 ngx_regex_studies = rcf->studies; |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
698 |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
699 return rcf; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
700 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
701 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
702 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
703 static char * |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
704 ngx_regex_init_conf(ngx_cycle_t *cycle, void *conf) |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
705 { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
706 ngx_regex_conf_t *rcf = conf; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
707 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
708 ngx_conf_init_value(rcf->pcre_jit, 0); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
709 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
710 return NGX_CONF_OK; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
711 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
712 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
713 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
714 static char * |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
715 ngx_regex_pcre_jit(ngx_conf_t *cf, void *post, void *data) |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
716 { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
717 ngx_flag_t *fp = data; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
718 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
719 if (*fp == 0) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
720 return NGX_CONF_OK; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
721 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
722 |
7981 | 723 #if (NGX_PCRE2) |
724 { | |
725 int r; | |
726 uint32_t jit; | |
727 | |
728 jit = 0; | |
729 r = pcre2_config(PCRE2_CONFIG_JIT, &jit); | |
730 | |
731 if (r != 0 || jit != 1) { | |
732 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
733 "PCRE2 library does not support JIT"); | |
734 *fp = 0; | |
735 } | |
736 } | |
737 #elif (NGX_HAVE_PCRE_JIT) | |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
738 { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
739 int jit, r; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
740 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
741 jit = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
742 r = pcre_config(PCRE_CONFIG_JIT, &jit); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
743 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
744 if (r != 0 || jit != 1) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
745 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
746 "PCRE library does not support JIT"); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
747 *fp = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
748 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
749 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
750 #else |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
751 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
4413
23ea4e72c85a
Fixed grammar in PCRE JIT error log message.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
752 "nginx was built without PCRE JIT support"); |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
753 *fp = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
754 #endif |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
755 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
756 return NGX_CONF_OK; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
757 } |