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
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]
** 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,
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 <lua.h>
- #include <lauxlib.h>
- ]], [[
- /* 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
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);
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] */
}
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);
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;
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;
/* 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 */
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);
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);
#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