Menu

#2807 format problem with wide ints

obsolete: 8.4.6
closed-fixed
8
2004-09-10
2004-07-15
No

The format command errors out on %d of a wide int, but
than converts the wide int to int so that subsequent
format works without error.

Place the following in a file "format_bug.tcl":

set x [file size format_bug.tcl]

puts stdout "First format:"
if {[catch {format "%d bytes" $x} res]} {
puts stdout "Error: $res\nTrace back: $errorInfo"
} else {
puts stdout $res
}

puts stdout "Second format:"
if {[catch {format "%d bytes" $x} res]} {
puts stdout "Error: $res\nTrace back: $errorInfo"
} else {
puts stdout $res
}

Running the above code produces:

First format:
Error:
Trace back:
while executing
"format "%d bytes" $x"
Second format:
337 bytes

Discussion

  • Brian Griffin

    Brian Griffin - 2004-07-15

    Logged In: YES
    user_id=22949

    I forgot to mention: This fails on 64-bit Solaris.

     
  • Jeffrey Hobbs

    Jeffrey Hobbs - 2004-07-15

    Logged In: YES
    user_id=72656

    This appears to be related to bug 699060 fixed in the 8.5
    head. It needs to be backported as it clearly breaks on 8.4
    (not all 64-bit plats, but something is wrong).

     
  • Jeffrey Hobbs

    Jeffrey Hobbs - 2004-07-15
    • priority: 5 --> 8
     
  • Don Porter

    Don Porter - 2004-07-15

    Logged In: YES
    user_id=80530

    Report 699060 claims the fix
    went into Tcl 8.4.3 .

     
  • Jeffrey Hobbs

    Jeffrey Hobbs - 2004-07-15

    Logged In: YES
    user_id=72656

    It may, and 702622 appears to be in 8.4 as well, but that
    doesn't discount the fact that %[duxX] have different code
    between 8.4 and the head - there are no ChangeLog docs to
    really indicate why they should be so separate.

     
  • Don Porter

    Don Porter - 2004-07-15

    Logged In: YES
    user_id=80530

    Is this bug present in Tcl 8.4.2 ?

     
  • Jeffrey Hobbs

    Jeffrey Hobbs - 2004-07-16

    Logged In: YES
    user_id=72656

    I found that this:

    - if (wideValue>ULONG_MAX || wideValue<LONG_MIN) {
    + if (wideValue>LONG_MAX || wideValue<LONG_MIN) {

    at line 2209 of tclCmdAH.c:Tcl_FormatObjCmd made it work on
    Solaris-64, which indicates a sign extension bug in the
    compiler.
    Note that the above fix isn't actually correct code for this
    case (although I wonder whether we should be mingling
    unsigned checks for %d as well as the %[uoxX] this case covers).

    Also, a shorter test case is:

    et x [expr {wide(1)}]
    set code [catch {format "%d bytes" $x} res]
    puts "1st format ($code): $res"
    set code [catch {format "%d bytes" $x} res]
    puts "2nd format ($code): $res"

     
  • Brian Griffin

    Brian Griffin - 2004-07-16

    Logged In: YES
    user_id=22949

    Compiler bugs aside, I question why isn't %d automatically promoted to
    %ld if/when Obj is a Wide int? Otherwise, tcl programmers are forced to
    concern themselves with type in a "typeless" language. This doesn't
    seem right to me.

    See, if the wide int was actually indeed larger than LONG_MAX (>32-
    bits) then an error would have been produced legitimately. This means
    at the tcl level one must concern themselves with %d vs %ld. But these
    notions were invented to deal with different types (int vs long). Tcl is
    not supposed to be "typed".

     
  • Donal K. Fellows

    Logged In: YES
    user_id=79902

    There are altogether too many ways for me to list right now
    in which I'm not satisfied with the current handling of
    64-bit values on 32-bit platforms. This is *not* the most
    surprising of them. :^(

     
  • Donal K. Fellows

    • status: open --> closed
     
  • Donal K. Fellows

    • status: closed --> closed-fixed
     
  • Donal K. Fellows

    Logged In: YES
    user_id=79902

    The fix for Bug 868489 seems to have cleared this up as well
    (or at least it all works for me now I've patched that.)

     
MongoDB Logo MongoDB