Bug 691505

Summary: writeobject writes tokens GS can't read back in
Product: Ghostscript Reporter: Marek Kubica <marek>
Component: PS InterpreterAssignee: Alex Cherepanov <alex>
Status: RESOLVED WORKSFORME    
Severity: normal    
Priority: P4    
Version: 8.71   
Hardware: PC   
OS: Linux   
Customer: Word Size: ---

Description Marek Kubica 2010-07-28 00:09:30 UTC
Hi,

I write some data to a file:

%!PS-3.0
(foo.ps) (w) file [ 1 2 3 ] 42 writeobject

When trying to read back the saved data using

$ gs foo.ps

I get

/syntaxerror in (bin obj seq, type=129, elements=1, size=36, non-zero unused field)

The same happens when trying to use

(foo.ps) (r) file token

Changing the object format does not change anything in this behaviour.

I am trying to embed Ghostscript into my own program, but I need bi-directional communication between the interpreter and my own program, so I thought I can serialize the stack somehow.
Comment 1 Alex Cherepanov 2010-07-28 03:04:51 UTC
Ghostscript works a designed.
PLRM p. 167 says:
  The scanner generates a syntaxerror when it encounters a binary
  object sequence that is malformed in any way. Possible causes include:
  ... an “unused” field that is not 0

PLRM p. 173 says:
  Accompanying the top-level object in the object sequence is a 1-byte
  tag, which is specified as an operand of printobject and writeobject.
  This tag is carried in the second byte of the object, which is
  otherwise unused (see Figure 3.3 on page 164).

I.e. writeobject with a tag other than 0 generates invalid binary object
sequence by Adobe design and Ghostscript implements this. The object can
read back by gs when the tag is 0.