Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
69168354
Kaydet (Commit)
69168354
authored
Haz 21, 2012
tarafından
Hynek Schlawack
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
#10053: Don't close FDs when FileIO.__init__ fails
Loosely based on the work by Hirokazu Yamamoto.
üst
a759d4e9
9ed8b4e4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
6 deletions
+20
-6
test_fileio.py
Lib/test/test_fileio.py
+11
-0
NEWS
Misc/NEWS
+3
-0
fileio.c
Modules/_io/fileio.c
+6
-6
No files found.
Lib/test/test_fileio.py
Dosyayı görüntüle @
69168354
...
...
@@ -404,6 +404,17 @@ class OtherFileTests(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
_FileIO
,
"/some/invalid/name"
,
"rt"
)
self
.
assertEqual
(
w
.
warnings
,
[])
def
testUnclosedFDOnException
(
self
):
class
MyException
(
Exception
):
pass
class
MyFileIO
(
_FileIO
):
def
__setattr__
(
self
,
name
,
value
):
if
name
==
"name"
:
raise
MyException
(
"blocked setting name"
)
return
super
(
MyFileIO
,
self
)
.
__setattr__
(
name
,
value
)
fd
=
os
.
open
(
__file__
,
os
.
O_RDONLY
)
self
.
assertRaises
(
MyException
,
MyFileIO
,
fd
)
os
.
close
(
fd
)
# should not raise OSError(EBADF)
def
test_main
():
# Historically, these tests have been sloppy about removing TESTFN.
...
...
Misc/NEWS
Dosyayı görüntüle @
69168354
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.3.0 Beta 1?
Core and Builtins
-----------------
- Issue #10053: Don'
t
close
FDs
when
FileIO
.
__init__
fails
.
Loosely
based
on
the
work
by
Hirokazu
Yamamoto
.
-
Issue
#
15096
:
Removed
support
for
ur
''
as
the
raw
notation
isn
't
compatible with Python 2.x'
s
raw
unicode
strings
.
...
...
Modules/_io/fileio.c
Dosyayı görüntüle @
69168354
...
...
@@ -227,6 +227,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
int
flags
=
0
;
int
fd
=
-
1
;
int
closefd
=
1
;
int
fd_is_own
=
0
;
assert
(
PyFileIO_Check
(
oself
));
if
(
self
->
fd
>=
0
)
{
...
...
@@ -376,6 +377,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
#endif
self
->
fd
=
open
(
name
,
flags
,
0666
);
Py_END_ALLOW_THREADS
fd_is_own
=
1
;
}
else
{
PyObject
*
fdobj
=
PyObject_CallFunction
(
opener
,
"Oi"
,
nameobj
,
flags
);
...
...
@@ -393,6 +395,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
if
(
self
->
fd
==
-
1
)
{
goto
error
;
}
fd_is_own
=
1
;
}
if
(
self
->
fd
<
0
)
{
...
...
@@ -421,13 +424,8 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
end of file (otherwise, it might be done only on the
first write()). */
PyObject
*
pos
=
portable_lseek
(
self
->
fd
,
NULL
,
2
);
if
(
pos
==
NULL
)
{
if
(
closefd
)
{
close
(
self
->
fd
);
self
->
fd
=
-
1
;
}
if
(
pos
==
NULL
)
goto
error
;
}
Py_DECREF
(
pos
);
}
...
...
@@ -435,6 +433,8 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
error:
ret
=
-
1
;
if
(
!
fd_is_own
)
self
->
fd
=
-
1
;
if
(
self
->
fd
>=
0
)
internal_close
(
self
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment