fix(sorters): fix sorters running after destroy, which can segfault (#1137)

* fix(sorters): fix sorters running after destroy, which can segfault

* fixup: Only check when we've set a status
This commit is contained in:
TJ DeVries
2021-08-20 13:12:29 -04:00
committed by GitHub
parent b47bb8df1e
commit bc470fe59f

View File

@@ -54,6 +54,7 @@ function Sorter:new(opts)
start = opts.start, start = opts.start,
finish = opts.finish, finish = opts.finish,
destroy = opts.destroy, destroy = opts.destroy,
_status = nil,
filter_function = opts.filter_function, filter_function = opts.filter_function,
scoring_function = opts.scoring_function, scoring_function = opts.scoring_function,
@@ -67,12 +68,14 @@ function Sorter:new(opts)
end end
function Sorter:_init() function Sorter:_init()
self._status = "init"
if self.init then if self.init then
self:init() self:init()
end end
end end
function Sorter:_destroy() function Sorter:_destroy()
self._status = "destroy"
if self.destroy then if self.destroy then
self:destroy() self:destroy()
end end
@@ -84,6 +87,7 @@ end
-- as he did in his example. -- as he did in his example.
-- Example can be found in ./scratch/prime_prompt_cache.lua -- Example can be found in ./scratch/prime_prompt_cache.lua
function Sorter:_start(prompt) function Sorter:_start(prompt)
self._status = "start"
if self.start then if self.start then
self:start(prompt) self:start(prompt)
end end
@@ -107,6 +111,7 @@ function Sorter:_start(prompt)
end end
function Sorter:_finish(prompt) function Sorter:_finish(prompt)
self._status = "finish"
if self.finish then if self.finish then
self:finish(prompt) self:finish(prompt)
end end
@@ -119,6 +124,10 @@ function Sorter:score(prompt, entry, cb_add, cb_filter)
return return
end end
if self._status and self._status ~= "start" then
return
end
local ordinal = entry.ordinal local ordinal = entry.ordinal
if self:_was_discarded(prompt, ordinal) then if self:_was_discarded(prompt, ordinal) then
return cb_filter(entry) return cb_filter(entry)