From: Rainer Jung Date: Tue, 4 Jul 2017 22:28:38 +0000 (+0000) Subject: mod_lua: Improve compatibility with Lua 5.1, 5.2 and 5.3. X-Git-Tag: 2.4.27~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9552c8947cd919a59d9ff2dbe45d842de5cce991;p=thirdparty%2Fapache%2Fhttpd.git mod_lua: Improve compatibility with Lua 5.1, 5.2 and 5.3. PR58188, PR60831, PR61245. CTR The following lua 5.2 and 5.3 compat change should be checked for runtime correctness by someone more knowledgeable about lua. Index: modules/lua/lua_apr.c --- modules/lua/lua_apr.c (original) +++ modules/lua/lua_apr.c Tue Jul 4 20:48:43 2017 @@ -82,7 +82,11 @@ static const luaL_Reg lua_table_methods[ int ap_lua_init(lua_State *L, apr_pool_t *p) { luaL_newmetatable(L, "Apr.Table"); +#if LUA_VERSION_NUM < 502 luaL_register(L, "apr_table", lua_table_methods); +#else + luaL_newlib(L, lua_table_methods); +#endif lua_pushstring(L, "__index"); lua_pushstring(L, "get"); lua_gettable(L, 2); git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1800835 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 3490b2a54e5..12110cff324 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.4.27 + *) mod_lua: Improve compatibility with Lua 5.1, 5.2 and 5.3. + PR58188, PR60831, PR61245. [Rainer Jung] + *) mod_http2: disable and give warning when mpm_prefork is encountered. The server will continue to work, but HTTP/2 will no longer be negotiated. [Stefan Eissing] diff --git a/modules/lua/README b/modules/lua/README index c8cacb40aa8..e0106e85679 100644 --- a/modules/lua/README +++ b/modules/lua/README @@ -23,6 +23,9 @@ ** TODO: document or remove block sections ** TODO: test per-dir behavior of block sections ** TODO: Suppress internal details (fs path to scripts, etc) in error responses +** TODO: Check whether we can tighten the mode flag in lua_load(), + luaL_loadfile() an dluaL_loadbuffer() from NULL (="bt") + to e.g. "t". * License Apache License, Version 2.0, diff --git a/modules/lua/config.m4 b/modules/lua/config.m4 index 1c20bee63f8..73d4f8aabe0 100644 --- a/modules/lua/config.m4 +++ b/modules/lua/config.m4 @@ -12,47 +12,19 @@ AC_DEFUN([CHECK_LUA_PATH], [dnl AC_MSG_CHECKING([for lua.h in $1/$2]) if test -f $1/$2/lua.h; then AC_MSG_RESULT([yes]) - save_CFLAGS=$CFLAGS save_LDFLAGS=$LDFLAGS - save_LIBS=$LIBS - CFLAGS="$CFLAGS" LDFLAGS="-L$1/$3 $LDFLAGS $lib_m" - AC_CHECK_LIB($4, luaL_newstate, [ - dnl mod_lua relies on some compatibility APIs to function. - AC_MSG_CHECKING([for luaL_register in -l$4]) - CFLAGS="$CFLAGS -I$1/$2" - LIBS="-l$4" - AC_LINK_IFELSE([ - AC_LANG_PROGRAM([[ - #define LUA_COMPAT_ALL - #define LUA_COMPAT_5_2 - #define LUA_COMPAT_5_1 - #define LUA_COMPAT_MODULE - - #include - #include - ]], [[ - /* This isn't a valid call, but we're testing linkability */ - luaL_register(NULL, NULL, NULL); - ]]) - ], [ - AC_MSG_RESULT([yes]) - LUA_LIBS="-L$1/$3 -l$4 $lib_m" - if test "x$ap_platform_runtime_link_flag" != "x"; then - APR_ADDTO(LUA_LIBS, [$ap_platform_runtime_link_flag$1/$3]) - fi - LUA_CFLAGS="-I$1/$2" - ], [ - AC_MSG_RESULT([no]) - ]) + LUA_LIBS="-L$1/$3 -l$4 $lib_m" + if test "x$ap_platform_runtime_link_flag" != "x"; then + APR_ADDTO(LUA_LIBS, [$ap_platform_runtime_link_flag$1/$3]) + fi + LUA_CFLAGS="-I$1/$2" ]) - CFLAGS=$save_CFLAGS LDFLAGS=$save_LDFLAGS - LIBS=$save_LIBS if test -n "${LUA_LIBS}"; then break diff --git a/modules/lua/lua_apr.c b/modules/lua/lua_apr.c index fd3ba20e7a7..8e34cf30828 100644 --- a/modules/lua/lua_apr.c +++ b/modules/lua/lua_apr.c @@ -82,7 +82,11 @@ static const luaL_Reg lua_table_methods[] = { int ap_lua_init(lua_State *L, apr_pool_t *p) { luaL_newmetatable(L, "Apr.Table"); +#if LUA_VERSION_NUM < 502 luaL_register(L, "apr_table", lua_table_methods); +#else + luaL_newlib(L, lua_table_methods); +#endif lua_pushstring(L, "__index"); lua_pushstring(L, "get"); lua_gettable(L, 2); diff --git a/modules/lua/lua_config.c b/modules/lua/lua_config.c index bc09bdcffb4..14674a901d9 100644 --- a/modules/lua/lua_config.c +++ b/modules/lua/lua_config.c @@ -265,13 +265,13 @@ void ap_lua_load_config_lmodule(lua_State *L) lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); - luaL_register(L, NULL, cfg_methods); /* [metatable] */ + luaL_setfuncs_compat(L, cfg_methods); /* [metatable] */ luaL_newmetatable(L, "Apache2.CommandParameters"); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); - luaL_register(L, NULL, cmd_methods); /* [metatable] */ + luaL_setfuncs_compat(L, cmd_methods); /* [metatable] */ } diff --git a/modules/lua/lua_request.c b/modules/lua/lua_request.c index 4cb4fd00674..f9f9ae640a3 100644 --- a/modules/lua/lua_request.c +++ b/modules/lua/lua_request.c @@ -345,7 +345,7 @@ static int req_parsebody(lua_State *L) char *multipart; const char *contentType; request_rec *r = ap_lua_check_request_rec(L, 1); - max_post_size = (apr_size_t) luaL_optint(L, 2, MAX_STRING_LEN); + max_post_size = (apr_size_t) luaL_optinteger(L, 2, MAX_STRING_LEN); multipart = apr_pcalloc(r->pool, 256); contentType = apr_table_get(r->headers_in, "Content-Type"); lua_newtable(L); @@ -418,7 +418,7 @@ static int lua_ap_requestbody(lua_State *L) r = ap_lua_check_request_rec(L, 1); filename = luaL_optstring(L, 2, 0); - maxSize = luaL_optint(L, 3, 0); + maxSize = (apr_off_t)luaL_optinteger(L, 3, 0); if (r) { apr_off_t size; @@ -1708,7 +1708,7 @@ static int lua_ap_make_etag(lua_State *L) luaL_checktype(L, 1, LUA_TUSERDATA); r = ap_lua_check_request_rec(L, 1); luaL_checktype(L, 2, LUA_TBOOLEAN); - force_weak = luaL_optint(L, 2, 0); + force_weak = (int)luaL_optinteger(L, 2, 0); returnValue = ap_make_etag(r, force_weak); lua_pushstring(L, returnValue); return 1; @@ -2040,7 +2040,7 @@ static int lua_set_cookie(lua_State *L) /* expiry */ lua_pushstring(L, "expires"); lua_gettable(L, -2); - expires = luaL_optint(L, -1, 0); + expires = (int)luaL_optinteger(L, -1, 0); lua_pop(L, 1); /* secure */ @@ -2955,27 +2955,27 @@ void ap_lua_load_request_lmodule(lua_State *L, apr_pool_t *p) lua_pushlightuserdata(L, dispatch); lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch"); - luaL_newmetatable(L, "Apache2.Request"); /* [metatable] */ + luaL_newmetatable(L, "Apache2.Request"); /* [metatable] */ lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); - luaL_register(L, NULL, request_methods); /* [metatable] */ + luaL_setfuncs_compat(L, request_methods); /* [metatable] */ lua_pop(L, 2); - luaL_newmetatable(L, "Apache2.Connection"); /* [metatable] */ + luaL_newmetatable(L, "Apache2.Connection"); /* [metatable] */ lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); - luaL_register(L, NULL, connection_methods); /* [metatable] */ + luaL_setfuncs_compat(L, connection_methods); /* [metatable] */ lua_pop(L, 2); - luaL_newmetatable(L, "Apache2.Server"); /* [metatable] */ + luaL_newmetatable(L, "Apache2.Server"); /* [metatable] */ lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); - luaL_register(L, NULL, server_methods); /* [metatable] */ + luaL_setfuncs_compat(L, server_methods); /* [metatable] */ lua_pop(L, 2); diff --git a/modules/lua/mod_lua.c b/modules/lua/mod_lua.c index 46e71f36522..6d791995953 100644 --- a/modules/lua/mod_lua.c +++ b/modules/lua/mod_lua.c @@ -1080,13 +1080,9 @@ static const char *register_named_block_function_hook(const char *name, else { luaL_Buffer b; luaL_buffinit(lvm, &b); -#if LUA_VERSION_NUM >= 503 - lua_dump(lvm, ldump_writer, &b, 0); -#else lua_dump(lvm, ldump_writer, &b); -#endif luaL_pushresult(&b); - spec->bytecode_len = lua_strlen(lvm, -1); + spec->bytecode_len = lua_rawlen(lvm, -1); spec->bytecode = apr_pstrmemdup(cmd->pool, lua_tostring(lvm, -1), spec->bytecode_len); lua_close(lvm); diff --git a/modules/lua/mod_lua.h b/modules/lua/mod_lua.h index cd2025b1b76..0e49cdc0d4b 100644 --- a/modules/lua/mod_lua.h +++ b/modules/lua/mod_lua.h @@ -41,23 +41,21 @@ #include "apr_hooks.h" #include "apr_reslist.h" -/* Allow for Lua 5.2 backwards compatibility */ -#define LUA_COMPAT_ALL -/* Allow for Lua 5.3 backwards compatibility */ -#define LUA_COMPAT_5_2 -#define LUA_COMPAT_5_1 -#define LUA_COMPAT_MODULE - #include "lua.h" #include "lauxlib.h" #include "lualib.h" #if LUA_VERSION_NUM > 501 /* Load mode for lua_load() */ -#define lua_load(a,b,c,d) lua_load(a,b,c,d,NULL) -#define lua_resume(a,b) lua_resume(a, NULL, b) +#define lua_load(a,b,c,d) lua_load(a,b,c,d,NULL) +#define lua_resume(a,b) lua_resume(a, NULL, b) +#define luaL_setfuncs_compat(a,b) luaL_setfuncs(a,b,0) #else -#define lua_rawlen(L,i) lua_objlen(L, (i)) +#define lua_rawlen(L,i) lua_objlen(L, (i)) +#define luaL_setfuncs_compat(a,b) luaL_register(a,NULL,b) +#endif +#if LUA_VERSION_NUM > 502 +#define lua_dump(a,b,c) lua_dump(a,b,c,0) #endif /* Create a set of AP_LUA_DECLARE(type), AP_LUA_DECLARE_NONSTD(type) and