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
e9d44ccb
Kaydet (Commit)
e9d44ccb
authored
May 25, 2011
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #12175: FileIO.readall() now only reads the file position and size once.
üst
5eb55599
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
7 deletions
+33
-7
NEWS
Misc/NEWS
+3
-0
fileio.c
Modules/_io/fileio.c
+30
-7
No files found.
Misc/NEWS
Dosyayı görüntüle @
e9d44ccb
...
@@ -161,6 +161,9 @@ Core and Builtins
...
@@ -161,6 +161,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #12175: FileIO.readall() now only reads the file position and size
once.
- Issue #12180: Fixed a few remaining errors in test_packaging when no
- Issue #12180: Fixed a few remaining errors in test_packaging when no
threading.
threading.
...
...
Modules/_io/fileio.c
Dosyayı görüntüle @
e9d44ccb
...
@@ -547,14 +547,14 @@ fileio_readinto(fileio *self, PyObject *args)
...
@@ -547,14 +547,14 @@ fileio_readinto(fileio *self, PyObject *args)
}
}
static
size_t
static
size_t
new_buffersize
(
fileio
*
self
,
size_t
currentsize
)
new_buffersize
(
fileio
*
self
,
size_t
currentsize
#ifdef HAVE_FSTAT
,
off_t
pos
,
off_t
end
#endif
)
{
{
#ifdef HAVE_FSTAT
#ifdef HAVE_FSTAT
off_t
pos
,
end
;
if
(
end
!=
(
off_t
)
-
1
)
{
struct
stat
st
;
if
(
fstat
(
self
->
fd
,
&
st
)
==
0
)
{
end
=
st
.
st_size
;
pos
=
lseek
(
self
->
fd
,
0L
,
SEEK_CUR
);
/* Files claiming a size smaller than SMALLCHUNK may
/* Files claiming a size smaller than SMALLCHUNK may
actually be streaming pseudo-files. In this case, we
actually be streaming pseudo-files. In this case, we
apply the more aggressive algorithm below.
apply the more aggressive algorithm below.
...
@@ -579,9 +579,14 @@ new_buffersize(fileio *self, size_t currentsize)
...
@@ -579,9 +579,14 @@ new_buffersize(fileio *self, size_t currentsize)
static
PyObject
*
static
PyObject
*
fileio_readall
(
fileio
*
self
)
fileio_readall
(
fileio
*
self
)
{
{
#ifdef HAVE_FSTAT
struct
stat
st
;
off_t
pos
,
end
;
#endif
PyObject
*
result
;
PyObject
*
result
;
Py_ssize_t
total
=
0
;
Py_ssize_t
total
=
0
;
int
n
;
int
n
;
size_t
newsize
;
if
(
self
->
fd
<
0
)
if
(
self
->
fd
<
0
)
return
err_closed
();
return
err_closed
();
...
@@ -592,8 +597,23 @@ fileio_readall(fileio *self)
...
@@ -592,8 +597,23 @@ fileio_readall(fileio *self)
if
(
result
==
NULL
)
if
(
result
==
NULL
)
return
NULL
;
return
NULL
;
#ifdef HAVE_FSTAT
#if defined(MS_WIN64) || defined(MS_WINDOWS)
pos
=
_lseeki64
(
self
->
fd
,
0L
,
SEEK_CUR
);
#else
pos
=
lseek
(
self
->
fd
,
0L
,
SEEK_CUR
);
#endif
if
(
fstat
(
self
->
fd
,
&
st
)
==
0
)
end
=
st
.
st_size
;
else
end
=
(
off_t
)
-
1
;
#endif
while
(
1
)
{
while
(
1
)
{
size_t
newsize
=
new_buffersize
(
self
,
total
);
#ifdef HAVE_FSTAT
newsize
=
new_buffersize
(
self
,
total
,
pos
,
end
);
#else
newsize
=
new_buffersize
(
self
,
total
);
#endif
if
(
newsize
>
PY_SSIZE_T_MAX
||
newsize
<=
0
)
{
if
(
newsize
>
PY_SSIZE_T_MAX
||
newsize
<=
0
)
{
PyErr_SetString
(
PyExc_OverflowError
,
PyErr_SetString
(
PyExc_OverflowError
,
"unbounded read returned more bytes "
"unbounded read returned more bytes "
...
@@ -632,6 +652,9 @@ fileio_readall(fileio *self)
...
@@ -632,6 +652,9 @@ fileio_readall(fileio *self)
return
NULL
;
return
NULL
;
}
}
total
+=
n
;
total
+=
n
;
#ifdef HAVE_FSTAT
pos
+=
n
;
#endif
}
}
if
(
PyBytes_GET_SIZE
(
result
)
>
total
)
{
if
(
PyBytes_GET_SIZE
(
result
)
>
total
)
{
...
...
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