Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Various improvements |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
7559790b52ea33052bad1bd00d0e3954 |
User & Date: | jan.nijtmans 2018-08-30 21:27:01.446 |
Context
2018-09-02
| ||
13:43 | TIP 478: Accepted 5/0/1 For: DKF, AK, JD, SL, JN Against: none Present: FV check-in: 0660968a3c user: dkf tags: trunk | |
2018-08-30
| ||
21:27 | Various improvements check-in: 7559790b52 user: jan.nijtmans tags: trunk | |
2018-08-26
| ||
14:51 | update index check-in: e2295f72f1 user: dkf tags: trunk | |
Changes
Changes to tip/514.md.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # TIP 514: Platform differences in handling int/wide Author: Jan Nijtmans <[email protected]> State: Draft Type: Project Vote: Pending Created: 20-Aug-2018 Post-History: Keywords: Tcl Tcl-Version: 8.7 ----- # Abstract | | | | < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # TIP 514: Platform differences in handling int/wide Author: Jan Nijtmans <[email protected]> State: Draft Type: Project Vote: Pending Created: 20-Aug-2018 Post-History: Keywords: Tcl Tcl-Version: 8.7 ----- # Abstract This TIP proposes to resolve the platform differences between int/wide/entier math functions and commands like "sting is integer"/"string is wide"/"string is entier". At the script level it should not be relevant whether the platform is 32-bit or 64-bit any more. Most Tcl command already accept unlimited integers, so there are hardly any commands left which need to checked for correct range. A few lacking places (e.g. "binary scan" and "binary format"), are corrected as part of this TIP implementation. # Rationale Some examples: <pre> % string is int -4294967296 |
︙ | ︙ | |||
62 63 64 65 66 67 68 | -9223372036854775808 </pre> So, int() does either 32-bit or 64-bit truncation, but the highest left-over bit becomes the sign-bit. wide() does 64-bit truncation. # Specification | | | | | | | | > > > > > > > > > > > | | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | -9223372036854775808 </pre> So, int() does either 32-bit or 64-bit truncation, but the highest left-over bit becomes the sign-bit. wide() does 64-bit truncation. # Specification * On all platforms, the int() math function is modified not to do truncation any more. int() will thus become synonym for entier(). The wide() and entier() functions will become deprecated in Tcl 9.0, but they will not be removed yet. * On all platforms, "string is integer" will become synonym to "string is entier". So these functions will report true (1) if the number looks like an integer with unlimited range. The "string is wideinteger" and "string is entier" commands will become deprecated in Tcl 9.0, but they will not be removed yet. * The C function Tcl\_GetIntFromObj() is changed to return TCL\_OK if the Tcl_Obj contains a value in the range of -2147483648..4294967295. So, it succeeds if the number fits in either a platform "int", either a platform "unsigned int" type. * The C function Tcl\_GetWideIntFromObj() is changed to return TCL\_OK if the Tcl\_Obj contains a value in the range of -9223372036854775808..9223372036854775807. So, it succeeds if the number fits in a Tcl\_WideInt. * The C function Tcl\_GetLongFromObj() is changed to behave like Tcl\_GetIntFromObj() if sizeof(long) == sizeof(int), and to behave like Tcl\_GetWideIntFromObj() if sizeof(long) == sizeof(Tcl_WideInt) # Implications * "string is integer" can no longer be used to check for a specific range. That doesn't matter any more, because the command argument that was being protected, doesn't throw an exception any more in case of under/overflow since the introduction of bignums. * int() can no longer be used for 32-bit/64-bit (platform-dependant) truncation. * If you still really want to protect some command argument from overflowing, Use Tcl\_GetWideIntFromObj() in this command, and use "string is wide" to check for proper range. But - still better - is use Tcl\_GetWideIntFromObj(), with falling back to Tcl\_GetBignumFromObj() if the range requires it. That's what Tcl itself is doing almost everywhere to prevent under/overflow errors. # Implementation Currently, the proposed implementation is available in the [all-wideint branch] (https://core.tcl.tk/tcl/timeline?r=tip-514). # Copyright This document has been placed in the public domain. |