[Python-checkins] commit of r41753 - in python/trunk: Lib/test/bad_coding2.py Lib/test/test_coding.py Misc/NEWS Parser/tokenizer.c Python/pythonrun.c

neal.norwitz python-checkins at python.org
Sun Dec 18 06:29:45 CET 2005


Author: neal.norwitz
Date: Sun Dec 18 06:29:30 2005
New Revision: 41753
Added:
 python/trunk/Lib/test/bad_coding2.py
Modified:
 python/trunk/Lib/test/test_coding.py
 python/trunk/Misc/NEWS
 python/trunk/Parser/tokenizer.c
 python/trunk/Python/pythonrun.c
Log:
Fix Bug #1378022, UTF-8 files with a leading BOM crashed the interpreter.
Needs backport.
Added: python/trunk/Lib/test/bad_coding2.py
==============================================================================
--- (empty file)
+++ python/trunk/Lib/test/bad_coding2.py	Sun Dec 18 06:29:30 2005
@@ -0,0 +1,2 @@
+#coding: utf8
+print '我'
\ No newline at end of file
Modified: python/trunk/Lib/test/test_coding.py
==============================================================================
--- python/trunk/Lib/test/test_coding.py	(original)
+++ python/trunk/Lib/test/test_coding.py	Sun Dec 18 06:29:30 2005
@@ -5,6 +5,13 @@
 class CodingTest(unittest.TestCase):
 def test_bad_coding(self):
 module_name = 'bad_coding'
+ self.verify_bad_module(module_name)
+
+ def test_bad_coding2(self):
+ module_name = 'bad_coding2'
+ self.verify_bad_module(module_name)
+
+ def verify_bad_module(self, module_name):
 self.assertRaises(SyntaxError, __import__, 'test.' + module_name)
 
 path = os.path.dirname(__file__)
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sun Dec 18 06:29:30 2005
@@ -12,6 +12,8 @@
 Core and builtins
 -----------------
 
+- Bug #1378022, UTF-8 files with a leading BOM crashed the interpreter.
+
 - Support for converting hex strings to floats no longer works.
 This was not portable. float('0x3') now raises a ValueError.
 
Modified: python/trunk/Parser/tokenizer.c
==============================================================================
--- python/trunk/Parser/tokenizer.c	(original)
+++ python/trunk/Parser/tokenizer.c	Sun Dec 18 06:29:30 2005
@@ -292,6 +292,12 @@
 			PyMem_DEL(cs);
 		}
 	}
+	if (!r) {
+		cs = tok->encoding;
+		if (!cs)
+			cs = "with BOM";
+		PyErr_Format(PyExc_SyntaxError, "encoding problem: %s", cs);
+	}
 	return r;
 }
 
Modified: python/trunk/Python/pythonrun.c
==============================================================================
--- python/trunk/Python/pythonrun.c	(original)
+++ python/trunk/Python/pythonrun.c	Sun Dec 18 06:29:30 2005
@@ -1439,8 +1439,8 @@
 		}
 		if (msg == NULL)
 			msg = "unknown decode error";
-		Py_DECREF(type);
-		Py_DECREF(value);
+		Py_XDECREF(type);
+		Py_XDECREF(value);
 		Py_XDECREF(tb);
 		break;
 	}


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /