[Vm-dev] Pharo.image and the VM simulator

Alistair Grant akgrant0710 at gmail.com
Mon Oct 8 06:18:42 UTC 2018

Hi Everyone,

I'm trying to get a Pharo image running in the VM simulator (as part of
working towards writing a FileAttributesPluginSimulator).  My image
happens to use UnixOSProcessPlugin>>getCurrentWorkingDirectory during
startup, and this isn't yet supported in the simulator (there's no
UnixOSProcessPluginSimulator class).

For reference, the method is:

"Answer a string containing the current working directory."

    | cwd cwdString bufferSize incrementBy maxSize buffer |
    <export: true>
    <var: 'buffer' type: #'char *'>
    <var: 'cwd' type: #'char *'>

    bufferSize := 100.
    incrementBy := 100.
    maxSize := 5000.

    [cwdString := interpreterProxy
        instantiateClass: interpreterProxy classString
       indexableSize: bufferSize.
    buffer := interpreterProxy arrayValueOf: cwdString.
    cwd := self get: buffer cwd: bufferSize. "getcwd(buffer, bufferSize)"
    (cwd = 0
    and: [bufferSize < maxSize])]
            [bufferSize := bufferSize + incrementBy].
        cwd = 0
                [interpreterProxy primitiveFail]
                [cwdString := self stringFromCString: cwd.
                interpreterProxy pop: 1 thenPush: cwdString]

In the simulator, cwdString and buffer are both SmallIntegers (the
Oop and begining of the string data respectively).

How can I write the contents of the string in to buffer as part of
the #get:cwd: simulation?

For reference I'd also like to have the answer given the oop

>From Clement's answer to Ben in
it seems like it may not be possible.  In that case I'd have to re-write
the primitive to avoid this type of code.

The only other similar code I could find used an uninitialised buffer on
the stack, so had something like:

self cCode: '' inSmalltalk:[ buffer := ByteArray new: 256 ].

and so passed the actual object to the function simulation.


More information about the Vm-dev mailing list