From 7f7ec9e1ed494832de1626a120ebc293ce3e1313 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 24 Dec 2020 17:57:28 +0100 Subject: util.stanza: Move misplaced argument to correct place valid_utf8() takes only one argument, so the false was probably meant to be valid_xml_cdata(text, attribute=false) --- util/stanza.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'util') diff --git a/util/stanza.lua b/util/stanza.lua index cf2818ec..a8c619d0 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -66,9 +66,9 @@ end local function check_text(text, text_type) if type(text) ~= "string" then error("invalid "..text_type.." value: expected string, got "..type(text)); - elseif not valid_xml_cdata(text) then + elseif not valid_xml_cdata(text, false) then error("invalid "..text_type.." value: contains control characters"); - elseif not valid_utf8(text, false) then + elseif not valid_utf8(text) then error("invalid "..text_type.." value: contains invalid utf8"); end end -- cgit v1.2.3 From 365e5b0cb481315525d4f2bfbf478340b8dc08d8 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 8 Jan 2021 23:23:56 +0100 Subject: util.timer: Ensure timers can't run more than once per tick (fixes #1620) See longer explanation in 2c559953ad41 --- util/timer.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'util') diff --git a/util/timer.lua b/util/timer.lua index 4670e196..bc3836be 100644 --- a/util/timer.lua +++ b/util/timer.lua @@ -15,6 +15,7 @@ local debug_traceback = debug.traceback; local tostring = tostring; local xpcall = require "util.xpcall".xpcall; local math_max = math.max; +local pairs = pairs; local _ENV = nil; -- luacheck: std none @@ -29,6 +30,7 @@ local next_time = nil; local function _traceback_handler(err) log("error", "Traceback[timer]: %s", debug_traceback(tostring(err), 2)); end local function _on_timer(now) local peek; + local readd; while true do peek = h:peek(); if peek == nil or peek > now then break; end @@ -38,11 +40,22 @@ local function _on_timer(now) --item(now, id, _param); local success, err = xpcall(callback, _traceback_handler, now, id, param); if success and type(err) == "number" then - h:insert(callback, err + now, id); -- re-add + if readd then + readd[id] = { callback, err + now }; + else + readd = { [id] = { callback, err + now } }; + end params[id] = param; end end + if readd then + for id,timer in pairs(readd) do + h:insert(timer[1], timer[2], id); + end + peek = h:peek(); + end + if peek ~= nil and _active_timers > 1 and peek == next_time then -- Another instance of _on_timer already set next_time to the same value, -- so it should be safe to not renew this timer event -- cgit v1.2.3