From 7cab8a5006da807d83f427217e2158079bb78145 Mon Sep 17 00:00:00 2001 From: Philipp Janda Date: Sun, 21 Feb 2016 12:28:13 +0100 Subject: Update comment in except.h --- src/except.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/except.h') diff --git a/src/except.h b/src/except.h index 1e7a245..2497c05 100644 --- a/src/except.h +++ b/src/except.h @@ -9,21 +9,26 @@ * error checking was taking a substantial amount of the coding. These * function greatly simplify the task of checking errors. * -* The main idea is that functions should return nil as its first return -* value when it finds an error, and return an error message (or value) +* The main idea is that functions should return nil as their first return +* values when they find an error, and return an error message (or value) * following nil. In case of success, as long as the first value is not nil, * the other values don't matter. * * The idea is to nest function calls with the "try" function. This function -* checks the first value, and calls "error" on the second if the first is -* nil. Otherwise, it returns all values it received. +* checks the first value, and, if it's falsy, wraps the second value in a +* table with metatable and calls "error" on it. Otherwise, it returns all +* values it received. Basically, it works like the Lua "assert" function, +* but it creates errors targeted specifically at "protect". * -* The protect function returns a new function that behaves exactly like the -* function it receives, but the new function doesn't throw exceptions: it -* returns nil followed by the error message instead. +* The "newtry" function is a factory for "try" functions that call a +* finalizer in protected mode before calling "error". * -* With these two function, it's easy to write functions that throw -* exceptions on error, but that don't interrupt the user script. +* The "protect" function returns a new function that behaves exactly like +* the function it receives, but the new function catches exceptions thrown +* by "try" functions and returns nil followed by the error message instead. +* +* With these three functions, it's easy to write functions that throw +* exceptions on error, but that don't interrupt the user script. \*=========================================================================*/ #include "lua.h" -- cgit v1.2.3-55-g6feb From 4bf3eb6db2315fef8f3d18c8ce742752f7e4fda2 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Wed, 27 Feb 2019 20:57:00 -0700 Subject: except: pragma visibility --- src/except.c | 10 ++-------- src/except.h | 6 +++++- 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'src/except.h') diff --git a/src/except.c b/src/except.c index dab70e7..9c3317f 100644 --- a/src/except.c +++ b/src/except.c @@ -3,14 +3,8 @@ * LuaSocket toolkit \*=========================================================================*/ #include "luasocket.h" - -#include - -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - #include "except.h" +#include #if LUA_VERSION_NUM < 502 #define lua_pcallk(L, na, nr, err, ctx, cont) \ @@ -126,7 +120,7 @@ static int global_protect(lua_State *L) { /*-------------------------------------------------------------------------*\ * Init module \*-------------------------------------------------------------------------*/ -LUASOCKET_PRIVATE int except_open(lua_State *L) { +int except_open(lua_State *L) { lua_newtable(L); /* metatable for wrapped exceptions */ lua_pushboolean(L, 0); lua_setfield(L, -2, "__metatable"); diff --git a/src/except.h b/src/except.h index 2497c05..baa7b09 100644 --- a/src/except.h +++ b/src/except.h @@ -31,8 +31,12 @@ * exceptions on error, but that don't interrupt the user script. \*=========================================================================*/ -#include "lua.h" +#include "luasocket.h" + +#pragma GCC visibility push(hidden) int except_open(lua_State *L); +#pragma GCC visibility pop + #endif -- cgit v1.2.3-55-g6feb From 21514304be9e98a4386cb18542582068a59c5586 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Thu, 28 Feb 2019 16:32:07 -0700 Subject: wrap visibility pragmas in #ifndef _WIN32 --- src/auxiliar.h | 4 ++++ src/buffer.h | 4 ++++ src/compat.h | 4 ++++ src/except.h | 4 ++++ src/inet.h | 4 ++++ src/io.h | 5 ++++- src/options.h | 4 ++++ src/select.h | 4 ++++ src/socket.h | 4 ++++ src/tcp.h | 4 ++++ src/timeout.c | 8 -------- src/timeout.h | 4 ++++ src/udp.h | 4 ++++ src/unixdgram.h | 4 ++++ src/unixstream.h | 4 ++++ src/wsocket.c | 8 -------- 16 files changed, 56 insertions(+), 17 deletions(-) (limited to 'src/except.h') diff --git a/src/auxiliar.h b/src/auxiliar.h index 234b00a..e8c3ead 100644 --- a/src/auxiliar.h +++ b/src/auxiliar.h @@ -31,7 +31,9 @@ #include "luasocket.h" +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int auxiliar_open(lua_State *L); void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func); @@ -45,6 +47,8 @@ void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx); void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx); int auxiliar_typeerror(lua_State *L, int narg, const char *tname); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* AUXILIAR_H */ diff --git a/src/buffer.h b/src/buffer.h index 4218ea0..a0901fc 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -33,7 +33,9 @@ typedef struct t_buffer_ { } t_buffer; typedef t_buffer *p_buffer; +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int buffer_open(lua_State *L); void buffer_init(p_buffer buf, p_io io, p_timeout tm); @@ -43,6 +45,8 @@ int buffer_meth_send(lua_State *L, p_buffer buf); int buffer_meth_receive(lua_State *L, p_buffer buf); int buffer_isempty(p_buffer buf); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* BUF_H */ diff --git a/src/compat.h b/src/compat.h index 8c32b07..fa2d7d7 100644 --- a/src/compat.h +++ b/src/compat.h @@ -3,12 +3,16 @@ #if LUA_VERSION_NUM==501 +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif void luasocket_setfuncs (lua_State *L, const luaL_Reg *l, int nup); void *luasocket_testudata ( lua_State *L, int arg, const char *tname); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #define luaL_setfuncs luasocket_setfuncs #define luaL_testudata luasocket_testudata diff --git a/src/except.h b/src/except.h index baa7b09..71c31fd 100644 --- a/src/except.h +++ b/src/except.h @@ -33,10 +33,14 @@ #include "luasocket.h" +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int except_open(lua_State *L); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif diff --git a/src/inet.h b/src/inet.h index 2e00e58..5618b61 100644 --- a/src/inet.h +++ b/src/inet.h @@ -22,7 +22,9 @@ #define LUASOCKET_INET_ATON #endif +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int inet_open(lua_State *L); @@ -47,6 +49,8 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt); int inet_pton(int af, const char *src, void *dst); #endif +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* INET_H */ diff --git a/src/io.h b/src/io.h index e08eb0e..b8a54df 100644 --- a/src/io.h +++ b/src/io.h @@ -56,12 +56,15 @@ typedef struct t_io_ { } t_io; typedef t_io *p_io; +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); const char *io_strerror(int err); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* IO_H */ - diff --git a/src/options.h b/src/options.h index 1457f43..41f7337 100644 --- a/src/options.h +++ b/src/options.h @@ -18,7 +18,9 @@ typedef struct t_opt { } t_opt; typedef t_opt *p_opt; +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps); int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps); @@ -93,6 +95,8 @@ int opt_get_ip6_v6only(lua_State *L, p_socket ps); int opt_get_error(lua_State *L, p_socket ps); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif diff --git a/src/select.h b/src/select.h index 95272db..5d45fe7 100644 --- a/src/select.h +++ b/src/select.h @@ -10,10 +10,14 @@ * true if there is data ready for reading (required for buffered input). \*=========================================================================*/ +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int select_open(lua_State *L); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* SELECT_H */ diff --git a/src/socket.h b/src/socket.h index 4adc562..e541f27 100644 --- a/src/socket.h +++ b/src/socket.h @@ -36,7 +36,9 @@ typedef struct sockaddr SA; * interface to sockets \*=========================================================================*/ +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int socket_waitfd(p_socket ps, int sw, p_timeout tm); int socket_open(void); @@ -64,6 +66,8 @@ const char *socket_strerror(int err); const char *socket_ioerror(p_socket ps, int err); const char *socket_gaistrerror(int err); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* SOCKET_H */ diff --git a/src/tcp.h b/src/tcp.h index 9b12b53..9b282ef 100644 --- a/src/tcp.h +++ b/src/tcp.h @@ -30,10 +30,14 @@ typedef struct t_tcp_ { typedef t_tcp *p_tcp; +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int tcp_open(lua_State *L); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* TCP_H */ diff --git a/src/timeout.c b/src/timeout.c index 0e3ee27..2bdc069 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -26,10 +26,6 @@ #define MAX(x, y) ((x) > (y) ? x : y) #endif -#ifndef _WIN32 -#pragma GCC visibility push(hidden) -#endif - /*=========================================================================*\ * Internal function prototypes \*=========================================================================*/ @@ -228,7 +224,3 @@ int timeout_lua_sleep(lua_State *L) return 0; } #endif - -#ifndef _WIN32 -#pragma GCC visibility pop -#endif diff --git a/src/timeout.h b/src/timeout.h index df05eaf..9e5250d 100644 --- a/src/timeout.h +++ b/src/timeout.h @@ -14,7 +14,9 @@ typedef struct t_timeout_ { } t_timeout; typedef t_timeout *p_timeout; +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif void timeout_init(p_timeout tm, double block, double total); double timeout_get(p_timeout tm); @@ -29,7 +31,9 @@ int timeout_open(lua_State *L); int timeout_meth_settimeout(lua_State *L, p_timeout tm); int timeout_meth_gettimeout(lua_State *L, p_timeout tm); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #define timeout_iszero(tm) ((tm)->block == 0.0) diff --git a/src/udp.h b/src/udp.h index 9e80ccd..07d5247 100644 --- a/src/udp.h +++ b/src/udp.h @@ -26,10 +26,14 @@ typedef struct t_udp_ { } t_udp; typedef t_udp *p_udp; +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int udp_open(lua_State *L); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* UDP_H */ diff --git a/src/unixdgram.h b/src/unixdgram.h index 433fe25..a1a0166 100644 --- a/src/unixdgram.h +++ b/src/unixdgram.h @@ -15,10 +15,14 @@ #include "unix.h" +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int unixdgram_open(lua_State *L); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* UNIXDGRAM_H */ diff --git a/src/unixstream.h b/src/unixstream.h index 8ffba8f..7916aff 100644 --- a/src/unixstream.h +++ b/src/unixstream.h @@ -16,10 +16,14 @@ \*=========================================================================*/ #include "unix.h" +#ifndef _WIN32 #pragma GCC visibility push(hidden) +#endif int unixstream_open(lua_State *L); +#ifndef _WIN32 #pragma GCC visibility pop +#endif #endif /* UNIXSTREAM_H */ diff --git a/src/wsocket.c b/src/wsocket.c index 1da984c..20da330 100755 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -12,10 +12,6 @@ #include "socket.h" #include "pierror.h" -#ifndef _WIN32 -#pragma GCC visibility push(hidden) -#endif - /* WinSock doesn't have a strerror... */ static const char *wstrerror(int err); @@ -436,7 +432,3 @@ const char *socket_gaistrerror(int err) { default: return gai_strerror(err); } } - -#ifndef _WIN32 -#pragma GCC visibility pop -#endif -- cgit v1.2.3-55-g6feb