[Cuis-dev] Using OSProcess package
Juan Vuletich
juan at cuis.st
Fri Dec 9 10:37:25 PST 2022
Hi Dave,
On 12/9/2022 2:33 PM, David T. Lewis via Cuis-dev wrote:
>
> Hi Juan,
>
> I have not had time to look in detail, but something is badly broken. I see
> "Bad file descriptor" errors in the console, and UnixProcessAccessorTestCase
> crashes the VM.
>
> I'll try to look at it this weekend and give a better answer.
>
> Dave
The problem is that what used to be instances of String, that can be
sent directly to the C world, only needing a zero byte at the end, are
now instances of UnicodeString. UnicodeString is a regular class (with
instance variables) and it can't be sent to the C world in the same way.
Something like UnicodeString that uses encapsulation to protect its
encoding is much better for the Smalltalk world. But unfortunately it
breaks the assumptions of code that deals with the external world.
Apologies for that.
I did some experiments:
If I add #asByteString to these methods like this:
AttachableFileStream >> name: aSymbolOrString attachTo: anIOHandle
writable: readWriteFlag
"Attach to an existing file handle, assumed to have been previously
opened by the underlying operating system."
name _ aSymbolOrString asByteString.
fileID _ anIOHandle.
readWriteFlag ifTrue: [self readWrite] ifFalse: [self readOnly].
self ascii.
self register.
UnixProcess >> forkJob: executableFile arguments: arrayOfStrings
environment: stringDictionary descriptors: arrayOf3Streams
"Call Unix vfork() and execve() to create a child process, and
answer the child process.
Delegate this to the singleton OSProcess>>thisOSProcess."
^ self forkAndExec: executableFile asByteString
arguments: (arrayOfStrings collect: [ :s | s asByteString ])
environment: stringDictionary
descriptors: arrayOf3Streams
and then evaluate:
OSProcessAccessor initialize
AttachableFileStream initialize
OSProcess initialize
ThisOSProcess initialize
then this appears to work on my Mac
OSProcess command: 'ls -l /etc'
However I think it would be much better to send the #bytes of the
UnicodeString. This is a ByteArray that holds the UTF-8 bytes of the
Unicode String. Still, it looks like the Plugin needs stuff to be actual
instances of String, so perhaps a hacked string that actually holds
UTF-8 bytes would be best. I think that's what the Clipboard gives us,
and we need to convert to a proper UnicodeString in the image.
I would suggest an adaptor message like #asZeroTerminatedBytes or
similar, that builds and answers what the plugin needs (avoiding the
explicit concatenation of `Character numericValue: 0`).
I didn't move beyond that experiment, because this is your code, and it
is also for other Smalltalk dialects, and you know better.
Thank you!
--
Juan Vuletich
cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
linkedin.com/in/juan-vuletich-75611b3
twitter.com/JuanVuletich
More information about the Cuis-dev
mailing list