[Vm-dev] oops to zero

Keith Hodges keith_hodges at yahoo.co.uk
Sat Sep 29 21:36:57 UTC 2007

I was so excited at the prospect of getting a certificate!
> Interpreter>>writeImageFileIO:
> you need to change the
> self putLong: (self startOfMemory) toFile: f.
> to I think
> self putLong: 0 toFile: f.
I had tried that:

but still no joy.

I have included my image writing method below

thanks for the support


writeImageFileIO: imageBytes

    | headerStart headerSize f bytesWritten sCWIfn okToWrite |
    self var: #f type: 'sqImageFile'.
    self var: #headerStart type: 'squeakFileOffsetType '.
    self var: #sCWIfn type: 'void *'.
    "kph mod - to support binary diffs"
    self adjustAllOopsBy: (0 - self startOfMemory).
    "If the security plugin can be loaded, use it to check for write 
    If not, assume it's ok"
    sCWIfn := self ioLoadFunction: 'secCanWriteImage' From: 
    sCWIfn ~= 0 ifTrue:[okToWrite := self cCode: '((sqInt 
        okToWrite ifFalse:[^self primitiveFail]].
    "local constants"
    headerStart := 0. 
    headerSize := 64.  "header size in bytes; do not change!"

    f := self cCode: 'sqImageFileOpen(imageName, "wb")'.
    f = nil ifTrue: [
        "could not open the image file for writing"
        self success: false.
        ^ nil].

    headerStart := self cCode: 
    self cCode: '/* Note: on Unix systems one could put an exec command 
here, padded to 512 bytes */'.
    "position file to start of header"
    self sqImageFile: f Seek: headerStart.

    self putLong: (self imageFormatVersion) toFile: f.
    self putLong: headerSize toFile: f.
    self putLong: imageBytes toFile: f.
    self putLong: 0 "(self startOfMemory) kph mod - for binary diffs" 
toFile: f.
    self putLong: specialObjectsOop toFile: f.
    self putLong: lastHash toFile: f.
    self putLong: (self ioScreenSize) toFile: f.
    self putLong: fullScreenFlag toFile: f.
    self putLong: extraVMMemory toFile: f.
    1 to: 7 do: [:i | self putLong: 0 toFile: f].  "fill remaining 
header words with zeros"
    successFlag ifFalse: [
        "file write or seek failure"
        self cCode: 'sqImageFileClose(f)'.
        ^ nil].

    "position file after the header"
    self sqImageFile: f Seek: headerStart + headerSize.

    "write the image data"
    bytesWritten := self cCode: 'sqImageFileWrite(pointerForOop(memory), 
sizeof(unsigned char), imageBytes, f)'.
    self success: bytesWritten = imageBytes.
    self cCode: 'sqImageFileClose(f)'.

    self adjustAllOopsBy: (self startOfMemory).

More information about the Vm-dev mailing list