[comp.lang.postscript] defeating save/restore

jeffe@eniac.seas.upenn.edu (George Jefferson ) (03/09/91)

help..

I am trying to add a bit of my own postscript code 
to existing code which wraps each page in a save/restore pair

My problem is that I would like to pass a value (integer, string whatever)
from one page to the next..

%this obviously won't do it.
save
.
.
/myx 1 def
.
restore
.
.
save
.
.
myx 10 10 string cvrs show %for example
restore


Is there a way to store a value at some low level which is not
destroyed by restore?

I do not want to try to defeat the restore all together, just pass 1 value.

--
-george            george@mech.seas.upenn.edu

fj@iesd.auc.dk (Frank Jensen) (03/11/91)

In article <38972@netnews.upenn.edu> jeffe@eniac.seas.upenn.edu (George Jefferson ) writes:

   help..

   I am trying to add a bit of my own postscript code 
   to existing code which wraps each page in a save/restore pair

   My problem is that I would like to pass a value (integer, string whatever)
   from one page to the next..

   %this obviously won't do it.
   save
   .
   .
   /myx 1 def
   .
   restore
   .
   .
   save
   .
   .
   myx 10 10 string cvrs show %for example
   restore


   Is there a way to store a value at some low level which is not
   destroyed by restore?

   I do not want to try to defeat the restore all together, just pass 1 value.

Try:	myx	% load the value of `myx' onto the operand stack
	restore
	exch /myx store	% pop the value on top of the operand stack
			% and store it
	save

Just make sure that the value of `myx' is not a composite object where
some of the components were allocated inside the save/restore pair.
In that case you will get an `invalid restore' error.

   --
   -george            george@mech.seas.upenn.edu

--
Frank Jensen,	fj@iesd.auc.dk
Department of Mathematics and Computer Science
Aalborg University
DENMARK

woody@chinacat.Unicom.COM (Woody Baker @ Eagle Signal) (03/11/91)

In article <38972@netnews.upenn.edu>, jeffe@eniac.seas.upenn.edu (George Jefferson ) writes:
> help..
> 
> I am trying to add a bit of my own postscript code 
> 
> 
> Is there a way to store a value at some low level which is not
> destroyed by restore?

I seem to remember that on at least on older version of PS, there was a bug
that allowed you to do this.  I think it was something like if you created
a string, then put a character into it with put, it would survive a
save/restore pair.  I know that Don Lancaster published some thing about it,
and even wrote code to use it, but IT IS A BUG AND IS NOT REPEATABLE
unless you have the buggy interpreter.

i.e.  Not wise to write code for others use that depends on it.

Cheers
Woody

cet1@cl.cam.ac.uk (C.E. Thompson) (03/11/91)

In article <1909@chinacat.Unicom.COM> woody@chinacat.Unicom.COM (Woody Baker @ Eagle Signal) writes:
>
>I seem to remember that on at least on older version of PS, there was a bug
>that allowed you to do this.  I think it was something like if you created
>a string, then put a character into it with put, it would survive a
>save/restore pair.  I know that Don Lancaster published some thing about it,
>and even wrote code to use it, but IT IS A BUG AND IS NOT REPEATABLE
>unless you have the buggy interpreter.
>
>i.e.  Not wise to write code for others use that depends on it.
>
Well, there are much cleaner ways of passing data out through a save/restore
boundary than to use this feature/bug. However, it is morally certain that 
all PostScript interpreters that have ever existed have had the feature/bug.
In fact, in the 2nd edition of the LRM (orange-and-white book) Adobe seem to
have given up claiming that this will ever change. Page 60, section 3.7.3,  
"restore resets the values of all composite objects in local VM, except  
strings, to their state at the time of the save"; and there is no equivalent
to the footnote on p.44 of the old LRM (red book). 

Chris Thompson
JANET:    cet1@uk.ac.cam.phx
Internet: cet1%phx.cam.ac.uk@nsfnet-relay.ac.uk

leland@cs.columbia.edu (Lee Woodbury) (03/12/91)

In article <1909@chinacat.Unicom.COM> woody@chinacat.Unicom.COM (Woody Baker @ Eagle Signal) writes:
>In article <38972@netnews.upenn.edu>, jeffe@eniac.seas.upenn.edu (George Jefferson ) writes:
>> Is there a way to store a value at some low level which is not
>> destroyed by restore?
>I seem to remember that on at least on older version of PS, there was a bug
>that allowed you to do this.  I think it was something like if you created
>a string, then put a character into it with put, it would survive a
>save/restore pair.  I know that Don Lancaster published some thing about it,
>and even wrote code to use it, but IT IS A BUG AND IS NOT REPEATABLE
>unless you have the buggy interpreter.
>
>i.e.  Not wise to write code for others use that depends on it.

Yeah, this is referred to in a footnote on p.43 in Section 3.7, "VIRTUAL
MEMORY," of the Red Book (1st ed):

	In the current PostScript design, restore actually
	does not undo changes made to the elements of strings.
	We consider this behavior to be a defect, and we do
	not recommend that PostScript programs take advantage
	of it.

Leland Woodbury
-- 
INTERNET: leland@cs.columbia.edu
  USENET: ...!columbia!cs.columbia.edu!leland
  BITNET: leland%cs.columbia.edu@cuvmb
  USMAIL: Columbia Univ., 457 CS, 500 W. 120 St., NYC 10027-6699

jtkohl@MIT.EDU (John T Kohl) (03/14/91)

In article <38972@netnews.upenn.edu> jeffe@eniac.seas.upenn.edu (George Jefferson ) writes:

> I am trying to add a bit of my own postscript code 
> to existing code which wraps each page in a save/restore pair

> My problem is that I would like to pass a value (integer, string whatever)
> from one page to the next..

I thought someone would have mentioned it by now, but...

The trick I've used on occasion is to leave a value on the stack.  The
hard part is usually making sure it's in the right place on the stack
and doesn't get wiped by other operators.  This might be helped by using
a mark and counttomark to figure out how far to roll the stack to deposit
the value.

Again, make sure it's not a composite object.  An integer should be no
problem....
--
John Kohl <jtkohl@ATHENA.MIT.EDU> or <jtkohl@MIT.EDU>
Digital Equipment Corporation/Project Athena
(The above opinions are MINE.  Don't put my words in somebody else's mouth!)

jeffe@eniac.seas.upenn.edu (George Jefferson ) (03/14/91)

I basically got two responses.

Many people sugested leaving my value on the stack.
 I suppose my question was not as well posed as it could have been,
 but there is a _lot_ of code between the 'restore' and the place where
 I am allowed to insert my code.  I would have to be very careful with 
 the stack indeed :-)

Several people mentioned the feature/bug of strings being exempt from
 restore - ing.  I am trying to write something which will be very
 portable, but I think I would try this as a last resort.

my own answer was..
 think of a way to avoid the problem..

thanks to all these people
(and probably a few that I missed)

John Kohl
Leland Woodbury
Robert A. Lerche
Dick Dunn
Berthold K.P. Horn
Jacques Kors
Mark Zellers
Frank Jensen
Luigi Perrotta
Chris Thompson
woody


--
-george            george@mech.seas.upenn.edu

fj@iesd.auc.dk (Frank Jensen) (03/15/91)

In article <39120@netnews.upenn.edu> jeffe@eniac.seas.upenn.edu (George Jefferson ) writes:

   ...

   Many people sugested leaving my value on the stack.
    I suppose my question was not as well posed as it could have been,
    but there is a _lot_ of code between the 'restore' and the place where
    I am allowed to insert my code.  I would have to be very careful with 
    the stack indeed :-)

I don't see the problem.  Suppose you have a special dictionary you
use to store your values, call it `mydict'.  Then you can use this
dictionary at will, provided you redefine `restore':

/-restore /restore load def		% save old `restore' operator

/restore
      { mydict {} forall mydict length	% load values onto the stack
	dup 2 mul 2 add -1 roll		% get restore object
	-restore			% do the restore
	mydict begin {def} repeat end	% save the values
      } def


   --
   -george            george@mech.seas.upenn.edu

--
Frank Jensen,   fj@iesd.auc.dk
Department of Mathematics and Computer Science
Aalborg University
DENMARK