diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-10-16 21:23:58 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-10-16 21:23:58 (GMT) |
commit | 9bc9d66eb1fed286693154405cc4c18626eff09e (patch) | |
tree | 6c16b6d5d2d06144f0867c6c5f75481cc874f22f /Modules | |
parent | 9714f99d60f5cb65fb63e084facd161937e7dc6d (diff) | |
download | cpython-9bc9d66eb1fed286693154405cc4c18626eff09e.zip cpython-9bc9d66eb1fed286693154405cc4c18626eff09e.tar.gz cpython-9bc9d66eb1fed286693154405cc4c18626eff09e.tar.bz2 |
Remove many calls to set MemoryError exceptions.
When PyString_FromStringAndSize() and _PyString_Resize() fail, they
set an exception. There's no need to set a new exception.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/zlibmodule.c | 32 |
1 files changed, 4 insertions, 28 deletions
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 7a9dcf0..6dd8c29 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -145,8 +145,6 @@ PyZlib_compress(PyObject *self, PyObject *args) { PyErr_SetString(PyExc_MemoryError, "Can't allocate memory to compress data"); - free(output); - return NULL; } @@ -266,11 +264,8 @@ PyZlib_decompress(PyObject *self, PyObject *args) zst.avail_in = length; zst.avail_out = r_strlen; - if (!(result_str = PyString_FromStringAndSize(NULL, r_strlen))) { - PyErr_SetString(PyExc_MemoryError, - "Can't allocate memory to decompress data"); + if (!(result_str = PyString_FromStringAndSize(NULL, r_strlen))) return NULL; - } /* Past the point of no return. From here on out, we need to make sure we clean up mallocs & INCREFs. */ @@ -334,8 +329,6 @@ PyZlib_decompress(PyObject *self, PyObject *args) case(Z_OK): /* need more memory */ if (_PyString_Resize(&result_str, r_strlen << 1) == -1) { - PyErr_SetString(PyExc_MemoryError, - "Out of memory while decompressing data"); inflateEnd(&zst); result_str = NULL; return_error = 1; @@ -528,11 +521,8 @@ PyZlib_objcompress(compobject *self, PyObject *args) if (PyString_AsStringAndSize(inputString, (char**)&input, &inplen) == -1) return NULL; - if (!(RetVal = PyString_FromStringAndSize(NULL, length))) { - PyErr_SetString(PyExc_MemoryError, - "Can't allocate memory to compress data"); + if (!(RetVal = PyString_FromStringAndSize(NULL, length))) return NULL; - } ENTER_ZLIB @@ -554,8 +544,6 @@ PyZlib_objcompress(compobject *self, PyObject *args) so extend the output buffer and try again */ while (err == Z_OK && self->zst.avail_out == 0) { if (_PyString_Resize(&RetVal, length << 1) == -1) { - PyErr_SetString(PyExc_MemoryError, - "Can't allocate memory to compress data"); return_error = 1; break; } @@ -635,11 +623,8 @@ PyZlib_objdecompress(compobject *self, PyObject *args) /* limit amount of data allocated to max_length */ if (max_length && length > max_length) length = max_length; - if (!(RetVal = PyString_FromStringAndSize(NULL, length))) { - PyErr_SetString(PyExc_MemoryError, - "Can't allocate memory to compress data"); + if (!(RetVal = PyString_FromStringAndSize(NULL, length))) return NULL; - } ENTER_ZLIB return_error = 0; @@ -673,8 +658,6 @@ PyZlib_objdecompress(compobject *self, PyObject *args) length = max_length; if (_PyString_Resize(&RetVal, length) == -1) { - PyErr_SetString(PyExc_MemoryError, - "Can't allocate memory to compress data"); return_error = 1; break; } @@ -709,8 +692,6 @@ PyZlib_objdecompress(compobject *self, PyObject *args) self->unused_data = PyString_FromStringAndSize( (char *)self->zst.next_in, self->zst.avail_in); if (self->unused_data == NULL) { - PyErr_SetString(PyExc_MemoryError, - "Can't allocate memory to unused_data"); Py_DECREF(RetVal); return_error = 1; } @@ -769,11 +750,8 @@ PyZlib_flush(compobject *self, PyObject *args) return PyString_FromStringAndSize(NULL, 0); } - if (!(RetVal = PyString_FromStringAndSize(NULL, length))) { - PyErr_SetString(PyExc_MemoryError, - "Can't allocate memory to compress data"); + if (!(RetVal = PyString_FromStringAndSize(NULL, length))) return NULL; - } ENTER_ZLIB @@ -792,8 +770,6 @@ PyZlib_flush(compobject *self, PyObject *args) so extend the output buffer and try again */ while (err == Z_OK && self->zst.avail_out == 0) { if (_PyString_Resize(&RetVal, length << 1) == -1) { - PyErr_SetString(PyExc_MemoryError, - "Can't allocate memory to compress data"); return_error = 1; break; } |