mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Py_UniversalNewlineFread(): Many changes.
+ 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.
This commit is contained in:
parent
ea572b21f8
commit
058b141ef7
2 changed files with 52 additions and 42 deletions
|
|
@ -41,7 +41,7 @@ extern DL_IMPORT(int) PyFile_WriteString(const char *, PyObject *);
|
|||
extern DL_IMPORT(int) PyObject_AsFileDescriptor(PyObject *);
|
||||
|
||||
/* The default encoding used by the platform file system APIs
|
||||
If non-NULL, this is different than the default encoding for strings
|
||||
If non-NULL, this is different than the default encoding for strings
|
||||
*/
|
||||
extern DL_IMPORT(const char *) Py_FileSystemDefaultEncoding;
|
||||
|
||||
|
|
@ -51,12 +51,12 @@ extern DL_IMPORT(const char *) Py_FileSystemDefaultEncoding;
|
|||
*/
|
||||
#define PY_STDIOTEXTMODE "b"
|
||||
char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
|
||||
size_t Py_UniversalNewlineFread(void *, size_t, FILE *, PyObject *);
|
||||
size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);
|
||||
#else
|
||||
#define PY_STDIOTEXTMODE ""
|
||||
#define Py_UniversalNewlineFgets(buf, len, fp, obj) (fgets((buf), (len), (fp)))
|
||||
#define Py_UniversalNewlineFread(buf, len, fp, obj) \
|
||||
(fread((buf), 1, (len), (fp)))
|
||||
#define Py_UniversalNewlineFgets(buf, len, fp, obj) fgets((buf), (len), (fp))
|
||||
#define Py_UniversalNewlineFread(buf, len, fp, obj)
|
||||
fread((buf), 1, (len), (fp))
|
||||
#endif /* WITH_UNIVERSAL_NEWLINES */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue