Mercurial > hg > nginx-quic
annotate src/core/ngx_regex.c @ 8770:060bf88d2473
Core: ngx_regex.c style cleanup.
Notably, ngx_pcre_pool and ngx_pcre_studies are renamed to ngx_regex_pool
and ngx_regex_studies, respectively.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sat, 25 Dec 2021 01:07:12 +0300 |
parents | 2ca57257252d |
children | 0b5f12d5c531 |
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 { |
8769
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 |
8770
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8769
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:
8769
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:
8769
diff
changeset
|
20 |
503 | 21 static void * ngx_libc_cdecl ngx_regex_malloc(size_t size); |
22 static void ngx_libc_cdecl ngx_regex_free(void *p); | |
8769
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
23 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
|
24 |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
25 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
|
26 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
27 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
|
28 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
|
29 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
30 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
|
31 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
|
32 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
33 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
34 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
|
35 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
36 { 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
|
37 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
|
38 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
|
39 0, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
40 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
|
41 &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
|
42 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
43 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
|
44 }; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
45 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
46 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
47 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
|
48 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
|
49 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
|
50 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
|
51 }; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
52 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
53 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
54 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
|
55 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
|
56 &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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 }; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
68 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
69 |
8770
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8769
diff
changeset
|
70 static ngx_pool_t *ngx_regex_pool; |
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8769
diff
changeset
|
71 static ngx_list_t *ngx_regex_studies; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
72 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
73 |
503 | 74 void |
75 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
|
76 { |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
77 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
|
78 pcre_free = ngx_regex_free; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
79 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
80 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
81 |
3325 | 82 static ngx_inline void |
83 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
|
84 { |
8770
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8769
diff
changeset
|
85 ngx_regex_pool = pool; |
3325 | 86 } |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
87 |
3325 | 88 |
89 static ngx_inline void | |
90 ngx_regex_malloc_done(void) | |
91 { | |
8770
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8769
diff
changeset
|
92 ngx_regex_pool = NULL; |
3325 | 93 } |
94 | |
95 | |
96 ngx_int_t | |
97 ngx_regex_compile(ngx_regex_compile_t *rc) | |
98 { | |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
99 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
|
100 char *p; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
101 pcre *re; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
102 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
|
103 ngx_regex_elt_t *elt; |
3325 | 104 |
105 ngx_regex_malloc_init(rc->pool); | |
106 | |
107 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
|
108 &errstr, &erroff, NULL); |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
109 |
3325 | 110 /* ensure that there is no current pool */ |
111 ngx_regex_malloc_done(); | |
112 | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
113 if (re == NULL) { |
3325 | 114 if ((size_t) erroff == rc->pattern.len) { |
115 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, | |
116 "pcre_compile() failed: %s in \"%V\"", | |
117 errstr, &rc->pattern) | |
8770
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8769
diff
changeset
|
118 - rc->err.data; |
3325 | 119 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 } else { |
3325 | 121 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, |
122 "pcre_compile() failed: %s in \"%V\" at \"%s\"", | |
123 errstr, &rc->pattern, rc->pattern.data + erroff) | |
8770
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8769
diff
changeset
|
124 - rc->err.data; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
125 } |
3325 | 126 |
127 return NGX_ERROR; | |
128 } | |
129 | |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
130 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
|
131 if (rc->regex == NULL) { |
5824
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
132 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
|
133 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
134 |
4638
6e1a48bcf915
Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents:
4423
diff
changeset
|
135 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
|
136 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
137 /* 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
|
138 |
8770
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8769
diff
changeset
|
139 if (ngx_regex_studies != NULL) { |
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8769
diff
changeset
|
140 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
|
141 if (elt == NULL) { |
5824
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
142 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
|
143 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
144 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
145 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
|
146 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
|
147 } |
3325 | 148 |
149 n = pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, &rc->captures); | |
150 if (n < 0) { | |
151 p = "pcre_fullinfo(\"%V\", PCRE_INFO_CAPTURECOUNT) failed: %d"; | |
152 goto failed; | |
153 } | |
154 | |
155 if (rc->captures == 0) { | |
156 return NGX_OK; | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 |
3325 | 159 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMECOUNT, &rc->named_captures); |
160 if (n < 0) { | |
161 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMECOUNT) failed: %d"; | |
162 goto failed; | |
163 } | |
164 | |
165 if (rc->named_captures == 0) { | |
166 return NGX_OK; | |
167 } | |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
168 |
3325 | 169 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &rc->name_size); |
170 if (n < 0) { | |
171 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMEENTRYSIZE) failed: %d"; | |
172 goto failed; | |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
173 } |
3325 | 174 |
175 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMETABLE, &rc->names); | |
176 if (n < 0) { | |
177 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMETABLE) failed: %d"; | |
178 goto failed; | |
179 } | |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
180 |
3325 | 181 return NGX_OK; |
182 | |
183 failed: | |
184 | |
185 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, p, &rc->pattern, n) | |
186 - rc->err.data; | |
5824
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
187 return NGX_ERROR; |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
188 |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
189 nomem: |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
190 |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
191 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
|
192 "regex \"%V\" compilation failed: no memory", |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
193 &rc->pattern) |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
194 - rc->err.data; |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
195 return NGX_ERROR; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
196 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
197 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
198 |
503 | 199 ngx_int_t |
1784 | 200 ngx_regex_exec_array(ngx_array_t *a, ngx_str_t *s, ngx_log_t *log) |
201 { | |
202 ngx_int_t n; | |
203 ngx_uint_t i; | |
204 ngx_regex_elt_t *re; | |
205 | |
206 re = a->elts; | |
207 | |
208 for (i = 0; i < a->nelts; i++) { | |
209 | |
210 n = ngx_regex_exec(re[i].regex, s, NULL, 0); | |
211 | |
212 if (n == NGX_REGEX_NO_MATCHED) { | |
213 continue; | |
214 } | |
215 | |
216 if (n < 0) { | |
217 ngx_log_error(NGX_LOG_ALERT, log, 0, | |
3325 | 218 ngx_regex_exec_n " failed: %i on \"%V\" using \"%s\"", |
1784 | 219 n, s, re[i].name); |
220 return NGX_ERROR; | |
221 } | |
222 | |
223 /* match */ | |
224 | |
225 return NGX_OK; | |
226 } | |
227 | |
228 return NGX_DECLINED; | |
229 } | |
230 | |
231 | |
503 | 232 static void * ngx_libc_cdecl |
233 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
|
234 { |
8770
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8769
diff
changeset
|
235 if (ngx_regex_pool) { |
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8769
diff
changeset
|
236 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
|
237 } |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
238 |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
239 return NULL; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
240 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
241 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
242 |
503 | 243 static void ngx_libc_cdecl |
244 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
|
245 { |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
246 return; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
247 } |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
248 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
249 |
8769
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
250 static void |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
251 ngx_regex_cleanup(void *data) |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
252 { |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
253 #if (NGX_HAVE_PCRE_JIT) |
8769
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
254 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
|
255 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 |
8769
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
260 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
|
261 elts = part->elts; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
262 |
7088 | 263 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
|
264 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
265 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
|
266 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
|
267 break; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
268 } |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
269 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
270 part = part->next; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
271 elts = part->elts; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
272 i = 0; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
273 } |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
274 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
275 /* |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
276 * 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
|
277 * have to explicitly call the pcre_free_study() function to free |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
278 * this memory. |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
279 */ |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
280 |
8769
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
281 if (elts[i].regex->extra != NULL) { |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
282 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
|
283 } |
8769
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
284 } |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
285 #endif |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
286 |
8769
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
287 /* |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
288 * On configuration parsing errors ngx_regex_module_init() will not |
8770
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8769
diff
changeset
|
289 * be called. Make sure ngx_regex_studies is properly cleared anyway. |
8769
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
290 */ |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
291 |
8770
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8769
diff
changeset
|
292 ngx_regex_studies = NULL; |
8769
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
293 } |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
294 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
295 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
296 static ngx_int_t |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
297 ngx_regex_module_init(ngx_cycle_t *cycle) |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
298 { |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
299 int opt; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
300 const char *errstr; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
301 ngx_uint_t i; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
302 ngx_list_part_t *part; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
303 ngx_regex_elt_t *elts; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
304 ngx_regex_conf_t *rcf; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
305 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
306 opt = 0; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
307 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
308 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
|
309 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
310 #if (NGX_HAVE_PCRE_JIT) |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
311 if (rcf->pcre_jit) { |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
312 opt = PCRE_STUDY_JIT_COMPILE; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
313 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
314 #endif |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
315 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
316 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
|
317 |
8769
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
318 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
|
319 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
|
320 |
7088 | 321 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
|
322 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
323 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
|
324 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
|
325 break; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
326 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
327 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
328 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
|
329 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
|
330 i = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
331 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
332 |
4638
6e1a48bcf915
Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents:
4423
diff
changeset
|
333 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
|
334 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
335 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
|
336 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
|
337 "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
|
338 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
|
339 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
340 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
341 #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
|
342 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
|
343 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
|
344 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
345 jit = 0; |
4638
6e1a48bcf915
Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents:
4423
diff
changeset
|
346 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
|
347 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
|
348 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
349 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
|
350 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
|
351 "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
|
352 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
|
353 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
354 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
355 #endif |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
356 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
357 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
358 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
|
359 |
8770
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8769
diff
changeset
|
360 ngx_regex_studies = NULL; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
361 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
362 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
|
363 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
364 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
365 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
366 static void * |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
367 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
|
368 { |
8769
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
369 ngx_regex_conf_t *rcf; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
370 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
|
371 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
372 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
|
373 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
|
374 return NULL; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
375 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
376 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
377 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
|
378 |
8769
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
379 cln = ngx_pool_cleanup_add(cycle->pool, 0); |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
380 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
|
381 return NULL; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
382 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
383 |
8769
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
384 cln->handler = ngx_regex_cleanup; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
385 cln->data = rcf; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
386 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
387 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
|
388 if (rcf->studies == NULL) { |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
389 return NULL; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
390 } |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
391 |
8770
060bf88d2473
Core: ngx_regex.c style cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8769
diff
changeset
|
392 ngx_regex_studies = rcf->studies; |
8769
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
393 |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
394 return rcf; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
395 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
396 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
397 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
398 static char * |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
399 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
|
400 { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
401 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
|
402 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
403 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
|
404 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
405 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
|
406 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
407 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
408 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
409 static char * |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
410 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
|
411 { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
412 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
|
413 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
414 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
|
415 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
|
416 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
417 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
418 #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
|
419 { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
420 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
|
421 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
422 jit = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
423 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
|
424 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
425 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
|
426 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
|
427 "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
|
428 *fp = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
429 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
430 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
431 #else |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
432 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
|
433 "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
|
434 *fp = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
435 #endif |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
436 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
437 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
|
438 } |