Issue 2768: os.fstat and other os.f* methods should use PyObject_AsFileDescriptor (original) (raw)

Issue2768

Created on 2008-05-05 11:27 by christian.heimes, last changed 2022-04-11 14:56 by admin. 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
2022-04-11 14:56:34 admin set github: 47017
2010-04-02 08:39:40 georg.brandl set status: open -> closedresolution: fixedmessages: +
2010-03-25 16:45:46 Neil Muller set files: + fileno_doc.diffmessages: +
2010-03-25 16:27:23 pitrou set assignee: georg.brandlcomponents: + Documentation, - Extension Modulesnosy: + georg.brandl
2010-03-25 16:23:58 Neil Muller set files: + fileno_doc.diffmessages: +
2010-03-25 16:00:28 pitrou set nosy: + loewismessages: +
2010-03-25 15:46:28 Neil Muller set files: + posixmodule_comb.patch
2010-03-25 15:45:18 Neil Muller set files: + posixmodule_comb_py3k.patchmessages: +
2009-06-05 22:30:48 Neil Muller set files: + posixmodule_comb_py3k.patchmessages: +
2009-06-05 22:11:00 Neil Muller set files: + posixmodule_comb.patchmessages: +
2009-05-12 13:20:53 pitrou set messages: +
2009-05-12 12:50:59 ajaksu2 set nosy: + pitrou, benjamin.petersonversions: + Python 2.7, Python 3.2, - Python 2.6, Python 3.0stage: patch review
2008-05-11 12:42:23 Neil Muller set files: + posixmodule_2.patchmessages: +
2008-05-10 13:55:21 Neil Muller set files: + test_posix.diffmessages: +
2008-05-10 13:04:45 Neil Muller set files: + posixmodule.diffkeywords: + patchmessages: + nosy: + Neil Muller
2008-05-05 11:27:43 christian.heimes create