summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Lang <gsview@ghostgum.com.au>2003-04-17 09:24:13 +0000
committerRussell Lang <gsview@ghostgum.com.au>2003-04-17 09:24:13 +0000
commited6b72cbe87a32ed0f6ee87217890a4706ea629e (patch)
tree4202d09b9702898d2dad0ab37249f66a9461652e
parentb63b3d6c29946b9463a5546c0570315487d369e2 (diff)
downloadghostpdl-ed6b72cbe87a32ed0f6ee87217890a4706ea629e.tar.gz
Call the gsapi polling function during the main interpreter loop
timeslice code. This allows a client to abort the interpreter when running "{} loop". Fixes Bug 686810 "CHECK_INTERRUPTS should allow shorter worst-case abort". DETAILS: PostScript which executed an infinite loop could not be stopped by the gsapi client. The time slice code in the main interpreter loop is executed once for every 32767 passes through the interpreter loop. Within the time slice code we now call the polling function and if the return value is non-zero, we set code to gs_error_interrupt to cause the interpreter to exit. This was not a client bug (as far as I know). The original request was from Zoltan Biro. git-svn-id: http://svn.ghostscript.com/ghostscript/trunk@3844 a1074d23-0009-0410-80fe-cf8c14f379e6
-rw-r--r--gs/doc/API.htm3
-rw-r--r--gs/src/gpcheck.h4
-rw-r--r--gs/src/iapi.h3
-rw-r--r--gs/src/int.mak3
-rw-r--r--gs/src/interp.c2
5 files changed, 14 insertions, 1 deletions
diff --git a/gs/doc/API.htm b/gs/doc/API.htm
index 2705fd955..b2363336c 100644
--- a/gs/doc/API.htm
+++ b/gs/doc/API.htm
@@ -305,6 +305,9 @@ This is used for handling window events or cooperative
multitasking. This function will only be called if
the Ghostscript interpreter was compiled with <b><tt>CHECK_INTERRUPTS</tt></b>
as described in <b><tt><a href="../src/gpcheck.h">gpcheck.h</a></tt></b>.
+The polling function should return zero if all is well,
+and return negative if it wants ghostscript to abort.
+The polling function must be fast.
</blockquote>
<h3><a name="set_display_callback"></a><b><tt>gsapi_set_display_callback()</tt></b></h3>
diff --git a/gs/src/gpcheck.h b/gs/src/gpcheck.h
index 66e03228d..ed1fb62cc 100644
--- a/gs/src/gpcheck.h
+++ b/gs/src/gpcheck.h
@@ -45,12 +45,16 @@ int gp_check_interrupts(void);
}
# define return_check_interrupt(code)\
return gs_return_check_interrupt(code)
+# define set_code_on_interrupt(pcode)\
+ if (*(pcode) == 0)\
+ *(pcode) = (gp_check_interrupts() != 0) ? gs_error_interrupt : 0;
#else
# define gp_check_interrupts() 0
# define process_interrupts() DO_NOTHING
# define return_if_interrupt() DO_NOTHING
# define return_check_interrupt(code)\
return (code)
+# define set_code_on_interrupt(pcode) DO_NOTHING
#endif
#endif /* gpcheck_INCLUDED */
diff --git a/gs/src/iapi.h b/gs/src/iapi.h
index 4545d37d7..dc92b8a05 100644
--- a/gs/src/iapi.h
+++ b/gs/src/iapi.h
@@ -174,6 +174,9 @@ gsapi_set_stdio(gs_main_instance *instance,
* multitasking. This function will only be called if
* Ghostscript was compiled with CHECK_INTERRUPTS
* as described in gpcheck.h.
+ * The polling function should return 0 if all is well,
+ * and negative if it wants ghostscript to abort.
+ * The polling function must be fast.
*/
GSDLLEXPORT int GSDLLAPI gsapi_set_poll(gs_main_instance *instance,
int (GSDLLCALLPTR poll_fn)(void *caller_handle));
diff --git a/gs/src/int.mak b/gs/src/int.mak
index b259586df..ebae1e9a5 100644
--- a/gs/src/int.mak
+++ b/gs/src/int.mak
@@ -1968,7 +1968,8 @@ $(PSOBJ)interp.$(OBJ) : $(PSSRC)interp.c $(GH) $(memory__h) $(string__h)\
$(ialloc_h) $(iastruct_h) $(icontext_h) $(icremap_h) $(iddict_h) $(igstate_h)\
$(iname_h) $(inamedef_h) $(interp_h) $(ipacked_h)\
$(isave_h) $(iscan_h) $(istack_h) $(itoken_h) $(iutil_h) $(ivmspace_h)\
- $(oper_h) $(ostack_h) $(sfilter_h) $(store_h) $(stream_h) $(strimpl_h)
+ $(oper_h) $(ostack_h) $(sfilter_h) $(store_h) $(stream_h) $(strimpl_h)\
+ $(gpcheck_h)
$(PSCC) $(PSO_)interp.$(OBJ) $(C_) $(PSSRC)interp.c
$(PSOBJ)ireclaim.$(OBJ) : $(PSSRC)ireclaim.c $(GH)\
diff --git a/gs/src/interp.c b/gs/src/interp.c
index 022683d52..960fdd069 100644
--- a/gs/src/interp.c
+++ b/gs/src/interp.c
@@ -46,6 +46,7 @@
#include "files.h" /* for file_check_read */
#include "oper.h"
#include "store.h"
+#include "gpcheck.h"
/*
* We may or may not optimize the handling of the special fast operators
@@ -1649,6 +1650,7 @@ res:
} else
code = 0;
ticks_left = gs_interp_time_slice_ticks;
+ set_code_on_interrupt(&code);
goto sched;
/* Error exits. */