Skip to content

Commit 8d069ee

Browse files
committed
Fix build, add guards and extract magic numbers
1 parent a3f548f commit 8d069ee

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

src/ngx_http_lua_common.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@
2222
#include <lauxlib.h>
2323

2424

25+
#if (NGX_PCRE)
26+
27+
#include <pcre.h>
28+
29+
#if (PCRE_MAJOR > 8) || (PCRE_MAJOR == 8 && PCRE_MINOR >= 21)
30+
# define LUA_HAVE_PCRE_JIT 1
31+
#else
32+
# define LUA_HAVE_PCRE_JIT 0
33+
#endif
34+
35+
#endif
36+
37+
2538
#if !defined(nginx_version) || (nginx_version < 1006000)
2639
#error at least nginx 1.6.0 is required but found an older version
2740
#endif
@@ -159,7 +172,11 @@ struct ngx_http_lua_main_conf_s {
159172
ngx_int_t regex_cache_entries;
160173
ngx_int_t regex_cache_max_entries;
161174
ngx_int_t regex_match_limit;
162-
pcre_jit_stack jit_stack;
175+
176+
#if (LUA_HAVE_PCRE_JIT)
177+
pcre_jit_stack *jit_stack;
178+
#endif
179+
163180
#endif
164181

165182
ngx_array_t *shm_zones; /* of ngx_shm_zone_t* */

src/ngx_http_lua_module.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
#include "ngx_http_lua_ssl_certby.h"
2929

3030

31+
#if (NGX_PCRE)
32+
33+
#if (PCRE_MAJOR > 8) || (PCRE_MAJOR == 8 && PCRE_MINOR >= 21)
34+
# define LUA_HAVE_PCRE_JIT 1
35+
# define NGX_LUA_RE_MIN_JIT_STACK_SIZE 32 * 1024
36+
#else
37+
# define LUA_HAVE_PCRE_JIT 0
38+
#endif
39+
40+
#endif
41+
42+
3143
static void *ngx_http_lua_create_main_conf(ngx_conf_t *cf);
3244
static char *ngx_http_lua_init_main_conf(ngx_conf_t *cf, void *conf);
3345
static void *ngx_http_lua_create_srv_conf(ngx_conf_t *cf);
@@ -798,7 +810,12 @@ ngx_http_lua_create_main_conf(ngx_conf_t *cf)
798810
#if (NGX_PCRE)
799811
lmcf->regex_cache_max_entries = NGX_CONF_UNSET;
800812
lmcf->regex_match_limit = NGX_CONF_UNSET;
801-
lmcf->jit_stack = pcre_jit_stack_alloc(32*1024, 32*1024);
813+
814+
#if (LUA_HAVE_PCRE_JIT)
815+
lmcf->jit_stack = pcre_jit_stack_alloc(NGX_LUA_RE_MIN_JIT_STACK_SIZE,
816+
NGX_LUA_RE_MIN_JIT_STACK_SIZE);
817+
#endif
818+
802819
#endif
803820
lmcf->postponed_to_rewrite_phase_end = NGX_CONF_UNSET;
804821
lmcf->postponed_to_access_phase_end = NGX_CONF_UNSET;

src/ngx_http_lua_regex.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
#define NGX_LUA_RE_DFA_MODE_WORKSPACE_COUNT (100)
4444

45+
#define NGX_LUA_RE_MIN_JIT_STACK_SIZE 32 * 1024
46+
4547

4648
typedef struct {
4749
#ifndef NGX_LUA_NO_FFI_API
@@ -2481,20 +2483,21 @@ ngx_http_lua_ffi_max_regex_cache_size(void)
24812483
return (uint32_t) lmcf->regex_cache_max_entries;
24822484
}
24832485

2486+
24842487
void
24852488
ngx_http_lua_ffi_set_jit_stack_size(int size)
24862489
{
2487-
int min_size;
24882490
ngx_http_lua_main_conf_t *lmcf;
24892491

2490-
min_size = MIN(32 * 1024, size);
2491-
lmcf = ngx_http_cycle_get_module_main_conf(ngx_cycle,
2492-
ngx_http_lua_module);
2493-
if (lmcf == NULL) {
2492+
if (size < NGX_LUA_RE_MIN_JIT_STACK_SIZE) {
24942493
return;
24952494
}
2495+
2496+
lmcf = ngx_http_cycle_get_module_main_conf(ngx_cycle,
2497+
ngx_http_lua_module);
24962498
pcre_jit_stack_free(lmcf->jit_stack);
2497-
lmcf->jit_stack = pcre_jit_stack_alloc(min_size, size);
2499+
lmcf->jit_stack = pcre_jit_stack_alloc(NGX_LUA_RE_MIN_JIT_STACK_SIZE,
2500+
size);
24982501
}
24992502
#endif /* NGX_LUA_NO_FFI_API */
25002503

0 commit comments

Comments
 (0)