Author: Jeff Rogers <firstname.lastname@example.org> State: Draft Type: Project Tcl-Version: 8.7 Vote: Pending Created: 24-May-2016 Post-History: Keywords: Tcl, C API
Tcl_SetNotifier cannot be used in its current state to replace a notifier than has been initialized because pointers to the old initialized value are kept in the interp's private data. This TIP proposes a way to change that.
The Tcl_SetNotifier API was introduced to allow replacement of the built-in notifier; it works by setting hooks for various notifier functions that are called in place of the builtin functions.
It was expected that this function would only be called before the Tcl library had been initialized and any state had been set up; however this prevents it from being usable from a module loaded by a running interpreter.
This TIP proposes changing the behavior of this API to, in addition to setting the function hooks will shut down a running notifier and restart the notifier if it has been running previously. This is the minimum change necessary to allow a new notifier to be loaded from within a running interpreter.
It is probably not always possible to stop a running notifier, especially if event sources have been created. It is not necessarily easy to detect such failure; the proposed implementation doesn't even try. And there is no way to report such failure if it was detected. As such, this remains a somewhat dangerous interface to use.
With this change in place, it will be possible to load a new notifier implementation (e.g., a poll() or libevent based one) from a Tcl program, provided it is the very first thing done. An implementation of a poll-based notifier that requires the functionality in this TIP can be found at http://fossil.etoyoc.com/sandbox/tcllib/artifact/ad30080cdee762a3
Change the implementation of Tcl_SetNotifier to check if a notifier is currently running; if it is, the current notifier will be finalized before the new hooks are swapped in, and afterwards the notifier will be re-initialized. If the notifier is not already initialized, there is no change to functionality.
A patch implementing the proposed change can be found at http://fossil.etoyoc.com/sandbox/tcllib/artifact/b2b272a285811272
This document has been placed in the public domain.