[Python-checkins] r51286 - in python/branches/release24-maint: Lib/test/test_bz2.py Misc/NEWS Modules/bz2module.c

georg.brandl python-checkins at python.org
Mon Aug 14 23:42:59 CEST 2006


Author: georg.brandl
Date: Mon Aug 14 23:42:58 2006
New Revision: 51286

Modified:
   python/branches/release24-maint/Lib/test/test_bz2.py
   python/branches/release24-maint/Misc/NEWS
   python/branches/release24-maint/Modules/bz2module.c
Log:
Patch #1535500: fix segfault in BZ2File.writelines and make sure it
raises the correct exceptions.
 (backport from rev. 51285)

Modified: python/branches/release24-maint/Lib/test/test_bz2.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_bz2.py	(original)
+++ python/branches/release24-maint/Lib/test/test_bz2.py	Mon Aug 14 23:42:58 2006
@@ -166,6 +166,8 @@
         sio = StringIO(self.TEXT)
         bz2f.writelines(sio.readlines())
         bz2f.close()
+        # patch #1535500
+        self.assertRaises(ValueError, bz2f.writelines, ["a"])
         f = open(self.filename, 'rb')
         self.assertEqual(self.decompress(f.read()), self.TEXT)
         f.close()

Modified: python/branches/release24-maint/Misc/NEWS
==============================================================================
--- python/branches/release24-maint/Misc/NEWS	(original)
+++ python/branches/release24-maint/Misc/NEWS	Mon Aug 14 23:42:58 2006
@@ -36,6 +36,9 @@
 Extension Modules
 -----------------
 
+- Patch #1535500: fix segfault in BZ2File.writelines and make sure it
+  raises the correct exceptions.
+
 - Bug #1471938: Fix curses module build problem on Solaris 8; patch by
   Paul Eggert.
 

Modified: python/branches/release24-maint/Modules/bz2module.c
==============================================================================
--- python/branches/release24-maint/Modules/bz2module.c	(original)
+++ python/branches/release24-maint/Modules/bz2module.c	Mon Aug 14 23:42:58 2006
@@ -812,12 +812,12 @@
 		case MODE_CLOSED:
 			PyErr_SetString(PyExc_ValueError,
 					"I/O operation on closed file");
-			goto cleanup;;
+			goto cleanup;
 
 		default:
 			PyErr_SetString(PyExc_IOError,
 					"file is not ready for writing");
-			goto cleanup;;
+			goto cleanup;
 	}
 
 	self->f_softspace = 0;
@@ -861,6 +861,21 @@
 	int bzerror;
 
 	ACQUIRE_LOCK(self);
+	switch (self->mode) {
+		case MODE_WRITE:
+			break;
+
+		case MODE_CLOSED:
+			PyErr_SetString(PyExc_ValueError,
+					"I/O operation on closed file");
+			goto error;
+
+		default:
+			PyErr_SetString(PyExc_IOError,
+					"file is not ready for writing");
+			goto error;
+	}
+
 	islist = PyList_Check(seq);
 	if  (!islist) {
 		iter = PyObject_GetIter(seq);
@@ -985,7 +1000,6 @@
 	size_t readsize;
 	int chunksize;
 	int bzerror;
-	int rewind = 0;
 	PyObject *ret = NULL;
 
 	if (!PyArg_ParseTuple(args, "O|i:seek", &offobj, &where))


More information about the Python-checkins mailing list