[Python-checkins] r58004 - python/trunk/Modules/_lsprof.c

armin.rigo python-checkins at python.org
Thu Sep 6 10:30:51 CEST 2007


Author: armin.rigo
Date: Thu Sep  6 10:30:51 2007
New Revision: 58004

Modified:
   python/trunk/Modules/_lsprof.c
Log:
Patch #1733973 by peaker:
ptrace_enter_call() assumes no exception is currently set.
This assumption is broken when throwing into a generator.


Modified: python/trunk/Modules/_lsprof.c
==============================================================================
--- python/trunk/Modules/_lsprof.c	(original)
+++ python/trunk/Modules/_lsprof.c	Thu Sep  6 10:30:51 2007
@@ -369,11 +369,20 @@
 	ProfilerEntry *profEntry;
 	ProfilerContext *pContext;
 
+	/* In the case of entering a generator expression frame via a
+	 * throw (gen_send_ex(.., 1)), we may already have an
+	 * Exception set here. We must not mess around with this
+	 * exception, and some of the code under here assumes that
+	 * PyErr_* is its own to mess around with, so we have to
+	 * save and restore any current exception. */
+	PyObject *last_type, *last_value, *last_tb;
+	PyErr_Fetch(&last_type, &last_value, &last_tb);
+
 	profEntry = getEntry(pObj, key);
 	if (profEntry == NULL) {
 		profEntry = newProfilerEntry(pObj, key, userObj);
 		if (profEntry == NULL)
-			return;
+			goto restorePyerr;
 	}
 	/* grab a ProfilerContext out of the free list */
 	pContext = pObj->freelistProfilerContext;
@@ -386,10 +395,13 @@
 			malloc(sizeof(ProfilerContext));
 		if (pContext == NULL) {
 			pObj->flags |= POF_NOMEMORY;
-			return;
+			goto restorePyerr;
 		}
 	}
 	initContext(pObj, pContext, profEntry);
+
+restorePyerr:
+	PyErr_Restore(last_type, last_value, last_tb);
 }
 
 static void


More information about the Python-checkins mailing list