<div>I think I understand the motivation pretty well; what I&#39;m saying is that I don&#39;t see that this is possible.&nbsp; IronPython has no access to the table being used by the C library to map between Windows HANDLEs and clib file descriptors, so we can&#39;t return a clib-compatible fd.&nbsp; </div>

<div>&nbsp;</div>
<div>Even if we were to return a Windows HANDLE as the fd from IronPython (something which is bad in several ways), this wouldn&#39;t be a value that could just be used directly by the C extension through the C library.<br>
</div>
<div class="gmail_quote">On Mon, Dec 15, 2008 at 10:18 AM, Tom Wright <span dir="ltr">&lt;<a href="mailto:tom.wright@resolversystems.com">tom.wright@resolversystems.com</a>&gt;</span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">Agreed. It is certainly possible with some work to get a file descriptor and pass it to C code.<br><br>This is not the problem, however. Ironclad&#39;s aim (eventually) is to allow *arbitrary* C extensions &nbsp;to work with Ironpython without changing the extensions. Ctypes aim is to allow arbitrary C code to be run by python (possibly in other python libraries which you really don&#39;t want to modify).<br>
<br>In CPython .fileno() is a file descriptor and some modules use this fact (specifically PIL) by passing file descriptors as integers into C code. I do not know how one can make this code work in IronPython unless .fileno() returns a file descriptor.<br>
<br>The game here is not making a particular C library work with IronPython by modifying this library but making as many libraries as possible work without modification. Of course whether this is worthwhile depends on how many libraries rely on this fact.<br>
<br>Sorry - I hope this is a little clearer.<br><br>Tom<br><br><br>Curt Hagenlocher wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="Ih2E3d">Ah, that was the function I was looking for.<br>&nbsp;Sure, the file descriptor exists in the C library under Windows. &nbsp;But the C library is basically doing exactly the same thing as IronPython is; it&#39;s maintaining the file descriptor number as an abstraction on top of the HANDLE that the operating system knows about. &nbsp;So we&#39;re dealing two similar abstractions with entirely unrelated interfaces:<br>
<br>IronPython fd built on top of .NET stream built on top of Windows HANDLE, vs<br>clib fd built directly on top of Windows HANDLE<br>&nbsp;To get from the IronPython fd to a clib fd, you need to translate down the first chain and up the second.<br>
</div>
<div class="Ih2E3d">On Mon, Dec 15, 2008 at 9:37 AM, Tom Wright &lt;<a target="_blank" href="mailto:tom.wright@resolversystems.com">tom.wright@resolversystems.com</a> &lt;mailto:<a target="_blank" href="mailto:tom.wright@resolversystems.com">tom.wright@resolversystems.com</a>&gt;&gt; wrote:<br>
<br>&nbsp; &nbsp;Not so: Though admittedly you have to do quite a bit of work to<br>&nbsp; &nbsp;get the file descriptor into .NET.<br>&nbsp; &nbsp; &nbsp;<a target="_blank" href="http://msdn.microsoft.com/en-us/library/bdts1c9x(VS.71).aspx">http://msdn.microsoft.com/en-us/library/bdts1c9x(VS.71).aspx</a><br>
</div>&nbsp; &nbsp;&lt;<a target="_blank" href="http://msdn.microsoft.com/en-us/library/bdts1c9x%28VS.71%29.aspx">http://msdn.microsoft.com/en-us/library/bdts1c9x%28VS.71%29.aspx</a>&gt; 
<div>
<div></div>
<div class="Wj3C7c"><br><br>&nbsp; &nbsp;To clarify - the C library was written to work with Python (not<br>&nbsp; &nbsp;IronPython) and is not my code.<br><br>&nbsp; &nbsp;Thanks,<br>&nbsp; &nbsp;Tom<br><br>&nbsp; &nbsp;Curt Hagenlocher wrote:<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp;There&#39;s no such thing as a file descriptor number in .NET --<br>
&nbsp; &nbsp; &nbsp; &nbsp;or, for that matter, in Windows itself! :) &nbsp;(The latter is<br>&nbsp; &nbsp; &nbsp; &nbsp;something of a semantic point, of course, as a HANDLE serves<br>&nbsp; &nbsp; &nbsp; &nbsp;something of the same role in Win32 as a file descriptor<br>&nbsp; &nbsp; &nbsp; &nbsp;number does in Unix.)<br>
<br>&nbsp; &nbsp; &nbsp; &nbsp;If you have a FileStream, I think you can turn it into a<br>&nbsp; &nbsp; &nbsp; &nbsp;Windows HANDLE by saying<br>&nbsp; &nbsp; &nbsp; &nbsp;IntPtr handle = stream.SafeFileHandle.DangerousGetHandle();<br>&nbsp; &nbsp; &nbsp; &nbsp;The C library should have a way to convert a HANDLE into a<br>
&nbsp; &nbsp; &nbsp; &nbsp;&quot;file descriptor&quot;, though I wasn&#39;t able to identify the<br>&nbsp; &nbsp; &nbsp; &nbsp;function name with a quick google.<br>&nbsp; &nbsp; &nbsp; &nbsp;I don&#39;t see a way to get handles for stdin, stdout or stderr,<br>&nbsp; &nbsp; &nbsp; &nbsp;though, except that these ought to be easy to translate by hand.<br>
&nbsp; &nbsp; &nbsp; &nbsp; On Mon, Dec 15, 2008 at 8:03 AM, Tom Wright<br>&nbsp; &nbsp; &nbsp; &nbsp;&lt;<a target="_blank" href="mailto:tom.wright@resolversystems.com">tom.wright@resolversystems.com</a><br>&nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a target="_blank" href="mailto:tom.wright@resolversystems.com">tom.wright@resolversystems.com</a>&gt;<br>
&nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a target="_blank" href="mailto:tom.wright@resolversystems.com">tom.wright@resolversystems.com</a><br>&nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a target="_blank" href="mailto:tom.wright@resolversystems.com">tom.wright@resolversystems.com</a>&gt;&gt;&gt; wrote:<br>
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Hi,<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; At the moment file.fileno() returns an arbitrary identifier<br>&nbsp; &nbsp; &nbsp; &nbsp;of a<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; python file rather than a true file descriptor. This is<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; semi-blocking the Ironclad port of PIL.<br>
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Code in PIL gets an integer using fileno() and passes it<br>&nbsp; &nbsp; &nbsp; &nbsp;directly<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; to C code where a call to write() is made. To fix this &nbsp;one<br>&nbsp; &nbsp; &nbsp; &nbsp;would<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; have to patch PIL, IronPython&#39;s file objects or the write<br>
&nbsp; &nbsp; &nbsp; &nbsp;function<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; provided to C code - none of these feel like a good course<br>&nbsp; &nbsp; &nbsp; &nbsp;of action.<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; When ctypes is ported to IronPython this may create similar<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; problems. Ideally fileno() would return a real file descriptor.<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Would this be possible?<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thanks,<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tom<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Resolver Systems<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _______________________________________________<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Users mailing list<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a target="_blank" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
&nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a target="_blank" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a>&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a target="_blank" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
&nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a target="_blank" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a>&gt;&gt;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a target="_blank" href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br><br>&nbsp; &nbsp; &nbsp; &nbsp;------------------------------------------------------------------------<br><br><br><br>&nbsp; &nbsp; &nbsp; &nbsp;_______________________________________________<br>&nbsp; &nbsp; &nbsp; &nbsp;Users mailing list<br>&nbsp; &nbsp; &nbsp; &nbsp;<a target="_blank" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a> &lt;mailto:<a target="_blank" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a>&gt;<br>
&nbsp; &nbsp; &nbsp; &nbsp;<a target="_blank" href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>&nbsp; &nbsp; &nbsp; &nbsp; <br><br>&nbsp; &nbsp;_______________________________________________<br>
&nbsp; &nbsp;Users mailing list<br>&nbsp; &nbsp;<a target="_blank" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a> &lt;mailto:<a target="_blank" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a>&gt;<br>
&nbsp; &nbsp;<a target="_blank" href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br><br><br>------------------------------------------------------------------------<br>
<br>_______________________________________________<br>Users mailing list<br><a target="_blank" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br><a target="_blank" href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
&nbsp;<br></div></div></blockquote>
<div>
<div></div>
<div class="Wj3C7c"><br>_______________________________________________<br>Users mailing list<br><a target="_blank" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br><a target="_blank" href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
</div></div></blockquote></div><br>