Tk Source Code

View Ticket
Login
Ticket UUID: 3567786
Title: wm.test segfaults
Type: Bug Version: obsolete: 8.6b3
Submitter: dgp Created on: 2012-09-14 17:55:25
Subsystem: 65. Generic Window Operations Assigned To: dgp
Priority: 9 Immediate Severity:
Status: Closed Last Modified: 2012-10-25 02:08:00
Resolution: Fixed Closed By: dgp
    Closed on: 2012-10-24 19:08:00
Description:
An --enable-aqua build on Snow Leopard
produces segfaults in the tests
wm-manage-* and wm-forget-* in wm.test.
User Comments: dgp added on 2012-10-25 02:08:00:

allow_comments - 1

wordtech added on 2012-09-17 21:02:23:
@ferrieux: The event loop stuff  is the source of several subtle and not-so-subtle bugs. (I don't have the bug numbers here, but if you look at ones assigned to me and/or das, you'll find them.) The basic issue is that when Tk-Aqua was based on the Carbon API, the event loop was easy to integrate because Carbon and Tk have similar models. When das was rewriting this for Cocoa, it turned out to be much more complex because Cocoa has a very different event loop than Tk; it's not just more complex, but, as practice has shown, fragile. I say the problem is insoluable because I am not qualified to dive into those issues, except to hack on workarounds; I'm not sure that a re-write is even feasible given the mismatch between Cocoa and Tk at that low level. In any event, das is really the only one qualified to look at this closely.

dgp added on 2012-09-17 05:37:25:
Another update.  branch now stops all the segfaults and panics
in wm.test.  Whether it introduces any new problems worse than
the ones it solves is something more eyeballs would help to determine.

dgp added on 2012-09-17 05:12:15:
More progress committed to bug-3567786 branch.

dgp added on 2012-09-16 22:41:24:
On that branch, the simplified script to cause a panic is:

toplevel .t
update
wm forget .t
wm manage .t
wm deiconify .t
update
exit

Panics in the last [update].

dgp added on 2012-09-16 22:06:33:
That panic is in the last [update] in the body
of test wm-manage-1.8

dgp added on 2012-09-16 22:03:28:
Branch bug-3567786 has some fixup attempts.  Solves the immediate
problem, but like a bulge in a balloon, they pop up somewher else.

On the branch the test suite looks fine with the exception of the test
wm-manage-1.8.  When I do:

make test TESTFLAGS="-file wm.test -match wm-manage-1.8"

I get a panic.  Stack trace:

#3  0x000000010022efb5 in Tcl_Panic (format=0x1002b7f90 "TkMacOSXSetupDrawingContext(): no context to draw into !") at /Users/dgp/fossil/tcl/generic/tclPanic.c:149
#4  0x00000001001041c8 in TkMacOSXSetupDrawingContext (d=4316589072, gc=0x101142510, useCG=1, dcPtr=0x7fff5fbfe4b0) at /Users/dgp/fossil/tk8.6/unix/../macosx/tkMacOSXDraw.c:1579
#5  0x0000000100102a3e in XFillRectangles (display=0x1010f9a10, d=4316589072, gc=0x101142510, rectangles=0x7fff5fbfe570, n_rectangles=1) at /Users/dgp/fossil/tk8.6/unix/../macosx/tkMacOSXDraw.c:1064
#6  0x000000010012d8c4 in XFillRectangle (display=0x1010f9a10, d=4316589072, gc=0x101142510, x=0, y=0, width=108, height=28) at /Users/dgp/fossil/tk8.6/unix/../xlib/xdraw.c:79
#7  0x0000000100005cc4 in Tk_Fill3DRectangle (tkwin=0x101497010, drawable=4316589072, border=0x101146710, x=0, y=0, width=108, height=28, borderWidth=0, relief=0) at /Users/dgp/fossil/tk8.6/unix/../generic/tk3d.c:986
#8  0x0000000100104d71 in TkpDrawFrame (tkwin=0x101497010, border=0x101146710, highlightWidth=0, borderWidth=0, relief=0) at /Users/dgp/fossil/tk8.6/unix/../macosx/tkMacOSXDraw.c:1991
#9  0x000000010004fed9 in DisplayFrame (clientData=0x10148fa10) at /Users/dgp/fossil/tk8.6/unix/../generic/tkFrame.c:1440
#10 0x0000000100256691 in TclServiceIdle () at /Users/dgp/fossil/tcl/generic/tclTimer.c:751
#11 0x000000010022add2 in Tcl_DoOneEvent (flags=34) at /Users/dgp/fossil/tcl/generic/tclNotify.c:984
#12 0x000000010005067b in MapFrame (clientData=0x10148fa10) at /Users/dgp/fossil/tk8.6/unix/../generic/tkFrame.c:1771
#13 0x0000000100256691 in TclServiceIdle () at /Users/dgp/fossil/tcl/generic/tclTimer.c:751
#14 0x000000010022add2 in Tcl_DoOneEvent (flags=-1) at /Users/dgp/fossil/tcl/generic/tclNotify.c:984
#15 0x0000000100012b29 in Tk_UpdateObjCmd (clientData=0x1010d0410, interp=0x10107e610, objc=1, objv=0x101083958) at /Users/dgp/fossil/tk8.6/unix/../generic/tkCmds.c:1214

dgp added on 2012-09-16 20:32:46:
The casting between a (MacDrawable *) and a (TkWindow *) I 
find very puzzling as well.

dgp added on 2012-09-16 20:01:07:
No segfault with individual test runs.  The recipe is the smallest I could find.

Stack trace:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000117
0x000000010011d20b in TkWmDeadWindow (winPtr=0x101133290) at /Users/dgp/fossil/tk8.6/unix/../macosx/tkMacOSXWm.c:729
729    if (wmPtr->hints.flags & IconPixmapHint) {
(gdb) bt
#0  0x000000010011d20b in TkWmDeadWindow (winPtr=0x101133290) at /Users/dgp/fossil/tk8.6/unix/../macosx/tkMacOSXWm.c:729
#1  0x000000010011efe8 in WmForgetCmd (tkwin=0x103027610, winPtr=0x1033e3010, interp=0x10107e610, objc=3, objv=0x101083958) at /Users/dgp/fossil/tk8.6/unix/../macosx/tkMacOSXWm.c:1653
#2  0x000000010011d8b0 in Tk_WmObjCmd (clientData=0x103027610, interp=0x10107e610, objc=3, objv=0x101083958) at /Users/dgp/fossil/tk8.6/unix/../macosx/tkMacOSXWm.c:926

This is in the first [wm forget .t.t] command in test wm-manage-1.8.

As explored over on the branch bug-3567779, it sure looks like there is
a disagreement about what should be passed to TkWmDeadWindow().
Comparing with TkWmNewWindow, it looks like it makes more sense to
pass in "winPtr" instead of "macWin".  But that leads to other problems.

That aside, the undeniable problem is that the value macWin passed in,
when treated as a (TkWIndow *) has a value in it wmInfoPtr field that
is not NULL and is not a valid pointer.  It doesn't look like anything so 
exotic as a race condition, or a mismatch to system update capabilities.
Rather it's a simple programming failure to keep the data structures in
a state consistent with the assumptions of the program.  Unfortunately,
it really need someone familiar with those assumptions to tackle the
matter with any efficiency.  All I can do is fumble and rage.

ferrieux added on 2012-09-16 16:37:42:
Sometimes leaks between tests are the issue. What happens if you run wm-manage-16, 17, and 18 individually (instead of the three in a row) ?

Re 'repeated rapid-fire calls to "update" causing the crash': update does no more than pointwise journeys into the event loop. So instead of causing the crash, I'd say they mereley reveal an underlying race condition.

Re 'Tk-Cocoa has deep-set issues with notifications and the event loop that are insoluable at this point' : what do you mean by 'at this point' ? Short of an overhaul ? Scary...

wordtech added on 2012-09-16 08:02:12:
Running the wm.test suite itself does cause the segfault, but stepping through the command line by line does not produce any crash. 


%  toplevel .t
.t
% toplevel .t.t
.t.t
% button .t.t.b -text "Manage This"
.t.t.b
% pack .t.t.b
% update
% lappend result [winfo manage .t.t]
wm
% lappend result [winfo toplevel .t.t.b]
wm .t.t
% wm forget .t.t
% wm forget .t.t
% pack .t.t
%  update
% lappend result [winfo manage .t.t]
wm .t.t pack
% lappend result [winfo toplevel .t.t.b]
wm .t.t pack .t
%  wm manage .t.t
%  wm deiconify .t.t
% update
% lappend result [winfo manage .t.t]
wm .t.t pack .t pack
% lappend result [winfo toplevel .t.t.b]
wm .t.t pack .t pack .t.t

I suspect it's the repeated rapid-fire calls to "update" that may be causing the crash. Tk-Cocoa has deep-set issues with notifications and the event loop that are insoluable at this point.

dgp added on 2012-09-15 22:34:17:
first segfault recipe:

make test TESTFLAGS='-file wm.test -match wm-manage-1.[678]'