Created on 2009-05-17.08:43:01 by markacy, last changed 2009-05-21.01:26:35 by pjenvey.
|msg4690 (view)||Author: Marek Szczypinski (markacy)||Date: 2009-05-17.08:43:00|
In python 2.5.4: Python 2.5.4 (r254:67916, Apr 24 2009, 09:21:35) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> type(sys.stdin.fileno()) <type 'int'> >>> type(sys.stdout.fileno()) <type 'int'> >>> type(sys.stderr.fileno()) <type 'int'> >>> print sys.stdin.fileno() 0 >>> print sys.stdout.fileno() 1 >>> print sys.stderr.fileno() 2 In Jython trunk: Jython 2.5rc2+ (trunk:6353M, maj 17 2009, 10:37:03) [Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_13 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> type(sys.stdin.fileno()) <type 'org.python.core.io.StreamIO'> >>> type(sys.stdout.fileno()) <type 'org.python.core.io.StreamIO'> >>> type(sys.stderr.fileno()) <type 'org.python.core.io.StreamIO'> >>> print sys.stdin.fileno() org.python.core.io.StreamIO@68fc8e75 >>> print sys.stdout.fileno() org.python.core.io.StreamIO@7afccada >>> print sys.stderr.fileno() org.python.core.io.StreamIO@f8600d6
|msg4692 (view)||Author: Philip Jenvey (pjenvey)||Date: 2009-05-18.04:48:36|
This is intentional as Java doesn't provide us direct access to real int fds Emulating them as ints is possible but doesn't seem worth the effort, at least for the moment. The only real apparent issue is the std descriptors 0/1/2 are sometimes passed around. We've fixed os.isatty to recognize them and handle them appropriately, but some other functions may need similar workarounds Does our current implementation actually break anything? All the related stdlib tests should be passing. If so, please reopen this and provide a specific use case (preferably a test)
|msg4697 (view)||Author: Marek Szczypinski (markacy)||Date: 2009-05-19.09:14:31|
So far it doesn't break anything :-) But I am trying to implement termios module using jna under the hood, and because linux/unix termios functions need an int file descriptor in order to work, I'm stuck. Since fds are not going to be changed, I could use an advice on how can I recognize if given jython fd is generated by sys.stdin.fileno(), etc, so I could call termios methods with appropriate int fd.
|msg4702 (view)||Author: Philip Jenvey (pjenvey)||Date: 2009-05-21.01:26:34|
We can provide access to the real FDs in some environments. They are available via a private field in java.io.FileDescriptor (at least on Sun and IIRC other common JVMs). You can circumvent the private field's protection via reflection unless the java security policy disallows you from doing so. I believe JRuby is doing this If you just need to work on the std streams, couldn't you check if the passed in fd in (fp.fileno() for fp in (sys.stdin, sys.stdout, sys.stderr))? Then map them to 0/1/2 accordingly? At least for the meantime, anyway. As we're not going to change fileno() until after the upcoming 2.5 release
|2009-05-21 01:26:35||pjenvey||set||messages: + msg4702|
|2009-05-19 09:14:32||markacy||set||messages: + msg4697|
|2009-05-18 04:48:38||pjenvey||set||status: open -> closed|
messages: + msg4692
nosy: + pjenvey