-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Schema #82
WIP: Schema #82
Changes from 6 commits
eff35ed
8de86bc
d6929fd
0798f56
ca224a2
dbd0036
641e8da
3a4664b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,31 @@ | |
*/ | ||
#include "lreq.h" | ||
|
||
static void* luv_push_req(lua_State* L, int index, size_t size) { | ||
uv_req_t* req; | ||
luv_req_t* data; | ||
|
||
data = calloc(1, sizeof(*data)); | ||
if (!data) luaL_error(L, "Problem allocating luv request"); | ||
|
||
req = lua_newuserdata(L, size); | ||
req->data = data; | ||
luaL_getmetatable(L, "uv_req"); | ||
lua_setmetatable(L, -2); | ||
|
||
lua_pushvalue(L, -1); | ||
data->req_ref = luaL_ref(L, LUA_REGISTRYINDEX); | ||
if (lua_isfunction(L, index)) { | ||
lua_pushvalue(L, index); | ||
data->callback_ref = luaL_ref(L, LUA_REGISTRYINDEX);; | ||
} | ||
else { | ||
data->callback_ref = LUA_NOREF; | ||
} | ||
|
||
return req; | ||
} | ||
|
||
|
||
static int luv_check_continuation(lua_State* L, int index) { | ||
if (lua_isnoneornil(L, index)) return LUA_NOREF; | ||
|
@@ -61,9 +86,10 @@ 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) { | ||
static luv_req_t* luv_cleanup_req(lua_State* L, luv_req_t* data) { | ||
luaL_unref(L, LUA_REGISTRYINDEX, data->req_ref); | ||
luaL_unref(L, LUA_REGISTRYINDEX, data->callback_ref); | ||
free(data->data); | ||
free(data); | ||
return NULL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return NULL? should it be void? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do that so I can do this: https://github.com/luvit/luv/blob/schema/src/fs.c#L277 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
*/ | ||
|
||
#include "luv.h" | ||
#include "schema.c" | ||
#include "util.c" | ||
#include "lhandle.c" | ||
#include "lreq.c" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef LSCHEMA_H | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may as well add the license header. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
#define LSCHEMA_H | ||
|
||
#include "luv.h" | ||
|
||
typedef const struct { | ||
const char* name; | ||
int (*checker)(lua_State* L, int index); | ||
} lschema_entry; | ||
|
||
static int luv_isfile(lua_State* L, int index); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no static here, and the next 3 lines There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But they are static on the C file. Shouldn't they match? The use of header files at all is questionable with the current way it builds since you could never use these header files without also including the corresponding C files. With dukluv I recently made the files actually standalone and link them together as a last step. It made the build a little slower and exported a lot more symbols into the final object, but it made my lint tool happier. |
||
static int luv_iscontinuation(lua_State* L, int index); | ||
static int luv_ispositive(lua_State* L, int index); | ||
void lschema_check(lua_State* L, lschema_entry schema[]); | ||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint64_t?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just trying to match what libuv is expecting to go through minimal typecasts.
offset declared at https://github.com/joyent/libuv/blob/a4f88760be1838603fe2eae89a651066cc42eedd/include/uv.h#L1072
though I got size wrong, it should be
unsigned int
from https://github.com/joyent/libuv/blob/a4f88760be1838603fe2eae89a651066cc42eedd/include/uv.h#L416There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k. that sounds reasonable.