[Python-checkins] r74131 - in python/branches/py3k: Lib/test/test_scope.py Python/peephole.c

alexandre.vassalotti python-checkins at python.org
Tue Jul 21 04:51:59 CEST 2009


Author: alexandre.vassalotti
Date: Tue Jul 21 04:51:58 2009
New Revision: 74131

Log:
Merged revisions 73683,73786 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r73683 | georg.brandl | 2009-06-29 10:44:49 -0400 (Mon, 29 Jun 2009) | 1 line
  
  Fix error handling in PyCode_Optimize, by Alexander Schremmer at EuroPython sprint.
........
  r73786 | benjamin.peterson | 2009-07-02 18:56:16 -0400 (Thu, 02 Jul 2009) | 1 line
  
  condense with assertRaises
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/test/test_scope.py
   python/branches/py3k/Python/peephole.c

Modified: python/branches/py3k/Lib/test/test_scope.py
==============================================================================
--- python/branches/py3k/Lib/test/test_scope.py	(original)
+++ python/branches/py3k/Lib/test/test_scope.py	Tue Jul 21 04:51:58 2009
@@ -272,19 +272,8 @@
             inner()
             y = 1
 
-        try:
-            errorInOuter()
-        except UnboundLocalError:
-            pass
-        else:
-            self.fail()
-
-        try:
-            errorInInner()
-        except NameError:
-            pass
-        else:
-            self.fail()
+        self.assertRaises(UnboundLocalError, errorInOuter)
+        self.assertRaises(NameError, errorInInner)
 
         # test for bug #1501934: incorrect LOAD/STORE_GLOBAL generation
         exec("""

Modified: python/branches/py3k/Python/peephole.c
==============================================================================
--- python/branches/py3k/Python/peephole.c	(original)
+++ python/branches/py3k/Python/peephole.c	Tue Jul 21 04:51:58 2009
@@ -330,7 +330,7 @@
 
 	/* Bail out if an exception is set */
 	if (PyErr_Occurred())
-		goto exitUnchanged;
+		goto exitError;
 
 	/* Bypass optimization when the lineno table is too complex */
 	assert(PyBytes_Check(lineno_obj));
@@ -348,7 +348,7 @@
 	/* Make a modifiable copy of the code string */
 	codestr = (unsigned char *)PyMem_Malloc(codelen);
 	if (codestr == NULL)
-		goto exitUnchanged;
+		goto exitError;
 	codestr = (unsigned char *)memcpy(codestr, 
 					  PyBytes_AS_STRING(code), codelen);
 
@@ -363,11 +363,11 @@
 	/* Mapping to new jump targets after NOPs are removed */
 	addrmap = (int *)PyMem_Malloc(codelen * sizeof(int));
 	if (addrmap == NULL)
-		goto exitUnchanged;
+		goto exitError;
 
 	blocks = markblocks(codestr, codelen);
 	if (blocks == NULL)
-		goto exitUnchanged;
+		goto exitError;
 	assert(PyList_Check(consts));
 
 	for (i=0 ; i<codelen ; i += CODESIZE(codestr[i])) {
@@ -413,7 +413,7 @@
 				name = _PyUnicode_AsString(PyTuple_GET_ITEM(names, j));
 				h = load_global(codestr, i, name, consts);
 				if (h < 0)
-					goto exitUnchanged;
+					goto exitError;
 				else if (h == 0)
 					continue;
 				cumlc = lastlc + 1;
@@ -667,6 +667,9 @@
 	PyMem_Free(blocks);
 	return code;
 
+ exitError:
+	code = NULL;
+
  exitUnchanged:
 	if (blocks != NULL)
 		PyMem_Free(blocks);
@@ -674,6 +677,6 @@
 		PyMem_Free(addrmap);
 	if (codestr != NULL)
 		PyMem_Free(codestr);
-	Py_INCREF(code);
+	Py_XINCREF(code);
 	return code;
 }


More information about the Python-checkins mailing list