Re: [code] [textadept] Patch for events

From: Mitchell <>
Date: Thu, 14 Jul 2016 12:13:21 -0400 (EDT)

Hi David,

On Thu, 14 Jul 2016, D K wrote:

> First of all, thanks for an excellent text editor.


> While scripting against textadept, I discovered two issues in
> core/events.lua.
>   The first issue is in events.connect and events.disconnect. When inserting
> a new event handler that is not at the length of the sequence+1
> (#handlers[event]+1), or when removing an old event handler that is not at
> the length of the sequence (#handlers[event]), other event handlers that uses
> the callback function to lookup their respective indeces in handlers[event]
> will be affected since table.remove/table.insert will shift all event
> handlers following the affected (removed/added) index in handlers[event].
> Before the defect fix, the following could therefore be true after using
> events.connect (with an index in the middle of the list) and
> events.disconnect (when removing an event that wasn't the last one in the
> list). It is assumed the callback function f exists in handlers[event]:
> local index = handlers[event][f]
> handlers[event][index] ~= f
> The consequence of that could in turn mean that when removing further event
> callbacks from the same event type, you can potentially remove an unrelated
> callback.
> The second defect concerns removing an event handler while events.emit is
> being processed. Since this will affect the length of the sequence
> handlers[event], the main for loop in events.emit will try to process more
> events than is actually available (it has already evaluated the length of the
> sequence in the for statement). By checking if we get a nil value and that
> the length of the array has been decreased, we exit the loop.
> The patch is against textadept-0cb79f5e9960, but it might work with later
> versions.

Thanks for bringing this to my attention :) I've applied something
similar[1]. It turns out juggling handler indices really isn't necessary.



You are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Thu 14 Jul 2016 - 12:13:21 EDT

This archive was generated by hypermail 2.2.0 : Fri 15 Jul 2016 - 06:33:40 EDT