[comp.sys.mac.programmer] Bug in System 6.0, or is it ME?

tomc@mntgfx.mentor.com (Tom Carstensen) (06/23/88)

I've been using MacNosy alot to do debugging, and every
once in a while I set the Trap Checksum/Disipline on
to more thoroughly check my program.

Every since I started using System 6.0, the debugger always
breaks when exiting a Dialog (ie GetNewDialog - ModalDialog -
CloseDialog).  It complains on the entry to TEDispose, ( I
believe its disposing of its TERecord it used for the dialog) and
I look at the TERec, and it looks like it's trying to dispose
of something that already been disposed of (There are FFFD
in a lot of the field, with the debugger puts there after
a DisposHdl() & DisposPtr().  If I tell the debugger to 
continue on, It breaks at DisposHdl, and the hdl is a
bad ptr (bogus).  This is also preventing me from checking
the rest of my program, since it can never get past this point.

Can anyone comment on this problem.  It there actually a hidden
bug in the CloseDialog routine, or is it my problem?

Note: I'm using CloseDialog instead of DisposDialog becuase
I'm allocating my own storage space for dialogs, and I don't
want it "freed".

:------------------------------------------------------------:
: Tom Carstensen         Usenet: tomc@mntgfx.MENTOR.COM      :
: Mentor Graphics                Delphi: CARSTENSEN          :
:                                GEnie:  CARSTENSEN          :
:                                                            :
:         If you are sick and tired, of all your dreadful    :
:         dimensions, let me stretch your TIME!              :
:                                       - Time Operator      :
:------------------------------------------------------------:

tecot@Apple.COM (Ed Tecot) (07/01/88)

In article <1988Jun22.110349.325@mntgfx.mentor.com> tomc@mntgfx.mentor.com (Tom Carstensen) writes:
>I've been using MacNosy alot to do debugging, and every
>once in a while I set the Trap Checksum/Disipline on
>to more thoroughly check my program.
>
>Every since I started using System 6.0, the debugger always
>breaks when exiting a Dialog (ie GetNewDialog - ModalDialog -
>CloseDialog).  It complains on the entry to TEDispose, ( I
>believe its disposing of its TERecord it used for the dialog) and
>I look at the TERec, and it looks like it's trying to dispose
>of something that already been disposed of (There are FFFD
>in a lot of the field, with the debugger puts there after
>a DisposHdl() & DisposPtr().  If I tell the debugger to 
>continue on, It breaks at DisposHdl, and the hdl is a
>bad ptr (bogus).  This is also preventing me from checking
>the rest of my program, since it can never get past this point.

This is a problem with MacNosy discipline.  I spoke with Steve Jasik about it
a few weeks ago.  The problem is that MacNosy's setting the pointer to FFFD
fools the dialog manager into thinking it hasn't yet disposed it.  The code
is something like:

	if (hTE != NIL) TEDispose(hTE);

I recommend not using MacNosy discipline until Steve fixes this.

						_emt

tomc@mntgfx.mentor.com (Tom Carstensen) (07/06/88)

In article <13112@apple.Apple.COM>, tecot@Apple.COM (Ed Tecot) writes:
> In article <1988Jun22.110349.325@mntgfx.mentor.com> tomc@mntgfx.mentor.com (Tom Carstensen) writes:
> >I've been using MacNosy alot to do debugging, and every
> >once in a while I set the Trap Checksum/Disipline on
> >to more thoroughly check my program.
> >
> >Every since I started using System 6.0, the debugger always
> >breaks when exiting a Dialog (ie GetNewDialog - ModalDialog -
> >CloseDialog).  It complains on the entry to TEDispose, ( I
> >believe its disposing of its TERecord it used for the dialog) and
> >I look at the TERec, and it looks like it's trying to dispose
> >of something that already been disposed of (There are FFFD
> >in a lot of the field, with the debugger puts there after
> >a DisposHdl() & DisposPtr().  If I tell the debugger to 
> >continue on, It breaks at DisposHdl, and the hdl is a
> >bad ptr (bogus).  This is also preventing me from checking
> >the rest of my program, since it can never get past this point.
> 
> This is a problem with MacNosy discipline.  I spoke with Steve Jasik about it
> a few weeks ago.  The problem is that MacNosy's setting the pointer to FFFD
> fools the dialog manager into thinking it hasn't yet disposed it.  The code
> is something like:
> 
> 	if (hTE != NIL) TEDispose(hTE);
> 
> I recommend not using MacNosy discipline until Steve fixes this.
> 

I didn't thing you could expect that a Disposed of handle or pointer would
be NULL (or NIL) ???  Should Apples code go something like this:

    TEDispose(hTE);
    hTE = NULL;
    . . .
    . . .
    if (hTE != NULL) TEDispose(hTE);
    
MacNosy's feature of putting FFFD in Disposed of handles has been an
EXTREMELY USEFUL feature for flushing a LOT of bugs in my program.

:------------------------------------------------------------:
: Tom Carstensen         Usenet: tomc@mntgfx.MENTOR.COM      :
: Mentor Graphics                Delphi: CARSTENSEN          :
:                                GEnie:  CARSTENSEN          :
:                                                            :
:         If you are sick and tired, of all your dreadful    :
:         dimensions, let me stretch your TIME!              :
:                                       - Time Operator      :
:------------------------------------------------------------:

tecot@apple.UUCP (07/13/88)

In article <1988Jul5.112217.267@mntgfx.mentor.com> tomc@mntgfx.mentor.com (Tom Carstensen) writes:
>I didn't thing you could expect that a Disposed of handle or pointer would
>be NULL (or NIL) ???  Should Apples code go something like this:
>
>    TEDispose(hTE);
>    hTE = NULL;
>    . . .
>    . . .
>    if (hTE != NULL) TEDispose(hTE);

I tried to simplify my description of the problem.  Having failed that, I will
go into the long-winded approach:

The Dialog Manager uses TextEdit in a wierd way.  The net effect of this was
that instead of calling TEDispose, it called DisposHandle.  The reason this
was done was because the Dialog Manager had already trashed the text handle.
The new TextEdit includes style information and if TEDispose was not called,
it would leave lots of orphans around, wasting memory.  A patch was made to
DisposHandle in the following manner:

if (Dialog Manager is giving me a TextEdit handle) {
	teH->textH = NewHandle(0);
	TEDispose(teH);
} else call real DisposHandle;

MacNosy discipline uses the following patch:
call real DisposHandle;
if (handle == DIRTY) then UserBreak;
else handle = DIRTY;

This breaks when TEDispose reenters DisposHandle.  If Steve had written
reentrant code he wouldn't have had a problem:

if (handle == DIRTY) then UserBreak;
else {
	call real DisposHandle;
	handle = DIRTY;
}

						_emt