Message10437

Author jeff.allen
Recipients amak, jeff.allen, zyasoft
Date 2015-11-07.12:23:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1446898984.83.0.812726396774.issue2320@psf.upfronthosting.co.za>
In-reply-to
Content
Well this is interesting but a bit frustrating.

My original complaint is perhaps slightly off beam: fileno() is not actually -1, since fileno() returns a variety of objects, but never (I think) an int. Rather this change:
https://hg.python.org/jython/rev/e1a246f6a178
ensures that fileno() often returns an object convertible to an int:
https://hg.python.org/jython/rev/e1a246f6a178#l4.49
If that int is not -1 it is used in calls to jnr-posix, otherwise we intend to use the Java FileDescriptor, e.g. here in fstat():
https://hg.python.org/jython/rev/e1a246f6a178#l5.459

That fails in practice on Windows because we do not arrange that the union actually contain the Java FileDescriptor, so jnr-posix is passed null. You'd think some test of fstat would fail, but no, and this is worth investigating separately.

The fstat failure is easily fixed here:
https://hg.python.org/jython/file/159a0fc6d562/src/org/python/modules/posix/PosixModule.java#l225
by adding "case -1: break;". And it works:

>>> f = io.open('x.tmp', 'wb')
>>> fd = f.fileno()
>>> os.fstat(fd)
nt.stat_result(st_mode=33188, st_ino=0, st_dev=0L, st_nlink=1, st_uid=0, st_gid=0, st_size=0, t_atime=1446677504, st_mtime=1446893184, st_ctime=1446677504)

... except that when we try to close the file afterwards, this happens:

>>> f.close()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Jeff\Documents\Eclipse\jython-trunk\dist\Lib\_io.py", line 208, in close
    self.raw.close()
IOError: The handle is invalid

At present, this causes errors (during clean up) in 5 regression tests. I find the cause to be that the call to fstat has closed the underlying Windows file handle. (Calling os.fstat(0) has a really bad effect.) I think this is a bug in jnr-posix, and that it is fixed here:
https://github.com/jnr/jnr-posix/commit/36fd37dcd0e1eb48e28840a17796dd47fb94b9c1

So I will not be adding my "case -1:" just yet. I'll see if we might use later versions of JARs so as to get that jnr-posix fix. If that update causes no other regressions, I'll add my "case -1:" fix separately. And maybe all in time for 2.7.1.

This does not even touch yet the idea I floated that we could keep a correspondence between integer file descriptors and file-like objects. I've spent enough time stepping through the innards of inside jnr-posix, to wonder if that does not give us what we need, without us piling stuff on top. This is not for 2.7.1, however.
History
Date User Action Args
2015-11-07 12:23:04jeff.allensetmessageid: <1446898984.83.0.812726396774.issue2320@psf.upfronthosting.co.za>
2015-11-07 12:23:04jeff.allensetrecipients: + jeff.allen, amak, zyasoft
2015-11-07 12:23:04jeff.allenlinkissue2320 messages
2015-11-07 12:23:03jeff.allencreate