<p>Hi Vincent,</p>
<p>This still isn't working because<br>
sqFileStdioHandlesIntoFile_WithHandle_IsWritable() doesn't take SQFile<br>
by reference (arrays are just pointers to the first element in C, which<br>
is why the array of SQFile structures doesn't need to be passed by<br>
reference explicitly):</p>
<pre><code>sqFileStdioHandlesIntoFile_WithHandle_IsWritable(SQFile *file, HANDLE handle, int isWritable) {
        file->sessionID = thisSession;
        file->file = handle;
        file->writable = isWritable;
        file->lastOp = 0; /* unused on win32 */
        file->isStdioStream = isFileHandleATTY(handle);
        AddHandleToTable(win32Files, handle);
}


sqFileStdioHandlesInto(SQFile files[3])
{
        sqFileStdioHandlesIntoFile_WithHandle_IsWritable(&files[0], GetStdHandle(STD_INPUT_HANDLE), false);
        sqFileStdioHandlesIntoFile_WithHandle_IsWritable(&files[1], GetStdHandle(STD_OUTPUT_HANDLE), true);
        sqFileStdioHandlesIntoFile_WithHandle_IsWritable(&files[2], GetStdHandle(STD_ERROR_HANDLE), true);

        return 7;
}
</code></pre>
<p>I think that gets the basic changes you wanted done.  But it still<br>
leaves stdio in cygwin terminals broken.  After a bit more reading it<br>
looks like cygwin terminals and Windows ReadConsole() and WriteConsole()<br>
functions are fundamentally incompatible.</p>
<p>I don't understand what ReadConsole() and WriteConsole() provide in<br>
terms of benefits over FILE* streams, so I can't really comment on<br>
the cost of replacing them.</p>
<p>Eliot, what are your thoughts about moving the stdio functionlity to use<br>
FILE* streams instead of HANDLE streams?</p>
<p>I think that would allow the VM to use fread(), feof(), and fwrite() to<br>
read and write stdio to terminals (cygwin), consoles (windows), pipes<br>
and regular files.</p>
<p>Another option may be to leave the existing console functionality and<br>
use the connectToFileDescriptor() routine to separately open the stdio<br>
streams as FILE* streams.  The image can then decide how it wants to<br>
interact with stdio.</p>
<p>(we should probably move this conversation to vm-dev and out of this<br>
particular PR)</p>
<p>Thanks,<br>
Alistair</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/254#issuecomment-384620453">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AhLyWxqXqMTUyyVz7vXD6WmnkcJAHHyFks5tsbtRgaJpZM4Tg0qx">mute the thread</a>.<img src="https://github.com/notifications/beacon/AhLyW-ZHtJ4Pev8_CRSwTmprFl3DiOjcks5tsbtRgaJpZM4Tg0qx.gif" height="1" width="1" alt="" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/254#issuecomment-384620453"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@akgrant43 in #254: Hi Vincent,\r\n\r\nThis still isn't working because \r\nsqFileStdioHandlesIntoFile_WithHandle_IsWritable() doesn't take SQFile \r\nby reference (arrays are just pointers to the first element in C, which \r\nis why the array of SQFile structures doesn't need to be passed by \r\nreference explicitly):\r\n\r\n\r\n```\r\nsqFileStdioHandlesIntoFile_WithHandle_IsWritable(SQFile *file, HANDLE handle, int isWritable) {\r\n        file-\u003esessionID = thisSession;\r\n        file-\u003efile = handle;\r\n        file-\u003ewritable = isWritable;\r\n        file-\u003elastOp = 0; /* unused on win32 */\r\n        file-\u003eisStdioStream = isFileHandleATTY(handle);\r\n        AddHandleToTable(win32Files, handle);\r\n}\r\n\r\n\r\nsqFileStdioHandlesInto(SQFile files[3])\r\n{\r\n        sqFileStdioHandlesIntoFile_WithHandle_IsWritable(\u0026files[0], GetStdHandle(STD_INPUT_HANDLE), false);\r\n        sqFileStdioHandlesIntoFile_WithHandle_IsWritable(\u0026files[1], GetStdHandle(STD_OUTPUT_HANDLE), true);\r\n        sqFileStdioHandlesIntoFile_WithHandle_IsWritable(\u0026files[2], GetStdHandle(STD_ERROR_HANDLE), true);\r\n\r\n        return 7;\r\n}\r\n```\r\n\r\n\r\nI think that gets the basic changes you wanted done.  But it still \r\nleaves stdio in cygwin terminals broken.  After a bit more reading it \r\nlooks like cygwin terminals and Windows ReadConsole() and WriteConsole() \r\nfunctions are fundamentally incompatible.\r\n\r\nI don't understand what ReadConsole() and WriteConsole() provide in \r\nterms of benefits over FILE* streams, so I can't really comment on \r\nthe cost of replacing them.\r\n\r\nEliot, what are your thoughts about moving the stdio functionlity to use \r\nFILE* streams instead of HANDLE streams?\r\n\r\nI think that would allow the VM to use fread(), feof(), and fwrite() to \r\nread and write stdio to terminals (cygwin), consoles (windows), pipes \r\nand regular files.\r\n\r\nAnother option may be to leave the existing console functionality and \r\nuse the connectToFileDescriptor() routine to separately open the stdio \r\nstreams as FILE* streams.  The image can then decide how it wants to \r\ninteract with stdio.\r\n\r\n(we should probably move this conversation to vm-dev and out of this \r\nparticular PR)\r\n\r\n\r\nThanks,\r\nAlistair\r\n\r\n"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/254#issuecomment-384620453"}}}</script>