Remove warnings and fix makefile for Win32.

This commit is contained in:
Diego Nehab 2012-12-11 17:43:49 -02:00
parent 618ce43ee3
commit 72a5347f97
9 changed files with 33 additions and 37 deletions

4
.gitignore vendored
View File

@ -1,4 +1,6 @@
*.o *.o
*.so *.so
*.so.* *.so.*
mac macosx.cmd
win32.cmd

View File

@ -51,8 +51,8 @@ void buffer_init(p_buffer buf, p_io io, p_timeout tm) {
* object:getstats() interface * object:getstats() interface
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
int buffer_meth_getstats(lua_State *L, p_buffer buf) { int buffer_meth_getstats(lua_State *L, p_buffer buf) {
lua_pushnumber(L, buf->received); lua_pushnumber(L, (lua_Number) buf->received);
lua_pushnumber(L, buf->sent); lua_pushnumber(L, (lua_Number) buf->sent);
lua_pushnumber(L, timeout_gettime() - buf->birthday); lua_pushnumber(L, timeout_gettime() - buf->birthday);
return 3; return 3;
} }
@ -61,8 +61,8 @@ int buffer_meth_getstats(lua_State *L, p_buffer buf) {
* object:setstats() interface * object:setstats() interface
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
int buffer_meth_setstats(lua_State *L, p_buffer buf) { int buffer_meth_setstats(lua_State *L, p_buffer buf) {
buf->received = (long) luaL_optnumber(L, 2, buf->received); buf->received = (long) luaL_optnumber(L, 2, (lua_Number) buf->received);
buf->sent = (long) luaL_optnumber(L, 3, buf->sent); buf->sent = (long) luaL_optnumber(L, 3, (lua_Number) buf->sent);
if (lua_isnumber(L, 4)) buf->birthday = timeout_gettime() - lua_tonumber(L, 4); if (lua_isnumber(L, 4)) buf->birthday = timeout_gettime() - lua_tonumber(L, 4);
lua_pushnumber(L, 1); lua_pushnumber(L, 1);
return 1; return 1;
@ -90,9 +90,9 @@ int buffer_meth_send(lua_State *L, p_buffer buf) {
if (err != IO_DONE) { if (err != IO_DONE) {
lua_pushnil(L); lua_pushnil(L);
lua_pushstring(L, buf->io->error(buf->io->ctx, err)); lua_pushstring(L, buf->io->error(buf->io->ctx, err));
lua_pushnumber(L, sent+start-1); lua_pushnumber(L, (lua_Number) (sent+start-1));
} else { } else {
lua_pushnumber(L, sent+start-1); lua_pushnumber(L, (lua_Number) (sent+start-1));
lua_pushnil(L); lua_pushnil(L);
lua_pushnil(L); lua_pushnil(L);
} }

View File

@ -105,8 +105,8 @@ static int inet_global_getnameinfo(lua_State *L) {
lua_newtable(L); lua_newtable(L);
for (i = 1, iter = resolved; iter; i++, iter = iter->ai_next) { for (i = 1, iter = resolved; iter; i++, iter = iter->ai_next) {
getnameinfo(iter->ai_addr, iter->ai_addrlen, host, getnameinfo(iter->ai_addr, (socklen_t) iter->ai_addrlen, host,
node ? sizeof(host) : 0, serv, service ? sizeof(serv) : 0, 0); node ? (socklen_t) sizeof(host) : 0, serv, service ? (socklen_t) sizeof(serv) : 0, 0);
if (node) { if (node) {
lua_pushnumber(L, i); lua_pushnumber(L, i);
@ -177,8 +177,8 @@ static int inet_global_getaddrinfo(lua_State *L)
lua_newtable(L); lua_newtable(L);
for (iterator = resolved; iterator; iterator = iterator->ai_next) { for (iterator = resolved; iterator; iterator = iterator->ai_next) {
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
getnameinfo(iterator->ai_addr, iterator->ai_addrlen, hbuf, getnameinfo(iterator->ai_addr, (socklen_t) iterator->ai_addrlen, hbuf,
sizeof(hbuf), sbuf, 0, NI_NUMERICHOST); (socklen_t) sizeof(hbuf), sbuf, 0, NI_NUMERICHOST);
lua_pushnumber(L, i); lua_pushnumber(L, i);
lua_newtable(L); lua_newtable(L);
switch (iterator->ai_family) { switch (iterator->ai_family) {
@ -413,7 +413,7 @@ const char *inet_tryconnect(p_socket ps, const char *address,
timeout_markstart(tm); timeout_markstart(tm);
/* try connecting to remote address */ /* try connecting to remote address */
err = socket_strerror(socket_connect(ps, (SA *) iterator->ai_addr, err = socket_strerror(socket_connect(ps, (SA *) iterator->ai_addr,
iterator->ai_addrlen, tm)); (socklen_t) iterator->ai_addrlen, tm));
/* if success, break out of loop */ /* if success, break out of loop */
if (err == NULL) break; if (err == NULL) break;
} }
@ -463,7 +463,7 @@ const char *inet_trybind(p_socket ps, const char *address, const char *serv,
/* try binding to local address */ /* try binding to local address */
err = socket_strerror(socket_bind(&sock, err = socket_strerror(socket_bind(&sock,
(SA *) iterator->ai_addr, (SA *) iterator->ai_addr,
iterator->ai_addrlen)); (socklen_t) iterator->ai_addrlen));
/* keep trying unless bind succeeded */ /* keep trying unless bind succeeded */
if (err) { if (err) {

View File

@ -114,7 +114,7 @@ SOCKET_macosx=usocket.o
SO_linux=so SO_linux=so
O_linux=o O_linux=o
CC_linux=gcc CC_linux=gcc
DEF_linux=-DLUASOCKET_$(DEBUG) \ DEF_linux=-DLUASOCKET_$(DEBUG) -DLUA_COMPAT_MODULE \
-DLUASOCKET_API='__attribute__((visibility("default")))' \ -DLUASOCKET_API='__attribute__((visibility("default")))' \
-DMIME_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))'
CFLAGS_linux= -I$(LUAINC) $(DEF) -pedantic -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic \ CFLAGS_linux= -I$(LUAINC) $(DEF) -pedantic -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic \
@ -130,11 +130,12 @@ SO_win32=dll
O_win32=obj O_win32=obj
CC_win32=cl CC_win32=cl
DEF_win32= /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" \ DEF_win32= /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" \
/D "LUASOCKET_API=__declspec(dllexport)" /D "LUASOCKET_$(DEBUG)" \ /D "LUASOCKET_API=__declspec(dllexport)" /D "_CRT_SECURE_NO_WARNINGS" \
/D "_CRT_SECURE_NO_WARNINGS" /D "_WINDLL" /D "_WINDLL" /D "LUA_COMPAT_MODULE" /D "MIME_API=__declspec(dllexport)" \
CFLAGS_win32=/I$(LUAINC) $(DEF) /O2 /Ot /MD /W3 /nologo /D "LUASOCKET_$(DEBUG)"
CFLAGS_win32=/I "$(LUAINC)" $(DEF) /O2 /Ot /MD /W3 /nologo
LDFLAGS_win32= /nologo /link /NOLOGO /DLL /INCREMENTAL:NO \ LDFLAGS_win32= /nologo /link /NOLOGO /DLL /INCREMENTAL:NO \
/LIBPATH:$(LUALIB) \ /LIBPATH:"$(LUALIB)" \
/MANIFEST \ /MANIFEST \
/MANIFESTFILE:"intermediate.manifest" \ /MANIFESTFILE:"intermediate.manifest" \
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" \ /MANIFESTUAC:"level='asInvoker' uiAccess='false'" \

View File

@ -504,7 +504,7 @@ static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) {
c = qpunbase[input[1]]; d = qpunbase[input[2]]; c = qpunbase[input[1]]; d = qpunbase[input[2]];
/* if it is an invalid, do not decode */ /* if it is an invalid, do not decode */
if (c > 15 || d > 15) luaL_addlstring(buffer, (char *)input, 3); if (c > 15 || d > 15) luaL_addlstring(buffer, (char *)input, 3);
else luaL_addchar(buffer, (c << 4) + d); else luaL_addchar(buffer, (char) ((c << 4) + d));
return 0; return 0;
case '\r': case '\r':
if (size < 2) return size; if (size < 2) return size;
@ -642,7 +642,7 @@ static int eolprocess(int c, int last, const char *marker,
return c; return c;
} }
} else { } else {
luaL_addchar(buffer, c); luaL_addchar(buffer, (char) c);
return 0; return 0;
} }
} }
@ -682,7 +682,7 @@ static int mime_global_eol(lua_State *L)
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
static size_t dot(int c, size_t state, luaL_Buffer *buffer) static size_t dot(int c, size_t state, luaL_Buffer *buffer)
{ {
luaL_addchar(buffer, c); luaL_addchar(buffer, (char) c);
switch (c) { switch (c) {
case '\r': case '\r':
return 1; return 1;
@ -717,7 +717,7 @@ static int mime_global_dot(lua_State *L)
while (input < last) while (input < last)
state = dot(*input++, state, &buffer); state = dot(*input++, state, &buffer);
luaL_pushresult(&buffer); luaL_pushresult(&buffer);
lua_pushnumber(L, state); lua_pushnumber(L, (lua_Number) state);
return 2; return 2;
} }

View File

@ -122,7 +122,7 @@ static void collect_fd(lua_State *L, int tab, int itab,
if (lua_isnil(L, tab)) return; if (lua_isnil(L, tab)) return;
/* otherwise we need it to be a table */ /* otherwise we need it to be a table */
luaL_checktype(L, tab, LUA_TTABLE); luaL_checktype(L, tab, LUA_TTABLE);
while (1) { for ( ;; ) {
t_socket fd; t_socket fd;
lua_pushnumber(L, i); lua_pushnumber(L, i);
lua_gettable(L, tab); lua_gettable(L, tab);
@ -147,7 +147,7 @@ static void collect_fd(lua_State *L, int tab, int itab,
if (*max_fd == SOCKET_INVALID || *max_fd < fd) if (*max_fd == SOCKET_INVALID || *max_fd < fd)
*max_fd = fd; *max_fd = fd;
/* make sure we can map back from descriptor to the object */ /* make sure we can map back from descriptor to the object */
lua_pushnumber(L, fd); lua_pushnumber(L, (lua_Number) fd);
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
lua_settable(L, itab); lua_settable(L, itab);
} }
@ -160,7 +160,7 @@ static int check_dirty(lua_State *L, int tab, int dtab, fd_set *set) {
int ndirty = 0, i = 1; int ndirty = 0, i = 1;
if (lua_isnil(L, tab)) if (lua_isnil(L, tab))
return 0; return 0;
while (1) { for ( ;; ) {
t_socket fd; t_socket fd;
lua_pushnumber(L, i); lua_pushnumber(L, i);
lua_gettable(L, tab); lua_gettable(L, tab);
@ -187,7 +187,7 @@ static void return_fd(lua_State *L, fd_set *set, t_socket max_fd,
for (fd = 0; fd < max_fd; fd++) { for (fd = 0; fd < max_fd; fd++) {
if (FD_ISSET(fd, set)) { if (FD_ISSET(fd, set)) {
lua_pushnumber(L, ++start); lua_pushnumber(L, ++start);
lua_pushnumber(L, fd); lua_pushnumber(L, (lua_Number) fd);
lua_gettable(L, itab); lua_gettable(L, itab);
lua_settable(L, tab); lua_settable(L, tab);
} }
@ -197,7 +197,7 @@ static void return_fd(lua_State *L, fd_set *set, t_socket max_fd,
static void make_assoc(lua_State *L, int tab) { static void make_assoc(lua_State *L, int tab) {
int i = 1, atab; int i = 1, atab;
lua_newtable(L); atab = lua_gettop(L); lua_newtable(L); atab = lua_gettop(L);
while (1) { for ( ;; ) {
lua_pushnumber(L, i); lua_pushnumber(L, i);
lua_gettable(L, tab); lua_gettable(L, tab);
if (!lua_isnil(L, -1)) { if (!lua_isnil(L, -1)) {

View File

@ -418,7 +418,7 @@ static const char *tryconnect6(const char *remoteaddr, const char *remoteserv,
/* finally try connecting to remote address */ /* finally try connecting to remote address */
err = socket_strerror(socket_connect(&tcp->sock, err = socket_strerror(socket_connect(&tcp->sock,
(SA *) iterator->ai_addr, (SA *) iterator->ai_addr,
iterator->ai_addrlen, tm)); (socklen_t) iterator->ai_addrlen, tm));
/* if success, break out of loop */ /* if success, break out of loop */
if (err == NULL) break; if (err == NULL) break;
} }

View File

@ -139,7 +139,7 @@ static int meth_send(lua_State *L) {
lua_pushstring(L, udp_strerror(err)); lua_pushstring(L, udp_strerror(err));
return 2; return 2;
} }
lua_pushnumber(L, sent); lua_pushnumber(L, (lua_Number) sent);
return 1; return 1;
} }
@ -189,7 +189,7 @@ static int meth_sendto(lua_State *L) {
lua_pushstring(L, udp_strerror(err)); lua_pushstring(L, udp_strerror(err));
return 2; return 2;
} }
lua_pushnumber(L, sent); lua_pushnumber(L, (lua_Number) sent);
return 1; return 1;
} }

View File

@ -181,8 +181,6 @@ int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len,
/* call select to avoid busy wait */ /* call select to avoid busy wait */
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err; if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
} }
/* can't reach here */
return IO_UNKNOWN;
} }
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
@ -214,8 +212,6 @@ int socket_send(p_socket ps, const char *data, size_t count,
/* avoid busy wait */ /* avoid busy wait */
if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err; if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err;
} }
/* can't reach here */
return IO_UNKNOWN;
} }
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
@ -237,7 +233,6 @@ int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent,
if (err != WSAEWOULDBLOCK) return err; if (err != WSAEWOULDBLOCK) return err;
if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err; if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err;
} }
return IO_UNKNOWN;
} }
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
@ -258,7 +253,6 @@ int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm
if (err != WSAEWOULDBLOCK) return err; if (err != WSAEWOULDBLOCK) return err;
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err; if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
} }
return IO_UNKNOWN;
} }
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
@ -280,7 +274,6 @@ int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got,
if (err != WSAEWOULDBLOCK) return err; if (err != WSAEWOULDBLOCK) return err;
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err; if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
} }
return IO_UNKNOWN;
} }
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\