Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #289 from luvit/bump-libuv-to-0.8-base
Bump libuv to 0.8
  • Loading branch information
philips committed Aug 8, 2012
2 parents 24d2aef + df9a2b6 commit c4570f3
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 72 deletions.
3 changes: 1 addition & 2 deletions common.gypi
Expand Up @@ -151,9 +151,8 @@
'GCC_INLINES_ARE_PRIVATE_EXTERN': 'YES',
'GCC_SYMBOLS_PRIVATE_EXTERN': 'NO',
'GCC_THREADSAFE_STATICS': 'NO', # -fno-threadsafe-statics
'GCC_VERSION': '4.2',
'GCC_WARN_ABOUT_MISSING_NEWLINE': 'YES', # -Wnewline-eof
'MACOSX_DEPLOYMENT_TARGET': '10.4', # -mmacosx-version-min=10.4
'MACOSX_DEPLOYMENT_TARGET': '10.6', # -mmacosx-version-min=10.6
'PREBINDING': 'NO', # No -Wl,-prebind
'USE_HEADERMAP': 'NO',
'OTHER_CFLAGS': [
Expand Down
2 changes: 1 addition & 1 deletion deps/uv
Submodule uv updated 132 files
7 changes: 0 additions & 7 deletions lib/luvit/luvit.lua
Expand Up @@ -120,7 +120,6 @@ function process:addHandlerType(name)
local code = constants[name]
if code then
native.activateSignalHandler(code)
native.unref()
end
end
Expand Down Expand Up @@ -179,11 +178,8 @@ OS_BINDING.clock = OLD_OS.clock
-- These shouldn't hold open the event loop
if OS_BINDING.type() ~= "win32" then
native.activateSignalHandler(constants.SIGPIPE)
native.unref()
native.activateSignalHandler(constants.SIGINT)
native.unref()
native.activateSignalHandler(constants.SIGTERM)
native.unref()
end
local traceback = require('debug').traceback
Expand Down Expand Up @@ -333,9 +329,6 @@ assert(xpcall(function ()
end

if interactive or showrepl then
if OS_BINDING.type() == "win32" then
native.ref()
end
repl.start()
end

Expand Down
1 change: 1 addition & 0 deletions lib/luvit/net.lua
Expand Up @@ -336,6 +336,7 @@ function Server:close(callback)
end
if self._handle then
self._handle:close()
self._handle = nil
end
self:_emitClosedIfDrained()
end
Expand Down
11 changes: 8 additions & 3 deletions lib/luvit/timer.lua
Expand Up @@ -84,9 +84,13 @@ expiration = function(timer, msecs)
end
end
end
timer:stop()
timer:close()
lists[msecs] = nil
-- Remove the timer if it wasn't already
-- removed by unenroll
if lists[msecs] ~= nil then
timer:stop()
timer:close()
lists[msecs] = nil
end
end
end
Expand Down Expand Up @@ -116,6 +120,7 @@ local function unenroll(item)
local list = lists[item._idleTimeout]
if list and isEmpty(list) then
-- empty list
list:stop()
list:close()
lists[item._idleTimeout] = nil
end
Expand Down
64 changes: 28 additions & 36 deletions lib/luvit/uv.lua
Expand Up @@ -8,6 +8,12 @@ local uv = Object:extend()

--------------------------------------------------------------------------------

-- Print all handles
uv.printAllHandles = native.printAllHandles

-- Print all active handles
uv.printActiveHandles = native.printActiveHandles

--[[
This class is never used directly, but is the inheritance chain of all libuv
objects.
Expand All @@ -17,7 +23,14 @@ uv.Handle = Handle

-- Wrapper around `uv_close`. Closes the underlying file descriptor of a handle.
-- Handle:close()
Handle.close = native.close
Handle.close = function(self)
if self._closed then
error("close called on closed handle")
return
end
native.close(self)
self._closed = true
end

--[[
This is used by Emitters to register with native events when the first listener
Expand Down Expand Up @@ -49,6 +62,12 @@ uv.Stream = Stream
-- Stream:shutdown(callback)
Stream.shutdown = native.shutdown

-- Stream:ref()
Stream.ref = native.ref

-- Stream:unref()
Stream.unref = native.unref

-- Stream:listen(callback)
Stream.listen = native.listen

Expand Down Expand Up @@ -184,17 +203,17 @@ Pipe.bind = native.pipeBind
Pipe.connect = native.pipeConnect

function Pipe:pause()
native.unref()
self:unref()
self:readStop()
end

function Pipe:pauseNoRef()
native.unref()
self:unref()
self:readStopNoRef()
end

function Pipe:resume()
native.ref()
self:ref()
self:readStart()
end

Expand All @@ -216,19 +235,19 @@ Tty.getWinsize = native.ttyGetWinsize
Tty.resetMode = native.ttyResetMode

function Tty:pause()
native.unref()
self:unref()
self:readStop()
end

-- TODO: The readStop() implementation assumes a reference is being held. This
-- will go away with a libuv upgrade.
function Tty:pauseNoRef()
native.unref()
self:unref()
self:readStopNoRef()
end

function Tty:resume()
native.ref()
self:ref()
self:readStart()
end

Expand All @@ -241,20 +260,11 @@ uv.Timer = Timer
function Timer:initialize()
self.userdata = native.newTimer()
self._active = false
-- uv_timer_init adds a loop reference. (That is, it calls uv_ref.) This
-- is not the behavior we want in Luvit. Timers should not increase the
-- ref count of the loop except when active.
native.unref()
end

function Timer:_update()
local was_active = self._active
self._active = native.timerGetActive(self)
if was_active == false and self._active == true then
native.ref()
elseif was_active == true and self._active == false then
native.unref()
end
end

-- Timer:start(timeout, interval, callback)
Expand All @@ -263,13 +273,6 @@ function Timer:start(timeout, interval, callback)
self:_update()
end

function Timer:close()
Handle.close(self)
if self._active == false then
native.ref()
end
end

-- Timer:stop()
function Timer:stop()
native.timerStop(self)
Expand Down Expand Up @@ -300,14 +303,14 @@ uv.createWriteableStdioStream = function(fd)
local fd_type = native.handleType(fd);
if (fd_type == "TTY") then
local tty = Tty:new(fd)
native.unref()
tty:unref()
return tty
elseif (fd_type == "FILE") then
return fs.SyncWriteStream:new(fd)
elseif (fd_type == "NAMED_PIPE") then
local pipe = Pipe:new(nil)
pipe:open(fd)
native.unref()
pipe:unref()
return pipe
else
error("Unknown stream file type " .. fd)
Expand All @@ -328,24 +331,13 @@ uv.createReadableStdioStream = function(fd)
error("Unknown stream file type " .. fd)
end

-- unref the event loop so that we don't block unless the user
-- wants stdin. This follows node's logic.
if fd_type ~= "FILE" then
-- fs.createReadStream returns iStream which is pure lua and doesn't have
-- pauseNoRef method
stdin:pauseNoRef()
end

return stdin
end

function Process:initialize(command, args, options)
self.stdin = Pipe:new(nil)
self.stdin:open(0)
self.stdout = Pipe:new(nil)
self.stdout:open(1)
self.stderr = Pipe:new(nil)
self.stderr:open(2)
args = args or {}
options = options or {}

Expand Down
6 changes: 4 additions & 2 deletions src/luv.c
Expand Up @@ -38,6 +38,8 @@ static const luaL_reg luv_f[] = {

/* Handle functions */
{"close", luv_close},
{"ref", luv_ref},
{"unref", luv_unref},
{"setHandler", luv_set_handler},

/* UDP functions */
Expand Down Expand Up @@ -149,8 +151,8 @@ static const luaL_reg luv_f[] = {

/* Misc functions */
{"run", luv_run},
{"ref", luv_ref},
{"unref", luv_unref},
{"printActiveHandles", luv_print_active_handles},
{"printAllHandles", luv_print_all_handles},
{"updateTime", luv_update_time},
{"now", luv_now},
{"hrtime", luv_hrtime},
Expand Down
12 changes: 12 additions & 0 deletions src/luv_handle.c
Expand Up @@ -89,6 +89,18 @@ int luv_close (lua_State* L) {
return 0;
}

int luv_ref(lua_State* L) {
uv_handle_t* handle = luv_checkudata(L, 1, "handle");
uv_ref(handle);
return 0;
}

int luv_unref(lua_State* L) {
uv_handle_t* handle = luv_checkudata(L, 1, "handle");
uv_unref(handle);
return 0;
}

int luv_set_handler(lua_State* L) {
const char* name;
luv_checkudata(L, 1, "handle");
Expand Down
3 changes: 3 additions & 0 deletions src/luv_handle.h
Expand Up @@ -39,4 +39,7 @@ void luv_on_close(uv_handle_t* handle);
int luv_close (lua_State* L);
int luv_set_handler(lua_State* L);

int luv_ref(lua_State* L);
int luv_unref(lua_State* L);

#endif
21 changes: 11 additions & 10 deletions src/luv_misc.c
Expand Up @@ -19,6 +19,7 @@
#include <assert.h>
#include <string.h>

#include "uv.h"
#include "luv_misc.h"
#include "utils.h"

Expand Down Expand Up @@ -216,16 +217,6 @@ int luv_run(lua_State* L) {
return 0;
}

int luv_ref (lua_State* L) {
uv_ref(luv_get_loop(L));
return 0;
}

int luv_unref(lua_State* L) {
uv_unref(luv_get_loop(L));
return 0;
}

int luv_update_time(lua_State* L) {
uv_update_time(luv_get_loop(L));
return 0;
Expand Down Expand Up @@ -393,5 +384,15 @@ int luv_handle_type(lua_State* L) {
return 1;
}

extern void uv_print_active_handles(uv_loop_t *loop);
extern void uv_print_all_handles(uv_loop_t *loop);

int luv_print_active_handles(lua_State* L) {
uv_print_active_handles(luv_get_loop(L));
return 0;
}

int luv_print_all_handles(lua_State* L) {
uv_print_all_handles(luv_get_loop(L));
return 0;
}
4 changes: 2 additions & 2 deletions src/luv_misc.h
Expand Up @@ -25,8 +25,6 @@

int luv_activate_signal_handler(lua_State* L);
int luv_run(lua_State* L);
int luv_ref (lua_State* L);
int luv_unref(lua_State* L);
int luv_update_time(lua_State* L);
int luv_now(lua_State* L);
int luv_hrtime(lua_State* L);
Expand All @@ -40,5 +38,7 @@ int luv_execpath(lua_State* L);
int luv_get_process_title(lua_State* L);
int luv_set_process_title(lua_State* L);
int luv_handle_type(lua_State* L);
int luv_print_active_handles(lua_State* L);
int luv_print_all_handles(lua_State* L);

#endif

0 comments on commit c4570f3

Please sign in to comment.