Overview
| Artifact ID: | a88f906fbfceb61a6bd18beef270a7d126edb88c5fc9c37e963d062e3273e54c |
|---|---|
| Ticket: | 2089279fffffffffffffffffffffffffffffffff
StringObj.3 Tcl_ObjPrintf inaccuracies |
| User & Date: | oehhar on 2024-02-01 09:33:26 |
Changes
- icomment:
Here are related messages from the core list for documentation: -------- Weitergeleitete Nachricht -------- Betreff: [TCLCORE] Backport %ll in Tcl_ObjPrintf Datum: Wed, 31 Jan 2024 16:15:45 +0100 Von: Eric Boudaillier <[email protected]> In Tcl 8.6, the documentation says that Tcl_ObjPrintf() works like [format]. However this is not true in 8.6.13. A fix has been done here: https://core.tcl-lang.org/tcl/info/eac13870dca5d4e7 <https://core.tcl-lang.org/tcl/info/eac13870dca5d4e7> for Tcl 9. Is it possible to backport this for the next 8.6.14? I'm trying to use Tcl_ObjPrintf("%lu") to create Tcl_Obj for unsigned 64 bits. Or is there a better way to do this? What I am really looking for is in this commit https://core.tcl-lang.org/tcl/info/4c2ed52f8f2e2e50, where a single "l" modifier creates a wideInt. OK, I should have looked at existing tickets before the code :-) There is already some (very old) tickets about this: * https://core.tcl-lang.org/tcl/tktview/2089279fffffffffffff this one, still open, already says that [format] use 64 bits for %l modifier, %lld for BigNum. * https://core.tcl-lang.org/tcl/tktview/2b6a4fa5ed30b44364b1 this one is what I observe, saying it is fixed in 8.7. So what about 8.6? * https://core.tcl-lang.org/tcl/tktview/3fbaa4e23bfa711c4340 similar to previous one, also for 8.7 only. Since we'll have no 8.7, could that be backported in 8.6? But I'll probably create a new ticket, it seems that the code in tip is still not aligned with what does [format]: case 1: Tcl_ListObjAppendElement(NULL, list, Tcl_NewWideIntObj( va_arg(argList, long))); break; case 2: Tcl_ListObjAppendElement(NULL, list, Tcl_NewWideIntObj( va_arg(argList, Tcl_WideInt))); break; -------- Weitergeleitete Nachricht -------- Datum: Wed, 31 Jan 2024 17:34:43 +0100 Von: Jan Nijtmans <[email protected]> Op wo 31 jan 2024 om 17:19 schreef Eric Boudaillier: > Since we'll have no 8.7, could that be backported in 8.6? It's a little bit tricky, but possible. If we implement "ll", it's tempting to use TCL_LL_MODIFIER, which results in "I64" on Win64. So we should implement that too. And because "format" uses the same functionality .... I think this should do it: <https://core.tcl-lang.org/tcl/info/c6795d89c8467204> -------- Weitergeleitete Nachricht -------- Datum: Wed, 31 Jan 2024 18:01:26 +0100 Von: Eric Boudaillier <[email protected]> I'm not sure... What you wrote for case 2 (%ll) is what I'd like for case 1 (%l), and what does [format]. case 2 needs to pass a bignum (same as case 3 for 'L' modifier - not in tip? where did I see that...). I32 and I64 are not specified in 8.6 format.n, not needed in my mind, I don't want to change the doc, just fix the code. It's not clear now if Tcl_ObjPrintf() is supposed to do what print() does or what [format] does, but the doc says [format]. I have used it because printf() was different across windows/linux/32/64 bits. -------- Weitergeleitete Nachricht -------- Datum: Wed, 31 Jan 2024 21:33:33 +0100 Von: Jan Nijtmans <[email protected]> Op wo 31 jan 2024 om 18:01 schreef Eric Boudaillier: > > I'm not sure... > What you wrote for case 2 (%ll) is what I'd like for case 1 (%l), and what does [format]. I'm sure. Tcl_WideInt stands for "long" on 64-bit platforms, "long long" on 32-bit platforms and __int64 on Windows. So, the portable way to format a Tcl_WideInt is using TCL_LL_MODIFIER, which is "l" on most platforms (like you), "ll" on 32-bit platforms and "I64" on Windows. If we want to support Tcl_WideInt in a portable way, we need to implement all of them, even though _you_ probably only need "l". case 1 is for "long" ("l"), case 2 is for "long long" ("ll") -------- Weitergeleitete Nachricht -------- Datum: Wed, 31 Jan 2024 20:39:47 +0000 Von: Donal Fellows <[email protected]> Jan Nijtmans <[email protected]> wrote: > I'm sure. Tcl_WideInt stands for "long" on 64-bit platforms, "long long" on 32- > bit platforms and __int64 on Windows. So, the portable way to format a > Tcl_WideInt is using TCL_LL_MODIFIER, which is "l" on most platforms (like > you), "ll" on 32-bit platforms and "I64" on Windows. If we want to support > Tcl_WideInt in a portable way, we need to implement all of them, even though > _you_ probably only need "l". It's a shame that it's currently the thing that's making Tcl builds noisy, with messages like this coming up rather often: .../tcl/generic/tclHash.c:636:21: warning: format '%u' expects argument of type unsigned int', but argument 5 has type 'size_t' {aka 'long long unsigned int'} [-Wformat=] 636 | snprintf(p, 60, "number of buckets with %d or more entries: %" TCL_Z_MODIFIER "u\n", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 637 | NUM_COUNTERS, overflow); | ~~~~~~~~ | | | size_t {aka long long unsigned int} .../tcl/generic/tclHash.c:636:84: note: format string is defined here 636 | snprintf(p, 60, "number of buckets with %d or more entries: %" TCL_Z_MODIFIER "u\n", | ~~~~~~~~~~~~~~~~~~~^ | | | unsigned int | %" TCL_Z_MODIFIER "llu I'm not picking on that specific site at all; it's just the first one I found in my local build logs. -------- Weitergeleitete Nachricht -------- Datum: Thu, 1 Feb 2024 05:55:22 +0100 Von: Eric Boudaillier <[email protected]> OK, let's separate the problems. I solved my unsigned 64 bits generation by using Tcl_Format("%lu"), which works as expected: %l for wide ints, for 32 bits / 64 bits builds. I wrongly used Tcl_ObjPrintf(), because there is a discrepancy on how it manages %l / %ll, even in Tcl 9.0b1 (windows 32 bits builds): Tcl_ObjPrintf("%lu") truncates to 32 bits, Tcl_Format("%lu").always formats 64 bits. The discrepancy between Tcl_ObjPrintf() and Tcl_Format() should be noted in the doc, and %l / %ll specified. Even the implementation is misleading, both are using Tcl_AppendFormatToObj().
- login: "oehhar"
- mimetype: "text/plain"
- username: "oehhar"