]> granicus.if.org Git - apache/commitdiff
mod_lua: Improve compatibility with Lua 5.1, 5.2 and 5.3.
authorRainer Jung <rjung@apache.org>
Tue, 4 Jul 2017 22:28:38 +0000 (22:28 +0000)
committerRainer Jung <rjung@apache.org>
Tue, 4 Jul 2017 22:28:38 +0000 (22:28 +0000)
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
modules/lua/README
modules/lua/config.m4
modules/lua/lua_apr.c
modules/lua/lua_config.c
modules/lua/lua_request.c
modules/lua/mod_lua.c
modules/lua/mod_lua.h

diff --git a/CHANGES b/CHANGES
index 3490b2a54e5d02b09816c0246c183a54a060674f..12110cff32443bedf270087199ff32f0b9e3fbf7 100644 (file)
--- 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]
   
index c8cacb40aa8548b7e39d793635c143dae282f89c..e0106e85679064b45212eecd588ae65a182ea147 100644 (file)
@@ -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,
index 1c20bee63f8bf330b71e6423d9832c7a493abab5..73d4f8aabe08c3e363fcf46b85e7d1ef02e61e9a 100644 (file)
@@ -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 <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
index fd3ba20e7a7c4a2a167fd79d4b3b5affa3c057c3..8e34cf30828b595147200dca0c3538ac6d805c55 100644 (file)
@@ -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);
index bc09bdcffb444f10b7e9b83c49177a5763bddde1..14674a901d9368aa5b9eda083aa86c699c899cd9 100644 (file)
@@ -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] */
 
 }
index 4cb4fd00674333eef8a9cda54a776a6dde2acca5..f9f9ae640a3ee4f368691f52e844b54e5d0f6247 100644 (file)
@@ -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);
 
index 46e71f365225eae2f96cbfe23e91ac6b3ed4227a..6d791995953ab038d7c923763e4345c8b9fbff50 100644 (file)
@@ -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);
index cd2025b1b760329d10e8d08079c58718bab4fb50..0e49cdc0d4b38eb8a47bedcfe8ef1d52bd422b16 100644 (file)
 #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