lua-users home
lua-l archive

[PATCH] luasocket namespace clash

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,
I'm couldnt find out how to get in touch with the luasocket developers
(within 5 mins) so I hope someone can send me in the right direction.
For people who might have the same issue, I post the patch here as well.
I had some serious problems with using luasocket in haserl some time
ago. Today someone sent me a link showing the reason: both haserl and
luasocket (and obviously also lighttpd's mod_magnet) defines
buffer_init().
http://erikarn.livejournal.com/77630.html
Attatched is a patch that solves the issue by renaming the buffer_*
funcs to ls_buffer*
thanks!
-nc
diff -ru luasocket-2.0.2-1.orig/luasocket-2.0.2/src/buffer.c luasocket-2.0.2-1/luasocket-2.0.2/src/buffer.c
--- luasocket-2.0.2-1.orig/luasocket-2.0.2/src/buffer.c	2008年08月20日 06:16:42 +0000
+++ luasocket-2.0.2-1/luasocket-2.0.2/src/buffer.c	2008年08月20日 06:30:15 +0000
@@ -33,7 +33,7 @@
 /*-------------------------------------------------------------------------*\
 * Initializes module
 \*-------------------------------------------------------------------------*/
-int buffer_open(lua_State *L) {
+int ls_buffer_open(lua_State *L) {
 (void) L;
 return 0;
 }
@@ -41,7 +41,7 @@
 /*-------------------------------------------------------------------------*\
 * Initializes C structure 
 \*-------------------------------------------------------------------------*/
-void buffer_init(p_buffer buf, p_io io, p_timeout tm) {
+void ls_buffer_init(p_buffer buf, p_io io, p_timeout tm) {
 	buf->first = buf->last = 0;
 buf->io = io;
 buf->tm = tm;
@@ -52,7 +52,7 @@
 /*-------------------------------------------------------------------------*\
 * object:getstats() interface
 \*-------------------------------------------------------------------------*/
-int buffer_meth_getstats(lua_State *L, p_buffer buf) {
+int ls_buffer_meth_getstats(lua_State *L, p_buffer buf) {
 lua_pushnumber(L, buf->received);
 lua_pushnumber(L, buf->sent);
 lua_pushnumber(L, timeout_gettime() - buf->birthday);
@@ -62,7 +62,7 @@
 /*-------------------------------------------------------------------------*\
 * object:setstats() interface
 \*-------------------------------------------------------------------------*/
-int buffer_meth_setstats(lua_State *L, p_buffer buf) {
+int ls_buffer_meth_setstats(lua_State *L, p_buffer buf) {
 buf->received = (long) luaL_optnumber(L, 2, buf->received); 
 buf->sent = (long) luaL_optnumber(L, 3, buf->sent); 
 if (lua_isnumber(L, 4)) buf->birthday = timeout_gettime() - lua_tonumber(L, 4);
@@ -73,7 +73,7 @@
 /*-------------------------------------------------------------------------*\
 * object:send() interface
 \*-------------------------------------------------------------------------*/
-int buffer_meth_send(lua_State *L, p_buffer buf) {
+int ls_buffer_meth_send(lua_State *L, p_buffer buf) {
 int top = lua_gettop(L);
 int err = IO_DONE;
 size_t size = 0, sent = 0;
@@ -106,7 +106,7 @@
 /*-------------------------------------------------------------------------*\
 * object:receive() interface
 \*-------------------------------------------------------------------------*/
-int buffer_meth_receive(lua_State *L, p_buffer buf) {
+int ls_buffer_meth_receive(lua_State *L, p_buffer buf) {
 int err = IO_DONE, top = lua_gettop(L);
 luaL_Buffer b;
 size_t size;
@@ -149,7 +149,7 @@
 /*-------------------------------------------------------------------------*\
 * Determines if there is any data in the read buffer
 \*-------------------------------------------------------------------------*/
-int buffer_isempty(p_buffer buf) {
+int ls_buffer_isempty(p_buffer buf) {
 return buf->first >= buf->last;
 }
 
@@ -244,7 +244,7 @@
 static void buffer_skip(p_buffer buf, size_t count) {
 buf->received += count;
 buf->first += count;
- if (buffer_isempty(buf)) 
+ if (ls_buffer_isempty(buf)) 
 buf->first = buf->last = 0;
 }
 
@@ -256,7 +256,7 @@
 int err = IO_DONE;
 p_io io = buf->io;
 p_timeout tm = buf->tm;
- if (buffer_isempty(buf)) {
+ if (ls_buffer_isempty(buf)) {
 size_t got;
 err = io->recv(io->ctx, buf->data, BUF_SIZE, &got, tm);
 buf->first = 0;
diff -ru luasocket-2.0.2-1.orig/luasocket-2.0.2/src/buffer.h luasocket-2.0.2-1/luasocket-2.0.2/src/buffer.h
--- luasocket-2.0.2-1.orig/luasocket-2.0.2/src/buffer.h	2008年08月20日 06:16:42 +0000
+++ luasocket-2.0.2-1/luasocket-2.0.2/src/buffer.h	2008年08月20日 06:30:15 +0000
@@ -36,12 +36,12 @@
 } t_buffer;
 typedef t_buffer *p_buffer;
 
-int buffer_open(lua_State *L);
-void buffer_init(p_buffer buf, p_io io, p_timeout tm);
-int buffer_meth_send(lua_State *L, p_buffer buf);
-int buffer_meth_receive(lua_State *L, p_buffer buf);
-int buffer_meth_getstats(lua_State *L, p_buffer buf);
-int buffer_meth_setstats(lua_State *L, p_buffer buf);
-int buffer_isempty(p_buffer buf);
+int ls_buffer_open(lua_State *L);
+void ls_buffer_init(p_buffer buf, p_io io, p_timeout tm);
+int ls_buffer_meth_send(lua_State *L, p_buffer buf);
+int ls_buffer_meth_receive(lua_State *L, p_buffer buf);
+int ls_buffer_meth_getstats(lua_State *L, p_buffer buf);
+int ls_buffer_meth_setstats(lua_State *L, p_buffer buf);
+int ls_buffer_isempty(p_buffer buf);
 
 #endif /* BUF_H */
diff -ru luasocket-2.0.2-1.orig/luasocket-2.0.2/src/luasocket.c luasocket-2.0.2-1/luasocket-2.0.2/src/luasocket.c
--- luasocket-2.0.2-1.orig/luasocket-2.0.2/src/luasocket.c	2008年08月20日 06:16:42 +0000
+++ luasocket-2.0.2-1/luasocket-2.0.2/src/luasocket.c	2008年08月20日 06:30:15 +0000
@@ -51,7 +51,7 @@
 {"auxiliar", auxiliar_open},
 {"except", except_open},
 {"timeout", timeout_open},
- {"buffer", buffer_open},
+ {"buffer", ls_buffer_open},
 {"inet", inet_open},
 {"tcp", tcp_open},
 {"udp", udp_open},
diff -ru luasocket-2.0.2-1.orig/luasocket-2.0.2/src/tcp.c luasocket-2.0.2-1/luasocket-2.0.2/src/tcp.c
--- luasocket-2.0.2-1.orig/luasocket-2.0.2/src/tcp.c	2008年08月20日 06:16:42 +0000
+++ luasocket-2.0.2-1/luasocket-2.0.2/src/tcp.c	2008年08月20日 06:30:15 +0000
@@ -104,22 +104,22 @@
 \*-------------------------------------------------------------------------*/
 static int meth_send(lua_State *L) {
 p_tcp tcp = (p_tcp) auxiliar_checkclass(L, "tcp{client}", 1);
- return buffer_meth_send(L, &tcp->buf);
+ return ls_buffer_meth_send(L, &tcp->buf);
 }
 
 static int meth_receive(lua_State *L) {
 p_tcp tcp = (p_tcp) auxiliar_checkclass(L, "tcp{client}", 1);
- return buffer_meth_receive(L, &tcp->buf);
+ return ls_buffer_meth_receive(L, &tcp->buf);
 }
 
 static int meth_getstats(lua_State *L) {
 p_tcp tcp = (p_tcp) auxiliar_checkclass(L, "tcp{client}", 1);
- return buffer_meth_getstats(L, &tcp->buf);
+ return ls_buffer_meth_getstats(L, &tcp->buf);
 }
 
 static int meth_setstats(lua_State *L) {
 p_tcp tcp = (p_tcp) auxiliar_checkclass(L, "tcp{client}", 1);
- return buffer_meth_setstats(L, &tcp->buf);
+ return ls_buffer_meth_setstats(L, &tcp->buf);
 }
 
 /*-------------------------------------------------------------------------*\
@@ -152,7 +152,7 @@
 static int meth_dirty(lua_State *L)
 {
 p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, "tcp{any}", 1);
- lua_pushboolean(L, !buffer_isempty(&tcp->buf));
+ lua_pushboolean(L, !ls_buffer_isempty(&tcp->buf));
 return 1;
 }
 
@@ -176,7 +176,7 @@
 io_init(&clnt->io, (p_send) socket_send, (p_recv) socket_recv, 
 (p_error) socket_ioerror, &clnt->sock);
 timeout_init(&clnt->tm, -1, -1);
- buffer_init(&clnt->buf, &clnt->io, &clnt->tm);
+ ls_buffer_init(&clnt->buf, &clnt->io, &clnt->tm);
 return 1;
 } else {
 lua_pushnil(L); 
@@ -329,7 +329,7 @@
 io_init(&tcp->io, (p_send) socket_send, (p_recv) socket_recv, 
 (p_error) socket_ioerror, &tcp->sock);
 timeout_init(&tcp->tm, -1, -1);
- buffer_init(&tcp->buf, &tcp->io, &tcp->tm);
+ ls_buffer_init(&tcp->buf, &tcp->io, &tcp->tm);
 return 1;
 } else {
 lua_pushnil(L);
diff -ru luasocket-2.0.2-1.orig/luasocket-2.0.2/src/unix.c luasocket-2.0.2-1/luasocket-2.0.2/src/unix.c
--- luasocket-2.0.2-1.orig/luasocket-2.0.2/src/unix.c	2008年08月20日 06:16:42 +0000
+++ luasocket-2.0.2-1/luasocket-2.0.2/src/unix.c	2008年08月20日 06:30:15 +0000
@@ -105,22 +105,22 @@
 \*-------------------------------------------------------------------------*/
 static int meth_send(lua_State *L) {
 p_unix un = (p_unix) auxiliar_checkclass(L, "unix{client}", 1);
- return buffer_meth_send(L, &un->buf);
+ return ls_buffer_meth_send(L, &un->buf);
 }
 
 static int meth_receive(lua_State *L) {
 p_unix un = (p_unix) auxiliar_checkclass(L, "unix{client}", 1);
- return buffer_meth_receive(L, &un->buf);
+ return ls_buffer_meth_receive(L, &un->buf);
 }
 
 static int meth_getstats(lua_State *L) {
 p_unix un = (p_unix) auxiliar_checkclass(L, "unix{client}", 1);
- return buffer_meth_getstats(L, &un->buf);
+ return ls_buffer_meth_getstats(L, &un->buf);
 }
 
 static int meth_setstats(lua_State *L) {
 p_unix un = (p_unix) auxiliar_checkclass(L, "unix{client}", 1);
- return buffer_meth_setstats(L, &un->buf);
+ return ls_buffer_meth_setstats(L, &un->buf);
 }
 
 /*-------------------------------------------------------------------------*\
@@ -149,7 +149,7 @@
 
 static int meth_dirty(lua_State *L) {
 p_unix un = (p_unix) auxiliar_checkgroup(L, "unix{any}", 1);
- lua_pushboolean(L, !buffer_isempty(&un->buf));
+ lua_pushboolean(L, !ls_buffer_isempty(&un->buf));
 return 1;
 }
 
@@ -172,7 +172,7 @@
 io_init(&clnt->io, (p_send)socket_send, (p_recv)socket_recv, 
 (p_error) socket_ioerror, &clnt->sock);
 timeout_init(&clnt->tm, -1, -1);
- buffer_init(&clnt->buf, &clnt->io, &clnt->tm);
+ ls_buffer_init(&clnt->buf, &clnt->io, &clnt->tm);
 return 1;
 } else {
 lua_pushnil(L); 
@@ -346,7 +346,7 @@
 io_init(&un->io, (p_send) socket_send, (p_recv) socket_recv, 
 (p_error) socket_ioerror, &un->sock);
 timeout_init(&un->tm, -1, -1);
- buffer_init(&un->buf, &un->io, &un->tm);
+ ls_buffer_init(&un->buf, &un->io, &un->tm);
 return 1;
 } else {
 lua_pushnil(L);

AltStyle によって変換されたページ (->オリジナル) /