summaryrefslogtreecommitdiffstats
path: root/Objects/fileobject.c
Commit message (Collapse)AuthorAgeFilesLines
* dump HAVE_FOPENRF stuff - obsoleteSkip Montanaro2004-06-111-26/+19
|
* Add weakref support to array.array and file objects.Raymond Hettinger2004-05-311-2/+5
|
* If a file is opened with an explicit buffer size >= 1, repeatedAndrew MacIntyre2004-04-041-0/+2
| | | | | | | | close() calls would attempt to free() the buffer already free()ed on the first close(). [bug introduced with patch #788249] Making sure that the buffer is free()ed in file object deallocation is a belt-n-braces bit of insurance against a memory leak.
* Changed file.name to be the object passed as the 'name' argument to file()Nicholas Bastin2004-03-211-17/+21
| | | | Fixes SF Bug #773356
* PyFile_WriteObject(): some of the local variables are only used whenFred Drake2004-03-191-0/+2
| | | | Py_USING_UNICODE is defined
* Remove support for --without-universal-newlines (see PEP 11).Skip Montanaro2004-02-071-35/+0
|
* Getting rid of code dependent on GUSI or the MetroWerks compiler.Jack Jansen2003-11-191-28/+0
|
* Patch #809535: Mention behaviour of seek on text files. Backported to 2.3.Martin v. Löwis2003-10-181-1/+3
|
* Simplify and speedup uses of Py_BuildValue():Raymond Hettinger2003-10-121-2/+2
| | | | | | * Py_BuildValue("(OOO)",a,b,c) --> PyTuple_Pack(3,a,b,c) * Py_BuildValue("()",a) --> PyTuple_New(0) * Py_BuildValue("O", a) --> Py_INCREF(a)
* Only release buffer after file has been closed. Fixes #800824.Martin v. Löwis2003-09-071-1/+1
| | | | Will backport to 2.2.
* SF bug 801631: file.truncate fault on windows.Tim Peters2003-09-071-74/+66
| | | | | | | | | | | | | | | | | file_truncate(): C doesn't define what fflush(fp) does if fp is open for update, and the preceding I/O operation on fp was input. On Windows, fflush() actually changes the current file position then. Because Windows doesn't support ftruncate() directly, this not only caused Python's file.truncate() to change the file position (contra our docs), it also caused the file not to change size. Repaired by getting the initial file position at the start, restoring it at the end, and tossing all the complicated micro-efficiency checks trying to avoid "provably unnecessary" seeks. file.truncate() can't be a frequent operation, and seeking to the current file position has got to be cheap anyway. Bugfix candidate.
* Patch #788249: Pass an explicit buffer to setvbuf in PyFile_SetBufSize().Martin v. Löwis2003-09-041-5/+19
| | | | Fixes #603724. Will backport to 2.3.
* Fix SF #789402, Memory leak on open()Neal Norwitz2003-08-151-0/+1
| | | | If opening a directory, the exception would leak.
* Only encode Unicode objects when printing them raw.Martin v. Löwis2003-05-181-1/+2
|
* Patch #612627: Add encoding attribute to file objects, and determineMartin v. Löwis2003-05-101-1/+41
| | | | the terminal encoding on Windows and Unix.
* Somewhere along the way, the softspace attr of file objects became read-Tim Peters2003-05-041-1/+2
| | | | only. Repaired, and added new tests to test_file.py.
* SF patch #683187, fix universal newline problems on errorNeal Norwitz2003-02-091-1/+4
|
* Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.Martin v. Löwis2003-01-031-1/+24
|
* SF patch #659536: Use PyArg_UnpackTuple where possible.Raymond Hettinger2002-12-291-1/+1
| | | | | | | Obtain cleaner coding and a system wide performance boost by using the fast, pre-parsed PyArg_Unpack function instead of PyArg_ParseTuple function which is driven by a format string.
* * Objects/fileobject.cGustavo Niemeyer2002-12-171-1/+1
| | | | | (file_read): Replaced assertion with mixed sign operation by a simple comment (thank you Raymond). The algorithm is clear enough in that point.
* Fixed bugGustavo Niemeyer2002-12-161-3/+30
| | | | | | | | | | | | | | | | | [#521782] unreliable file.read() error handling * Objects/fileobject.c (file_read): Clear errors before leaving the loop in all situations, and also check if some data was read before exiting the loop with an EWOULDBLOCK exception. * Doc/lib/libstdtypes.tex * Objects/fileobject.c Document that sometimes a read() operation can return less data than what the user asked, if running in non-blocking mode. * Misc/NEWS Document the fix.
* Patch #650834: Document 'U' in file mode, remove stale variables.Martin v. Löwis2002-12-111-5/+1
|
* Fix --disable-unicode compilation problems.Martin v. Löwis2002-11-211-0/+4
|
* Patch 594001: PEP 277 - Unicode file name support for Windows NT.Mark Hammond2002-10-031-13/+83
|
* Reflow long lines.Jeremy Hylton2002-08-141-26/+32
|
* Make readahead functions staticNeal Norwitz2002-08-061-5/+8
|
* SF patch 580331 by Oren Tirosh: make file objects their own iterator.Guido van Rossum2002-08-061-31/+130
| | | | | | | | | | | | | | | | | | | | | | For a file f, iter(f) now returns f (unless f is closed), and f.next() is similar to f.readline() when EOF is not reached; however, f.next() uses a readahead buffer that messes up the file position, so mixing f.next() and f.readline() (or other methods) doesn't work right. Calling f.seek() drops the readahead buffer, but other operations don't. The real purpose of this change is to reduce the confusion between objects and their iterators. By making a file its own iterator, it's made clearer that using the iterator modifies the file object's state (in particular the current position). A nice side effect is that this speeds up "for line in f:" by not having to use the xreadlines module. The f.xreadlines() method is still supported for backwards compatibility, though it is the same as iter(f) now. (I made some cosmetic changes to Oren's code, and added a test for "file closed" to file_iternext() and file_iter().)
* WINDOWS_LEAN_AND_MEAN: There is no such symbol, although a very fewTim Peters2002-07-141-1/+1
| | | | | | | MSDN sample programs use it, apparently in error. The correct name is WIN32_LEAN_AND_MEAN. After switching to the correct name, in two cases more was needed because the code actually relied on things that disappear when WIN32_LEAN_AND_MEAN is defined.
* Patch #569753: Remove support for WIN16.Martin v. Löwis2002-06-301-3/+3
| | | | Rename all occurrences of MS_WIN32 to MS_WINDOWS.
* Patch #568124: Add doc string macros.Martin v. Löwis2002-06-131-30/+36
|
* file_doc: Add some description of the U mode character, but only whenBarry Warsaw2002-05-221-0/+10
| | | | WITH_UNIVERSAL_NEWLINES is enabled.
* Repair widespread misuse of _PyString_Resize. Since it's clear peopleTim Peters2002-04-271-3/+1
| | | | | | | | | | | | | | | | | | | | | | don't understand how this function works, also beefed up the docs. The most common usage error is of this form (often spread out across gotos): if (_PyString_Resize(&s, n) < 0) { Py_DECREF(s); s = NULL; goto outtahere; } The error is that if _PyString_Resize runs out of memory, it automatically decrefs the input string object s (which also deallocates it, since its refcount must be 1 upon entry), and sets s to NULL. So if the "if" branch ever triggers, it's an error to call Py_DECREF(s): s is already NULL! A correct way to write the above is the simpler (and intended) if (_PyString_Resize(&s, n) < 0) goto outtahere; Bugfix candidate.
* Py_UniversalNewlineFread(): small speed boost on non-Windows boxes.Tim Peters2002-04-211-3/+3
|
* Py_UniversalNewlineFread(): Many changes.Tim Peters2002-04-211-37/+47
| | | | | | | | | | | | | | | | | | | | + Continued looping until n bytes in the buffer have been filled, not just when n bytes have been read from the file. This repairs the bug that f.readlines() only sucked up the first 8192 bytes of the file on Windows when universal newlines was enabled and f was opened in U mode (see Python-Dev -- this was the ultimate cause of the test_inspect.py failure). + Changed prototye to take a char* buffer (void* doesn't make much sense). + Squashed size_t vs int mismatches (in particular, besides the unsigned vs signed distinction, size_t may be larger than int). + Gets out under all error conditions now (it's possible for fread() to suffer an error even if it returns a number larger than 0 -- any "short read" is an error or EOF condition). + Rearranged and simplified declarations.
* Mass checkin of universal newline support.Jack Jansen2002-04-141-17/+294
| | | | | | | | Highlights: import and friends will understand any of \r, \n and \r\n as end of line. Python file input will do the same if you use mode 'U'. Everything can be disabled by configuring with --without-universal-newlines. See PEP278 for details.
* PyObject_Del can now be used as a function designator.Neil Schemenauer2002-04-121-1/+1
|
* SF bug 538827: Python open w/ MSVC6: bad error msgs.Tim Peters2002-04-081-2/+15
| | | | | | | open_the_file: Some (not all) flavors of Windows set errno to EINVAL when passed a syntactically invalid filename. Python turned that into an incomprehensible complaint about the mode string. Fixed by special-casing MSVC.
* isatty() should return a bool.Guido van Rossum2002-04-071-1/+1
|
* Add the 'bool' type and its values 'False' and 'True', as described inGuido van Rossum2002-04-031-3/+3
| | | | | | | | | | | | | PEP 285. Everything described in the PEP is here, and there is even some documentation. I had to fix 12 unit tests; all but one of these were printing Boolean outcomes that changed from 0/1 to False/True. (The exception is test_unicode.py, which did a type(x) == type(y) style comparison. I could've fixed that with a single line using issubtype(x, type(y)), but instead chose to be explicit about those places where a bool is expected. Still to do: perhaps more documentation; change standard library modules to return False/True from predicates.
* Convert file.readinto() to stop using METH_OLDARGS & PyArg_Parse.Neal Norwitz2002-04-011-2/+2
| | | | Add test for file.readinto().
* Grow the string buffer at a mildly exponential rate for the getc versionNeil Schemenauer2002-03-231-13/+16
| | | | | | | | of get_line. This makes test_bufio finish in 1.7 seconds instead of 57 seconds on my machine (with Py_DEBUG defined). Also, rename the local variables n1 and n2 to used_v_size and total_v_size.
* Give Python a debug-mode pymalloc, much as sketched on Python-Dev.Tim Peters2002-03-231-8/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When WITH_PYMALLOC is defined, define PYMALLOC_DEBUG to enable the debug allocator. This can be done independent of build type (release or debug). A debug build automatically defines PYMALLOC_DEBUG when pymalloc is enabled. It's a detected error to define PYMALLOC_DEBUG when pymalloc isn't enabled. Two debugging entry points defined only under PYMALLOC_DEBUG: + _PyMalloc_DebugCheckAddress(const void *p) can be used (e.g., from gdb) to sanity-check a memory block obtained from pymalloc. It sprays info to stderr (see next) and dies via Py_FatalError if the block is detectably damaged. + _PyMalloc_DebugDumpAddress(const void *p) can be used to spray info about a debug memory block to stderr. A tiny start at implementing "API family" checks isn't good for anything yet. _PyMalloc_DebugRealloc() has been optimized to do little when the new size is <= old size. However, if the new size is larger, it really can't call the underlying realloc() routine without either violating its contract, or knowing something non-trivial about how the underlying realloc() works. A memcpy is always done in this case. This was a disaster for (and only) one of the std tests: test_bufio creates single text file lines up to a million characters long. On Windows, fileobject.c's get_line() uses the horridly funky getline_via_fgets(), which keeps growing and growing a string object hoping to find a newline. It grew the string object 1000 bytes each time, so for a million-character string it took approximately forever (I gave up after a few minutes). So, also: fileobject.c, getline_via_fgets(): When a single line is outrageously long, grow the string object at a mildly exponential rate, instead of just 1000 bytes at a time. That's enough so that a debug-build test_bufio finishes in about 5 seconds on my Win98SE box. I'm curious to try this on Win2K, because it has very different memory behavior than Win9X, and test_bufio always took a factor of 10 longer to complete on Win2K. It *could* be that the endless reallocs were simply killing it on Win2K even in the release build.
* Check in (hopefully) corrected version of last change.Neil Schemenauer2002-03-231-0/+29
|
* Undo last commit. It's causing the tests to file.Neil Schemenauer2002-03-221-28/+0
|
* Disallow open()ing of directories. Closes SF bug 487277.Neil Schemenauer2002-03-221-0/+28
|
* Patch #530105: Allow file object may to be subtypedMartin v. Löwis2002-03-151-11/+0
|
* Change Windows file.truncate() to (a) restore the original file position,Tim Peters2002-03-121-27/+40
| | | | | | | | | | | | and (b) stop trying to prevent file growth. Beef up the file.truncate() docs. Change test_largefile.py to stop assuming that f.truncate() moves the file pointer to the truncation point, and to verify instead that it leaves the file position alone. Remove the test for what happens when a specified size exceeds the original file size (it's ill-defined, according to the Single Unix Spec).
* file_truncate(): provide full "large file" support on Windows, byTim Peters2002-03-111-20/+55
| | | | | | | | | | | | | | | | | | | | dropping MS's inadequate _chsize() function. This was inspired by SF patch 498109 ("fileobject truncate support for win32"), which I rejected. libstdtypes.tex: Someone who knows should update the availability blurb. For example, if it's available on Linux, it would be good to say so. test_largefile: Uncommented the file.truncate() tests, and reworked to do more. The old comment about "permission errors" in the truncation tests under Windows was almost certainly due to that the file wasn't open for *write* access at this point, so of course MS wouldn't let you truncate it. I'd be appalled if a Unixish system did. CAUTION: Someone should run this test on Linux (etc) too. The truncation part was commented out before. Note that test_largefile isn't run by default.
* OS/2 EMX port changes (Objects part of patch #450267):Andrew MacIntyre2002-02-261-0/+4
| | | | | | | | | | | | Objects/ fileobject.c stringobject.c unicodeobject.c This commit doesn't include the cleanup patches for stringobject.c and unicodeobject.c which are shown separately in the patch manager. Those patches will be regenerated and applied in a subsequent commit, so as to preserve a fallback position (this commit to those files).
* Include <unistd.h> in Python.h. Fixes #500924.Martin v. Löwis2002-01-121-4/+0
|