[gs-cvs] rev 6960 - in trunk/gs: lib src

lpd at ghostscript.com lpd at ghostscript.com
Fri Aug 4 08:20:43 PDT 2006


Author: lpd
Date: 2006-08-04 08:20:42 -0700 (Fri, 04 Aug 2006)
New Revision: 6960

Modified:
   trunk/gs/lib/gs_btokn.ps
   trunk/gs/lib/gs_dps1.ps
   trunk/gs/lib/gs_dps2.ps
   trunk/gs/lib/gs_init.ps
   trunk/gs/lib/gs_lev2.ps
   trunk/gs/src/zstack.c
Log:
Replaces relevant uses of index by .argindex, and adds a few other checks,
so that pseudo-operators will cause a stackunderflow rather than a
rangecheck when given too few arguments.  Only the following init files have
been modified: gs_{btokn,dps1,dps2,init,lev2}.ps -- many more require
updating.  However, since the only reason for this change is to satisfy the
Genoa test suite, further updates can be done as needed.


Modified: trunk/gs/lib/gs_btokn.ps
===================================================================
--- trunk/gs/lib/gs_btokn.ps	2006-08-04 14:07:13 UTC (rev 6959)
+++ trunk/gs/lib/gs_btokn.ps	2006-08-04 15:20:42 UTC (rev 6960)
@@ -282,6 +282,7 @@
   (%stdout) (w) file 2 index 2 index writeobject pop pop
 } odef
 /writeobject {		% <file> <obj> <tag> writeobject -
+  2 .argindex pop	% check # of args
   3 copy exch
 		% We must allocate the array in local VM
 		% to avoid a possible invalidaccess.
@@ -293,7 +294,7 @@
 /.objectprinttest {		% <obj> .objectprinttest -
 		% This is a pseudo-operator so it will restore the stack
 		% if it gets an error.
-  mark 0 0 3 index .cntobj cleartomark pop
+  mark 0 0 3 .argindex .cntobj cleartomark pop
 } bind odef
 /.printerror {
   $error /binary get .languagelevel 2 ge and {

Modified: trunk/gs/lib/gs_dps1.ps
===================================================================
--- trunk/gs/lib/gs_dps1.ps	2006-08-04 14:07:13 UTC (rev 6959)
+++ trunk/gs/lib/gs_dps1.ps	2006-08-04 15:20:42 UTC (rev 6960)
@@ -68,13 +68,13 @@
 % ------ Fonts ------ %
 
 /selectfont		% <fontname> <size> selectfont -
- { 1 index findfont
+ { 1 .argindex findfont
    1 index dup type /arraytype eq { makefont } { scalefont } ifelse
    setfont pop pop
  } odef
 % undefinefont has to take local/global VM into account.
 /undefinefont		% <fontname> undefinefont -
- { .FontDirectory 1 index .undef
+ { .FontDirectory 1 .argindex .undef
    .currentglobal
     {		% Current mode is global; delete from local directory too.
       //systemdict /LocalFontDirectory .knownget

Modified: trunk/gs/lib/gs_dps2.ps
===================================================================
--- trunk/gs/lib/gs_dps2.ps	2006-08-04 14:07:13 UTC (rev 6959)
+++ trunk/gs/lib/gs_dps2.ps	2006-08-04 15:20:42 UTC (rev 6960)
@@ -113,7 +113,7 @@
 /sethalftone {		% <dict> sethalftone -
 	% We must create the new dictionary in the same VM as the
 	% operand; otherwise, invalidaccess errors may occur.
-  .currentglobal 1 index dup gcheck .setglobal
+  .currentglobal 1 .argindex dup gcheck .setglobal
   dup //.halftonetypes 1 index /HalftoneType get get exec exec
   .setglobal pop
 } odef
@@ -179,7 +179,7 @@
 % behavior of Adobe interpreters.
 /defineuserobject {		% <index> <value> defineuserobject -
   .UserObjects .knownget {
-    length dup 3 index le {
+    length dup 3 .argindex le {
 		% Stack: index value len
       2 index eq { 1 index 2 mul } { 1 index 1 add } ifelse
       .localvmarray .UserObjects get
@@ -189,15 +189,15 @@
       pop
     } ifelse
   } {
-    .UserObjects 3 index 1 add 10 .max .localvmarray put
+    .UserObjects 3 .argindex 1 add 10 .max .localvmarray put
   } ifelse
-  .UserObjects get 2 index 2 index put pop pop
+  .UserObjects get 2 .argindex 2 index put pop pop
 } odef
 /execuserobject {		% <index> execuserobject -
-  .UserObjects get 1 index get exch pop exec
+  .UserObjects get 1 .argindex get exch pop exec
 } odef
 /undefineuserobject {		% <index> undefineuserobject -
-  .UserObjects get 1 index null put pop
+  .UserObjects get 1 .argindex null put pop
 } odef
 
 % ------ Cache control ------ %

Modified: trunk/gs/lib/gs_init.ps
===================================================================
--- trunk/gs/lib/gs_init.ps	2006-08-04 14:07:13 UTC (rev 6959)
+++ trunk/gs/lib/gs_init.ps	2006-08-04 15:20:42 UTC (rev 6960)
@@ -265,6 +265,7 @@
 % Define a special version of def for storing local objects into global
 % dictionaries.  Like .forceput, this exists only during initialization.
 /.forcedef {		% <key> <value> .forcedef -
+  1 .argindex pop	% check # of args
   currentdict 3 1 roll .forceput
 } .bind odef
 
@@ -379,7 +380,7 @@
     .beginpage
 } odef
 /currentmatrix {
-	.currentmatrix 6 index astore pop
+	.currentmatrix 6 .argindex astore pop
 } odef
 % .currentnumcopies is redefined in Level 2.
 /.currentnumcopies { #copies } odef
@@ -446,7 +447,7 @@
 	  } loop
 	} bind def
 /filter
-	{ //filterdict 1 index .knownget
+	{ //filterdict 1 .argindex .knownget
 	   { exch pop exec }
 	   { /filter .systemvar /undefined signalerror }
 	  ifelse
@@ -515,7 +516,7 @@
 } bind def
 % The following is only for compatibility with Adobe interpreters.
 /setdash {
-	1 index length 11 gt { /setdash .systemvar /limitcheck signalerror } if
+	1 .argindex length 11 gt { /setdash .systemvar /limitcheck signalerror } if
 	//setdash
 } odef
 /setdevice
@@ -569,7 +570,7 @@
 % should use .internalstopped to avoid setting newerror et al.
 /.internalstopped { //null 1 .stopped //null ne } bind def
 /store {	% Don't alter operands before completing.
-	1 index where { 2 index 2 index put pop pop } { def } ifelse
+	1 .argindex where { 2 index 2 index put pop pop } { def } ifelse
 } odef
 /.typenames mark .typenames counttomark packedarray exch pop def
 /type {
@@ -582,7 +583,7 @@
 /.wheredict 10 dict def
 /.where /where load def
 /where {
-	//.wheredict 1 index .knownget { exec } { .where } ifelse
+	//.wheredict 1 .argindex .knownget { exec } { .where } ifelse
 } odef
 
 % internaldict is defined in systemdict, but the dictionary is allocated
@@ -1953,10 +1954,6 @@
 } .bind executeonly odef
 
 /deletefile {
-  count 1 lt {
-    //deletefile /stackunderflow signalerror
-  }
-  if
   dup { deletefile } stopped {
     pop //deletefile $error /errorname get signalerror
   } {
@@ -1975,7 +1972,7 @@
 % the file can be deleted later, even if SAFER is set.
 /.tempfile {
   .tempfile	% filename file
-  //SAFETY /tempfiles get 2 index true .forceput
+  //SAFETY /tempfiles get 2 .argindex true .forceput
 } .bind executeonly odef
 
 % If we are running in SAFER mode, lock things down
@@ -2071,7 +2068,8 @@
       { .currentglobal                    % w h bit [] {}...{} multi ncomp glob
         //false .setglobal
         9 dict begin                      % w h bit [] {}...{} multi ncomp glob
-        2 index { 1 index 7 add } { 8 } ifelse
+        2 .argindex { 1 index 7 add } { 8 } ifelse
+	dup .argindex pop		  % check # of arguments
         copy gsave pop                    % preserve the arguments
         { 0 /DeviceGray 0 /DeviceRGB /DeviceCMYK }
         1 index get setcolorspace         % ... glob w h bit [] {}...{} multi ncomp
@@ -2113,7 +2111,8 @@
         image
       }
       { /INTERPOLATE .systemvar
-          { .currentglobal //false .setglobal
+          { 4 .argindex pop		% check # of args
+	    .currentglobal //false .setglobal
             8 dict begin .setglobal
             /ImageType 1 def
             /DataSource 1 index def
@@ -2139,6 +2138,7 @@
     .interpolate imagemask
   } {
     /INTERPOLATE .systemvar {
+      4 .argindex pop			% check # of args
       .currentglobal //false .setglobal
       8 dict begin .setglobal
       /ImageType 1 def

Modified: trunk/gs/lib/gs_lev2.ps
===================================================================
--- trunk/gs/lib/gs_lev2.ps	2006-08-04 14:07:13 UTC (rev 6959)
+++ trunk/gs/lib/gs_lev2.ps	2006-08-04 15:20:42 UTC (rev 6960)
@@ -50,7 +50,7 @@
 } .bind def
 /.checksetparams {		% <newdict> <opname> <checkdict>
 				%   .checksetparams <newdict>
-  2 index {
+  2 .argindex {
 		% Stack: newdict opname checkdict key newvalue
     3 copy 3 1 roll .knownget {
       exec not {
@@ -109,7 +109,7 @@
 systemdict begin
 /psuserparams 48 dict def
 /getuserparam {			% <name> getuserparam <value>
-  /userparams .systemvar 1 index get exch pop
+  /userparams .systemvar 1 .argindex get exch pop
 } odef
 % Fill in userparams (created by the interpreter) with current values.
 mark .currentuserparams
@@ -179,7 +179,7 @@
   /pssystemparams 40 dict readonly def
 } if
 /getsystemparam {		% <name> getsystemparam <value>
-  //pssystemparams 1 index .knownget { exch pop } { .getsystemparam } ifelse
+  //pssystemparams 1 .argindex .knownget { exch pop } { .getsystemparam } ifelse
 } odef
 end
 /currentsystemparams {		% - currentsystemparams <dict>
@@ -188,6 +188,7 @@
 /setsystemparams {		% <dict> setsystemparams -
 	% Check that we will be able to set the PostScript-level
 	% system parameters.
+   dup pop		% check # of args
    /SAFETY .systemvar /safe get {
      % SAFER mode disallows some changes
      [ /GenericResourceDir /FontResourceDir /GenericResourcePathSep ] {
@@ -234,7 +235,7 @@
 
 % Redefine cache parameter setting to interact properly with userparams.
 /setcachelimit {
-  mark /MaxFontItem 2 index .dicttomark setuserparams pop
+  mark /MaxFontItem 2 .argindex .dicttomark setuserparams pop
 } .bind odef
 /setcacheparams {
 	% The MaxFontCache parameter is a system parameter, which we might
@@ -398,7 +399,7 @@
 
 % VMReclaim and VMThreshold are user parameters.
 /setvmthreshold {		% <int> setvmthreshold -
-  mark /VMThreshold 2 index .dicttomark setuserparams pop
+  mark /VMThreshold 2 .argindex .dicttomark setuserparams pop
 } odef
 /vmreclaim {			% <int> vmreclaim -
   dup 0 gt {
@@ -468,7 +469,7 @@
 /.startjob {			% <exit_bool> <password> <finish_proc>
 				%   .startjob <ok_bool>
   vmstatus pop pop serverdict /.jobsavelevel get eq
-  2 index .checkpassword 0 gt and {
+  2 .argindex .checkpassword 0 gt and {
     exch .checkpassword exch count 3 roll count 3 sub { pop } repeat
     cleardictstack
 		% Reset the e-stack back to the 2 .stopped in .runexec,
@@ -660,7 +661,7 @@
 
 % ------ Color spaces ------ %
 
-% Move setcolorsapce, setcolor, and colorspacedict to level2dict
+% Move setcolorspace, setcolor, and colorspacedict to level2dict
 level2dict /setcolorspace .cspace_util 1 index get put
 level2dict /setcolor .cspace_util 1 index get put
 level2dict /colorspacedict .cspace_util 1 index get put
@@ -692,7 +693,7 @@
 /findcolorrendering {		% <intentname> findcolorrendering
 				%   <crdname> <found>
   /ColorRendering /ProcSet findresource
-  1 index dup type /nametype eq { .namestring } if (.) concatstrings
+  1 .argindex dup type /nametype eq { .namestring } if (.) concatstrings
   1 index /GetPageDeviceName get exec dup type /nametype eq { .namestring } if (.) concatstrings
   2 index /GetHalftoneName get exec dup type /nametype eq { .namestring } if
   concatstrings concatstrings
@@ -829,7 +830,7 @@
 def
 
 /makepattern {			% <proto_dict> <matrix> makepattern <pattern>
-  //.patterntypes 2 index /PatternType get get
+  //.patterntypes 2 .argindex /PatternType get get
   .currentglobal false .setglobal exch
 		% Stack: proto matrix global buildproc
   3 index dup length 1 add dict .copydict

Modified: trunk/gs/src/zstack.c
===================================================================
--- trunk/gs/src/zstack.c	2006-08-04 14:07:13 UTC (rev 6959)
+++ trunk/gs/src/zstack.c	2006-08-04 15:20:42 UTC (rev 6960)
@@ -82,6 +82,23 @@
     return 0;
 }
 
+/* <obj_n> ... <obj_0> <n> .argindex <obj_n> ... <obj_0> <obj_n> */
+int
+zargindex(i_ctx_t *i_ctx_p)
+{
+    int code = zindex(i_ctx_p);
+
+    /*
+     * Pseudo-operators should use .argindex rather than index to access
+     * their arguments on the stack, so that if there aren't enough, the
+     * result will be a stackunderflow rather than a rangecheck.  (This is,
+     * in fact, the only reason this operator exists.)
+     */
+    if (code == e_rangecheck && osp->value.intval >= 0)
+	code = gs_note_error(e_stackunderflow);
+    return code;
+}
+
 /* <obj_n-1> ... <obj_0> <n> <i> roll */
 /*      <obj_(i-1)_mod_ n> ... <obj_0> <obj_n-1> ... <obj_i_mod_n> */
 int
@@ -282,6 +299,7 @@
 
 const op_def zstack_op_defs[] =
 {
+    {"2.argindex", zargindex},
     {"0clear", zclear_stack},
     {"0cleartomark", zcleartomark},
     {"0count", zcount},



More information about the gs-cvs mailing list