comparison 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
comparison
equal deleted inserted replaced
8769:2ca57257252d 8770:060bf88d2473
12 typedef struct { 12 typedef struct {
13 ngx_flag_t pcre_jit; 13 ngx_flag_t pcre_jit;
14 ngx_list_t *studies; 14 ngx_list_t *studies;
15 } ngx_regex_conf_t; 15 } ngx_regex_conf_t;
16 16
17
18 static ngx_inline void ngx_regex_malloc_init(ngx_pool_t *pool);
19 static ngx_inline void ngx_regex_malloc_done(void);
17 20
18 static void * ngx_libc_cdecl ngx_regex_malloc(size_t size); 21 static void * ngx_libc_cdecl ngx_regex_malloc(size_t size);
19 static void ngx_libc_cdecl ngx_regex_free(void *p); 22 static void ngx_libc_cdecl ngx_regex_free(void *p);
20 static void ngx_regex_cleanup(void *data); 23 static void ngx_regex_cleanup(void *data);
21 24
62 NULL, /* exit master */ 65 NULL, /* exit master */
63 NGX_MODULE_V1_PADDING 66 NGX_MODULE_V1_PADDING
64 }; 67 };
65 68
66 69
67 static ngx_pool_t *ngx_pcre_pool; 70 static ngx_pool_t *ngx_regex_pool;
68 static ngx_list_t *ngx_pcre_studies; 71 static ngx_list_t *ngx_regex_studies;
69 72
70 73
71 void 74 void
72 ngx_regex_init(void) 75 ngx_regex_init(void)
73 { 76 {
77 80
78 81
79 static ngx_inline void 82 static ngx_inline void
80 ngx_regex_malloc_init(ngx_pool_t *pool) 83 ngx_regex_malloc_init(ngx_pool_t *pool)
81 { 84 {
82 ngx_pcre_pool = pool; 85 ngx_regex_pool = pool;
83 } 86 }
84 87
85 88
86 static ngx_inline void 89 static ngx_inline void
87 ngx_regex_malloc_done(void) 90 ngx_regex_malloc_done(void)
88 { 91 {
89 ngx_pcre_pool = NULL; 92 ngx_regex_pool = NULL;
90 } 93 }
91 94
92 95
93 ngx_int_t 96 ngx_int_t
94 ngx_regex_compile(ngx_regex_compile_t *rc) 97 ngx_regex_compile(ngx_regex_compile_t *rc)
110 if (re == NULL) { 113 if (re == NULL) {
111 if ((size_t) erroff == rc->pattern.len) { 114 if ((size_t) erroff == rc->pattern.len) {
112 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, 115 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
113 "pcre_compile() failed: %s in \"%V\"", 116 "pcre_compile() failed: %s in \"%V\"",
114 errstr, &rc->pattern) 117 errstr, &rc->pattern)
115 - rc->err.data; 118 - rc->err.data;
116 119
117 } else { 120 } else {
118 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, 121 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
119 "pcre_compile() failed: %s in \"%V\" at \"%s\"", 122 "pcre_compile() failed: %s in \"%V\" at \"%s\"",
120 errstr, &rc->pattern, rc->pattern.data + erroff) 123 errstr, &rc->pattern, rc->pattern.data + erroff)
121 - rc->err.data; 124 - rc->err.data;
122 } 125 }
123 126
124 return NGX_ERROR; 127 return NGX_ERROR;
125 } 128 }
126 129
131 134
132 rc->regex->code = re; 135 rc->regex->code = re;
133 136
134 /* do not study at runtime */ 137 /* do not study at runtime */
135 138
136 if (ngx_pcre_studies != NULL) { 139 if (ngx_regex_studies != NULL) {
137 elt = ngx_list_push(ngx_pcre_studies); 140 elt = ngx_list_push(ngx_regex_studies);
138 if (elt == NULL) { 141 if (elt == NULL) {
139 goto nomem; 142 goto nomem;
140 } 143 }
141 144
142 elt->regex = rc->regex; 145 elt->regex = rc->regex;
227 230
228 231
229 static void * ngx_libc_cdecl 232 static void * ngx_libc_cdecl
230 ngx_regex_malloc(size_t size) 233 ngx_regex_malloc(size_t size)
231 { 234 {
232 ngx_pool_t *pool; 235 if (ngx_regex_pool) {
233 pool = ngx_pcre_pool; 236 return ngx_palloc(ngx_regex_pool, size);
234
235 if (pool) {
236 return ngx_palloc(pool, size);
237 } 237 }
238 238
239 return NULL; 239 return NULL;
240 } 240 }
241 241
284 } 284 }
285 #endif 285 #endif
286 286
287 /* 287 /*
288 * On configuration parsing errors ngx_regex_module_init() will not 288 * On configuration parsing errors ngx_regex_module_init() will not
289 * be called. Make sure ngx_pcre_studies is properly cleared anyway. 289 * be called. Make sure ngx_regex_studies is properly cleared anyway.
290 */ 290 */
291 291
292 ngx_pcre_studies = NULL; 292 ngx_regex_studies = NULL;
293 } 293 }
294 294
295 295
296 static ngx_int_t 296 static ngx_int_t
297 ngx_regex_module_init(ngx_cycle_t *cycle) 297 ngx_regex_module_init(ngx_cycle_t *cycle)
355 #endif 355 #endif
356 } 356 }
357 357
358 ngx_regex_malloc_done(); 358 ngx_regex_malloc_done();
359 359
360 ngx_pcre_studies = NULL; 360 ngx_regex_studies = NULL;
361 361
362 return NGX_OK; 362 return NGX_OK;
363 } 363 }
364 364
365 365
387 rcf->studies = ngx_list_create(cycle->pool, 8, sizeof(ngx_regex_elt_t)); 387 rcf->studies = ngx_list_create(cycle->pool, 8, sizeof(ngx_regex_elt_t));
388 if (rcf->studies == NULL) { 388 if (rcf->studies == NULL) {
389 return NULL; 389 return NULL;
390 } 390 }
391 391
392 ngx_pcre_studies = rcf->studies; 392 ngx_regex_studies = rcf->studies;
393 393
394 return rcf; 394 return rcf;
395 } 395 }
396 396
397 397