diff options
| author | Gregory P. Smith <greg@mad-scientist.com> | 2008-06-09 04:58:54 (GMT) |
|---|---|---|
| committer | Gregory P. Smith <greg@mad-scientist.com> | 2008-06-09 04:58:54 (GMT) |
| commit | dd96db63f689e2f0d8ae5a1436b3b3395eec7de5 (patch) | |
| tree | b2299acac9ce44fc488fc7b2ae2a44548cd5fbb8 /Objects/fileobject.c | |
| parent | e98839a1f48b2915f1cc747884e64f4d6e4c8e7a (diff) | |
| download | cpython-dd96db63f689e2f0d8ae5a1436b3b3395eec7de5.zip cpython-dd96db63f689e2f0d8ae5a1436b3b3395eec7de5.tar.gz cpython-dd96db63f689e2f0d8ae5a1436b3b3395eec7de5.tar.bz2 | |
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.
Diffstat (limited to 'Objects/fileobject.c')
| -rw-r--r-- | Objects/fileobject.c | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 4ea97f5..8cc829b 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -26,7 +26,7 @@ #include <io.h> #endif -#define BUF(v) PyBytes_AS_STRING((PyBytesObject *)v) +#define BUF(v) PyString_AS_STRING((PyStringObject *)v) #ifndef DONT_HAVE_ERRNO_H #include <errno.h> @@ -160,7 +160,7 @@ fill_file_fields(PyFileObject *f, FILE *fp, PyObject *name, char *mode, Py_INCREF(name); f->f_name = name; - f->f_mode = PyBytes_FromString(mode); + f->f_mode = PyString_FromString(mode); f->f_close = close; f->f_softspace = 0; @@ -370,7 +370,7 @@ PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE *)) PyFileObject *f = (PyFileObject *)PyFile_Type.tp_new(&PyFile_Type, NULL, NULL); if (f != NULL) { - PyObject *o_name = PyBytes_FromString(name); + PyObject *o_name = PyString_FromString(name); if (o_name == NULL) return NULL; if (fill_file_fields(f, fp, o_name, mode, close) == NULL) { @@ -525,20 +525,20 @@ file_repr(PyFileObject *f) #ifdef Py_USING_UNICODE PyObject *ret = NULL; PyObject *name = PyUnicode_AsUnicodeEscapeString(f->f_name); - const char *name_str = name ? PyBytes_AsString(name) : "?"; - ret = PyBytes_FromFormat("<%s file u'%s', mode '%s' at %p>", + const char *name_str = name ? PyString_AsString(name) : "?"; + ret = PyString_FromFormat("<%s file u'%s', mode '%s' at %p>", f->f_fp == NULL ? "closed" : "open", name_str, - PyBytes_AsString(f->f_mode), + PyString_AsString(f->f_mode), f); Py_XDECREF(name); return ret; #endif } else { - return PyBytes_FromFormat("<%s file '%s', mode '%s' at %p>", + return PyString_FromFormat("<%s file '%s', mode '%s' at %p>", f->f_fp == NULL ? "closed" : "open", - PyBytes_AsString(f->f_name), - PyBytes_AsString(f->f_mode), + PyString_AsString(f->f_name), + PyString_AsString(f->f_mode), f); } } @@ -958,7 +958,7 @@ file_read(PyFileObject *f, PyObject *args) "requested number of bytes is more than a Python string can hold"); return NULL; } - v = PyBytes_FromStringAndSize((char *)NULL, buffersize); + v = PyString_FromStringAndSize((char *)NULL, buffersize); if (v == NULL) return NULL; bytesread = 0; @@ -989,7 +989,7 @@ file_read(PyFileObject *f, PyObject *args) } if (bytesrequested < 0) { buffersize = new_buffersize(f, buffersize); - if (_PyBytes_Resize(&v, buffersize) < 0) + if (_PyString_Resize(&v, buffersize) < 0) return NULL; } else { /* Got what was requested. */ @@ -997,7 +997,7 @@ file_read(PyFileObject *f, PyObject *args) } } if (bytesread != buffersize) - _PyBytes_Resize(&v, bytesread); + _PyString_Resize(&v, bytesread); return v; } @@ -1115,7 +1115,7 @@ getline_via_fgets(PyFileObject *f, FILE *fp) size_t increment; /* amount to increment the buffer */ size_t prev_v_size; - /* Optimize for normal case: avoid _PyBytes_Resize if at all + /* Optimize for normal case: avoid _PyString_Resize if at all * possible via first reading into stack buffer "buf". */ total_v_size = INITBUFSIZE; /* start small and pray */ @@ -1133,7 +1133,7 @@ getline_via_fgets(PyFileObject *f, FILE *fp) clearerr(fp); if (PyErr_CheckSignals()) return NULL; - v = PyBytes_FromStringAndSize(buf, pvfree - buf); + v = PyString_FromStringAndSize(buf, pvfree - buf); return v; } /* fgets read *something* */ @@ -1162,7 +1162,7 @@ getline_via_fgets(PyFileObject *f, FILE *fp) assert(p > pvfree && *(p-1) == '\0'); --p; /* don't include \0 from fgets */ } - v = PyBytes_FromStringAndSize(buf, p - buf); + v = PyString_FromStringAndSize(buf, p - buf); return v; } /* yuck: fgets overwrote all the newlines, i.e. the entire @@ -1183,7 +1183,7 @@ getline_via_fgets(PyFileObject *f, FILE *fp) * into its buffer. */ total_v_size = MAXBUFSIZE << 1; - v = PyBytes_FromStringAndSize((char*)NULL, (int)total_v_size); + v = PyString_FromStringAndSize((char*)NULL, (int)total_v_size); if (v == NULL) return v; /* copy over everything except the last null byte */ @@ -1238,13 +1238,13 @@ getline_via_fgets(PyFileObject *f, FILE *fp) Py_DECREF(v); return NULL; } - if (_PyBytes_Resize(&v, (int)total_v_size) < 0) + if (_PyString_Resize(&v, (int)total_v_size) < 0) return NULL; /* overwrite the trailing null byte */ pvfree = BUF(v) + (prev_v_size - 1); } if (BUF(v) + total_v_size != p) - _PyBytes_Resize(&v, p - BUF(v)); + _PyString_Resize(&v, p - BUF(v)); return v; #undef INITBUFSIZE #undef MAXBUFSIZE @@ -1276,7 +1276,7 @@ get_line(PyFileObject *f, int n) return getline_via_fgets(f, fp); #endif total_v_size = n > 0 ? n : 100; - v = PyBytes_FromStringAndSize((char *)NULL, total_v_size); + v = PyString_FromStringAndSize((char *)NULL, total_v_size); if (v == NULL) return NULL; buf = BUF(v); @@ -1349,7 +1349,7 @@ get_line(PyFileObject *f, int n) Py_DECREF(v); return NULL; } - if (_PyBytes_Resize(&v, total_v_size) < 0) + if (_PyString_Resize(&v, total_v_size) < 0) return NULL; buf = BUF(v) + used_v_size; end = BUF(v) + total_v_size; @@ -1357,7 +1357,7 @@ get_line(PyFileObject *f, int n) used_v_size = buf - BUF(v); if (used_v_size != total_v_size) - _PyBytes_Resize(&v, used_v_size); + _PyString_Resize(&v, used_v_size); return v; } @@ -1402,7 +1402,7 @@ PyFile_GetLine(PyObject *f, int n) result = PyEval_CallObject(reader, args); Py_DECREF(reader); Py_DECREF(args); - if (result != NULL && !PyBytes_Check(result) && + if (result != NULL && !PyString_Check(result) && !PyUnicode_Check(result)) { Py_DECREF(result); result = NULL; @@ -1411,9 +1411,9 @@ PyFile_GetLine(PyObject *f, int n) } } - if (n < 0 && result != NULL && PyBytes_Check(result)) { - char *s = PyBytes_AS_STRING(result); - Py_ssize_t len = PyBytes_GET_SIZE(result); + if (n < 0 && result != NULL && PyString_Check(result)) { + char *s = PyString_AS_STRING(result); + Py_ssize_t len = PyString_GET_SIZE(result); if (len == 0) { Py_DECREF(result); result = NULL; @@ -1422,10 +1422,10 @@ PyFile_GetLine(PyObject *f, int n) } else if (s[len-1] == '\n') { if (result->ob_refcnt == 1) - _PyBytes_Resize(&result, len-1); + _PyString_Resize(&result, len-1); else { PyObject *v; - v = PyBytes_FromStringAndSize(s, len-1); + v = PyString_FromStringAndSize(s, len-1); Py_DECREF(result); result = v; } @@ -1473,7 +1473,7 @@ file_readline(PyFileObject *f, PyObject *args) if (!PyArg_ParseTuple(args, "|i:readline", &n)) return NULL; if (n == 0) - return PyBytes_FromString(""); + return PyString_FromString(""); if (n < 0) n = 0; return get_line(f, n); @@ -1539,18 +1539,18 @@ file_readlines(PyFileObject *f, PyObject *args) } if (big_buffer == NULL) { /* Create the big buffer */ - big_buffer = PyBytes_FromStringAndSize( + big_buffer = PyString_FromStringAndSize( NULL, buffersize); if (big_buffer == NULL) goto error; - buffer = PyBytes_AS_STRING(big_buffer); + buffer = PyString_AS_STRING(big_buffer); memcpy(buffer, small_buffer, nfilled); } else { /* Grow the big buffer */ - if ( _PyBytes_Resize(&big_buffer, buffersize) < 0 ) + if ( _PyString_Resize(&big_buffer, buffersize) < 0 ) goto error; - buffer = PyBytes_AS_STRING(big_buffer); + buffer = PyString_AS_STRING(big_buffer); } continue; } @@ -1559,7 +1559,7 @@ file_readlines(PyFileObject *f, PyObject *args) do { /* Process complete lines */ p++; - line = PyBytes_FromStringAndSize(q, p-q); + line = PyString_FromStringAndSize(q, p-q); if (line == NULL) goto error; err = PyList_Append(list, line); @@ -1578,7 +1578,7 @@ file_readlines(PyFileObject *f, PyObject *args) } if (nfilled != 0) { /* Partial last line */ - line = PyBytes_FromStringAndSize(buffer, nfilled); + line = PyString_FromStringAndSize(buffer, nfilled); if (line == NULL) goto error; if (sizehint > 0) { @@ -1588,7 +1588,7 @@ file_readlines(PyFileObject *f, PyObject *args) Py_DECREF(line); goto error; } - PyBytes_Concat(&line, rest); + PyString_Concat(&line, rest); Py_DECREF(rest); if (line == NULL) goto error; @@ -1695,7 +1695,7 @@ file_writelines(PyFileObject *f, PyObject *seq) could potentially execute Python code. */ for (i = 0; i < j; i++) { PyObject *v = PyList_GET_ITEM(list, i); - if (!PyBytes_Check(v)) { + if (!PyString_Check(v)) { const char *buffer; if (((f->f_binary && PyObject_AsReadBuffer(v, @@ -1708,7 +1708,7 @@ file_writelines(PyFileObject *f, PyObject *seq) "writelines() argument must be a sequence of strings"); goto error; } - line = PyBytes_FromStringAndSize(buffer, + line = PyString_FromStringAndSize(buffer, len); if (line == NULL) goto error; @@ -1724,8 +1724,8 @@ file_writelines(PyFileObject *f, PyObject *seq) errno = 0; for (i = 0; i < j; i++) { line = PyList_GET_ITEM(list, i); - len = PyBytes_GET_SIZE(line); - nwritten = fwrite(PyBytes_AS_STRING(line), + len = PyString_GET_SIZE(line); + nwritten = fwrite(PyString_AS_STRING(line), 1, len, f->f_fp); if (nwritten != len) { FILE_ABORT_ALLOW_THREADS(f) @@ -1921,13 +1921,13 @@ get_newlines(PyFileObject *f, void *closure) Py_INCREF(Py_None); return Py_None; case NEWLINE_CR: - return PyBytes_FromString("\r"); + return PyString_FromString("\r"); case NEWLINE_LF: - return PyBytes_FromString("\n"); + return PyString_FromString("\n"); case NEWLINE_CR|NEWLINE_LF: return Py_BuildValue("(ss)", "\r", "\n"); case NEWLINE_CRLF: - return PyBytes_FromString("\r\n"); + return PyString_FromString("\r\n"); case NEWLINE_CR|NEWLINE_CRLF: return Py_BuildValue("(ss)", "\r", "\r\n"); case NEWLINE_LF|NEWLINE_CRLF: @@ -2029,10 +2029,10 @@ readahead(PyFileObject *f, int bufsize) horrified by the recursive call: maximum recursion depth is limited by logarithmic buffer growth to about 50 even when reading a 1gb line. */ -static PyBytesObject * +static PyStringObject * readahead_get_line_skip(PyFileObject *f, int skip, int bufsize) { - PyBytesObject* s; + PyStringObject* s; char *bufptr; char *buf; Py_ssize_t len; @@ -2043,17 +2043,17 @@ readahead_get_line_skip(PyFileObject *f, int skip, int bufsize) len = f->f_bufend - f->f_bufptr; if (len == 0) - return (PyBytesObject *) - PyBytes_FromStringAndSize(NULL, skip); + return (PyStringObject *) + PyString_FromStringAndSize(NULL, skip); bufptr = (char *)memchr(f->f_bufptr, '\n', len); if (bufptr != NULL) { bufptr++; /* Count the '\n' */ len = bufptr - f->f_bufptr; - s = (PyBytesObject *) - PyBytes_FromStringAndSize(NULL, skip+len); + s = (PyStringObject *) + PyString_FromStringAndSize(NULL, skip+len); if (s == NULL) return NULL; - memcpy(PyBytes_AS_STRING(s)+skip, f->f_bufptr, len); + memcpy(PyString_AS_STRING(s)+skip, f->f_bufptr, len); f->f_bufptr = bufptr; if (bufptr == f->f_bufend) drop_readahead(f); @@ -2068,7 +2068,7 @@ readahead_get_line_skip(PyFileObject *f, int skip, int bufsize) PyMem_Free(buf); return NULL; } - memcpy(PyBytes_AS_STRING(s)+skip, bufptr, len); + memcpy(PyString_AS_STRING(s)+skip, bufptr, len); PyMem_Free(buf); } return s; @@ -2080,13 +2080,13 @@ readahead_get_line_skip(PyFileObject *f, int skip, int bufsize) static PyObject * file_iternext(PyFileObject *f) { - PyBytesObject* l; + PyStringObject* l; if (f->f_fp == NULL) return err_closed(); l = readahead_get_line_skip(f, 0, READAHEAD_BUFSIZE); - if (l == NULL || PyBytes_GET_SIZE(l) == 0) { + if (l == NULL || PyString_GET_SIZE(l) == 0) { Py_XDECREF(l); return NULL; } @@ -2103,7 +2103,7 @@ file_new(PyTypeObject *type, PyObject *args, PyObject *kwds) assert(type != NULL && type->tp_alloc != NULL); if (not_yet_string == NULL) { - not_yet_string = PyBytes_InternFromString("<uninitialized file>"); + not_yet_string = PyString_InternFromString("<uninitialized file>"); if (not_yet_string == NULL) return NULL; } @@ -2394,7 +2394,7 @@ PyFile_WriteString(const char *s, PyObject *f) return 0; } else if (!PyErr_Occurred()) { - PyObject *v = PyBytes_FromString(s); + PyObject *v = PyString_FromString(s); int err; if (v == NULL) return -1; |
