@@ -205,7 +205,7 @@ static int nkeys = 0; /* PyThread_create_key() hands out nkeys+1 next */
205205 * segfaults. Now we lock the whole routine.
206206 */
207207static struct key *
208- find_key (int key , int update , void * value )
208+ find_key (int key , void * value )
209209{
210210 struct key * p , * prev_p ;
211211 long id = PyThread_get_thread_ident ();
@@ -215,11 +215,8 @@ find_key(int key, int update, void *value)
215215 PyThread_acquire_lock (keymutex , 1 );
216216 prev_p = NULL ;
217217 for (p = keyhead ; p != NULL ; p = p -> next ) {
218- if (p -> id == id && p -> key == key ) {
219- if (update )
220- p -> value = value ;
218+ if (p -> id == id && p -> key == key )
221219 goto Done ;
222- }
223220 /* Sanity check. These states should never happen but if
224221 * they do we must abort. Otherwise we'll end up spinning in
225222 * in a tight loop with the lock held. A similar check is done
@@ -230,7 +227,7 @@ find_key(int key, int update, void *value)
230227 if (p -> next == keyhead )
231228 Py_FatalError ("tls find_key: circular list(!)" );
232229 }
233- if (! update && value == NULL ) {
230+ if (value == NULL ) {
234231 assert (p == NULL );
235232 goto Done ;
236233 }
@@ -282,12 +279,19 @@ PyThread_delete_key(int key)
282279 PyThread_release_lock (keymutex );
283280}
284281
282+ /* Confusing: If the current thread has an association for key,
283+ * value is ignored, and 0 is returned. Else an attempt is made to create
284+ * an association of key to value for the current thread. 0 is returned
285+ * if that succeeds, but -1 is returned if there's not enough memory
286+ * to create the association. value must not be NULL.
287+ */
285288int
286289PyThread_set_key_value (int key , void * value )
287290{
288291 struct key * p ;
289292
290- p = find_key (key , 1 , value );
293+ assert (value != NULL );
294+ p = find_key (key , value );
291295 if (p == NULL )
292296 return -1 ;
293297 else
@@ -300,7 +304,7 @@ PyThread_set_key_value(int key, void *value)
300304void *
301305PyThread_get_key_value (int key )
302306{
303- struct key * p = find_key (key , 0 , NULL );
307+ struct key * p = find_key (key , NULL );
304308
305309 if (p == NULL )
306310 return NULL ;
0 commit comments