Menu

#483 [TIP#275] unsigned field flag for binary scan

TIP Implementation
closed-accepted
5
2006-10-06
2006-09-26
Pat Thoyts
No

This patch adds a format field flag to mark fields to
be read as unsigned. The flag must come between the
type identifier and the count (if any). For instance
% binary scan \xff\xff cuc a b; list $a $b
255 1-

Discussion

  • Donal K. Fellows

    • labels: 310751 --> 12. ByteArray Object
     
  • Pat Thoyts

    Pat Thoyts - 2006-09-28
    • assigned_to: dkf --> patthoyts
     
  • Pat Thoyts

    Pat Thoyts - 2006-09-28

    Logged In: YES
    user_id=202636

    Ensure unsigned results from 32bit longs and wide values.
    Avoid caching unsigned longs to avoid confusion with signed
    values from the cached Tcl_Objs. Added tests.

     
  • Pat Thoyts

    Pat Thoyts - 2006-09-28

    context diff, tclBinary.c and binary.test (unix eols)

     
  • Andreas Kupries

    Andreas Kupries - 2006-09-28
    • summary: unsigned field flag for binary scan --> [TIP#275] unsigned field flag for binary scan
     
  • Donal K. Fellows

    • milestone: --> TIP Implementation
     
  • Don Porter

    Don Porter - 2006-10-02

    Logged In: YES
    user_id=80530

    Failures on LP64 system:

    ==== binary-29.10 Tcl_BinaryObjCmd: scan FAILED
    ==== Contents of test case:

    catch {unset arg1 arg2}
    list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff iui
    arg1 arg2] $arg1 $arg2

    ---- Result was:
    2 -1 -1
    ---- Result should have been (exact matching):
    2 4294967295 -1
    ==== binary-29.10 FAILED

    ==== binary-29.11 Tcl_BinaryObjCmd: scan FAILED
    ==== Contents of test case:

    catch {unset arg1 arg2}
    list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff iiu
    arg1 arg2] $arg1 $arg2

    ---- Result was:
    2 -1 -1
    ---- Result should have been (exact matching):
    2 -1 4294967295
    ==== binary-29.11 FAILED

    ==== binary-29.12 Tcl_BinaryObjCmd: scan FAILED
    ==== Contents of test case:

    catch {unset arg1 arg2}
    list [binary scan \x80\x00\x00\x00\x00\x00\x00\x80 iuiu
    arg1 arg2] $arg1 $arg2

    ---- Result was:
    2 128 -2147483648
    ---- Result should have been (exact matching):
    2 128 2147483648
    ==== binary-29.12 FAILED

    ==== binary-30.10 Tcl_BinaryObjCmd: scan FAILED
    ==== Contents of test case:

    catch {unset arg1 arg2}
    list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff IuI
    arg1 arg2] $arg1 $arg2

    ---- Result was:
    2 -1 -1
    ---- Result should have been (exact matching):
    2 4294967295 -1
    ==== binary-30.10 FAILED

    ==== binary-30.11 Tcl_BinaryObjCmd: scan FAILED
    ==== Contents of test case:

    catch {unset arg1 arg2}
    list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff IIu
    arg1 arg2] $arg1 $arg2

    ---- Result was:
    2 -1 -1
    ---- Result should have been (exact matching):
    2 -1 4294967295
    ==== binary-30.11 FAILED

    ==== binary-30.12 Tcl_BinaryObjCmd: scan FAILED
    ==== Contents of test case:

    catch {unset arg1 arg2}
    list [binary scan \x80\x00\x00\x00\x00\x00\x00\x80 IuIu
    arg1 arg2] $arg1 $arg2

    ---- Result was:
    2 -2147483648 128
    ---- Result should have been (exact matching):
    2 2147483648 128
    ==== binary-30.12 FAILED

    ==== binary-39.9 ScanNumber: no sign extension FAILED
    ==== Contents of test case:

    catch {unset arg1}
    list [binary scan
    \x01\x01\x01\x02\x81\x01\x01\x01\x01\x82\x01\x01\x01\x01\x82\x01\x01\x01\x01\x81
    iu5 arg1] $arg1

    ---- Result was:
    1 {33620225 16843137 16876033 25297153 -2130640639}
    ---- Result should have been (exact matching):
    1 {33620225 16843137 16876033 25297153 2164326657}
    ==== binary-39.9 FAILED

    ==== binary-39.10 ScanNumber: no sign extension FAILED
    ==== Contents of test case:

    catch {unset arg1}
    list [binary scan
    \x01\x01\x01\x02\x81\x01\x01\x01\x01\x82\x01\x01\x01\x01\x82\x01\x01\x01\x01\x81
    Iu5 arg1] $arg1

    ---- Result was:
    1 {16843010 -2130640639 25297153 16876033 16843137}
    ---- Result should have been (exact matching):
    1 {16843010 2164326657 25297153 16876033 16843137}
    ==== binary-39.10 FAILED

     
  • Don Porter

    Don Porter - 2006-10-02
     
  • Don Porter

    Don Porter - 2006-10-02

    Logged In: YES
    user_id=80530

    Revised patch corrects those failures.

     
  • Pat Thoyts

    Pat Thoyts - 2006-10-06
    • status: open --> closed-accepted
     
  • Pat Thoyts

    Pat Thoyts - 2006-10-06

    Logged In: YES
    user_id=202636

    Added dgp's fix and some more tests. Updated the manual page
    and committed.