Change use of CRYPTO_THREADID so that we always use both the ulong and
authorBodo Möller <bodo@openssl.org>
Mon, 19 May 2008 20:45:25 +0000 (20:45 +0000)
committerBodo Möller <bodo@openssl.org>
Mon, 19 May 2008 20:45:25 +0000 (20:45 +0000)
ptr members.

(So if the id_callback is bogus, we still have &errno.)

CHANGES
crypto/cryptlib.c
crypto/crypto.h

diff --git a/CHANGES b/CHANGES
index cf5c17cfcaeb7a2bb726d7471a6ecd136f3a5f76..2f26937ebddace2ef1beebd69ea1d4b1373ec9bd 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,7 +4,12 @@
 
  Changes between 0.9.8g and 0.9.9  [xx XXX xxxx]
 
-  *) To support arbitrarily-typed thread IDs, deprecate the existing
+  *) Not all of this is true any longer.
+     Will have to be updated to reflect all subsequent changes to cryptlib.c.
+                                                                       --bodo
+
+
+     To support arbitrarily-typed thread IDs, deprecate the existing
      type-specific APIs for a general purpose CRYPTO_THREADID
      interface. Applications can choose the thread ID
      callback type it wishes to register, as before;
index 73bdfd8ce9f8f2afc00e7542b84818c51cdcbe99..cb858d551985d4783ebc481c53fa3281a5121f5c 100644 (file)
@@ -434,29 +434,30 @@ void CRYPTO_set_idptr_callback(void *(*func)(void))
 
 void CRYPTO_THREADID_set(CRYPTO_THREADID *id)
        {
-       memset(id, 0, sizeof(*id));
+       if (id_callback)
+               id->ulong = id_callback();
+       else
+               id->ulong = 0;
+
        if (idptr_callback)
                id->ptr = idptr_callback();
-       else if (id_callback)
-               id->ulong = id_callback();
        else
                id->ptr = &errno;
        }
 
 int CRYPTO_THREADID_cmp(const CRYPTO_THREADID *id1, const CRYPTO_THREADID *id2)
        {
+       if (id1->ulong != id2->ulong)
+               return ((id1->ulong < id2->ulong) ? -1 : 1);
        if (id1->ptr != id2->ptr)
                return ((id1->ptr < id2->ptr) ? -1 : 1);
-       if (id1->ulong != id2->ulong)
-               return ((id1->ulong < id2->ulong ) ? -1 : 1);
        return 0;
        }
 
 unsigned long CRYPTO_THREADID_hash(const CRYPTO_THREADID *id)
        {
-       if (idptr_callback || !id_callback)
-               return (unsigned long)id->ptr;
-       return id->ulong;
+       /* will need further processing to arrive at a good hash (mem_dbg.c uses this) */
+       return id->ulong + (unsigned long)id->ptr;
        }
 
 void CRYPTO_THREADID_cpy(CRYPTO_THREADID *dst, const CRYPTO_THREADID *src)
index bb9b89c6a5e89f700693529d51ca0d72ae328252..437ed63df19054e94a66f2513a4b633cf3461a7b 100644 (file)
@@ -307,8 +307,8 @@ DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS)
  * apart when someone decides to extend this in some way. */
 typedef struct crypto_threadid
        {
-       void *ptr;
        unsigned long ulong;
+       void *ptr;
        } CRYPTO_THREADID;
 
 /* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA