[Vm-dev] Stdin/stdout/stderr support
Igor Stasenko
siguctua at gmail.com
Sat Aug 30 13:43:46 UTC 2008
2008/8/30 David T. Lewis <lewis at mail.msen.com>:
>
> On Fri, Aug 29, 2008 at 10:38:18PM +0200, Bert Freudenberg wrote:
>>
>> Am 29.08.2008 um 22:18 schrieb Igor Stasenko:
>> >
>> >i mean that its better to use file handles which is available on all
>> >platforms. and they actually should be open at the process startup
>>
>> Maybe you misunderstood my patch then.
>>
>> If the image tries to open a file named "/dev/stderr" then the VM now
>> actually returns the pre-opened stderr rather than opening the named
>> file. So this is independent of whether a file named "/dev/stderr"
>> actually does exists or not, and it uses the proper file handles.
>
> Yes this will work, but I agree with Igor.
>
> This approach seems too platform-specific to be included in ./Cross.
> It relies on file path name conventions that apply to some (not all)
> Unix systems, and that do not make sense on other platforms. It introduces
> hidden and undocumented behavior (I will not allow you to close the file
> stream if you happen to have referred to it by some particular path name).
>
> Given that folks agree that the concept of stdin/stdout/stderr should
> be supported in Squeak, then there is no reason not to implement it in
> a way that makes sense on all platforms. A set of three optional primitives
> is sufficient, and will provide the same access mechanism regardless of platform.
>
> For example, here is the Windows implementation from OSPP:
>
> /* Answer a two element array containing the sqFile data structure representing
> standard output stream for my OS process, and a flag (true or false) to indicate
> whether the sqFile data structure contains a valid HANDLE. If no standard output
> stream is available for this OS process, the sqFile data structure will contain an
> invalid HANDLE value, which will result in failures on subsequent accesses. */
>
> EXPORT(sqInt) primitiveGetStdOutput(void) {
> sqInt thisSession;
> HANDLE invalid;
> sqInt result;
> HANDLE handle;
> SQFile *file;
> sqInt fileOop;
>
> thisSession = sessionIdentifierFrom(interpreterProxy->stackObjectValue(0));
> invalid = INVALID_HANDLE_VALUE;
> result = interpreterProxy->instantiateClassindexableSize(interpreterProxy->classArray(), 2);
pushRemappableOop(result)
> fileOop = interpreterProxy->instantiateClassindexableSize(interpreterProxy->classByteArray(), fileRecordSize());
result = popRemappableOop();
> file = interpreterProxy->arrayValueOf(fileOop);
> handle = GetStdHandle(STD_OUTPUT_HANDLE);
> if (handle != invalid) {
> interpreterProxy->stObjectatput(result, 2, interpreterProxy->trueObject());
> } else {
> interpreterProxy->stObjectatput(result, 2, interpreterProxy->falseObject());
> }
> file->file = handle;
> file->sessionID = thisSession;
> file->writable = 1;
> file->lastOp = 0;
> interpreterProxy->stObjectatput(result, 1, fileOop);
> interpreterProxy->pop(2);
> interpreterProxy->push(result);
> }
>
>
Good, but maybe it can be more simplier?
Just return a valid file handle on success, or fail primitive if not.
Also, it can be a single prim (primitiveGetStdFileHandle) , with
additional argument indicating which std stream to return e.g.
0 - for stdin
1 - for stdout
2 - for stderr
--
Best regards,
Igor Stasenko AKA sig.
More information about the Vm-dev
mailing list