openresty / lua-resty-balancer

A generic consistent hash implementation for OpenResty/Lua
322 stars 77 forks source link

bug: compile error on mac. #13

Closed ingydotnet closed 7 years ago

ingydotnet commented 7 years ago
 ~/src/OR/edgelang-fan/lua-resty-balancer master|…1 make
cc -Wall -O3 -flto -g -DFP_RELAX=0 -DDEBUG -fPIC -MMD -fvisibility=hidden -DBUILDING_SO -c chash.c
chash.c:81:29: error: unknown type name 'u_char'; did you mean 'char'?
crc32_update(uint32_t *crc, u_char *p, size_t len)
                            ^~~~~~
                            char
chash.c:103:9: error: unknown type name 'u_char'; did you mean 'char'?
        u_char                          byte[4];
        ^~~~~~
        char
chash.c:125:30: error: use of undeclared identifier 'u_char'
        prev_hash.byte[0] = (u_char) (hash & 0xff);
                             ^
chash.c:126:30: error: use of undeclared identifier 'u_char'
        prev_hash.byte[1] = (u_char) ((hash >> 8) & 0xff);
                             ^
chash.c:127:30: error: use of undeclared identifier 'u_char'
        prev_hash.byte[2] = (u_char) ((hash >> 16) & 0xff);
                             ^
chash.c:128:30: error: use of undeclared identifier 'u_char'
        prev_hash.byte[3] = (u_char) ((hash >> 24) & 0xff);
                             ^
6 errors generated.
make: *** [chash.o] Error 1# Creating a new issue for 'agentzh/lua-resty-balancer':
agentzh commented 7 years ago

The fix should be

#ifndef u_char
#define u_char  unsigned char
#endif
agentzh commented 7 years ago

@doujiang24 OK, I've tested the following patch on my Mac OS X and it builds and passes the test suite now:

diff --git a/Makefile b/Makefile
index 98a57c8..cd8f2bf 100644
--- a/Makefile
+++ b/Makefile
@@ -12,11 +12,7 @@ OS := $(shell uname)
 SRC := chash.c
 OBJ := $(SRC:.c=.o)

-ifeq ($(OS), Darwin)
-C_SO_NAME := libchash.dylib
-else
 C_SO_NAME := libchash.so
-endif

 CFLAGS := -Wall -O3 -flto -g -DFP_RELAX=0 -DDEBUG
 THE_CFLAGS := $(CFLAGS) -fPIC -MMD -fvisibility=hidden
diff --git a/chash.c b/chash.c
index 2c7bf3b..1d13dd3 100644
--- a/chash.c
+++ b/chash.c
@@ -4,6 +4,10 @@
 #include "chash.h"

+#ifndef u_char
+#define u_char  unsigned char
+#endif
+

 #define crc32_final(crc)                                                  \
     crc ^= 0xffffffff
doujiang24 commented 7 years ago

@ingydotnet @agentzh Fixed in https://github.com/doujiang24/lua-resty-balancer/commit/d058c569d5434cd3ef3331047793c9c2a7b5151a, thanks a lot :)