Bug 688903

Summary: gswin32.exe doesn't close
Product: Ghostscript Reporter: leonardo <leonardo>
Component: MS Windows Display DriverAssignee: leonardo <leonardo>
Status: NOTIFIED WORKSFORME    
Severity: normal CC: sags5495
Priority: P4 Keywords: bountiable
Version: master   
Hardware: PC   
OS: Windows XP   
Customer: Word Size: ---
Attachments: Suggested patch for: Enable stdout during shutdown.
Workaroud: Signal stdin EOF, not stdin error, during shutdown.
Suggested patch for: EOF is not Ctrl+Z

Description leonardo 2006-09-21 13:57:12 UTC
Command line :

gswin32.exe

When the window is opened, try to close it by mouse with the system button in 
the upper right corner. It doesn't close. After that nothing can be typed into 
the window, including the 'quit'. Only way to close is to kill with Task 
Manager.
Comment 1 SaGS 2006-09-22 01:12:13 UTC
I have not examined the code, but the patch I suggested for bug 
#688817 "Endless 'interrupt in interrupt' with GSAPI" makes the problem 
dissapear. If the "[X]" button generates an "interrupt" error, it all makes 
sense.
Comment 2 SaGS 2006-10-04 08:39:52 UTC
I looked into the code, and found that when the text window receives a 
WM_CLOSE message, it sets a flag used by the polling function 
src\dwmain.c::poll() to stop the interpreter. What happens next is exactly 
what I described in bug #688817. The error messages are not visible because 
i/o is deliberately suppressed during the closing sequence.
Comment 3 leonardo 2006-10-04 09:06:10 UTC
Hmm, can you make another patch, which allows to veiw error messages in this 
state ?
Comment 4 SaGS 2006-10-05 06:54:27 UTC
Created attachment 2520 [details]
Suggested patch for: Enable stdout during shutdown.

The patch enables writes to the text window even after it receives 
a WM_CLOSE message ([x] button, [Alt+F4], etc). Result shows that 
bug #688817 "Endless 'interrupt in interrupt' with GSAPI" applies, 
and also shows another bug. See screen captures below.

(A) If the interpreter is running, it is stopped purely via the 
polling callback, and we see bug #688817:

    ======================================================================
    AFPL Ghostscript SVN PRE-RELEASE 8.55 (2006-05-20)
    Copyright (C) 2006 artofcode LLC, Benicia, CA.  All rights reserved.
    This software comes with NO WARRANTY: see the file PUBLIC for details.
    GS>{ 1 pop } loop[Enter][Alt+F4]
    Unrecoverable error: interrupt in interrupt
    Operand stack:
	--nostringval--
    Unrecoverable error: interrupt in interrupt
    Operand stack:
	--nostringval--  interrupt  Unrecoverable error: interrupt in interrupt

    Operand stack:
	--nostringval--  interrupt  Unrecoverable error: interrupt in interrupt

    ...
    Operand stack:
	--nostringval--  interrupt  Unrecoverable error: interrupt in interrupt

    Operand stack:
	Unrecoverable error: execstackoverflow in .writecvs
    Operand stack:
	--nostringval--  interrupt  Unrecoverable error: interrupt in
Unrecoverable
    error: execstackoverflow in .writecvs
    Operand stack:
	--nostringval--  interrupt  Unrecoverable error: Unrecoverable error:
execst
    ackoverflow in .writecvs
    Operand stack:
	--nostringval--  interrupt  Unrecoverable error: Unrecoverable error:
execst
    ackoverflow in .writecvs
    ... etc etc etc
    ======================================================================

(B) If the interpreter waits for input, bug #688817 still 
appears, but first the interpreter is struggling to cope with a 
stdin error. It seems this case is not handled gracefully. 
For a workaround, see comment #5 below.

    ======================================================================
    AFPL Ghostscript SVN PRE-RELEASE 8.55 (2006-05-20)
    Copyright (C) 2006 artofcode LLC, Benicia, CA.  All rights reserved.
    This software comes with NO WARRANTY: see the file PUBLIC for details.
    GS>(some text in buffer) ==[Alt+F4]Error: Error: /undefinedGS<6>Error:
Error: /undefined
    GS<12>Error: Error: /undefinedGS<18>Error: Error: /undefinedGS<24>Error:
/ioerro
    r in --.systemvmfile--
    Operand stack:
    Error: /ioerrorGS<30>Error: Error: /undefinedGS<36>Error: Error:
/undefinedGS<42
    >Error: Error: /undefinedGS<48>Error: /ioerror in --.systemvmfile--
    Operand stack:Error: /typecheckGS<56>Error: Error: /undefinedGS<62>Error:
Error:
    /undefinedGS<68>Error: Error: /undefined in --execute--
    Operand stack:
    GS<75>Error: Error: /undefinedGS<81>Error: Error: /undefinedGS<87>Error:
Error:
    ...
    Operand stack:
    GS<545>Error: Error: /undefinedGS<551>Error: Error: /undefinedGS<557>Error:
Erro
    r: /undefinedGS<563>Error: Error: /undefined in --execute--
    Operand stack:GS<570>Error: Error: /undefinedGS<576>Error: Error:
/undefinedGS<5
    82>Error: Unrecoverable error: interrupt in interrupt
    Operand stack:
	--nostringval--  --nostringval--  Unrecoverable error: interrupt in
interrup
    t
    Operand stack:
	--nostringval--  --nostringval--  Unrecoverable error: interrupt in
interrup
    t
    ...
    Operand stack:
	--nostringval--  --nostringval--  Unrecoverable error: interrupt in
interrup
    t
    Operand stack:
	Unrecoverable error: execstackoverflow in execute
    Operand stack:
	--nostringval--  --nostringval--  Unrecoverable error: Unrecoverable
error:
    execstackoverflow in execute
    Operand stack:
	--nostringval--  --nostringval--  Unrecoverable error: Unrecoverable
error:
    execstackoverflow in execute
    ... etc etc etc
    ======================================================================

(C) With attachment #2390 [details] applied (from bug 688817 comment #1), the 
interpreter stops promptly. The problem with handling the stdin error 
still exists.

    ======================================================================
    AFPL Ghostscript SVN PRE-RELEASE 8.55 (2006-05-20)
    Copyright (C) 2006 artofcode LLC, Benicia, CA.  All rights reserved.
    This software comes with NO WARRANTY: see the file PUBLIC for details.
    GS>{ 1 pop } loop[Enter][Alt+F4]
    ======================================================================
    AFPL Ghostscript SVN PRE-RELEASE 8.55 (2006-05-20)
    Copyright (C) 2006 artofcode LLC, Benicia, CA.  All rights reserved.
    This software comes with NO WARRANTY: see the file PUBLIC for details.
    GS>(some text in buffer) ==[Alt+F4]Error:
    ======================================================================
Comment 5 SaGS 2006-10-05 06:55:37 UTC
Created attachment 2521 [details]
Workaroud: Signal stdin EOF, not stdin error, during shutdown.

For gswin32.exe, while the text window is closing the stdin 
callback returns -1 to indicate error. The docs allow this 
explicitely. However, the interpreter does not seem capable to 
deal well with this.

Attached patch does not fix this problem, but it is a workaround 
for it. Instead of signaling a stdin error, it will signal 
stdin EOF, which seems to be handled correctly. (The shutdown 
flag "tw->quitnow" is check during the "text_getch(tw)" call 
from src\dwtext.c::text_read_line().
Comment 6 SaGS 2006-10-05 06:56:20 UTC
Created attachment 2522 [details]
Suggested patch for: EOF is not Ctrl+Z

While we are here: EOF is actually -1 (system dependent?), not 26, 
and I think src\dwtext.c::text_gets() should handle it the same 
as Ctrl+Z. Note: the 'stdin error' above does not come from this.
Comment 7 leonardo 2006-10-05 07:25:56 UTC
I like the suggested patches.
I'll test and commit them in the next week.
Comment 8 leonardo 2007-08-31 03:56:39 UTC
Current HEAD works fine. I'm not sure who fixed it - maybe Windows Update ? The 
patches suggested here were not committed - at least I can't find them in 
http://cvs.ghostscript.com/cgi-
bin/viewcvs.cgi/ghostscript/trunk/gs/src/dwtext.c . Closing with worksforme.