summaryrefslogtreecommitdiff
path: root/Modules/bz2module.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/bz2module.c')
-rw-r--r--Modules/bz2module.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/Modules/bz2module.c b/Modules/bz2module.c
index 957689596d..b0075a07f9 100644
--- a/Modules/bz2module.c
+++ b/Modules/bz2module.c
@@ -1303,7 +1303,11 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs)
break;
case 'U':
+#ifdef __VMS
+ self->f_univ_newline = 0;
+#else
self->f_univ_newline = 1;
+#endif
break;
default:
@@ -1336,8 +1340,10 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs)
#ifdef WITH_THREAD
self->lock = PyThread_allocate_lock();
- if (!self->lock)
+ if (!self->lock) {
+ PyErr_SetString(PyExc_MemoryError, "unable to allocate lock");
goto error;
+ }
#endif
if (mode_char == 'r')
@@ -1359,10 +1365,12 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs)
return 0;
error:
- Py_DECREF(self->file);
+ Py_CLEAR(self->file);
#ifdef WITH_THREAD
- if (self->lock)
+ if (self->lock) {
PyThread_free_lock(self->lock);
+ self->lock = NULL;
+ }
#endif
return -1;
}
@@ -1562,7 +1570,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
}
}
- _PyString_Resize(&ret, (int)(BZS_TOTAL_OUT(bzs) - totalout));
+ _PyString_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
RELEASE_LOCK(self);
return ret;
@@ -1628,7 +1636,7 @@ BZ2Comp_flush(BZ2CompObject *self)
}
if (bzs->avail_out != 0)
- _PyString_Resize(&ret, (int)(BZS_TOTAL_OUT(bzs) - totalout));
+ _PyString_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
RELEASE_LOCK(self);
return ret;
@@ -1670,8 +1678,10 @@ BZ2Comp_init(BZ2CompObject *self, PyObject *args, PyObject *kwargs)
#ifdef WITH_THREAD
self->lock = PyThread_allocate_lock();
- if (!self->lock)
+ if (!self->lock) {
+ PyErr_SetString(PyExc_MemoryError, "unable to allocate lock");
goto error;
+ }
#endif
memset(&self->bzs, 0, sizeof(bz_stream));
@@ -1686,8 +1696,10 @@ BZ2Comp_init(BZ2CompObject *self, PyObject *args, PyObject *kwargs)
return 0;
error:
#ifdef WITH_THREAD
- if (self->lock)
+ if (self->lock) {
PyThread_free_lock(self->lock);
+ self->lock = NULL;
+ }
#endif
return -1;
}
@@ -1852,7 +1864,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args)
}
if (bzs->avail_out != 0)
- _PyString_Resize(&ret, (int)(BZS_TOTAL_OUT(bzs) - totalout));
+ _PyString_Resize(&ret, (Py_ssize_t)(BZS_TOTAL_OUT(bzs) - totalout));
RELEASE_LOCK(self);
return ret;
@@ -1882,8 +1894,10 @@ BZ2Decomp_init(BZ2DecompObject *self, PyObject *args, PyObject *kwargs)
#ifdef WITH_THREAD
self->lock = PyThread_allocate_lock();
- if (!self->lock)
+ if (!self->lock) {
+ PyErr_SetString(PyExc_MemoryError, "unable to allocate lock");
goto error;
+ }
#endif
self->unused_data = PyString_FromString("");
@@ -1903,10 +1917,12 @@ BZ2Decomp_init(BZ2DecompObject *self, PyObject *args, PyObject *kwargs)
error:
#ifdef WITH_THREAD
- if (self->lock)
+ if (self->lock) {
PyThread_free_lock(self->lock);
+ self->lock = NULL;
+ }
#endif
- Py_XDECREF(self->unused_data);
+ Py_CLEAR(self->unused_data);
return -1;
}
@@ -2061,7 +2077,7 @@ bz2_compress(PyObject *self, PyObject *args, PyObject *kwargs)
}
if (bzs->avail_out != 0)
- _PyString_Resize(&ret, (int)BZS_TOTAL_OUT(bzs));
+ _PyString_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs));
BZ2_bzCompressEnd(bzs);
return ret;
@@ -2140,7 +2156,7 @@ bz2_decompress(PyObject *self, PyObject *args)
}
if (bzs->avail_out != 0)
- _PyString_Resize(&ret, (int)BZS_TOTAL_OUT(bzs));
+ _PyString_Resize(&ret, (Py_ssize_t)BZS_TOTAL_OUT(bzs));
BZ2_bzDecompressEnd(bzs);
return ret;