summaryrefslogtreecommitdiffstats
path: root/Modules/bz2module.c
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2008-06-09 04:58:54 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2008-06-09 04:58:54 (GMT)
commitdd96db63f689e2f0d8ae5a1436b3b3395eec7de5 (patch)
treeb2299acac9ce44fc488fc7b2ae2a44548cd5fbb8 /Modules/bz2module.c
parente98839a1f48b2915f1cc747884e64f4d6e4c8e7a (diff)
downloadcpython-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 'Modules/bz2module.c')
-rw-r--r--Modules/bz2module.c108
1 files changed, 54 insertions, 54 deletions
diff --git a/Modules/bz2module.c b/Modules/bz2module.c
index ee24b5d..bbabe10 100644
--- a/Modules/bz2module.c
+++ b/Modules/bz2module.c
@@ -34,7 +34,7 @@ typedef fpos_t Py_off_t;
#error "Large file support, but neither off_t nor fpos_t is large enough."
#endif
-#define BUF(v) PyBytes_AS_STRING((PyBytesObject *)v)
+#define BUF(v) PyString_AS_STRING((PyStringObject *)v)
#define MODE_CLOSED 0
#define MODE_READ 1
@@ -241,7 +241,7 @@ Util_GetLine(BZ2FileObject *f, int n)
int univ_newline = f->f_univ_newline;
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;
@@ -307,7 +307,7 @@ Util_GetLine(BZ2FileObject *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;
@@ -315,7 +315,7 @@ Util_GetLine(BZ2FileObject *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;
}
@@ -438,10 +438,10 @@ Util_ReadAhead(BZ2FileObject *f, int bufsize)
/* This is a hacked version of Python's
* fileobject.c:readahead_get_line_skip(). */
-static PyBytesObject *
+static PyStringObject *
Util_ReadAheadGetLineSkip(BZ2FileObject *f, int skip, int bufsize)
{
- PyBytesObject* s;
+ PyStringObject* s;
char *bufptr;
char *buf;
int len;
@@ -452,17 +452,17 @@ Util_ReadAheadGetLineSkip(BZ2FileObject *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 = 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)
Util_DropReadAhead(f);
@@ -476,7 +476,7 @@ Util_ReadAheadGetLineSkip(BZ2FileObject *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;
@@ -509,7 +509,7 @@ BZ2File_read(BZ2FileObject *self, PyObject *args)
case MODE_READ:
break;
case MODE_READ_EOF:
- ret = PyBytes_FromString("");
+ ret = PyString_FromString("");
goto cleanup;
case MODE_CLOSED:
PyErr_SetString(PyExc_ValueError,
@@ -531,7 +531,7 @@ BZ2File_read(BZ2FileObject *self, PyObject *args)
"more than a Python string can hold");
goto cleanup;
}
- ret = PyBytes_FromStringAndSize((char *)NULL, buffersize);
+ ret = PyString_FromStringAndSize((char *)NULL, buffersize);
if (ret == NULL)
goto cleanup;
bytesread = 0;
@@ -557,14 +557,14 @@ BZ2File_read(BZ2FileObject *self, PyObject *args)
}
if (bytesrequested < 0) {
buffersize = Util_NewBufferSize(buffersize);
- if (_PyBytes_Resize(&ret, buffersize) < 0)
+ if (_PyString_Resize(&ret, buffersize) < 0)
goto cleanup;
} else {
break;
}
}
if (bytesread != buffersize)
- _PyBytes_Resize(&ret, bytesread);
+ _PyString_Resize(&ret, bytesread);
cleanup:
RELEASE_LOCK(self);
@@ -594,7 +594,7 @@ BZ2File_readline(BZ2FileObject *self, PyObject *args)
case MODE_READ:
break;
case MODE_READ_EOF:
- ret = PyBytes_FromString("");
+ ret = PyString_FromString("");
goto cleanup;
case MODE_CLOSED:
PyErr_SetString(PyExc_ValueError,
@@ -607,7 +607,7 @@ BZ2File_readline(BZ2FileObject *self, PyObject *args)
}
if (sizehint == 0)
- ret = PyBytes_FromString("");
+ ret = PyString_FromString("");
else
ret = Util_GetLine(self, (sizehint < 0) ? 0 : sizehint);
@@ -701,17 +701,17 @@ BZ2File_readlines(BZ2FileObject *self, 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 */
- _PyBytes_Resize(&big_buffer, buffersize);
- buffer = PyBytes_AS_STRING(big_buffer);
+ _PyString_Resize(&big_buffer, buffersize);
+ buffer = PyString_AS_STRING(big_buffer);
}
continue;
}
@@ -720,7 +720,7 @@ BZ2File_readlines(BZ2FileObject *self, PyObject *args)
while (p != NULL) {
/* 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);
@@ -743,7 +743,7 @@ BZ2File_readlines(BZ2FileObject *self, 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) {
@@ -753,7 +753,7 @@ BZ2File_readlines(BZ2FileObject *self, PyObject *args)
Py_DECREF(line);
goto error;
}
- PyBytes_Concat(&line, rest);
+ PyString_Concat(&line, rest);
Py_DECREF(rest);
if (line == NULL)
goto error;
@@ -915,7 +915,7 @@ BZ2File_writelines(BZ2FileObject *self, 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;
Py_ssize_t len;
if (PyObject_AsCharBuffer(v, &buffer, &len)) {
@@ -926,7 +926,7 @@ BZ2File_writelines(BZ2FileObject *self, PyObject *seq)
"strings");
goto error;
}
- line = PyBytes_FromStringAndSize(buffer,
+ line = PyString_FromStringAndSize(buffer,
len);
if (line == NULL)
goto error;
@@ -942,9 +942,9 @@ BZ2File_writelines(BZ2FileObject *self, PyObject *seq)
Py_BEGIN_ALLOW_THREADS
for (i = 0; i < j; i++) {
line = PyList_GET_ITEM(list, i);
- len = PyBytes_GET_SIZE(line);
+ len = PyString_GET_SIZE(line);
BZ2_bzWrite (&bzerror, self->fp,
- PyBytes_AS_STRING(line), len);
+ PyString_AS_STRING(line), len);
if (bzerror != BZ_OK) {
Py_BLOCK_THREADS
Util_CatchBZ2Error(bzerror);
@@ -1224,13 +1224,13 @@ BZ2File_get_newlines(BZ2FileObject *self, 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:
@@ -1448,7 +1448,7 @@ BZ2File_getiter(BZ2FileObject *self)
static PyObject *
BZ2File_iternext(BZ2FileObject *self)
{
- PyBytesObject* ret;
+ PyStringObject* ret;
ACQUIRE_LOCK(self);
if (self->mode == MODE_CLOSED) {
PyErr_SetString(PyExc_ValueError,
@@ -1457,7 +1457,7 @@ BZ2File_iternext(BZ2FileObject *self)
}
ret = Util_ReadAheadGetLineSkip(self, 0, READAHEAD_BUFSIZE);
RELEASE_LOCK(self);
- if (ret == NULL || PyBytes_GET_SIZE(ret) == 0) {
+ if (ret == NULL || PyString_GET_SIZE(ret) == 0) {
Py_XDECREF(ret);
return NULL;
}
@@ -1559,7 +1559,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
return NULL;
if (datasize == 0)
- return PyBytes_FromString("");
+ return PyString_FromString("");
ACQUIRE_LOCK(self);
if (!self->running) {
@@ -1568,7 +1568,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
goto error;
}
- ret = PyBytes_FromStringAndSize(NULL, bufsize);
+ ret = PyString_FromStringAndSize(NULL, bufsize);
if (!ret)
goto error;
@@ -1591,7 +1591,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
break; /* no more input data */
if (bzs->avail_out == 0) {
bufsize = Util_NewBufferSize(bufsize);
- if (_PyBytes_Resize(&ret, bufsize) < 0) {
+ if (_PyString_Resize(&ret, bufsize) < 0) {
BZ2_bzCompressEnd(bzs);
goto error;
}
@@ -1601,7 +1601,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
}
}
- _PyBytes_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
+ _PyString_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
RELEASE_LOCK(self);
return ret;
@@ -1636,7 +1636,7 @@ BZ2Comp_flush(BZ2CompObject *self)
}
self->running = 0;
- ret = PyBytes_FromStringAndSize(NULL, bufsize);
+ ret = PyString_FromStringAndSize(NULL, bufsize);
if (!ret)
goto error;
@@ -1657,7 +1657,7 @@ BZ2Comp_flush(BZ2CompObject *self)
}
if (bzs->avail_out == 0) {
bufsize = Util_NewBufferSize(bufsize);
- if (_PyBytes_Resize(&ret, bufsize) < 0)
+ if (_PyString_Resize(&ret, bufsize) < 0)
goto error;
bzs->next_out = BUF(ret);
bzs->next_out = BUF(ret) + (BZS_TOTAL_OUT(bzs)
@@ -1667,7 +1667,7 @@ BZ2Comp_flush(BZ2CompObject *self)
}
if (bzs->avail_out != 0)
- _PyBytes_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
+ _PyString_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
RELEASE_LOCK(self);
return ret;
@@ -1849,7 +1849,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args)
goto error;
}
- ret = PyBytes_FromStringAndSize(NULL, bufsize);
+ ret = PyString_FromStringAndSize(NULL, bufsize);
if (!ret)
goto error;
@@ -1868,7 +1868,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args)
if (bzs->avail_in != 0) {
Py_DECREF(self->unused_data);
self->unused_data =
- PyBytes_FromStringAndSize(bzs->next_in,
+ PyString_FromStringAndSize(bzs->next_in,
bzs->avail_in);
}
self->running = 0;
@@ -1882,7 +1882,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args)
break; /* no more input data */
if (bzs->avail_out == 0) {
bufsize = Util_NewBufferSize(bufsize);
- if (_PyBytes_Resize(&ret, bufsize) < 0) {
+ if (_PyString_Resize(&ret, bufsize) < 0) {
BZ2_bzDecompressEnd(bzs);
goto error;
}
@@ -1894,7 +1894,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args)
}
if (bzs->avail_out != 0)
- _PyBytes_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
+ _PyString_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
RELEASE_LOCK(self);
return ret;
@@ -1930,7 +1930,7 @@ BZ2Decomp_init(BZ2DecompObject *self, PyObject *args, PyObject *kwargs)
}
#endif
- self->unused_data = PyBytes_FromString("");
+ self->unused_data = PyString_FromString("");
if (!self->unused_data)
goto error;
@@ -2063,7 +2063,7 @@ bz2_compress(PyObject *self, PyObject *args, PyObject *kwargs)
* data in one shot. We will check it later anyway. */
bufsize = datasize + (datasize/100+1) + 600;
- ret = PyBytes_FromStringAndSize(NULL, bufsize);
+ ret = PyString_FromStringAndSize(NULL, bufsize);
if (!ret)
return NULL;
@@ -2095,7 +2095,7 @@ bz2_compress(PyObject *self, PyObject *args, PyObject *kwargs)
}
if (bzs->avail_out == 0) {
bufsize = Util_NewBufferSize(bufsize);
- if (_PyBytes_Resize(&ret, bufsize) < 0) {
+ if (_PyString_Resize(&ret, bufsize) < 0) {
BZ2_bzCompressEnd(bzs);
Py_DECREF(ret);
return NULL;
@@ -2106,7 +2106,7 @@ bz2_compress(PyObject *self, PyObject *args, PyObject *kwargs)
}
if (bzs->avail_out != 0)
- _PyBytes_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs));
+ _PyString_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs));
BZ2_bzCompressEnd(bzs);
return ret;
@@ -2134,9 +2134,9 @@ bz2_decompress(PyObject *self, PyObject *args)
return NULL;
if (datasize == 0)
- return PyBytes_FromString("");
+ return PyString_FromString("");
- ret = PyBytes_FromStringAndSize(NULL, bufsize);
+ ret = PyString_FromStringAndSize(NULL, bufsize);
if (!ret)
return NULL;
@@ -2175,7 +2175,7 @@ bz2_decompress(PyObject *self, PyObject *args)
}
if (bzs->avail_out == 0) {
bufsize = Util_NewBufferSize(bufsize);
- if (_PyBytes_Resize(&ret, bufsize) < 0) {
+ if (_PyString_Resize(&ret, bufsize) < 0) {
BZ2_bzDecompressEnd(bzs);
Py_DECREF(ret);
return NULL;
@@ -2186,7 +2186,7 @@ bz2_decompress(PyObject *self, PyObject *args)
}
if (bzs->avail_out != 0)
- _PyBytes_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs));
+ _PyString_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs));
BZ2_bzDecompressEnd(bzs);
return ret;
@@ -2223,7 +2223,7 @@ initbz2(void)
if (m == NULL)
return;
- PyModule_AddObject(m, "__author__", PyBytes_FromString(__author__));
+ PyModule_AddObject(m, "__author__", PyString_FromString(__author__));
Py_INCREF(&BZ2File_Type);
PyModule_AddObject(m, "BZ2File", (PyObject *)&BZ2File_Type);