classification
Title: os.fstat and other os.f* methods should use PyObject_AsFileDescriptor
Type: enhancement Stage: patch review
Components: Documentation Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: Neil Muller, benjamin.peterson, christian.heimes, georg.brandl, loewis, pitrou
Priority: normal Keywords: easy, patch

Created on 2008-05-05 11:27 by christian.heimes, last changed 2010-04-02 08:39 by georg.brandl. This issue is now closed.

Files
File name Uploaded Description Edit
posixmodule.diff Neil Muller, 2008-05-10 13:04 PAtch to use PyObject_FileDescriptor in posixmodule.c
test_posix.diff Neil Muller, 2008-05-10 13:55 Add tests for code path added by patch to posixmodule.c
posixmodule_2.patch Neil Muller, 2008-05-11 12:42 Updated patch
posixmodule_comb.patch Neil Muller, 2009-06-05 22:10 Updated patch, combining previous work
posixmodule_comb_py3k.patch Neil Muller, 2009-06-05 22:30 patch for python version 3
posixmodule_comb_py3k.patch Neil Muller, 2010-03-25 15:45 Update py3k patch
posixmodule_comb.patch Neil Muller, 2010-03-25 15:46 Updated patch against trunk
fileno_doc.diff Neil Muller, 2010-03-25 16:23 Mention fileno method when describing file descriptor functions
fileno_doc.diff Neil Muller, 2010-03-25 16:45 Slightly more complete doc patch.
Messages (12)
msg66266 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-05-05 11:27
os.fstat doesn't accept a file object with a fileno() method. This can
easily be fixed by using PyObject_AsFileDescriptor(). Other os.f*
methods may suffer from the same issue.
msg66516 - (view) Author: Neil Muller (Neil Muller) Date: 2008-05-10 13:04
The attached patch changes most functions in posixmodule which require a
filedescriptor to use PyObjectAsDescriptor

There are a few cases, where I'm not certain of the usefulness of
changing the functions to support objects with fileno that I've left
untouched.
These are:
  tcgetpgrp
  tcsetpgrp
  closerange
  dup2
  fdopen
  isatty

The extension to these cases is trivial, though.
msg66522 - (view) Author: Neil Muller (Neil Muller) Date: 2008-05-10 13:55
Patches to test_posix.py to also test using file objects in os.fstat and
such.
msg66624 - (view) Author: Neil Muller (Neil Muller) Date: 2008-05-11 12:42
This patch combines the two earlier patches, and also updates the
docstrings and os.rst to reflect the changed behaviour.
msg87623 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-05-12 13:20
Please produce a single patch comprising all changes. Also, there seem
to be some misindentations in the modified C code.
msg88977 - (view) Author: Neil Muller (Neil Muller) Date: 2009-06-05 22:10
Updated combined patch for python trunk added (indentation issues
hopefully also fixed).
msg88979 - (view) Author: Neil Muller (Neil Muller) Date: 2009-06-05 22:30
Similar patch for the python 3 branch.
msg101709 - (view) Author: Neil Muller (Neil Muller) Date: 2010-03-25 15:45
Poking this issue with updated patches.

Patch against py3k.
msg101713 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-03-25 16:00
Actually, I'm not sure it's a good idea. For example, calling os.ftruncate(fobj) on a py3k file object will bypass the object's internal buffering, ignoring any pending buffered data; the right thing to do is to call fobj.truncate() instead.

It may be better to simply mention in the docs that fileno() can be used on file-like objects to get a file descriptor, if needed.
msg101718 - (view) Author: Neil Muller (Neil Muller) Date: 2010-03-25 16:23
Fair enough.

Possible doc patch attached.
msg101719 - (view) Author: Neil Muller (Neil Muller) Date: 2010-03-25 16:45
More fleshed out doc patch. Mention caveats about using file descriptors directly, add note to ftruncate similar to that for other dangerous methods.
msg102144 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-04-02 08:39
I applied the first part of the patch in r79580.  I don't see that the second part is necessary, the other functions don't have such a note.
History
Date User Action Args
2010-04-02 08:39:40georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg102144
2010-03-25 16:45:46Neil Mullersetfiles: + fileno_doc.diff

messages: + msg101719
2010-03-25 16:27:23pitrousetassignee: georg.brandl

components: + Documentation, - Extension Modules
nosy: + georg.brandl
2010-03-25 16:23:58Neil Mullersetfiles: + fileno_doc.diff

messages: + msg101718
2010-03-25 16:00:28pitrousetnosy: + loewis
messages: + msg101713
2010-03-25 15:46:28Neil Mullersetfiles: + posixmodule_comb.patch
2010-03-25 15:45:18Neil Mullersetfiles: + posixmodule_comb_py3k.patch

messages: + msg101709
2009-06-05 22:30:48Neil Mullersetfiles: + posixmodule_comb_py3k.patch

messages: + msg88979
2009-06-05 22:11:00Neil Mullersetfiles: + posixmodule_comb.patch

messages: + msg88977
2009-05-12 13:20:53pitrousetmessages: + msg87623
2009-05-12 12:50:59ajaksu2setnosy: + pitrou, benjamin.peterson
versions: + Python 2.7, Python 3.2, - Python 2.6, Python 3.0

stage: patch review
2008-05-11 12:42:23Neil Mullersetfiles: + posixmodule_2.patch
messages: + msg66624
2008-05-10 13:55:21Neil Mullersetfiles: + test_posix.diff
messages: + msg66522
2008-05-10 13:04:45Neil Mullersetfiles: + posixmodule.diff
keywords: + patch
messages: + msg66516
nosy: + Neil Muller
2008-05-05 11:27:43christian.heimescreate