Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions modules/ngx_http_lua_module/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ env:
- LUAJIT_INC=$LUAJIT_PREFIX/include/luajit-2.1
- LUA_INCLUDE_DIR=$LUAJIT_INC
- PCRE_VER=8.45
- PCRE2_VER=10.37
- PCRE_PREFIX=/opt/pcre
- PCRE2_PREFIX=/opt/pcre2
- PCRE_LIB=$PCRE_PREFIX/lib
- PCRE2_LIB=$PCRE2_PREFIX/lib
- PCRE_INC=$PCRE_PREFIX/include
- PCRE2_INC=$PCRE2_PREFIX/include
- OPENSSL_PREFIX=/opt/ssl
- OPENSSL_LIB=$OPENSSL_PREFIX/lib
- OPENSSL_INC=$OPENSSL_PREFIX/include
Expand All @@ -52,7 +56,7 @@ env:
- TEST_NGINX_SLEEP=0.006
jobs:
- NGINX_VERSION=1.21.4 OPENSSL_VER=1.1.0l OPENSSL_PATCH_VER=1.1.0d
- NGINX_VERSION=1.21.4 OPENSSL_VER=1.1.1s OPENSSL_PATCH_VER=1.1.1f
- NGINX_VERSION=1.21.4 OPENSSL_VER=1.1.1s OPENSSL_PATCH_VER=1.1.1f USE_PCRE2=Y

services:
- memcached
Expand All @@ -68,7 +72,8 @@ before_install:
- pyenv global 2.7
install:
- if [ ! -f download-cache/drizzle7-$DRIZZLE_VER.tar.gz ]; then wget -P download-cache http://openresty.org/download/drizzle7-$DRIZZLE_VER.tar.gz; fi
- if [ ! -f download-cache/pcre-$PCRE_VER.tar.gz ]; then wget -P download-cache https://downloads.sourceforge.net/project/pcre/pcre/${PCRE_VER}/pcre-${PCRE_VER}.tar.gz; fi
- if [ "$USE_PCRE2" != "Y" ] && [ ! -f download-cache/pcre-$PCRE_VER.tar.gz ]; then wget -P download-cache https://downloads.sourceforge.net/project/pcre/pcre/${PCRE_VER}/pcre-${PCRE_VER}.tar.gz; fi
- if [ "$USE_PCRE2" = "Y" ] && [ ! -f download-cache/pcre2-$PCRE2_VER.tar.gz ]; then wget -P download-cache https://downloads.sourceforge.net/project/pcre/pcre2/${PCRE2_VER}/pcre2-${PCRE2_VER}.tar.gz; fi
- if [ ! -f download-cache/openssl-$OPENSSL_VER.tar.gz ]; then wget -P download-cache https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz || wget -P download-cache https://www.openssl.org/source/old/${OPENSSL_VER//[a-z]/}/openssl-$OPENSSL_VER.tar.gz; fi
- git clone https://github.com/openresty/test-nginx.git
- git clone https://github.com/openresty/openresty.git ../openresty
Expand Down Expand Up @@ -116,12 +121,8 @@ script:
- sudo make install-libdrizzle-1.0 > build.log 2>&1 || (cat build.log && exit 1)
- cd ../mockeagain/ && make CC=$CC -j$JOBS && cd ..
- cd lua-cjson/ && make -j$JOBS && sudo make install && cd ..
- tar zxf download-cache/pcre-$PCRE_VER.tar.gz
- cd pcre-$PCRE_VER/
- ./configure --prefix=$PCRE_PREFIX --enable-jit --enable-utf --enable-unicode-properties > build.log 2>&1 || (cat build.log && exit 1)
- make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1)
- sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1)
- cd ..
- if [ "$USE_PCRE2" != "Y" ]; then tar zxf download-cache/pcre-$PCRE_VER.tar.gz; cd pcre-$PCRE_VER/; ./configure --prefix=$PCRE_PREFIX --enable-jit --enable-utf --enable-unicode-properties > build.log 2>&1 || (cat build.log && exit 1); make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1); sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1); cd ..; fi
- if [ "$USE_PCRE2" = "Y" ]; then tar zxf download-cache/pcre2-$PCRE2_VER.tar.gz; cd pcre2-$PCRE2_VER/; ./configure --prefix=$PCRE2_PREFIX --enable-jit --enable-utf > build.log 2>&1 || (cat build.log && exit 1); make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1); sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1); cd ..; fi
- tar zxf download-cache/openssl-$OPENSSL_VER.tar.gz
- cd openssl-$OPENSSL_VER/
- patch -p1 < ../../openresty/patches/openssl-$OPENSSL_PATCH_VER-sess_set_get_cb_yield.patch
Expand Down
21 changes: 16 additions & 5 deletions modules/ngx_http_lua_module/src/ngx_http_lua_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ typedef struct {


#if (NGX_PCRE)
#include <pcre.h>
# if (PCRE_MAJOR > 8) || (PCRE_MAJOR == 8 && PCRE_MINOR >= 21)
# if (NGX_PCRE2)
# define LUA_HAVE_PCRE_JIT 1
# else
# define LUA_HAVE_PCRE_JIT 0

#include <pcre.h>

# if (PCRE_MAJOR > 8) || (PCRE_MAJOR == 8 && PCRE_MINOR >= 21)
# define LUA_HAVE_PCRE_JIT 1
# else
# define LUA_HAVE_PCRE_JIT 0
# endif
# endif
#endif

Expand Down Expand Up @@ -221,9 +227,14 @@ struct ngx_http_lua_main_conf_s {
ngx_int_t regex_cache_entries;
ngx_int_t regex_cache_max_entries;
ngx_int_t regex_match_limit;
# if (LUA_HAVE_PCRE_JIT)
#endif

#if (LUA_HAVE_PCRE_JIT)
#if (NGX_PCRE2)
pcre2_jit_stack *jit_stack;
#else
pcre_jit_stack *jit_stack;
# endif
#endif
#endif

ngx_array_t *shm_zones; /* of ngx_shm_zone_t* */
Expand Down
14 changes: 14 additions & 0 deletions modules/ngx_http_lua_module/src/ngx_http_lua_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ static char *ngx_http_lua_ssl_conf_command_check(ngx_conf_t *cf, void *post,
#endif
static char *ngx_http_lua_malloc_trim(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
#if (NGX_PCRE2)
extern void ngx_http_lua_regex_cleanup(void *data);
#endif


static ngx_conf_post_t ngx_http_lua_lowat_post =
Expand Down Expand Up @@ -839,6 +842,17 @@ ngx_http_lua_init(ngx_conf_t *cf)
cln->data = lmcf;
cln->handler = ngx_http_lua_sema_mm_cleanup;

#if (NGX_PCRE2)
/* add the cleanup of pcre2 regex */
cln = ngx_pool_cleanup_add(cf->pool, 0);
if (cln == NULL) {
return NGX_ERROR;
}

cln->data = lmcf;
cln->handler = ngx_http_lua_regex_cleanup;
#endif

#ifdef HAVE_NGX_LUA_PIPE
ngx_http_lua_pipe_init();
#endif
Expand Down
84 changes: 83 additions & 1 deletion modules/ngx_http_lua_module/src/ngx_http_lua_pcrefix.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,61 @@

static ngx_pool_t *ngx_http_lua_pcre_pool = NULL;


#if (NGX_PCRE2)
static ngx_uint_t ngx_regex_direct_alloc;
#else
static void *(*old_pcre_malloc)(size_t);
static void (*old_pcre_free)(void *ptr);
#endif


/* XXX: work-around to nginx regex subsystem, must init a memory pool
* to use PCRE functions. As PCRE still has memory-leaking problems,
* and nginx overwrote pcre_malloc/free hooks with its own static
* functions, so nobody else can reuse nginx regex subsystem... */
static void *
#if (NGX_PCRE2)

void *
ngx_http_lua_pcre_malloc(size_t size, void *data)
{
dd("lua pcre pool is %p", ngx_http_lua_pcre_pool);

if (ngx_http_lua_pcre_pool) {
return ngx_palloc(ngx_http_lua_pcre_pool, size);
}

if (ngx_regex_direct_alloc) {
return ngx_alloc(size, ngx_cycle->log);
}

fprintf(stderr, "error: lua pcre malloc failed due to empty pcre pool");

return NULL;
}


void
ngx_http_lua_pcre_free(void *ptr, void *data)
{
dd("lua pcre pool is %p", ngx_http_lua_pcre_pool);

if (ngx_http_lua_pcre_pool) {
ngx_pfree(ngx_http_lua_pcre_pool, ptr);
return;
}

if (ngx_regex_direct_alloc) {
ngx_free(ptr);
return;
}

fprintf(stderr, "error: lua pcre free failed due to empty pcre pool");
}

#else

void *
ngx_http_lua_pcre_malloc(size_t size)
{
dd("lua pcre pool is %p", ngx_http_lua_pcre_pool);
Expand Down Expand Up @@ -54,6 +100,41 @@ ngx_http_lua_pcre_free(void *ptr)
fprintf(stderr, "error: lua pcre free failed due to empty pcre pool");
}

#endif


#if (NGX_PCRE2)

ngx_pool_t *
ngx_http_lua_pcre_malloc_init(ngx_pool_t *pool)
{
ngx_pool_t *old_pool;

dd("lua pcre pool was %p", ngx_http_lua_pcre_pool);

ngx_regex_direct_alloc = (pool == NULL) ? 1 : 0;

old_pool = ngx_http_lua_pcre_pool;
ngx_http_lua_pcre_pool = pool;

dd("lua pcre pool is %p", ngx_http_lua_pcre_pool);

return old_pool;
}


void
ngx_http_lua_pcre_malloc_done(ngx_pool_t *old_pool)
{
dd("lua pcre pool was %p", ngx_http_lua_pcre_pool);

ngx_http_lua_pcre_pool = old_pool;
ngx_regex_direct_alloc = 0;

dd("lua pcre pool is %p", ngx_http_lua_pcre_pool);
}

#else

ngx_pool_t *
ngx_http_lua_pcre_malloc_init(ngx_pool_t *pool)
Expand Down Expand Up @@ -101,6 +182,7 @@ ngx_http_lua_pcre_malloc_done(ngx_pool_t *old_pool)
}
}

#endif
#endif /* NGX_PCRE */

/* vi:set ft=c ts=4 sw=4 et fdm=marker: */
7 changes: 7 additions & 0 deletions modules/ngx_http_lua_module/src/ngx_http_lua_pcrefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@


#if (NGX_PCRE)

ngx_pool_t *ngx_http_lua_pcre_malloc_init(ngx_pool_t *pool);
void ngx_http_lua_pcre_malloc_done(ngx_pool_t *old_pool);

#if NGX_PCRE2
void *ngx_http_lua_pcre_malloc(size_t size, void *data);
void ngx_http_lua_pcre_free(void *ptr, void *data);
#endif

#endif


Expand Down
Loading