diff --git a/src/async.c b/src/async.c index 9492ac56..c27be20e 100644 --- a/src/async.c +++ b/src/async.c @@ -14,8 +14,7 @@ * limitations under the License. * */ -#include "luv.h" -#include "lthreadpool.h" +#include "private.h" static uv_async_t* luv_check_async(lua_State* L, int index) { uv_async_t* handle = (uv_async_t*)luv_checkudata(L, index, "uv_async"); diff --git a/src/check.c b/src/check.c index 60b75909..77f2ac53 100644 --- a/src/check.c +++ b/src/check.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" static uv_check_t* luv_check_check(lua_State* L, int index) { uv_check_t* handle = (uv_check_t*)luv_checkudata(L, index, "uv_check"); diff --git a/src/dns.c b/src/dns.c index 54e4be18..6cb092c8 100644 --- a/src/dns.c +++ b/src/dns.c @@ -15,7 +15,7 @@ * */ -#include "luv.h" +#include "private.h" #ifndef WIN32 #include #include diff --git a/src/fs.c b/src/fs.c index aaeedb7a..a42e20db 100644 --- a/src/fs.c +++ b/src/fs.c @@ -15,7 +15,7 @@ * */ -#include "luv.h" +#include "private.h" static uv_fs_t* luv_check_fs(lua_State* L, int index) { uv_fs_t* req = (uv_fs_t*)luaL_checkudata(L, index, "uv_req"); diff --git a/src/fs_event.c b/src/fs_event.c index b3bea1f1..0bb4d633 100644 --- a/src/fs_event.c +++ b/src/fs_event.c @@ -15,7 +15,7 @@ * */ -#include "luv.h" +#include "private.h" static uv_fs_event_t* luv_check_fs_event(lua_State* L, int index) { uv_fs_event_t* handle = (uv_fs_event_t*)luv_checkudata(L, index, "uv_fs_event"); diff --git a/src/handle.c b/src/handle.c index 98fc02b4..c88dbd67 100644 --- a/src/handle.c +++ b/src/handle.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" static void* luv_newuserdata(lua_State* L, size_t sz) { void* handle = malloc(sz); diff --git a/src/idle.c b/src/idle.c index 5144a4d9..725945e7 100644 --- a/src/idle.c +++ b/src/idle.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" static uv_idle_t* luv_check_idle(lua_State* L, int index) { uv_idle_t* handle = (uv_idle_t*)luv_checkudata(L, index, "uv_idle"); diff --git a/src/lhandle.h b/src/lhandle.h index 52a02553..0465d1d8 100644 --- a/src/lhandle.h +++ b/src/lhandle.h @@ -50,28 +50,4 @@ typedef struct { luv_handle_extra_gc extra_gc; } luv_handle_t; -#ifdef LUV_SOURCE -/* Traceback for lua_pcall */ -static int luv_traceback (lua_State *L); - -/* Setup the handle at the top of the stack */ -static luv_handle_t* luv_setup_handle(lua_State* L, luv_ctx_t* ctx); - -/* Store a lua callback in a luv_handle for future callbacks. - Either replace an existing callback by id or append a new one at the end. -*/ -static void luv_check_callback(lua_State* L, luv_handle_t* data, luv_callback_id id, int index); - -/* Lookup a function and call it with nargs - If there is no such function, pop the args. -*/ -static void luv_call_callback(lua_State* L, luv_handle_t* data, luv_callback_id id, int nargs); - -/* Push a userdata on the stack from a handle */ -static void luv_find_handle(lua_State* L, luv_handle_t* data); - -/* Unref the handle from the lua world, allowing it to GC */ -static void luv_unref_handle(lua_State* L, luv_handle_t* data); -#endif - #endif diff --git a/src/loop.c b/src/loop.c index a1789c11..2a59fa01 100644 --- a/src/loop.c +++ b/src/loop.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" static int luv_loop_close(lua_State* L) { int ret = uv_loop_close(luv_loop(L)); diff --git a/src/lreq.c b/src/lreq.c index b12ec4fc..41cc03f3 100644 --- a/src/lreq.c +++ b/src/lreq.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "lreq.h" +#include "private.h" static int luv_check_continuation(lua_State* L, int index) { diff --git a/src/lreq.h b/src/lreq.h index 785dd4c6..47daa88e 100644 --- a/src/lreq.h +++ b/src/lreq.h @@ -30,20 +30,4 @@ typedef struct { // This is an arbitrary value that we can assume will never be returned by luaL_ref #define LUV_REQ_MULTIREF (-0x1234) -#ifdef LUV_SOURCE -/* Used in the top of a setup function to check the arg - and ref the callback to an integer. -*/ -static int luv_check_continuation(lua_State* L, int index); - -/* setup a luv_req_t. The userdata is assumed to be at the - top of the stack. -*/ -static luv_req_t* luv_setup_req(lua_State* L, luv_ctx_t* ctx, int ref); - -static void luv_fulfill_req(lua_State* L, luv_req_t* data, int nargs); - -static void luv_cleanup_req(lua_State* L, luv_req_t* data); -#endif - #endif diff --git a/src/lthreadpool.h b/src/lthreadpool.h index d6f26b97..ddb3bf85 100644 --- a/src/lthreadpool.h +++ b/src/lthreadpool.h @@ -62,11 +62,4 @@ typedef struct { #define LUVF_THREAD_SIDE(i) ((i)&0x01) #define LUVF_THREAD_ASYNC(i) ((i)&0x02) -#ifdef LUV_SOURCE -static const char* luv_getmtname(lua_State *L, int idx); -static int luv_thread_arg_set(lua_State* L, luv_thread_arg_t* args, int idx, int top, int flags); -static int luv_thread_arg_push(lua_State* L, luv_thread_arg_t* args, int flags); -static void luv_thread_arg_clear(lua_State* L, luv_thread_arg_t* args, int flags); -#endif - #endif //LUV_LTHREADPOOL_H diff --git a/src/luv.c b/src/luv.c index 601ec595..8cf4ece9 100644 --- a/src/luv.c +++ b/src/luv.c @@ -19,7 +19,6 @@ #if (LUA_VERSION_NUM != 503) #include "compat-5.3.h" #endif -#define LUV_SOURCE #include "luv.h" #include "util.c" diff --git a/src/luv.h b/src/luv.h index 81ca9813..87f2a06b 100644 --- a/src/luv.h +++ b/src/luv.h @@ -50,11 +50,6 @@ #define MAX_TITLE_LENGTH (8192) #endif -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-function" -#endif - // luv flags to control luv_CFpcall routine #define LUVF_CALLBACK_NOEXIT 0x01 // Don't exit when LUA_ERRMEM #define LUVF_CALLBACK_NOTRACEBACK 0x02 // Don't traceback when error @@ -117,45 +112,8 @@ LUALIB_API void luv_set_callback(lua_State* L, luv_CFpcall pcall); */ LUALIB_API int luaopen_luv (lua_State *L); -#include "util.h" -#include "lhandle.h" -#include "lreq.h" - -#ifdef LUV_SOURCE -/* From stream.c */ -static uv_stream_t* luv_check_stream(lua_State* L, int index); -static void luv_alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf); - -/* From misc.c */ -static void luv_prep_buf(lua_State *L, int idx, uv_buf_t *pbuf); -static uv_buf_t* luv_prep_bufs(lua_State* L, int index, size_t *count, int **refs); -static uv_buf_t* luv_check_bufs(lua_State* L, int index, size_t *count, luv_req_t* req_data); -static uv_buf_t* luv_check_bufs_noref(lua_State* L, int index, size_t *count); - -/* from tcp.c */ -static void parse_sockaddr(lua_State* L, struct sockaddr_storage* address); -static void luv_connect_cb(uv_connect_t* req, int status); - -/* From fs.c */ -static void luv_push_stats_table(lua_State* L, const uv_stat_t* s); - -/* from constants.c */ -static int luv_af_string_to_num(const char* string); -static const char* luv_af_num_to_string(const int num); -static int luv_sock_string_to_num(const char* string); -static const char* luv_sock_num_to_string(const int num); -static int luv_sig_string_to_num(const char* string); -static const char* luv_sig_num_to_string(const int num); - -/* from util.c */ -static int luv_optboolean(lua_State*L, int idx, int defaultval); -#endif - typedef lua_State* (*luv_acquire_vm)(); typedef void (*luv_release_vm)(lua_State* L); LUALIB_API void luv_set_thread_cb(luv_acquire_vm acquire, luv_release_vm release); -#if defined(__clang__) -#pragma clang diagnostic pop -#endif #endif diff --git a/src/pipe.c b/src/pipe.c index 9508845f..5ad4124e 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" static uv_pipe_t* luv_check_pipe(lua_State* L, int index) { uv_pipe_t* handle = (uv_pipe_t*)luv_checkudata(L, index, "uv_pipe"); diff --git a/src/poll.c b/src/poll.c index 86694ff3..887c05fd 100644 --- a/src/poll.c +++ b/src/poll.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" static uv_poll_t* luv_check_poll(lua_State* L, int index) { uv_poll_t* handle = (uv_poll_t*)luv_checkudata(L, index, "uv_poll"); diff --git a/src/prepare.c b/src/prepare.c index f88f374f..6f8ae07b 100644 --- a/src/prepare.c +++ b/src/prepare.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" static uv_prepare_t* luv_check_prepare(lua_State* L, int index) { uv_prepare_t* handle = (uv_prepare_t*)luv_checkudata(L, index, "uv_prepare"); diff --git a/src/private.h b/src/private.h new file mode 100644 index 00000000..5404fb17 --- /dev/null +++ b/src/private.h @@ -0,0 +1,123 @@ +#ifndef LUV_PRIVATE_H +#define LUV_PRIVATE_H + +#include +#if (LUA_VERSION_NUM != 503) +#include "compat-5.3.h" +#endif + +#include "luv.h" +#include "util.h" +#include "lhandle.h" +#include "lreq.h" +#include "lthreadpool.h" + +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-function" +#endif + +/* From stream.c */ +static uv_stream_t* luv_check_stream(lua_State* L, int index); +static void luv_alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf); + +/* From lhandle.c */ +/* Traceback for lua_pcall */ +static int luv_traceback (lua_State *L); + +/* Setup the handle at the top of the stack */ +static luv_handle_t* luv_setup_handle(lua_State* L, luv_ctx_t* ctx); + +/* Store a lua callback in a luv_handle for future callbacks. + Either replace an existing callback by id or append a new one at the end. +*/ +static void luv_check_callback(lua_State* L, luv_handle_t* data, luv_callback_id id, int index); + +/* Lookup a function and call it with nargs + If there is no such function, pop the args. +*/ +static void luv_call_callback(lua_State* L, luv_handle_t* data, luv_callback_id id, int nargs); + +/* Push a userdata on the stack from a handle */ +static void luv_find_handle(lua_State* L, luv_handle_t* data); + +/* Unref the handle from the lua world, allowing it to GC */ +static void luv_unref_handle(lua_State* L, luv_handle_t* data); + +/* From lreq.c */ +/* Used in the top of a setup function to check the arg + and ref the callback to an integer. +*/ +static int luv_check_continuation(lua_State* L, int index); + +/* setup a luv_req_t. The userdata is assumed to be at the + top of the stack. +*/ +static luv_req_t* luv_setup_req(lua_State* L, luv_ctx_t* ctx, int ref); +static void luv_fulfill_req(lua_State* L, luv_req_t* data, int nargs); +static void luv_cleanup_req(lua_State* L, luv_req_t* data); + +/* From handle.c */ +static void* luv_checkudata(lua_State* L, int ud, const char* tname); +static void* luv_newuserdata(lua_State* L, size_t sz); + + +/* From misc.c */ +static void luv_prep_buf(lua_State *L, int idx, uv_buf_t *pbuf); +static uv_buf_t* luv_prep_bufs(lua_State* L, int index, size_t *count, int **refs); +static uv_buf_t* luv_check_bufs(lua_State* L, int index, size_t *count, luv_req_t* req_data); +static uv_buf_t* luv_check_bufs_noref(lua_State* L, int index, size_t *count); + +/* From tcp.c */ +static void parse_sockaddr(lua_State* L, struct sockaddr_storage* address); +static void luv_connect_cb(uv_connect_t* req, int status); + +/* From fs.c */ +static void luv_push_stats_table(lua_State* L, const uv_stat_t* s); + +/* From constants.c */ +static int luv_af_string_to_num(const char* string); +static const char* luv_af_num_to_string(const int num); +static int luv_sock_string_to_num(const char* string); +static const char* luv_sock_num_to_string(const int num); +static int luv_sig_string_to_num(const char* string); +static const char* luv_sig_num_to_string(const int num); + +/* From util.c */ +// Push a Libuv error code onto the Lua stack +static int luv_error(lua_State* L, int status); + +// Common error handling pattern for binding uv functions that only return success/error. +// If the binding returns a value other than success/error, this function should not be used. +static int luv_result(lua_State* L, int status); + +// Push the error name onto the stack if status is an error code, +// or push nil onto the stack if it's not an error code +static void luv_status(lua_State* L, int status); + +// Return true if the object is a function or a callable table +static int luv_is_callable(lua_State* L, int index); + +// Check if the argument is callable and throw an error if it's not +static void luv_check_callable(lua_State* L, int index); + +static int luv_optboolean(lua_State*L, int idx, int defaultval); + +/* From thread.c */ +static lua_State* luv_thread_acquire_vm(); + +/* From work.c */ +static const char* luv_thread_dumped(lua_State* L, int idx, size_t* l); +static const char* luv_getmtname(lua_State *L, int idx); +static int luv_thread_arg_set(lua_State* L, luv_thread_arg_t* args, int idx, int top, int flags); +static int luv_thread_arg_push(lua_State* L, luv_thread_arg_t* args, int flags); +static void luv_thread_arg_clear(lua_State* L, luv_thread_arg_t* args, int flags); + +static luv_acquire_vm acquire_vm_cb = NULL; +static luv_release_vm release_vm_cb = NULL; + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + +#endif diff --git a/src/process.c b/src/process.c index 5bf3a1b4..7562aec4 100644 --- a/src/process.c +++ b/src/process.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" #include static int luv_disable_stdio_inheritance(lua_State* L) { diff --git a/src/req.c b/src/req.c index b01a8003..1593716a 100644 --- a/src/req.c +++ b/src/req.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" static uv_req_t* luv_check_req(lua_State* L, int index) { uv_req_t* req = (uv_req_t*)luaL_checkudata(L, index, "uv_req"); diff --git a/src/signal.c b/src/signal.c index eaf3a37c..4a1fa04a 100644 --- a/src/signal.c +++ b/src/signal.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" static uv_signal_t* luv_check_signal(lua_State* L, int index) { uv_signal_t* handle = (uv_signal_t*)luv_checkudata(L, index, "uv_signal"); diff --git a/src/stream.c b/src/stream.c index 05e2f570..96df5148 100644 --- a/src/stream.c +++ b/src/stream.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" static uv_stream_t* luv_check_stream(lua_State* L, int index) { int isStream; diff --git a/src/tcp.c b/src/tcp.c index 05229074..d9d3bdf5 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" static uv_tcp_t* luv_check_tcp(lua_State* L, int index) { uv_tcp_t* handle = (uv_tcp_t*)luv_checkudata(L, index, "uv_tcp"); diff --git a/src/thread.c b/src/thread.c index 8c1aec76..0dd337dc 100644 --- a/src/thread.c +++ b/src/thread.c @@ -14,11 +14,7 @@ * limitations under the License. * */ -#include "luv.h" -#include "lthreadpool.h" -#if (LUA_VERSION_NUM != 503) -#include "compat-5.3.h" -#endif +#include "private.h" typedef struct { uv_thread_t handle; @@ -28,9 +24,6 @@ typedef struct { luv_thread_arg_t args; } luv_thread_t; -static luv_acquire_vm acquire_vm_cb = NULL; -static luv_release_vm release_vm_cb = NULL; - static lua_State* luv_thread_acquire_vm() { lua_State* L = luaL_newstate(); diff --git a/src/timer.c b/src/timer.c index 88d6e881..ed4c5177 100644 --- a/src/timer.c +++ b/src/timer.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" static uv_timer_t* luv_check_timer(lua_State* L, int index) { uv_timer_t* handle = (uv_timer_t*) luv_checkudata(L, index, "uv_timer"); diff --git a/src/tty.c b/src/tty.c index 614dc451..93c1c1e9 100644 --- a/src/tty.c +++ b/src/tty.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" static uv_tty_t* luv_check_tty(lua_State* L, int index) { uv_tty_t* handle = (uv_tty_t*)luv_checkudata(L, index, "uv_tty"); diff --git a/src/udp.c b/src/udp.c index 55158a5a..f28a4c61 100644 --- a/src/udp.c +++ b/src/udp.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" static uv_udp_t* luv_check_udp(lua_State* L, int index) { uv_udp_t* handle = (uv_udp_t*)luv_checkudata(L, index, "uv_udp"); diff --git a/src/util.c b/src/util.c index a5dbf096..eb596e35 100644 --- a/src/util.c +++ b/src/util.c @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "luv.h" +#include "private.h" void luv_stack_dump(lua_State* L, const char* name) { int i, l; diff --git a/src/util.h b/src/util.h index bb10cf94..0967090b 100644 --- a/src/util.h +++ b/src/util.h @@ -27,23 +27,4 @@ void luv_stack_dump(lua_State* L, const char* name); -#ifdef LUV_SOURCE -// Push a Libuv error code onto the Lua stack -static int luv_error(lua_State* L, int status); - -// Common error handling pattern for binding uv functions that only return success/error. -// If the binding returns a value other than success/error, this function should not be used. -static int luv_result(lua_State* L, int status); - -// Push the error name onto the stack if status is an error code, -// or push nil onto the stack if it's not an error code -static void luv_status(lua_State* L, int status); - -// Return true if the object is a function or a callable table -static int luv_is_callable(lua_State* L, int index); - -// Check if the argument is callable and throw an error if it's not -static void luv_check_callable(lua_State* L, int index); -#endif - #endif diff --git a/src/work.c b/src/work.c index a89b6bb2..1a056aa8 100644 --- a/src/work.c +++ b/src/work.c @@ -14,8 +14,7 @@ * limitations under the License. * */ -#include "luv.h" -#include "lthreadpool.h" +#include "private.h" typedef struct { lua_State* L; /* vm in main */