[Python-checkins] r73683 - python/trunk/Python/peephole.c

georg.brandl python-checkins at python.org
Mon Jun 29 16:44:49 CEST 2009


Author: georg.brandl
Date: Mon Jun 29 16:44:49 2009
New Revision: 73683

Log:
Fix error handling in PyCode_Optimize, by Alexander Schremmer at EuroPython sprint.

Modified:
   python/trunk/Python/peephole.c

Modified: python/trunk/Python/peephole.c
==============================================================================
--- python/trunk/Python/peephole.c	(original)
+++ python/trunk/Python/peephole.c	Mon Jun 29 16:44:49 2009
@@ -305,7 +305,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(PyString_Check(lineno_obj));
@@ -323,7 +323,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, 
 					  PyString_AS_STRING(code), codelen);
 
@@ -338,11 +338,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])) {
@@ -394,7 +394,7 @@
 				}
 				if (j == PyList_GET_SIZE(consts)) {
 					if (PyList_Append(consts, Py_None) == -1)
-					        goto exitUnchanged;                                        
+					        goto exitError;
 				}
 				assert(PyList_GET_ITEM(consts, j) == Py_None);
 				codestr[i] = LOAD_CONST;
@@ -647,6 +647,9 @@
 	PyMem_Free(blocks);
 	return code;
 
+ exitError:
+	code = NULL;
+
  exitUnchanged:
 	if (blocks != NULL)
 		PyMem_Free(blocks);
@@ -654,6 +657,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