comparison src/core/ngx_regex.c @ 381:02a511569afb

nginx-0.0.7-2004-07-07-19:01:00 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 07 Jul 2004 15:01:00 +0000
parents 5cfd65b8b0a7
children da8c5707af39
comparison
equal deleted inserted replaced
380:5ce6561246a5 381:02a511569afb
5 5
6 static void *ngx_regex_malloc(size_t size); 6 static void *ngx_regex_malloc(size_t size);
7 static void ngx_regex_free(void *p); 7 static void ngx_regex_free(void *p);
8 8
9 9
10 /* THREADS: this pool should be private for each thread */
11 static ngx_pool_t *ngx_pcre_pool; 10 static ngx_pool_t *ngx_pcre_pool;
12 11
13 12
14 void ngx_regex_init() 13 void ngx_regex_init()
15 { 14 {
19 18
20 19
21 ngx_regex_t *ngx_regex_compile(ngx_str_t *pattern, ngx_int_t options, 20 ngx_regex_t *ngx_regex_compile(ngx_str_t *pattern, ngx_int_t options,
22 ngx_pool_t *pool, ngx_str_t *err) 21 ngx_pool_t *pool, ngx_str_t *err)
23 { 22 {
24 int erroff; 23 int erroff;
25 const char *errstr; 24 const char *errstr;
26 ngx_regex_t *re; 25 ngx_regex_t *re;
26 #if (NGX_THREADS)
27 ngx_core_tls_t *tls;
28
29 #if (NGX_SUPPRESS_WARN)
30 tls = NULL;
31 #endif
32
33 if (ngx_threaded) {
34 tls = ngx_thread_get_tls(ngx_core_tls_key);
35 tls->pool = pool;
36 } else {
37 ngx_pcre_pool = pool;
38 }
39
40 #else
27 41
28 ngx_pcre_pool = pool; 42 ngx_pcre_pool = pool;
43
44 #endif
29 45
30 re = pcre_compile((const char *) pattern->data, (int) options, 46 re = pcre_compile((const char *) pattern->data, (int) options,
31 &errstr, &erroff, NULL); 47 &errstr, &erroff, NULL);
32 48
33 if (re == NULL) { 49 if (re == NULL) {
42 } 58 }
43 } 59 }
44 60
45 /* ensure that there is no current pool */ 61 /* ensure that there is no current pool */
46 62
63 #if (NGX_THREADS)
64 if (ngx_threaded) {
65 tls->pool = NULL;
66 } else {
67 ngx_pcre_pool = NULL;
68 }
69 #else
47 ngx_pcre_pool = NULL; 70 ngx_pcre_pool = NULL;
71 #endif
48 72
49 return re; 73 return re;
50 } 74 }
51 75
52 76
66 } 90 }
67 91
68 92
69 static void *ngx_regex_malloc(size_t size) 93 static void *ngx_regex_malloc(size_t size)
70 { 94 {
71 if (ngx_pcre_pool) { 95 ngx_pool_t *pool;
72 return ngx_palloc(ngx_pcre_pool, size); 96 #if (NGX_THREADS)
97 ngx_core_tls_t *tls;
98
99 if (ngx_threaded) {
100 tls = ngx_thread_get_tls(ngx_core_tls_key);
101 pool = tls->pool;
102 } else {
103 pool = ngx_pcre_pool;
104 }
105 #else
106 pool = ngx_pcre_pool;
107 #endif
108
109 if (pool) {
110 return ngx_palloc(pool, size);
73 } 111 }
74 112
75 return NULL; 113 return NULL;
76 } 114 }
77 115