summaryrefslogtreecommitdiffstats
path: root/Objects/fileobject.c
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2006-04-21 10:40:58 (GMT)
committerThomas Wouters <thomas@python.org>2006-04-21 10:40:58 (GMT)
commit49fd7fa4431da299196d74087df4a04f99f9c46f (patch)
tree35ace5fe78d3d52c7a9ab356ab9f6dbf8d4b71f4 /Objects/fileobject.c
parent9ada3d6e29d5165dadacbe6be07bcd35cfbef59d (diff)
downloadcpython-49fd7fa4431da299196d74087df4a04f99f9c46f.zip
cpython-49fd7fa4431da299196d74087df4a04f99f9c46f.tar.gz
cpython-49fd7fa4431da299196d74087df4a04f99f9c46f.tar.bz2
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
number of tests, all because of the codecs/_multibytecodecs issue described here (it's not a Py3K issue, just something Py3K discovers): http://mail.python.org/pipermail/python-dev/2006-April/064051.html Hye-Shik Chang promised to look for a fix, so no need to fix it here. The tests that are expected to break are: test_codecencodings_cn test_codecencodings_hk test_codecencodings_jp test_codecencodings_kr test_codecencodings_tw test_codecs test_multibytecodec This merge fixes an actual test failure (test_weakref) in this branch, though, so I believe merging is the right thing to do anyway.
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r--Objects/fileobject.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index f96ee7b..632ab04 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -48,6 +48,10 @@
#define NEWLINE_LF 2 /* \n newline seen */
#define NEWLINE_CRLF 4 /* \r\n newline seen */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
FILE *
PyFile_AsFile(PyObject *f)
{
@@ -313,7 +317,8 @@ PyFile_SetBufSize(PyObject *f, int bufsize)
PyMem_Free(file->f_setbuf);
file->f_setbuf = NULL;
} else {
- file->f_setbuf = PyMem_Realloc(file->f_setbuf, bufsize);
+ file->f_setbuf = (char *)PyMem_Realloc(file->f_setbuf,
+ bufsize);
}
#ifdef HAVE_SETVBUF
setvbuf(file->f_fp, file->f_setbuf, type, bufsize);
@@ -818,7 +823,7 @@ file_read(PyFileObject *f, PyObject *args)
buffersize = new_buffersize(f, (size_t)0);
else
buffersize = bytesrequested;
- if (buffersize > INT_MAX) {
+ if (buffersize > PY_SSIZE_T_MAX) {
PyErr_SetString(PyExc_OverflowError,
"requested number of bytes is more than a Python string can hold");
return NULL;
@@ -1093,7 +1098,7 @@ getline_via_fgets(FILE *fp)
assert(*(pvend-1) == '\0');
increment = total_v_size >> 2; /* mild exponential growth */
total_v_size += increment;
- if (total_v_size > INT_MAX) {
+ if (total_v_size > PY_SSIZE_T_MAX) {
PyErr_SetString(PyExc_OverflowError,
"line is longer than a Python string can hold");
Py_DECREF(v);
@@ -1204,7 +1209,7 @@ get_line(PyFileObject *f, int n)
used_v_size = total_v_size;
increment = total_v_size >> 2; /* mild exponential growth */
total_v_size += increment;
- if (total_v_size > INT_MAX) {
+ if (total_v_size > PY_SSIZE_T_MAX) {
PyErr_SetString(PyExc_OverflowError,
"line is longer than a Python string can hold");
Py_DECREF(v);
@@ -1391,12 +1396,12 @@ file_readlines(PyFileObject *f, PyObject *args)
goto cleanup;
}
totalread += nread;
- p = memchr(buffer+nfilled, '\n', nread);
+ p = (char *)memchr(buffer+nfilled, '\n', nread);
if (p == NULL) {
/* Need a larger buffer to fit this line */
nfilled += nread;
buffersize *= 2;
- if (buffersize > INT_MAX) {
+ if (buffersize > PY_SSIZE_T_MAX) {
PyErr_SetString(PyExc_OverflowError,
"line is longer than a Python string can hold");
goto error;
@@ -1431,7 +1436,7 @@ file_readlines(PyFileObject *f, PyObject *args)
if (err != 0)
goto error;
q = p;
- p = memchr(q, '\n', end-q);
+ p = (char *)memchr(q, '\n', end-q);
} while (p != NULL);
/* Move the remaining incomplete line to the start */
nfilled = end-q;
@@ -1790,7 +1795,7 @@ drop_readahead(PyFileObject *f)
/* Make sure that file has a readahead buffer with at least one byte
(unless at EOF) and no more than bufsize. Returns negative value on
- error */
+ error, will set MemoryError if bufsize bytes cannot be allocated. */
static int
readahead(PyFileObject *f, int bufsize)
{
@@ -1802,7 +1807,8 @@ readahead(PyFileObject *f, int bufsize)
else
drop_readahead(f);
}
- if ((f->f_buf = PyMem_Malloc(bufsize)) == NULL) {
+ if ((f->f_buf = (char *)PyMem_Malloc(bufsize)) == NULL) {
+ PyErr_NoMemory();
return -1;
}
Py_BEGIN_ALLOW_THREADS
@@ -1844,7 +1850,7 @@ readahead_get_line_skip(PyFileObject *f, int skip, int bufsize)
if (len == 0)
return (PyStringObject *)
PyString_FromStringAndSize(NULL, skip);
- bufptr = memchr(f->f_bufptr, '\n', len);
+ bufptr = (char *)memchr(f->f_bufptr, '\n', len);
if (bufptr != NULL) {
bufptr++; /* Count the '\n' */
len = bufptr - f->f_bufptr;
@@ -2056,7 +2062,7 @@ PyTypeObject PyFile_Type = {
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
- (initproc)file_init, /* tp_init */
+ file_init, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
file_new, /* tp_new */
PyObject_Del, /* tp_free */
@@ -2432,3 +2438,8 @@ Py_UniversalNewlineFread(char *buf, size_t n,
f->f_skipnextlf = skipnextlf;
return dst - buf;
}
+
+#ifdef __cplusplus
+}
+#endif
+