fd5d1e8
From b15794f391547a983c64afed029a883fed3c3c1c Mon Sep 17 00:00:00 2001
fd5d1e8
From: Matt Domsch <matt@domsch.com>
fd5d1e8
Date: Sat, 25 Apr 2020 23:04:38 -0500
fd5d1e8
Subject: [PATCH] support for lua 5.3
fd5d1e8
fd5d1e8
---
fd5d1e8
 miltertest/miltertest.c | 14 +++----
fd5d1e8
 opendkim/opendkim-lua.c | 82 +++++++++++++++++++++++++----------------
fd5d1e8
 2 files changed, 58 insertions(+), 38 deletions(-)
fd5d1e8
fd5d1e8
diff --git a/miltertest/miltertest.c b/miltertest/miltertest.c
fd5d1e8
index 04e50c04..37dc601d 100644
fd5d1e8
--- a/miltertest/miltertest.c
fd5d1e8
+++ b/miltertest/miltertest.c
fd5d1e8
@@ -4009,12 +4009,12 @@ main(int argc, char **argv)
fd5d1e8
 	}
fd5d1e8
 
fd5d1e8
 	/* register functions */
fd5d1e8
-#if LUA_VERSION_NUM == 502
fd5d1e8
-        luaL_newlib(l, mt_library);
fd5d1e8
+#if LUA_VERSION_NUM >= 502
fd5d1e8
+	luaL_newlib(l, mt_library);
fd5d1e8
 	lua_setglobal(l, "mt");
fd5d1e8
-#else /* LUA_VERSION_NUM == 502 */
fd5d1e8
+#else /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	luaL_register(l, "mt", mt_library);
fd5d1e8
-#endif /* LUA_VERSION_NUM == 502 */
fd5d1e8
+#endif /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	lua_pop(l, 1);
fd5d1e8
 
fd5d1e8
 	/* register constants */
fd5d1e8
@@ -4163,13 +4163,13 @@ main(int argc, char **argv)
fd5d1e8
 	lua_setglobal(l, "SMFIF_SETSYMLIST");
fd5d1e8
 #endif /* SMFIF_SETSYMLIST */
fd5d1e8
 
fd5d1e8
-#if LUA_VERSION_NUM == 502
fd5d1e8
+#if LUA_VERSION_NUM >= 502
fd5d1e8
 	switch (lua_load(l, mt_lua_reader, (void *) &io,
fd5d1e8
 	                 script == NULL ? "(stdin)" : script, NULL))
fd5d1e8
-#else /* LUA_VERSION_NUM == 502 */
fd5d1e8
+#else /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	switch (lua_load(l, mt_lua_reader, (void *) &io,
fd5d1e8
 	                 script == NULL ? "(stdin)" : script))
fd5d1e8
-#endif /* LUA_VERSION_NUM == 502 */
fd5d1e8
+#endif /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	{
fd5d1e8
 	  case 0:
fd5d1e8
 		break;
fd5d1e8
diff --git a/opendkim/opendkim-lua.c b/opendkim/opendkim-lua.c
fd5d1e8
index 4720862c..3786aa4b 100644
fd5d1e8
--- a/opendkim/opendkim-lua.c
fd5d1e8
+++ b/opendkim/opendkim-lua.c
fd5d1e8
@@ -285,11 +285,11 @@ dkimf_lua_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
fd5d1e8
 		free(ptr);
fd5d1e8
 		return NULL;
fd5d1e8
 	}
fd5d1e8
-# if LUA_VERSION_NUM == 502
fd5d1e8
+# if LUA_VERSION_NUM >= 502
fd5d1e8
 	else if (nsize != 0 && ptr == NULL)
fd5d1e8
-# else /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# else /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	else if (nsize != 0 && osize == 0)
fd5d1e8
-# endif /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# endif /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	{
fd5d1e8
 		return malloc(nsize);
fd5d1e8
 	}
fd5d1e8
@@ -485,12 +485,12 @@ dkimf_lua_setup_hook(void *ctx, const char *script, size_t scriptlen,
fd5d1e8
 	**  Register functions.
fd5d1e8
 	*/
fd5d1e8
 
fd5d1e8
-# if LUA_VERSION_NUM == 502
fd5d1e8
+# if LUA_VERSION_NUM >= 502
fd5d1e8
 	luaL_newlib(l, dkimf_lua_lib_setup);
fd5d1e8
 	lua_setglobal(l, "odkim");
fd5d1e8
-# else /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# else /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	luaL_register(l, "odkim", dkimf_lua_lib_setup);
fd5d1e8
-# endif /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# endif /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	lua_pop(l, 1);
fd5d1e8
 
fd5d1e8
 	/*
fd5d1e8
@@ -532,11 +532,11 @@ dkimf_lua_setup_hook(void *ctx, const char *script, size_t scriptlen,
fd5d1e8
 	/* import other globals */
fd5d1e8
 	dkimf_import_globals(ctx, l);
fd5d1e8
 
fd5d1e8
-# if LUA_VERSION_NUM == 502
fd5d1e8
+# if LUA_VERSION_NUM >= 502
fd5d1e8
 	switch (lua_load(l, dkimf_lua_reader, (void *) &io, name, NULL))
fd5d1e8
-# else /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# else /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	switch (lua_load(l, dkimf_lua_reader, (void *) &io, name))
fd5d1e8
-# endif /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# endif /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	{
fd5d1e8
 	  case 0:
fd5d1e8
 		break;
fd5d1e8
@@ -564,8 +564,12 @@ dkimf_lua_setup_hook(void *ctx, const char *script, size_t scriptlen,
fd5d1e8
 		io.lua_io_len = 0;
fd5d1e8
 		io.lua_io_alloc = 0;
fd5d1e8
 
fd5d1e8
+#if LUA_VERSION_NUM >= 503
fd5d1e8
+		if (lua_dump(l, dkimf_lua_writer, &io, 0) == 0)
fd5d1e8
+#else
fd5d1e8
 		if (lua_dump(l, dkimf_lua_writer, &io) == 0)
fd5d1e8
-		{
fd5d1e8
+#endif
fd5d1e8
+	        {
fd5d1e8
 			*keep = (void *) io.lua_io_script;
fd5d1e8
 			*funclen = io.lua_io_len;
fd5d1e8
 		}
fd5d1e8
@@ -640,12 +644,12 @@ dkimf_lua_screen_hook(void *ctx, const char *script, size_t scriptlen,
fd5d1e8
 	**  Register functions.
fd5d1e8
 	*/
fd5d1e8
 
fd5d1e8
-# if LUA_VERSION_NUM == 502
fd5d1e8
+# if LUA_VERSION_NUM >= 502
fd5d1e8
 	luaL_newlib(l, dkimf_lua_lib_screen);
fd5d1e8
 	lua_setglobal(l, "odkim");
fd5d1e8
-# else /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# else /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	luaL_register(l, "odkim", dkimf_lua_lib_screen);
fd5d1e8
-# endif /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# endif /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	lua_pop(l, 1);
fd5d1e8
 
fd5d1e8
 	/*
fd5d1e8
@@ -677,11 +681,11 @@ dkimf_lua_screen_hook(void *ctx, const char *script, size_t scriptlen,
fd5d1e8
 	/* import other globals */
fd5d1e8
 	dkimf_import_globals(ctx, l);
fd5d1e8
 
fd5d1e8
-# if LUA_VERSION_NUM == 502
fd5d1e8
+# if LUA_VERSION_NUM >= 502
fd5d1e8
 	switch (lua_load(l, dkimf_lua_reader, (void *) &io, name, NULL))
fd5d1e8
-# else /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# else /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	switch (lua_load(l, dkimf_lua_reader, (void *) &io, name))
fd5d1e8
-# endif /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# endif /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	{
fd5d1e8
 	  case 0:
fd5d1e8
 		break;
fd5d1e8
@@ -709,7 +713,11 @@ dkimf_lua_screen_hook(void *ctx, const char *script, size_t scriptlen,
fd5d1e8
 		io.lua_io_len = 0;
fd5d1e8
 		io.lua_io_alloc = 0;
fd5d1e8
 
fd5d1e8
+#if LUA_VERSION_NUM >= 503
fd5d1e8
+		if (lua_dump(l, dkimf_lua_writer, &io, 0) == 0)
fd5d1e8
+#else		  
fd5d1e8
 		if (lua_dump(l, dkimf_lua_writer, &io) == 0)
fd5d1e8
+#endif
fd5d1e8
 		{
fd5d1e8
 			*keep = (void *) io.lua_io_script;
fd5d1e8
 			*funclen = io.lua_io_len;
fd5d1e8
@@ -785,12 +793,12 @@ dkimf_lua_stats_hook(void *ctx, const char *script, size_t scriptlen,
fd5d1e8
 	**  Register functions.
fd5d1e8
 	*/
fd5d1e8
 
fd5d1e8
-# if LUA_VERSION_NUM == 502
fd5d1e8
+# if LUA_VERSION_NUM >= 502
fd5d1e8
 	luaL_newlib(l, dkimf_lua_lib_stats);
fd5d1e8
 	lua_setglobal(l, "odkim");
fd5d1e8
-# else /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# else /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	luaL_register(l, "odkim", dkimf_lua_lib_stats);
fd5d1e8
-# endif /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# endif /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	lua_pop(l, 1);
fd5d1e8
 
fd5d1e8
 	/*
fd5d1e8
@@ -914,11 +922,11 @@ dkimf_lua_stats_hook(void *ctx, const char *script, size_t scriptlen,
fd5d1e8
 	/* import other globals */
fd5d1e8
 	dkimf_import_globals(ctx, l);
fd5d1e8
 
fd5d1e8
-# if LUA_VERSION_NUM == 502
fd5d1e8
+# if LUA_VERSION_NUM >= 502
fd5d1e8
 	switch (lua_load(l, dkimf_lua_reader, (void *) &io, name, NULL))
fd5d1e8
-# else /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# else /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	switch (lua_load(l, dkimf_lua_reader, (void *) &io, name))
fd5d1e8
-# endif /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# endif /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	{
fd5d1e8
 	  case 0:
fd5d1e8
 		break;
fd5d1e8
@@ -946,7 +954,11 @@ dkimf_lua_stats_hook(void *ctx, const char *script, size_t scriptlen,
fd5d1e8
 		io.lua_io_len = 0;
fd5d1e8
 		io.lua_io_alloc = 0;
fd5d1e8
 
fd5d1e8
+#if LUA_VERSION_NUM >= 503
fd5d1e8
+		if (lua_dump(l, dkimf_lua_writer, &io, 0) == 0)
fd5d1e8
+#else
fd5d1e8
 		if (lua_dump(l, dkimf_lua_writer, &io) == 0)
fd5d1e8
+#endif
fd5d1e8
 		{
fd5d1e8
 			*keep = (void *) io.lua_io_script;
fd5d1e8
 			*funclen = io.lua_io_len;
fd5d1e8
@@ -1022,12 +1034,12 @@ dkimf_lua_final_hook(void *ctx, const char *script, size_t scriptlen,
fd5d1e8
 	**  Register functions.
fd5d1e8
 	*/
fd5d1e8
 
fd5d1e8
-# if LUA_VERSION_NUM == 502
fd5d1e8
+# if LUA_VERSION_NUM >= 502
fd5d1e8
 	luaL_newlib(l, dkimf_lua_lib_final);
fd5d1e8
 	lua_setglobal(l, "odkim");
fd5d1e8
-# else /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# else /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	luaL_register(l, "odkim", dkimf_lua_lib_final);
fd5d1e8
-# endif /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# endif /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	lua_pop(l, 1);
fd5d1e8
 
fd5d1e8
 	/*
fd5d1e8
@@ -1151,11 +1163,11 @@ dkimf_lua_final_hook(void *ctx, const char *script, size_t scriptlen,
fd5d1e8
 	/* import other globals */
fd5d1e8
 	dkimf_import_globals(ctx, l);
fd5d1e8
 
fd5d1e8
-# if LUA_VERSION_NUM == 502
fd5d1e8
+# if LUA_VERSION_NUM >= 502
fd5d1e8
 	switch (lua_load(l, dkimf_lua_reader, (void *) &io, name, NULL))
fd5d1e8
-# else /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# else /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	switch (lua_load(l, dkimf_lua_reader, (void *) &io, name))
fd5d1e8
-# endif /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# endif /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	{
fd5d1e8
 	  case 0:
fd5d1e8
 		break;
fd5d1e8
@@ -1183,7 +1195,11 @@ dkimf_lua_final_hook(void *ctx, const char *script, size_t scriptlen,
fd5d1e8
 		io.lua_io_len = 0;
fd5d1e8
 		io.lua_io_alloc = 0;
fd5d1e8
 
fd5d1e8
+#if LUA_VERSION_NUM >= 503
fd5d1e8
+		if (lua_dump(l, dkimf_lua_writer, &io, 0) == 0)
fd5d1e8
+#else
fd5d1e8
 		if (lua_dump(l, dkimf_lua_writer, &io) == 0)
fd5d1e8
+#endif		
fd5d1e8
 		{
fd5d1e8
 			*keep = (void *) io.lua_io_script;
fd5d1e8
 			*funclen = io.lua_io_len;
fd5d1e8
@@ -1252,11 +1268,11 @@ dkimf_lua_db_hook(const char *script, size_t scriptlen, const char *query,
fd5d1e8
 		lua_pushstring(l, query);
fd5d1e8
 	lua_setglobal(l, "query");
fd5d1e8
 
fd5d1e8
-# if LUA_VERSION_NUM == 502
fd5d1e8
+# if LUA_VERSION_NUM >= 502
fd5d1e8
 	switch (lua_load(l, dkimf_lua_reader, (void *) &io, script, NULL))
fd5d1e8
-# else /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# else /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	switch (lua_load(l, dkimf_lua_reader, (void *) &io, script))
fd5d1e8
-# endif /* LUA_VERSION_NUM == 502 */
fd5d1e8
+# endif /* LUA_VERSION_NUM >= 502 */
fd5d1e8
 	{
fd5d1e8
 	  case 0:
fd5d1e8
 		break;
fd5d1e8
@@ -1284,7 +1300,11 @@ dkimf_lua_db_hook(const char *script, size_t scriptlen, const char *query,
fd5d1e8
 		io.lua_io_len = 0;
fd5d1e8
 		io.lua_io_alloc = 0;
fd5d1e8
 
fd5d1e8
+#if LUA_VERSION_NUM >= 503
fd5d1e8
+		if (lua_dump(l, dkimf_lua_writer, &io, 0) == 0)
fd5d1e8
+#else
fd5d1e8
 		if (lua_dump(l, dkimf_lua_writer, &io) == 0)
fd5d1e8
+#endif
fd5d1e8
 		{
fd5d1e8
 			*keep = (void *) io.lua_io_script;
fd5d1e8
 			*funclen = io.lua_io_len;
fd5d1e8
-- 
fd5d1e8
2.25.4
fd5d1e8