summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2004-10-09 22:47:13 (GMT)
committerTim Peters <tim.peters@gmail.com>2004-10-09 22:47:13 (GMT)
commitf9becec8cd989743aeb22d02a0ededddeecc89a6 (patch)
treec4c4aa8d3053caf18f08444bb066e3e4f3d766a3 /Python
parentfda787fcec40a7ff9c4a92ba73091d22bcc8f857 (diff)
downloadcpython-f9becec8cd989743aeb22d02a0ededddeecc89a6.zip
cpython-f9becec8cd989743aeb22d02a0ededddeecc89a6.tar.gz
cpython-f9becec8cd989743aeb22d02a0ededddeecc89a6.tar.bz2
_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.
Diffstat (limited to 'Python')
-rw-r--r--Python/pystate.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index d88d2d1..ba9be97 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -395,7 +395,9 @@ _PyGILState_Init(PyInterpreterState *i, PyThreadState *t)
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 @@ PyGILState_Ensure(void)
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