19 #if (NGX_HAVE_PCRE_JIT)
20 static void ngx_pcre_free_studies(
void *data);
25 static void *ngx_regex_create_conf(
ngx_cycle_t *cycle);
26 static char *ngx_regex_init_conf(
ngx_cycle_t *cycle,
void *conf);
28 static char *ngx_regex_pcre_jit(
ngx_conf_t *cf,
void *post,
void *data);
29 static ngx_conf_post_t ngx_regex_pcre_jit_post = { ngx_regex_pcre_jit };
39 &ngx_regex_pcre_jit_post },
47 ngx_regex_create_conf,
54 &ngx_regex_module_ctx,
58 ngx_regex_module_init,
75 pcre_malloc = ngx_regex_malloc;
76 pcre_free = ngx_regex_free;
87 tls = ngx_thread_get_tls(ngx_core_tls_key);
99 ngx_regex_malloc_done(
void)
105 tls = ngx_thread_get_tls(ngx_core_tls_key);
112 ngx_pcre_pool = NULL;
125 ngx_regex_malloc_init(rc->
pool);
128 &errstr, &erroff, NULL);
131 ngx_regex_malloc_done();
136 "pcre_compile() failed: %s in \"%V\"",
142 "pcre_compile() failed: %s in \"%V\" at \"%s\"",
151 if (rc->
regex == NULL) {
159 if (ngx_pcre_studies != NULL) {
169 n = pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, &rc->
captures);
171 p =
"pcre_fullinfo(\"%V\", PCRE_INFO_CAPTURECOUNT) failed: %d";
179 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMECOUNT, &rc->
named_captures);
181 p =
"pcre_fullinfo(\"%V\", PCRE_INFO_NAMECOUNT) failed: %d";
189 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &rc->
name_size);
191 p =
"pcre_fullinfo(\"%V\", PCRE_INFO_NAMEENTRYSIZE) failed: %d";
195 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMETABLE, &rc->
names);
197 p =
"pcre_fullinfo(\"%V\", PCRE_INFO_NAMETABLE) failed: %d";
220 for (i = 0; i < a->
nelts; i++) {
245 ngx_regex_malloc(
size_t size)
252 tls = ngx_thread_get_tls(ngx_core_tls_key);
256 pool = ngx_pcre_pool;
261 pool = ngx_pcre_pool;
274 ngx_regex_free(
void *p)
280 #if (NGX_HAVE_PCRE_JIT)
283 ngx_pcre_free_studies(
void *data)
291 part = &studies->
part;
294 for (i = 0 ; ; i++) {
296 if (i >= part->
nelts) {
297 if (part->
next == NULL) {
306 if (elts[i].regex->extra != NULL) {
307 pcre_free_study(elts[i].regex->extra);
326 #if (NGX_HAVE_PCRE_JIT)
334 opt = PCRE_STUDY_JIT_COMPILE;
347 cln->
handler = ngx_pcre_free_studies;
348 cln->
data = ngx_pcre_studies;
353 ngx_regex_malloc_init(cycle->
pool);
355 part = &ngx_pcre_studies->
part;
358 for (i = 0 ; ; i++) {
360 if (i >= part->
nelts) {
361 if (part->
next == NULL) {
370 elts[
i].
regex->
extra = pcre_study(elts[i].regex->code, opt, &errstr);
372 if (errstr != NULL) {
374 "pcre_study() failed: %s in \"%s\"",
375 errstr, elts[i].
name);
378 #if (NGX_HAVE_PCRE_JIT)
379 if (opt & PCRE_STUDY_JIT_COMPILE) {
383 n = pcre_fullinfo(elts[i].regex->code, elts[i].
regex->
extra,
384 PCRE_INFO_JIT, &jit);
386 if (n != 0 || jit != 1) {
388 "JIT compiler does not support pattern: \"%s\"",
395 ngx_regex_malloc_done();
397 ngx_pcre_studies = NULL;
416 if (ngx_pcre_studies == NULL) {
425 ngx_regex_init_conf(
ngx_cycle_t *cycle,
void *conf)
436 ngx_regex_pcre_jit(
ngx_conf_t *cf,
void *post,
void *data)
444 #if (NGX_HAVE_PCRE_JIT)
449 r = pcre_config(PCRE_CONFIG_JIT, &jit);
451 if (r != 0 || jit != 1) {
453 "PCRE library does not support JIT");
459 "nginx was built without PCRE JIT support");