Subject: [alpine-aports] [PATCH] community/lua-hiredis

From: Nathan Angelacos <[email-masked]>
Date: Fri, 29 Apr 2016 01:50:34 +0000

Make sure libhiredis is liked to the module
	Apply various codefixes from github to bring
		code base to  e6355d4 (Mar 24 2014)
	Apply https://github.com/agladysh/lua-hiredis/pull/6
---
 .../lua-hiredis/0002-lua-hiredis-master.patch      | 245 +++++++++++++++++++++
 .../lua-hiredis/0003-lua-5-2-compatbility.patch    |  36 +++
 community/lua-hiredis/APKBUILD                     |  18 +-
 3 files changed, 292 insertions(+), 7 deletions(-)
 create mode 100644 community/lua-hiredis/0002-lua-hiredis-master.patch
 create mode 100644 community/lua-hiredis/0003-lua-5-2-compatbility.patch

diff --git a/community/lua-hiredis/0002-lua-hiredis-master.patch b/community/lua-hiredis/0002-lua-hiredis-master.patch
new file mode 100644
index 0000000..83b8be7
--- /dev/null
+++ b/community/lua-hiredis/0002-lua-hiredis-master.patch
@@ -0,0 +1,245 @@
+diff --git a/AUTHORS b/AUTHORS
+index ffdadfa..bd5ee8a 100644
+--- a/AUTHORS
++++ b/AUTHORS
+@@ -3,3 +3,8 @@ lua-hiredis bindings authors:
+ 
+ Alexander Gladysh <[email-masked]>
+ 
++lua-hiredis bindings contributors:
++----------------------------------
++
++Stein Ivar Berghei <[email-masked]>
++Peter Melnichenko <[email-masked]>
+diff --git a/COPYRIGHT b/COPYRIGHT
+index 0af707a..4f31953 100644
+--- a/COPYRIGHT
++++ b/COPYRIGHT
+@@ -9,7 +9,7 @@ Note that hiredis library itself (included for convenience) is licensed under BS
+ 
+ ===============================================================================
+ 
+-Copyright (C) 2011—2012 lua-hiredis bindings authors
++Copyright (C) 2011—2014 lua-hiredis bindings authors
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+diff --git a/README.md b/README.md
+index bfc065b..1121f09 100644
+--- a/README.md
++++ b/README.md
+@@ -14,7 +14,12 @@ is not 1.0 yet. But all the features necessary for regular usage are here.
+ API
+ ---
+ 
+-* `hiredis.connect(host : string, port : number) : conn / nil, err, error_code`
++* `hiredis.connect(host / socket : string, port : number / nil) : conn / nil, err, error_code`
++
++  * `hiredis.connect("localhost", 6379)` connects to Redis at `localhost:6379`
++    via TCP/IP socket.
++  * `hiredis.connect("/var/run/redis/redis.sock")` connects to Redis at
++    `/var/run/redis/redis.sock` via Unix domain socket.
+ 
+ * `hiredis.unwrap_reply(reply) : reply / name, hiredis.REPLY_STATUS / nil, err`
+ 
+diff --git a/TODO b/TODO
+index 49e1097..2e1b220 100644
+--- a/TODO
++++ b/TODO
+@@ -1,10 +1,7 @@
+ TODO:
+ -----
+ 
+- -- hiredis.unwrap_reply should pass everything through without looking
+-    if it is called with more than one argument,
+-    so this would not lose an error:
+-        hiredis.unwrap_reply(conn.command())
++ -- Make nolibs rockspec default, remove lib/*
+  -- Document current API.
+  -- Run splint all over it.
+  -- Run under valgrind
+diff --git a/make.sh b/make.sh
+index 0c012f2..4657b4c 100755
+--- a/make.sh
++++ b/make.sh
+@@ -6,14 +6,14 @@ echo "----> Going pedantic all over the source"
+ 
+ # Ugh. hiredis.h is not c89-compatible
+ echo "--> c89..."
+-gcc -O2 -fPIC -I/usr/include/lua5.1 -c src/lua-hiredis.c -o /dev/null -Isrc/ -Ilib/hiredis/ -Wall --pedantic --std=c89 #-Werror
++gcc -O2 -fPIC -I/usr/include/lua5.1 -c src/lua-hiredis.c -o /dev/null -Isrc/ -Ilib/ -Wall --pedantic --std=c89 #-Werror
+ 
+ echo "--> c99..."
+-gcc -O2 -fPIC -I/usr/include/lua5.1 -c src/lua-hiredis.c -o /dev/null -Isrc/ -Ilib/hiredis/ -Wall --pedantic -Werror --std=c99
++gcc -O2 -fPIC -I/usr/include/lua5.1 -c src/lua-hiredis.c -o /dev/null -Isrc/ -Ilib/ -Wall --pedantic -Werror --std=c99
+ 
+ # Ugh. hiredis.h is not c++98-compatible
+ echo "--> c++98..."
+-gcc -xc++ -O2 -fPIC -I/usr/include/lua5.1 -c src/lua-hiredis.c -o /dev/null -Isrc/c/ -Ilib/hiredis/ --pedantic -Wall --std=c++98 #-Werror
++gcc -xc++ -O2 -fPIC -I/usr/include/lua5.1 -c src/lua-hiredis.c -o /dev/null -Isrc/c/ -Ilib/ --pedantic -Wall --std=c++98 #-Werror
+ 
+ echo "----> Making rock"
+ sudo luarocks make rockspec/lua-hiredis-scm-1.rockspec
+diff --git a/rockspec/lua-hiredis-scm-1.rockspec b/rockspec/lua-hiredis-scm-1.rockspec
+index a9ec60a..65f87ae 100644
+--- a/rockspec/lua-hiredis-scm-1.rockspec
++++ b/rockspec/lua-hiredis-scm-1.rockspec
+@@ -31,6 +31,7 @@ build = {
+             "src/",
+ 
+             -- bundled hiredis code --
++            "lib/",
+             "lib/hiredis/"
+          }
+       }
+diff --git a/src/lua-hiredis.c b/src/lua-hiredis.c
+index f8b2fdf..3dfafc1 100644
+--- a/src/lua-hiredis.c
++++ b/src/lua-hiredis.c
+@@ -14,7 +14,7 @@ extern "C" {
+ }
+ #endif
+ 
+-#include "hiredis.h"
++#include "hiredis/hiredis.h"
+ 
+ #if 0
+   #define SPAM(a) printf a
+@@ -23,7 +23,7 @@ extern "C" {
+ #endif
+ 
+ #define LUAHIREDIS_VERSION     "lua-hiredis 0.2.1"
+-#define LUAHIREDIS_COPYRIGHT   "Copyright (C) 2011—2012, lua-hiredis authors"
++#define LUAHIREDIS_COPYRIGHT   "Copyright (C) 2011—2013, lua-hiredis authors"
+ #define LUAHIREDIS_DESCRIPTION "Bindings for hiredis Redis-client library"
+ 
+ #define LUAHIREDIS_CONN_MT   "lua-hiredis.connection"
+@@ -77,7 +77,7 @@ static int lconst_tostring(lua_State * L)
+ }
+ 
+ /* const API */
+-static const struct luaL_reg CONST_MT[] =
++static const struct luaL_Reg CONST_MT[] =
+ {
+   { "__tostring", lconst_tostring },
+ 
+@@ -136,7 +136,7 @@ static int lstatus_index(lua_State * L)
+ }
+ 
+ /* status API */
+-static const struct luaL_reg STATUS_MT[] =
++static const struct luaL_Reg STATUS_MT[] =
+ {
+   { "__index", lstatus_index },
+ 
+@@ -418,7 +418,7 @@ static int lconn_tostring(lua_State * L)
+   return 1;
+ }
+ 
+-static const luaL_reg M[] =
++static const luaL_Reg M[] =
+ {
+   { "command", lconn_command },
+   { "append_command", lconn_append_command },
+@@ -436,12 +436,18 @@ static int lhiredis_connect(lua_State * L)
+   luahiredis_Connection * pResult = NULL;
+   redisContext * pContext = NULL;
+ 
+-  const char * host = luaL_checkstring(L, 1);
+-  int port = luaL_checkint(L, 2);
++  const char * host_or_socket = luaL_checkstring(L, 1);
+ 
+-  /* TODO: Support Timeout, Unix and UnixTimeout flavors */
++  /* TODO: Support Timeout and UnixTimeout flavors */
++  if (lua_isnoneornil(L, 2))
++  {
++    pContext = redisConnectUnix(host_or_socket);
++  }
++  else
++  {
++    pContext = redisConnect(host_or_socket, luaL_checkint(L, 2));
++  }
+ 
+-  pContext = redisConnect(host, port);
+   if (!pContext)
+   {
+     luaL_checkstack(L, 2, "not enough stack to push error");
+@@ -567,13 +573,13 @@ static int lhiredis_unwrap_reply(lua_State * L)
+   return 1;
+ }
+ 
+-static const struct luaL_reg E[] = /* Empty */
++static const struct luaL_Reg E[] = /* Empty */
+ {
+   { NULL, NULL }
+ };
+ 
+ /* Lua module API */
+-static const struct luaL_reg R[] =
++static const struct luaL_Reg R[] =
+ {
+   { "connect", lhiredis_connect },
+   { "unwrap_reply", lhiredis_unwrap_reply },
+diff --git a/test/test.lua b/test/test.lua
+index 2f15c04..d47fc00 100644
+--- a/test/test.lua
++++ b/test/test.lua
+@@ -8,6 +8,12 @@ local CACHED_ERR = nil
+ 
+ --------------------------------------------------------------------------------
+ 
++local UDS_SOCKET = "/var/run/redis/redis.sock"
++local HOST = "localhost"
++local PORT = 6379
++
++--------------------------------------------------------------------------------
++
+ assert(type(hiredis.NIL == "table"))
+ assert(hiredis.NIL.name == "NIL")
+ assert(hiredis.NIL.type == hiredis.REPLY_NIL)
+@@ -53,7 +59,44 @@ assert(hiredis.connect("badaddress", 1) == nil)
+ 
+ --------------------------------------------------------------------------------
+ 
+-local conn = assert(hiredis.connect("localhost", 6379))
++assert(hiredis.connect("/var/run/redis/inexistant.sock") == nil)
++
++--------------------------------------------------------------------------------
++
++local ok, posix = pcall(require, "posix")
++if not ok then
++  print("WARNING: luaposix not found, can't test Unix Domain Socket support")
++  print("         consider installing it as follows:")
++  print("")
++  print("         sudo luarocks install luaposix")
++  print("")
++elseif not posix.stat(UDS_SOCKET) then
++  print("WARNING: Redis Unix domain socket file not found.")
++  print("         Can't test Unix Domain Socket support.")
++  print("         consider running Redis as follows:")
++  print("")
++  print("         sudo redis-server --unixsocket ".. UDS_SOCKET .. " --port 0")
++  print("")
++else
++  local net_unix = assert(io.open("/proc/net/unix", "r"))
++  local sockets = assert(net_unix:read("*a"))
++  net_unix:close()
++  if not sockets:find(UDS_SOCKET, nil, true) then
++    print("WARNING: Redis Unix domain socket file not open.")
++    print("         Can't test Unix Domain Socket support.")
++    print("         consider running Redis as follows:")
++    print("")
++    print("        sudo redis-server --unixsocket ".. UDS_SOCKET .. " --port 0")
++    print("")
++  else
++    local conn = assert(hiredis.connect(UDS_SOCKET))
++    assert(conn:command("quit"))
++  end
++end
++
++--------------------------------------------------------------------------------
++
++local conn = assert(hiredis.connect(HOST, PORT))
+ 
+ --------------------------------------------------------------------------------
+ 
diff --git a/community/lua-hiredis/0003-lua-5-2-compatbility.patch b/community/lua-hiredis/0003-lua-5-2-compatbility.patch
new file mode 100644
index 0000000..8ca7458
--- /dev/null
+++ b/community/lua-hiredis/0003-lua-5-2-compatbility.patch
@@ -0,0 +1,36 @@
+diff --git a/AUTHORS b/AUTHORS
+index bd5ee8a..f10d214 100644
+--- a/AUTHORS
++++ b/AUTHORS
+@@ -8,3 +8,4 @@ lua-hiredis bindings contributors:
+ 
+ Stein Ivar Berghei <[email-masked]>
+ Peter Melnichenko <[email-masked]>
++Andey Kunitsyn <[email-masked]>
+diff --git a/src/lua-hiredis.c b/src/lua-hiredis.c
+index 3dfafc1..079cbd9 100644
+--- a/src/lua-hiredis.c
++++ b/src/lua-hiredis.c
+@@ -34,6 +34,22 @@ extern "C" {
+ 
+ #define LUAHIREDIS_KEY_NIL "NIL"
+ 
++#if LUA_VERSION_NUM >= 502
++static void luaL_register(lua_State * L, const char * name, const luaL_Reg * l) 
++{
++  if (name) 
++  {
++    lua_newtable(L);
++    luaL_setfuncs(L, l, 0);
++    lua_pushvalue(L,-1);
++    lua_setglobal(L,name);
++  } else 
++  {
++    luaL_setfuncs(L,l,0);
++  }
++}
++#endif
++
+ typedef struct luahiredis_Enum
+ {
+   const char * name;
diff --git a/community/lua-hiredis/APKBUILD b/community/lua-hiredis/APKBUILD
index 190ce31..d399853 100644
--- a/community/lua-hiredis/APKBUILD
+++ b/community/lua-hiredis/APKBUILD
@@ -4,7 +4,7 @@ _luaversions="5.1 5.2 5.3"
 
 pkgname=lua-hiredis
 pkgver=0.2.1
-pkgrel=0
+pkgrel=1
 pkgdesc="Binding to libhiredis for Lua"
 url="https://github.com/agladysh/lua-hiredis"
 arch="all"
@@ -22,9 +22,10 @@ done
 
 install=""
 source="lua-hiredis-$pkgver.tar.gz::https://github.com/agladysh/lua-hiredis/archive/v$pkgver.tar.gz
-	0001-lua-5-3-compatibility.patch
+	0002-lua-hiredis-master.patch
+	0003-lua-5-2-compatbility.patch
 	"
-
+#	0001-lua-5-3-compatibility.patch
 _builddir="$srcdir"/lua-hiredis-$pkgver
 prepare() {
 	local i
@@ -55,15 +56,18 @@ _split() {
 	${CC:-gcc} ${CFLAGS} $(pkg-config --cflags hiredis) \
 		$(pkg-config --cflags lua$_ver) -shared -fPIC \
 		-I/usr/include/lua$_ver -I/usr/include/hiredis \
-		-o hiredis.so src/lua-hiredis.c \
+		-lhiredis -o hiredis.so src/lua-hiredis.c \
 		|| return 1
 	install -Dm755 hiredis.so \
 		"$subpkgdir"/usr/lib/lua/$_ver/hiredis.so || return 1
 }
 
 md5sums="edd68a6f0b39ba9cae100de275853696  lua-hiredis-0.2.1.tar.gz
-acf9dc5b26d8ce3fa341099467ae8776  0001-lua-5-3-compatibility.patch"
+ea686bff78a4307d0f7874aa63fc0204  0002-lua-hiredis-master.patch
+44515c8cf4b2c9ece011e7af8e97aa86  0003-lua-5-2-compatbility.patch"
 sha256sums="38976799776cc702f4b8cc396babda4152975855d593a17da1343eeb2cebcb34  lua-hiredis-0.2.1.tar.gz
-de2edefec93d90adf2b594e81a284b82f4b5712e9422fd3e4d41f84afdae9a80  0001-lua-5-3-compatibility.patch"
+b333f545078b8a42eee27135ac764ec2c436ef2d89193f8a6ba931de1061a5a9  0002-lua-hiredis-master.patch
+48cdfa61013f4c644c75bb2119224c08ef6e86d76c5e25fb7818c22ba67b3913  0003-lua-5-2-compatbility.patch"
 sha512sums="b53eea8b51ddfbfa4592e7a3bb004416edd6240a860656ec809b603349357d3e754a2b5f2a92cb33d0a46259beae86f1c99981e848193f112888982d97cb94b7  lua-hiredis-0.2.1.tar.gz
-78f15aac6088dd37de5d462e9ac26c1c3d0ea3d5e783df155f4be5b5415113eb0954feea499335003e89c40768d8005b0d158101acc197aa80aa57109c32ffca  0001-lua-5-3-compatibility.patch"
+0017a218a126e0b96a5cc4126a0b8dc7600ef6029af24f3ca685e46cabade03d25a3c318b3d80c907785f2f2abc7dfb2c9a047e6a7c53e082ab682a3ac5ca18b  0002-lua-hiredis-master.patch
+9cf63994de040d8818c3db3053d506244e7a4a647ae71609533b5c889517d6addf01dde185f83d7472f4580dea4d26dce69e5e5ad86ca7c70343eaffe0d7e137  0003-lua-5-2-compatbility.patch"
-- 
2.8.1

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---