From: <apn...@ya...> - 2024-11-28 03:48:33
|
In Tcl 8.6, if TCL_WIDE_INT_IS_LONG was defined, Tcl_WideInt was typdef'ed as "long". In Tcl 9.0, even if TCL_WIDE_INT_IS_LONG was defined, Tcl_WideInt is typdef'ed as "long long" (see gcc warning below) ../../src/column.c:5682:61: warning: passing argument 3 of '__builtin_saddl_overflow' from incompatible pointer type [-Wincompatible-pointer-types] 5682 | if (addfn_(pbucket[bucket_index], pdata[i], &pbucket[bucket_index])) \ | ^~~~~~~~~~~~~~~~~~~~~~ | | | Tcl_WideInt * {aka long long int *} In my extension's use case, to detect Tcl_WideInt overflow on addition, I was calling one of the gcc builtins '__builtin_saddl_overflow' (note single l indicating long) or '__builtin_saddll_overflow' (note ll indicating long long) depending on whether TCL_WIDE_INT_IS_LONG is defined or not. This generates the above warning because TWIIL is defined but Tcl_WideInt is defined as "long long" and not "long". Could someone clarify - Is this difference between Tcl 8 and 9 intentional? What is the purpose of the TCL_WIDE_INT_IS_LONG #define if not to indicate which Tcl_WideInt typedef was in effect? How else can I detect whether to call the "long" version or "long long" of a runtime function for Tcl_WideInt values? (Platform Ubuntu 20, gcc 9) /Ashok |
From: Jan N. <jan...@gm...> - 2024-11-28 08:41:48
|
> > Could someone clarify - Is this difference between Tcl 8 and 9 > intentional? What is the purpose of the TCL_WIDE_INT_IS_LONG #define if > not to indicate which Tcl_WideInt typedef was in effect? How else can I > detect whether to call the “long” version or “long long” of a runtime > function for Tcl_WideInt values? > Tcl Improvement Proposals: TIP 476: Scan/Printf format consistency <https://core.tcl-lang.org/tips/doc/trunk/tip/476.md> Lessons: - don't use 'long', everything you do with it needs to be tested on both 32 and 64-bit platforms - In Tcl 9 - eventually - all uses of Tcl_WideInt can simply be replaced with 'long long' TCL_WIDE_INT_IS_LONG should be interpreted as TCL_WIDE_INT_HAS_SAME_SIZE_AS_LONG But better, don't use it any more Hope this helps, Jan Nijtmans |
From: <apn...@ya...> - 2024-11-28 10:27:49
|
Thanks for the link, Jan. I haven’t used TCL_WIDE_INT_IS_LONG before but was intending to use it as follows so the appropriate built-in is called in both 8.6 and 9.0 for all platforms. Tcl_WideInt a, b, result; int status; #ifdef TCL_WIDE_INT_IS_LONG status = __builtin_saddl_overflow(a, b, &result); #else status = __builtin_saddll_overflow(a, b, &result); #endif I’ve modified it now to be #if TCL_MAJOR_VERSION < 9 && defined(TCL_WIDE_INT_IS_LONG) Not ideal, suggestions for better approaches appreciated. /Ashok From: Jan Nijtmans <jan...@gm...> Sent: Thursday, November 28, 2024 2:11 PM To: apn...@ya... Cc: tcl...@li... Subject: Re: [TCLCORE] Confusion around TCL_WIDE_INT_IS_LONG in Tcl 8 vs Tcl 9 Could someone clarify - Is this difference between Tcl 8 and 9 intentional? What is the purpose of the TCL_WIDE_INT_IS_LONG #define if not to indicate which Tcl_WideInt typedef was in effect? How else can I detect whether to call the “long” version or “long long” of a runtime function for Tcl_WideInt values? Tcl Improvement Proposals: TIP 476: Scan/Printf format consistency <https://core.tcl-lang.org/tips/doc/trunk/tip/476.md> Lessons: - don't use 'long', everything you do with it needs to be tested on both 32 and 64-bit platforms - In Tcl 9 - eventually - all uses of Tcl_WideInt can simply be replaced with 'long long' TCL_WIDE_INT_IS_LONG should be interpreted as TCL_WIDE_INT_HAS_SAME_SIZE_AS_LONG But better, don't use it any more Hope this helps, Jan Nijtmans |
From: Harald O. <har...@el...> - 2024-11-28 10:40:15
Attachments:
OpenPGP_signature.asc
|
Hi Ashok, that looks interesting. What I read from the TIP, the correct the check would be: #if defined(TCL_WIDE_INT_IS_LONG) && TCL_WIDE_INT_IS_LONG = 1 It would be great to mention this in the migration notes. In Tcl 9: -> Tcl_WideInt is now always "long long". define "TCL_WIDE_INT_IS_LONG" is always 0. Thanks, Harald Am 28.11.2024 um 11:27 schrieb apnmbx-public--- via Tcl-Core: > Thanks for the link, Jan. I haven’t used TCL_WIDE_INT_IS_LONG before but > was intending to use it as follows so the appropriate built-in is called > in both 8.6 and 9.0 for all platforms. > > Tcl_WideInt a, b, result; > > int status; > > #ifdef TCL_WIDE_INT_IS_LONG > > status = __builtin_saddl_overflow(a, b, &result); > > #else > > status = __builtin_saddll_overflow(a, b, &result); > > #endif > > I’ve modified it now to be > > #if TCL_MAJOR_VERSION < 9 && defined(TCL_WIDE_INT_IS_LONG) > > Not ideal, suggestions for better approaches appreciated. > > /Ashok > > *From:*Jan Nijtmans <jan...@gm...> > *Sent:* Thursday, November 28, 2024 2:11 PM > *To:* apn...@ya... > *Cc:* tcl...@li... > *Subject:* Re: [TCLCORE] Confusion around TCL_WIDE_INT_IS_LONG in Tcl 8 > vs Tcl 9 > > Could someone clarify - Is this difference between Tcl 8 and 9 > intentional? What is the purpose of the TCL_WIDE_INT_IS_LONG > #define if not to indicate which Tcl_WideInt typedef was in effect? > How else can I detect whether to call the “long” version or “long > long” of a runtime function for Tcl_WideInt values? > > Tcl Improvement Proposals: TIP 476: Scan/Printf format consistency > <https://core.tcl-lang.org/tips/doc/trunk/tip/476.md> > > Lessons: > > - don't use 'long', everything you do with it needs to be tested on > both 32 and 64-bit platforms > > - In Tcl 9 - eventually - all uses of Tcl_WideInt can simply be > replaced with 'long long' > > TCL_WIDE_INT_IS_LONG should be interpreted as > > TCL_WIDE_INT_HAS_SAME_SIZE_AS_LONG > > But better, don't use it any more > > Hope this helps, > > Jan |
From: Jan N. <jan...@gm...> - 2024-11-28 12:45:14
|
Op do 28 nov 2024 om 11:40 schreef Harald Oehlmann: > Hi Ashok, > that looks interesting. What I read from the TIP, the correct the check > would be: > > #if defined(TCL_WIDE_INT_IS_LONG) && TCL_WIDE_INT_IS_LONG = 1 > No, that's not correct. In Tcl 9.0 (and 8.7 as well) TCL_WIDE_INT_IS_LONG is defined on 64-bit platforms, undefined 32-bit platforms. It still can still be used to test if LONG is 64-bit or 32-bit. That's how it is used inside Tcl Hope this helps, Jan Nijtmans |