Menu

#1835 TkParsePadAmount does not properly handle lists

obsolete: 8.4.9
closed-fixed
5
2005-01-11
2005-01-09
No

TkParsePadAmount manually parses through -padx/-pady
values as a string, and fails to properly handle
whitespace in the process, rather than treating the
argument as a list object. This results in 'bad screen
distance ""' errors if you do e.g.:

pack $w -pady { 5 0 }

...or...

pack $w -pady [list 5 0]

...instead of...

pack $w -pady {5 0}

Attached is a patch to correct the problem versus head,
which should also be safe for 8.4 (TkParsePadAmount is
the same in the two branches).

Discussion

  • Michael Kirkham

    Michael Kirkham - 2005-01-09

    Patch TkParsePadAmount to treat argument as list object

     
  • Michael Kirkham

    Michael Kirkham - 2005-01-09

    Logged In: YES
    user_id=498198

    [list 5 0] may actually be okay, but { 5 0 } definitely is not.

     
  • Chengye Mao

    Chengye Mao - 2005-01-09

    Logged In: YES
    user_id=191079

    The bug was due to fail to handle the leading spaces. To
    avoid converting the input string to a list, I only fix the bug
    by adding code to pass the leading spaces at the beginning.
    The patch works fine but requires converting the input string
    to a list first. It may be less efficient than processing the
    input string directly. However, if this is not the case, then
    the patch should be used.

     
  • Michael Kirkham

    Michael Kirkham - 2005-01-11

    Logged In: YES
    user_id=498198

    I ran some benchmarks with both patches and it seems to
    favor one or the other depending on the form of the pad
    list, but only +/- a microsecond or two per iteration (in
    500k tested). I did use a proc for the packing, which may
    affect the results (I would guess that it might only need
    conversion to a list once in a proc, but I'm not certain).

    I really don't like the way it modifies the string by
    inserting a null byte, though, and a little testing reveals
    a bug in that too!

    % set foo {foo bar}
    foo bar
    % puts $foo
    foo bar
    % button .b
    .b
    % pack .b -padx $foo
    bad pad value "foo": must be positive screen distance
    % puts $foo
    foobar

    The value of foo has magically changed. Oops!

     
  • Donal K. Fellows

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

    Unified diff against 8.4 branch tip

     
  • Donal K. Fellows

    Logged In: YES
    user_id=79902

    Fixed (in 8.4 branch and HEAD) with attached patch. Note
    that this version should be faster than the original one
    because it won't shimmer in at least one common case. It
    also cleans up the location of the code.

     
  • Donal K. Fellows

    • assigned_to: chengyemao --> dkf
    • milestone: --> obsolete: 8.4.9
    • status: closed --> closed-fixed
     
  • Vince Darley

    Vince Darley - 2005-01-11
    • status: closed-fixed --> open
     
  • Vince Darley

    Vince Darley - 2005-01-11

    Logged In: YES
    user_id=32170

    Now the padx/pady code doesn't handle non-lists!!

    % frame .msg
    % pack .msg -padx 3m -pady 3m
    wrong number of parts to pad specification

    This works in tk 8.4.9/8.5a2.

     
  • Donal K. Fellows

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

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

    Logged In: YES
    user_id=79902

    D'oh!