Skip to content

Commit

Permalink
Refactoring header files
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaozg committed Mar 29, 2020
1 parent 76654fe commit 6457667
Show file tree
Hide file tree
Showing 30 changed files with 146 additions and 141 deletions.
3 changes: 1 addition & 2 deletions src/async.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

#include "luv.h"
#include "private.h"
#ifndef WIN32
#include <sys/types.h>
#include <sys/socket.h>
Expand Down
2 changes: 1 addition & 1 deletion src/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/fs_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
24 changes: 0 additions & 24 deletions src/lhandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/lreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
*/
#include "lreq.h"
#include "private.h"


static int luv_check_continuation(lua_State* L, int index) {
Expand Down
16 changes: 0 additions & 16 deletions src/lreq.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 0 additions & 7 deletions src/lthreadpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion src/luv.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#if (LUA_VERSION_NUM != 503)
#include "compat-5.3.h"
#endif
#define LUV_SOURCE
#include "luv.h"

#include "util.c"
Expand Down
42 changes: 0 additions & 42 deletions src/luv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/prepare.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
123 changes: 123 additions & 0 deletions src/private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#ifndef LUV_PRIVATE_H
#define LUV_PRIVATE_H

#include <lua.h>
#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
2 changes: 1 addition & 1 deletion src/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
*/
#include "luv.h"
#include "private.h"
#include <math.h>

static int luv_disable_stdio_inheritance(lua_State* L) {
Expand Down
2 changes: 1 addition & 1 deletion src/req.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 6457667

Please sign in to comment.