Artifact [379a24a559]

Login

Artifact 379a24a55969a481f8d3549e8b3a071e7f0d2e95e56d31b1068761dc52a741e6:


# TIP 585: Promote the INDEX\_TEMP\_TABLE flag of Tcl_GetIndexFromObj*() to the public interface
	Author:         Francois Vogel <[email protected]>
	State:          Final
	Type:           Project
	Vote:           Done
	Vote-Summary:   Accepted 6/0/0
	Votes-For:      DGP, FV, JN, KW, MC, SL
	Votes-Against:  none
	Votes-Present:  none
	Created:        30-Aug-2020
	Post-History:   
	Keywords:       Tcl Tcl_GetIndexFromObj() Tcl_GetIndexFromObjStruct()
	Tcl-Version:    8.7
	Tcl-Branch:     tip-585
-----

# Abstract

This TIP proposes to promote the <b>INDEX\_TEMP\_TABLE</b> flag of <b>Tcl\_GetIndexFromObj*()</b> to the public interface as <b>TCL\_INDEX\_TEMP\_TABLE</b>, so that the tables used may not be always static.

# Rationale

<b>Tcl\_GetIndexFromObjStruct()</b> is largely used in the Tcl/Tk codebase.
It expects an array of static entries <b>structTablePtr</b> as input, that must not change between invocations. This is well documented, and is almost always the case since in the current codebase this function is mainly used to retrieve indices from options lists. Because these options lists are static, caching of indices can be done, which increases efficiency when looking several times for the same index in the same table.

However, in some cases it would be useful to be able to instruct <b>Tcl\_GetIndexFromObjStruct()</b> that the table passed to it is not static, meaning caching of indices shall not be used. There is such a use case in the [revised_text](https://core.tcl-lang.org/tk/timeline?r=revised_text) branch of Tk, specifically in function <b>GetDumpFlags()</b> [here](https://core.tcl-lang.org/tk/artifact/3a0f54457fe24143?ln=7264,7329). Based on some input parameters, this function builds a list of options that depends on those input parameters, and is therefore not static when <b>Tcl\_GetIndexFromObjStruct()</b> is called repeatedly. This is the root cause for [bug \[8980ba1d0b\]](https://core.tcl-lang.org/tk/tktview?name=8980ba1d0b) according to my analysis dated 2020-08-25 20:34:47. in that ticket. In this use case it is needed to be able to disable indices caching in <b>Tcl\_GetIndexFromObjStruct()</b>.

As it turns out, <b>Tcl\_GetIndexFromObjStruct()</b> already has this capability through its <b>INDEX\_TEMP\_TABLE</b> flag. This flag is already used internally by Tcl.

The proposal of the present TIP is therefore to promote this flag to the public interface as <b>TCL\_INDEX\_TEMP\_TABLE</b>, so that Tk can make use of it in the above use case and more.

# Implementation

Available in the [`tip-585`](https://core.tcl-lang.org/tcl/timeline?r=tip-585&unhide) branch.

This branch targets 8.7.

# Rejected alternatives

[It has been proposed]
(https://sourceforge.net/p/tcl/mailman/tcl-core/thread/1c40b945-b105-3897-1db0-8333a0f04e10%40wu.ac.at/#msg37097636)
that instead of exposing <b>INDEX\_TEMP\_TABLE</b> a new public routine be provided
featuring a non-caching version of Tcl\_GetIndexFromObj*(), which would be needed for shared
Tcl_Objs only. While this could of course be done, I think exposing the existing <b>INDEX\_TEMP\_TABLE</b> flag is simpler.

# Copyright

This document has been placed in the public domain.