Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Make ghostscript signal an /interrupt error when it received a SIGINT

31 views
Skip to first unread message

luser- -droog

unread,
Apr 25, 2013, 7:32:39 PM4/25/13
to
With my Mandelbrot explorer (https://code.google.com/p/xpost/downloads/detail?name=mandel2.ps),
I'd like to be able to interrupt the drawing and return to the menu if
the resolution is too high and it's taking too long.

The PLRM, 1ed, says

> interrupt (error)

> processes an external request to interrupt execution of a PostScript
> program. When the interpreter receives an interrupt request, it executes
> interrupt as if it were an error (i.e. it looks up the name 'interrupt' in
> errordict). Execution of interrupt is sandwiched between execution of
> two objects being interpreted in normal sequence.

> The precise nature of an external interrupt request depends on the en-
> vironment in which the PostScript interpreter is running. In typical
> environments, receipt of a control-C character from a serial communi-
> cation channel gives rise to the interrupt error. This permits a user to
> explicitly abort a PostScript computation. The default definition of
> interrupt executes a stop.


I tried wrapping the drawing functions in a stopped context.

% The Main Loop
% - draw the object according to currrent parameters
% - enter menu loop
% - showpage
{
{
createtable findmaxmin sketch flushpage
} stopped clear
menu
showpage
} loop

But ctrl-C just kills the whole interpreter.

Is there a special mode or flag to enable /interrupt errors with GS?

luser- -droog

unread,
Apr 26, 2013, 6:33:25 PM4/26/13
to
I found something. But I don't know how to make use of it yet.

In psi/interp.c, I found this:

/*
* Invoke the interpreter. If execution completes normally, return 0.
* If an error occurs, the action depends on user_errors as follows:
* user_errors < 0: always return an error code.
* user_errors >= 0: let the PostScript machinery handle all errors.
* (This will eventually result in a fatal error if no 'stopped'
* is active.)
* In case of a quit or a fatal error, also store the exit code.
* Set *perror_object to null or the error object.
*/
static int gs_call_interp(i_ctx_t **, ref *, int, int *, ref *);
int
gs_interpret(i_ctx_t **pi_ctx_p, ref * pref, int user_errors, int *pexit_code,
ref * perror_object)
{

It looks like this `user_errors` parameter controls the behavior I'm talking about (I think). But I haven't traced it back out. I don't know where this function is called.

Helge Blischke

unread,
Apr 30, 2013, 12:35:23 PM4/30/13
to
Looking (not too deeply) into the Ghostscript sources reveals:
it seems that capturing signals like this is mainly restricted to
events associated with the PostScript input (currentfile and friends).
I guess it is not trivial to enhance gs to treat CTRL-C as an interrupt
error without fidling around with the kernel of ghostscript's ps interpreter
ans how it is hooked up to the operating system (to be precise: the OS
abstraction level).

So I'd suggest you file a feature request at bugs.ghostscript.com.

Helge

luser- -droog

unread,
Apr 30, 2013, 11:26:02 PM4/30/13
to
On Tuesday, April 30, 2013 11:35:23 AM UTC-5, Helge Blischke wrote:
> luser- -droog wrote:
>
> > But ctrl-C just kills the whole interpreter.
> >
>
> > Is there a special mode or flag to enable /interrupt errors with GS?
>
>
> Looking (not too deeply) into the Ghostscript sources reveals:
> it seems that capturing signals like this is mainly restricted to
> events associated with the PostScript input (currentfile and friends).
> I guess it is not trivial to enhance gs to treat CTRL-C as an interrupt
> error without fidling around with the kernel of ghostscript's ps interpreter
> ans how it is hooked up to the operating system (to be precise: the OS
> abstraction level).
>
>
> So I'd suggest you file a feature request at bugs.ghostscript.com.
>
>
> Helge

Thanks for the suggestion. Done.
0 new messages