homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: io.FileIO('foo', 'rt') prints a RuntimeWarning
Type: resource usage Stage:
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: christian.heimes Nosy List: LambertDW, amaury.forgeotdarc, barry, christian.heimes, vstinner
Priority: release blocker Keywords: needs review, patch

Created on 2008年10月30日 01:02 by amaury.forgeotdarc, last changed 2022年04月11日 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue_4237.patch christian.heimes, 2008年10月30日 14:15
Messages (9)
msg75346 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008年10月30日 01:02
>>> import io
>>> io.FileIO('foo', 'rt')
__main__:1: RuntimeWarning: Trying to close unclosable fd!
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ValueError: invalid mode: rt
The ValueError is expected, but the warning is not.
This happens on file deallocation: the file object is in an invalid 
state.
msg75349 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008年10月30日 01:11
Verified. The issue should be easy to fix.
I wonder why 'rt' is an invalid mode. Python 2.x supports 'rt'.
msg75350 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008年10月30日 01:18
I propose to move self->closefd closer to the top of the function:
Index: Modules/_fileio.c
===================================================================
--- Modules/_fileio.c (Revision 67040)
+++ Modules/_fileio.c (Arbeitskopie)
@@ -181,6 +181,7 @@
 self->readable = self->writable = 0;
 self->seekable = -1;
+ self->closefd = closefd;
 s = mode;
 while (*s) {
 switch (*s++) {
@@ -243,7 +244,6 @@
 if (fd >= 0) {
 self->fd = fd;
- self->closefd = closefd;
 }
 else {
 self->closefd = 1;
msg75351 - (view) Author: David W. Lambert (LambertDW) Date: 2008年10月30日 02:34
>>> print(io.read.__doc__)
 ...
 The default mode is 'rt' (open for reading text).
 ...
msg75357 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008年10月30日 08:46
'rt' is a valid mode for open() or io.open().
But io.FileIO is the unbuffered raw binary file...
Python 2.6 has exactly the same problem and displays the same
RuntimeWarning.
Christian, the change you propose does not fix another case:
>>> io.FileIO([])
msg75370 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008年10月30日 14:15
The new patch fixes the problem and adds a unit test, too.
The bug was caused by a design flaw -- which was partly my fault. Some
elements of the PyFileIOObject struct were initialized in __new__ while
other parts were initialized in __init__. I've moved the initialization
to __new__.
We should add a rule that all struct members must be properly
initialized in __new__. In the past Victor's fuzzying tool has revealed
several crashers related to similar design flaws.
I'm raising the severity of the bug to release blocker because I can't
predict if the problem can be abused to crash the interpreter. We should
also review all __new__ and __init__ methods of objects and extension
modules for similar issues.
msg75375 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008年10月30日 18:05
The patch looks fine to me
msg75382 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008年10月30日 21:26
Fixed in r67051 (py3k), r67052 (trunk)
msg75386 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008年10月30日 22:03
Merged into the release26 branch, too.
History
Date User Action Args
2022年04月11日 14:56:40adminsetgithub: 48487
2008年10月30日 22:03:14christian.heimessetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg75386
2008年10月30日 21:26:55christian.heimessetassignee: barry -> christian.heimes
messages: + msg75382
resolution: accepted
versions: - Python 3.0, Python 2.7
2008年10月30日 18:05:03amaury.forgeotdarcsetmessages: + msg75375
2008年10月30日 14:15:54christian.heimessetfiles: + issue_4237.patch
priority: normal -> release blocker
type: resource usage
assignee: barry
components: + Interpreter Core
versions: + Python 2.7
nosy: + vstinner, barry
messages: + msg75370
2008年10月30日 08:46:14amaury.forgeotdarcsetmessages: + msg75357
2008年10月30日 02:34:22LambertDWsetmessages: + msg75351
2008年10月30日 02:15:41LambertDWsetnosy: + LambertDW
2008年10月30日 01:18:52christian.heimessetkeywords: + patch, needs review
messages: + msg75350
2008年10月30日 01:11:55christian.heimessetpriority: normal
nosy: + christian.heimes
messages: + msg75349
2008年10月30日 01:02:18amaury.forgeotdarccreate

AltStyle によって変換されたページ (->オリジナル) /