[Python-checkins] python/dist/src/Python pystate.c,2.33,2.34

tim_one at users.sourceforge.net tim_one at users.sourceforge.net
Sun Oct 10 00:47:16 CEST 2004


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17819/Python

Modified Files:
	pystate.c 
Log Message:
_PyGILState_Init(), PyGILState_Ensure():  Since PyThread_set_key_value()
can fail, check its return value, and die if it does fail.

_PyGILState_Init():  Assert that the thread doesn't already have an
association for autoTLSkey.  If it does, PyThread_set_key_value() will
ignore the attempt to (re)set the association, which the code clearly
doesn't want.


Index: pystate.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pystate.c,v
retrieving revision 2.33
retrieving revision 2.34
diff -u -d -r2.33 -r2.34
--- pystate.c	9 Oct 2004 17:38:29 -0000	2.33
+++ pystate.c	9 Oct 2004 22:47:13 -0000	2.34
@@ -395,7 +395,9 @@
 	autoTLSkey = PyThread_create_key();
 	autoInterpreterState = i;
 	/* Now stash the thread state for this thread in TLS */
-	PyThread_set_key_value(autoTLSkey, (void *)t);
+	assert(PyThread_get_key_value(autoTLSkey) == NULL);
+	if (PyThread_set_key_value(autoTLSkey, (void *)t) < 0)
+		Py_FatalError("Couldn't create autoTLSkey mapping");
 	assert(t->gilstate_counter == 0); /* must be a new thread state */
 	t->gilstate_counter = 1;
 }
@@ -434,7 +436,8 @@
 		tcur = PyThreadState_New(autoInterpreterState);
 		if (tcur == NULL)
 			Py_FatalError("Couldn't create thread-state for new thread");
-		PyThread_set_key_value(autoTLSkey, (void *)tcur);
+		if (PyThread_set_key_value(autoTLSkey, (void *)tcur) < 0)
+			Py_FatalError("Couldn't create autoTLSkey mapping");
 		current = 0; /* new thread state is never current */
 	}
 	else



More information about the Python-checkins mailing list