TIP 664: Enable compiler warnings for missing int → Tcl_Size conversions

Author:		Jan Nijtmans <[email protected]>
State:		Withdrawn
Type:		Project
Vote:		Done
Created:	02-05-2023
Tcl-Version:	9.0
Tcl-Branch:	tip-664
Vote-Summary:	Accepted 7/0/0
Votes-For:	AF, AK, DKF, JN, KW, MC, SL
Votes-Against:	none
Votes-Present:	none
Obsoleted-By:	661


The TIPs 481 and 616 introduced macro constructs which hide the C API changes from Tcl 8.6 to Tcl 9 and disable compiler warnings. This tip proposes to enable those compiler warnings, as a help for people who want to make their extension fully capable of handling strings > 2^31.

If users want to disable this warning they can do that by using their normal compiler options, e.g. (for clang/gcc):

    configure CFLAGS=-Wno-incompatible-pointer-types
Users disabling/ignoring this warning are not harmed in any way, although it is not recommended. This should encourage, rather than force, extension writers to update their code.

All battery-included extensions (Itcl, tdbc*, thread) are already converted to use Tcl_Size everywhere necessary.


When TIPs 481 and 616 were implemented/proposed, the Tcl_Size type didn't exist yet. The main goal for Tcl 9.0 was - at that time - to keep everything source-compatible as much as possible. That means that extensions using Tcl_GetStringFromObj(obj, &len)

Currently, extension-writers are starting to make their extensions Tcl-9-ready, which means that they are able to use string/list lengths > 2^31. That means the int len variable has to be replaced by a Tcl_Size len variable. But Tcl doesn't provide any help finding those instances. This TIP makes it much easier for extension-writers to find those places in their code, without any functional disadvantage: If the compiler warning is ignored, still the extension will work as expected as long as no strings/lists exceed the 2^31 limit.


Implementation is in Tcl branch "tip-664".

It only removes a lot of type-casts from tclDecls.h, which were originally put there just to prevent this compiler-warning. There is no change in implementation of any functions, so the only effect of this proposal is to enable compiler-warnings for this specific case, nothing else.


If an extension which is originally written for Tcl 8.6 is built with Tcl 9 and the compiler warnings are ignored by the developer, and no strings or lists are used larger than 2^31 in size, everything will function as before. Any use of strings or lists larger then that in the extension will result in an error-message, wherever possible. Only Tcl_GetStringFromObj() and Tcl_GetUnicodeFromObj() are not capable of returning an error-message, they will panic (as they do now).


This document has been placed in the public domain.