]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Support building against Lua 5.4 by adjusting to the 3-arg form of
authorJoe Orton <jorton@apache.org>
Fri, 7 Aug 2020 12:21:35 +0000 (12:21 +0000)
committerJoe Orton <jorton@apache.org>
Fri, 7 Aug 2020 12:21:35 +0000 (12:21 +0000)
lua_resume().

* modules/lua/config.m4 (CHECK_LUA): Check for lua5.4 paths.

* modules/lua/mod_lua.c (lua_output_filter_handle,
  lua_input_filter_handle): Check that exactly one item is on the
  stack as indicated by lua_resume().

Submitted by: Lubos Uhliarik <luhliari redhat.com>, jorton
PR: 64591
Github: closes #130, closes #133, closes #134

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1880678 13f79535-47bb-0310-9956-ffa450edef68

modules/lua/config.m4
modules/lua/mod_lua.c
modules/lua/mod_lua.h

index 76f33e06e40bcbd76c41f06df68dd52bec9e2205..9fefa626decaaa132936cf1984ae0faea547005c 100644 (file)
@@ -34,7 +34,7 @@ AC_DEFUN([CHECK_LUA_PATH], [dnl
     fi
 ])
 
-dnl Check for Lua 5.3/5.2/5.1 Libraries
+dnl Check for Lua Libraries
 dnl CHECK_LUA(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
 dnl Sets:
 dnl  LUA_CFLAGS
@@ -44,7 +44,7 @@ AC_DEFUN([CHECK_LUA],
 
 AC_ARG_WITH(
     lua,
-    [AC_HELP_STRING([--with-lua=PATH],[Path to the Lua 5.3/5.2/5.1 prefix])],
+    [AC_HELP_STRING([--with-lua=PATH],[Path to the Lua installation prefix])],
     lua_path="$withval",
     :)
 
@@ -55,7 +55,7 @@ else
     test_paths="${lua_path}"
 fi
 
-for pklua in lua lua5.3 lua5.2 lua5.1; do
+for pklua in lua lua5.4 lua5.3 lua5.2 lua5.1; do
   if test -n "$PKGCONFIG" -a -z "$lua_path" \
      && $PKGCONFIG --atleast-version=5.1 $pklua; then
     LUA_LIBS="`$PKGCONFIG --libs $pklua`"
index c6790ac9df9e41cd2093eb6a9261791f42d9b7ee..a7795c4749fcd08c2b65c58c26e40f44eef02b70 100644 (file)
@@ -342,7 +342,7 @@ static apr_status_t lua_setup_filter_ctx(ap_filter_t* f, request_rec* r, lua_fil
 {
     apr_pool_t *pool;
     ap_lua_vm_spec *spec;
-    int n, rc;
+    int n, rc, nres;
     lua_State *L;
     lua_filter_ctx *ctx;    
     ap_lua_server_cfg *server_cfg = ap_get_module_config(r->server->module_config,
@@ -410,7 +410,7 @@ static apr_status_t lua_setup_filter_ctx(ap_filter_t* f, request_rec* r, lua_fil
             /* If a Lua filter is interested in filtering a request, it must first do a yield, 
              * otherwise we'll assume that it's not interested and pretend we didn't find it.
              */
-            rc = lua_resume(L, 1);
+            rc = lua_resume(L, 1, &nres);
             if (rc == LUA_YIELD) {
                 if (f->frec->providers == NULL) { 
                     /* Not wired by mod_filter */
@@ -432,7 +432,7 @@ static apr_status_t lua_setup_filter_ctx(ap_filter_t* f, request_rec* r, lua_fil
 static apr_status_t lua_output_filter_handle(ap_filter_t *f, apr_bucket_brigade *pbbIn)
 {
     request_rec *r = f->r;
-    int rc;
+    int rc, nres;
     lua_State *L;
     lua_filter_ctx* ctx;
     conn_rec *c = r->connection;
@@ -492,7 +492,7 @@ static apr_status_t lua_output_filter_handle(ap_filter_t *f, apr_bucket_brigade
             lua_setglobal(L, "bucket");
             
             /* If Lua yielded, it means we have something to pass on */
-            if (lua_resume(L, 0) == LUA_YIELD) {
+            if (lua_resume(L, 0, &nres) == LUA_YIELD && nres == 1) {
                 size_t olen;
                 const char* output = lua_tolstring(L, 1, &olen);
                 if (olen > 0) { 
@@ -524,7 +524,7 @@ static apr_status_t lua_output_filter_handle(ap_filter_t *f, apr_bucket_brigade
             apr_bucket *pbktEOS;
             lua_pushnil(L);
             lua_setglobal(L, "bucket");
-            if (lua_resume(L, 0) == LUA_YIELD) {
+            if (lua_resume(L, 0, &nres) == LUA_YIELD && nres == 1) {
                 apr_bucket *pbktOut;
                 size_t olen;
                 const char* output = lua_tolstring(L, 1, &olen);
@@ -558,7 +558,7 @@ static apr_status_t lua_input_filter_handle(ap_filter_t *f,
                                        apr_off_t nBytes) 
 {
     request_rec *r = f->r;
-    int rc, lastCall = 0;
+    int rc, lastCall = 0, nres;
     lua_State *L;
     lua_filter_ctx* ctx;
     conn_rec *c = r->connection;
@@ -621,7 +621,7 @@ static apr_status_t lua_input_filter_handle(ap_filter_t *f,
             lua_setglobal(L, "bucket");
             
             /* If Lua yielded, it means we have something to pass on */
-            if (lua_resume(L, 0) == LUA_YIELD) {
+            if (lua_resume(L, 0, &nres) == LUA_YIELD && nres == 1) {
                 size_t olen;
                 const char* output = lua_tolstring(L, 1, &olen);
                 pbktOut = apr_bucket_heap_create(output, olen, 0, c->bucket_alloc);
@@ -643,7 +643,7 @@ static apr_status_t lua_input_filter_handle(ap_filter_t *f,
             apr_bucket *pbktEOS = apr_bucket_eos_create(c->bucket_alloc);
             lua_pushnil(L);
             lua_setglobal(L, "bucket");
-            if (lua_resume(L, 0) == LUA_YIELD) {
+            if (lua_resume(L, 0, &nres) == LUA_YIELD && nres == 1) {
                 apr_bucket *pbktOut;
                 size_t olen;
                 const char* output = lua_tolstring(L, 1, &olen);
index 0e49cdc0d4b38eb8a47bedcfe8ef1d52bd422b16..72b4de744c02659b7159b560d2a838868f1855e6 100644 (file)
 #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)
+
+#if LUA_VERSION_NUM > 503
+#define lua_resume(a,b,c)    lua_resume(a, NULL, b, c)
+#else
+/* ### For version < 5.4, assume that exactly one stack item is on the
+ * stack, which is what the code did before but seems dubious. */
+#define lua_resume(a,b,c)    (*(c) = 1, lua_resume(a, NULL, b))
+#endif
+
 #define luaL_setfuncs_compat(a,b) luaL_setfuncs(a,b,0)
 #else
 #define lua_rawlen(L,i)    lua_objlen(L, (i))