Benjamin Peterson
eb08a9290f
coalesce GILless sections in new_buffersize ( #5059 )
...
830daae1c8
added some new GIL-releasing to new_buffersize. This is fine, but it's better to avoid reacquiring the GIL for as long as possible. Also, it should use FILE_(BEGIN|END)_ALLOW_THREADS to avoid having the file closed from under it.
2018-01-02 15:52:42 -08:00
Benjamin Peterson
dbf52e02f1
bpo-31530: fix crash when multiple threads iterate over a file, round 2 ( #5060 )
...
Multiple threads iterating over a file can corrupt the file's internal readahead
buffer resulting in crashes. To fix this, cache buffer state thread-locally for
the duration of a file_iternext call and only update the file's internal state
after reading completes.
No attempt is made to define or provide "reasonable" semantics for iterating
over a file on multiple threads. (Non-crashing) races are still
present. Duplicated, corrupt, and missing data will happen.
This was originally fixed by 6401e56717
, which
raised an exception from seek() and next() when concurrent operations were
detected. Alas, this simpler solution breaks legitimate use cases such as
capturing the standard streams when multiple threads are logging.
2018-01-02 09:25:41 -08:00
Nir Soffer
830daae1c8
[2.7] bpo-32186: Release the GIL during fstat and lseek calls ( #4651 )
...
In fileio, there were 3 fstat() calls and one lseek() call that did not
release the GIL during the call. This can cause all threads to hang for
unlimited time when using io.FileIO with inaccessible NFS server.
Same issue seen in fileio exists also in fileobject, fixed in the same
way.
2017-12-07 21:25:39 +01:00
Serhiy Storchaka
6401e56717
[2.7] bpo-31530: Stop crashes when iterating over a file on multiple threads. ( #3672 )
2017-11-10 12:58:55 +02:00
Benjamin Peterson
a72d15c97f
consistently use Py_TYPE, Py_REFCNT, and correct initializer macros ( #3563 )
...
This no-op change makes 2.7 more consistent with 3.x to ease comparison and backports.
2017-09-13 21:20:29 -07:00
Serhiy Storchaka
3c9ce74c21
Issue #23908 : os functions, open() and the io.FileIO constructor now reject
...
unicode paths with embedded null character on Windows instead of silently
truncate them.
2016-07-01 23:34:44 +03:00
Martin Panter
8d496add74
Issue #27171 : Fix typos in documentation, code comments, and tests
2016-06-02 10:35:44 +00:00
Serhiy Storchaka
763a61ca95
Issue #26200 : Added Py_SETREF and replaced Py_XSETREF with Py_SETREF
...
in places where Py_DECREF was used.
2016-04-10 18:05:12 +03:00
Serhiy Storchaka
bc62af1bbe
Issue #22570 : Renamed Py_SETREF to Py_XSETREF.
2016-04-06 09:51:18 +03:00
Serhiy Storchaka
5951f2300f
Issue #20440 : Massive replacing unsafe attribute setting code with special
...
macro Py_SETREF.
2015-12-24 10:35:35 +02:00
Benjamin Peterson
95bc0e4703
use Py_ssize_t for file offset and length computations in iteration ( closes #22526 )
2014-09-30 21:17:15 -04:00
Antoine Pitrou
b0acc1b0a3
Issue #21350 : Fix file.writelines() to accept arbitrary buffer objects, as advertised.
...
Patch by Brian Kearns.
2014-05-08 19:26:04 +02:00
Serhiy Storchaka
78ad6583d6
Circumventing a bug in glibc (issue #17976 ).
...
Patch by Jaakko Moisio.
2013-12-17 17:32:20 +02:00
Serhiy Storchaka
6d562319d2
Issue #17976 : Fixed potential problem with file.write() not detecting IO error
...
by inspecting the return value of fwrite(). Based on patches by Jaakko Moisio
and test by Victor Stinner.
2013-12-17 14:40:06 +02:00
Serhiy Storchaka
74f49ab28b
Issue #15989 : Fix several occurrences of integer overflow
...
when result of PyInt_AsLong() or PyLong_AsLong() narrowed
to int without checks.
This is a backport of changesets 13e2e44db99d and 525407d89277.
2013-01-19 12:55:39 +02:00
Benjamin Peterson
5ca88d2b18
get the core to compile --disable-unicode
2013-01-01 23:04:16 -06:00
Gregory P. Smith
b2ac4d693a
Fixes issue #12268 for file readline, readlines and read() and readinto methods.
...
They no longer lose data when an underlying read system call is interrupted.
IOError is no longer raised due to a read system call returning EINTR from
within these methods.
2012-06-25 20:57:36 -07:00
Antoine Pitrou
02a380105d
Issue #14505 : Fix file descriptor leak when deallocating file objects created with PyFile_FromString().
2012-04-05 14:07:52 +02:00
Ezio Melotti
eace3a7261
#14161 : fix compile error under Windows.
2012-03-12 01:28:45 +02:00
Ezio Melotti
11f8b6872a
#14161 : fix the __repr__ of file objects to escape the file name.
2012-03-12 01:17:02 +02:00
Nadeem Vawda
36248154a9
Issue #13159 : Replace FileIO's quadratic-time buffer growth algorithm with a linear-time one.
...
Also fix the builtin file class and the bz2 module, which used the same algorithm.
2011-10-13 13:52:46 +02:00
Victor Stinner
63c22fac72
Issue #7732 : Fix a crash on importing a module if a directory has the same name
...
than a Python module (e.g. "__init__.py"): don't close the file twice.
PyFile_FromFile() does also close the file if PyString_FromString() failed. It
did already close the file on fill_file_fields() error (e.g. if the file is a
directory).
2011-09-23 19:37:03 +02:00
Antoine Pitrou
638cee62d5
Issue #9295 : Fix a crash under Windows when calling close() on a file
...
object with custom buffering from two threads at once.
2010-10-28 14:50:57 +00:00
Benjamin Peterson
bf775542b0
iterators passed to writelines() can close their files; don't segfault #10125
2010-10-16 19:20:12 +00:00
Victor Stinner
caafd77060
Issue #4947 : The write() method of sys.stdout and sys.stderr uses their
...
encoding and errors attributes instead of using utf-8 in strict mode, to get
the same behaviour than the print statement.
2010-09-08 10:51:01 +00:00
Antoine Pitrou
83137c2e16
Issue #7079 : Fix a possible crash when closing a file object while using
...
it from another thread. Patch by Daniel Stutzbach.
2010-05-17 19:56:59 +00:00
Antoine Pitrou
c83ea137d7
Untabify C files. Will watch buildbots.
2010-05-09 14:46:46 +00:00
Benjamin Peterson
bea424af98
more _PyString_Resize error checking
2010-04-03 00:57:33 +00:00
Andrew M. Kuchling
00b6a5c03d
#7706 : DONT_HAVE_ERRNO_H is no longer defined by configure (after rev.46819).
2010-02-22 23:10:52 +00:00
Antoine Pitrou
bb445a1f22
Issue #5677 : Explicitly forbid write operations on read-only file objects,
...
and read operations on write-only file objects. On Windows, the system C
library would return a bogus result; on Solaris, it was possible to crash
the interpreter. Patch by Stefan Krah.
2010-02-05 17:05:54 +00:00
Hirokazu Yamamoto
5c3dd9a1ee
Issue #6368 : Fixed unused variable warning on Unix.
2009-06-29 15:52:21 +00:00
Hirokazu Yamamoto
a3c5609079
Issue #4856 : Remove checks for win NT.
2009-06-28 10:23:00 +00:00
Hirokazu Yamamoto
b24bb27d22
Issue #3527 : Removed Py_WIN_WIDE_FILENAMES which is not used any more.
2009-05-17 02:52:09 +00:00
Kristján Valur Jónsson
fd4c872726
issue 4804: Provide checks for the format string of strftime, and for the "mode" string of fopen on Windows. These strings are user provided from python and so we can avoid invoking the C runtime invalid parameter handler by first checking that they are valid.
2009-02-04 10:05:25 +00:00
Benjamin Peterson
fe231b07e4
#4764 set IOError.filename when trying to open a directory on POSIX platforms
2008-12-29 17:47:42 +00:00
Amaury Forgeot d'Arc
17617a07d1
#3965 : on Windows, open() crashes if the filename or the mode is invalid,
...
and if the filename is a unicode string.
Reviewed by Martin von Loewis.
2008-09-25 20:52:56 +00:00
Martin v. Löwis
f91d46a17d
Issue #3139 : Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
...
by denying s# to parse objects that have a releasebuffer procedure,
and introducing s*.
More module might need to get converted to use s*.
2008-08-12 14:49:50 +00:00
Gregory P. Smith
99a3dce92d
More reverting of r63675 per the mailing list discussions. This restores
...
occurances of PyBytes_ in the code to their original PyString_ names. The
bytesobject.c file will be renamed back to stringobject.c in a future checkin.
2008-06-10 17:42:36 +00:00
Gregory P. Smith
dd96db63f6
This reverts r63675 based on the discussion in this thread:
...
http://mail.python.org/pipermail/python-dev/2008-June/079988.html
Python 2.6 should stick with PyString_* in its codebase. The PyBytes_* names
in the spirit of 3.0 are available via a #define only. See the email thread.
2008-06-09 04:58:54 +00:00
Martin v. Löwis
99815892f6
New environment variable PYTHONIOENCODING.
2008-06-01 07:20:46 +00:00
Christian Heimes
593daf545b
Renamed PyString to PyBytes
2008-05-26 12:51:38 +00:00
Georg Brandl
a9916b55de
#2353 : raise Py3k warning in file.xreadlines().
2008-05-17 22:11:54 +00:00
Benjamin Peterson
f19a7b90bd
A little reformating of Py3k warnings
2008-04-27 18:40:21 +00:00
Benjamin Peterson
9f4f48114f
Use PyErr_WarnPy3k throughout
2008-04-27 03:01:45 +00:00
Gregory P. Smith
aa63d0d4af
Make file objects as thread safe as the underlying libc FILE* implementation.
...
close() will now raise an IOError if any operations on the file object
are currently in progress in other threads.
Most code was written by Antoine Pitrou (pitrou). Additional testing,
documentation and test suite cleanup done by me (gregory.p.smith).
Fixes issue 815646 and 595601 (as well as many other bugs and
references to this problem dating back to the dawn of Python).
2008-04-06 23:11:17 +00:00
Georg Brandl
65bb42dc1b
#2348 : add py3k warning for file.softspace.
2008-03-21 20:38:24 +00:00
Brett Cannon
10ed0f50a9
Remove all traces of HAVE_STRERROR.
...
The removal of strerror.c led to the function check being removed from
configure.in.
2008-03-18 15:35:58 +00:00
Gregory P. Smith
887290d275
Fix the IOError message text when opening a file with an invalid filename.
...
Error reported by Ilan Schnell.
2008-03-18 00:20:01 +00:00
Georg Brandl
ad61bc8d9b
#2067 : file.__exit__() now calls subclasses' close() method.
2008-02-23 15:11:18 +00:00
Christian Heimes
d7e1b2bd17
static PyObject* variables should use PyString_InternFromString() instead of PyObject_FromString() to store a python string in a function level static var.
2008-01-28 02:07:53 +00:00