Tk Library Source Code

View Ticket
Login
Ticket UUID: 532791
Title: Error unsetting element in linked matrix
Type: Bug Version: None
Submitter: kenj Created on: 2002-03-20 23:04:45
Subsystem: struct :: matrix Assigned To: andreas_kupries
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2002-04-02 02:55:10
Resolution: Fixed Closed By: andreas_kupries
    Closed on: 2002-04-01 19:55:10
Description:
Linked matrix objects don't correctly handle individual array 
elements being unset. Here's a simple test case run 
interactively:

% package require struct
1.2
% 
::struct::matrix test
test
% test add columns 3
% test add row 
{1 2 3}
% test add row {a b c}
% test link arr
% array get arr
0,0 1 
1,0 2 0,1 a 2,0 3 1,1 b 2,1 c
% unset arr(0,0)
% array get arr
1,0 2 
0,1 a 2,0 3 1,1 b 2,1 c
% test get rect 0 0 end end
{1 2 3} {a b 
c}

This bug also renders matrix objects unusable with a TkTable 
widget (by linking to the same global array variable), as TkTable 
makes extensive use of unsetting individual elements of a linked 
array variable in its row and column manipulations.
User Comments: andreas_kupries added on 2002-04-02 02:55:10:
Logged In: YES 
user_id=75003

Patch v2 committed.

andreas_kupries added on 2002-04-02 02:53:53:

File Added - 20402: 532791a.diff

Logged In: YES 
user_id=75003

Extended patch containing additional test.

andreas_kupries added on 2002-04-02 02:48:28:

File Added - 20401: 532791.diff

Logged In: YES 
user_id=75003

Here is the patch.

andreas_kupries added on 2002-03-22 00:23:43:
Logged In: YES 
user_id=75003

Ok, I will work on a patch doing this then.

kenj added on 2002-03-21 13:18:17:
Logged In: YES 
user_id=260635

Yes, I think that would be the correct behavior for it. In the sample 
application in which I discovered the bug, I had a TkTable widget and a 
matrix object both linked to the same global array variable. The goal was 
for changes in one to be propagated to the other. I discovered that when I 
deleted a row or column from the TkTable, the matrix object didn't pick up 
the change, even though the global array variable correctly reflected 
the change.

Doing a bit of tracing and debugging, I noticed that the 
MatTraceIn assumes that if it was triggered because of a "u" operation, 
the entire array variable must have been unset and so it unlinks the matrix 
object from the array. I believe that an appropriate behavior would be to 
check if only a single array element was unset, and if so, set the linked 
cell in the matrix to a null string.

Based on my (inexpert) analysis of 
the TkTable's trace output I generated, I believe that this behavior 
would correctly keep a TkTable widget and matrix object synchronized 
through the global array. (When deleting rows or columns, the TkTable 
widget copies the contents of a cell into an adjacent cell, then deletes 
the contents of the original cell. For the linked array variable, this 
results in a "w" operation to create a new array element reflecting the 
copy to the new cell, and a "u" to delete the original cell's array 
element.)

andreas_kupries added on 2002-03-21 11:54:11:
Logged In: YES 
user_id=75003

I guess the behaviour you ask for is
to set the linked cell in the matrix
to the empty string, right ?

Attachments: