Define a STORE lock (the STORE type will be committed later).
[openssl.git] / crypto / cryptlib.c
index 26c1da7074f985802a3192827d7ce227b6aae1e7..9c38f15ab2b97c81f2da56b3a3f1755472074a08 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/cryptlib.c */
 /* ====================================================================
- * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2003 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -166,7 +166,9 @@ static const char* lock_names[CRYPTO_NUM_LOCKS] =
        "ec",
        "ecdh",
        "bn",
-#if CRYPTO_NUM_LOCKS != 36
+       "ec_pre_comp",
+       "store",
+#if CRYPTO_NUM_LOCKS != 38
 # error "Inconsistency between crypto.h and cryptlib.c"
 #endif
        };
@@ -269,10 +271,18 @@ int CRYPTO_get_new_dynlockid(void)
        i=sk_CRYPTO_dynlock_find(dyn_locks,NULL);
        /* If there was none, push, thereby creating a new one */
        if (i == -1)
-               i=sk_CRYPTO_dynlock_push(dyn_locks,pointer);
+               /* Since sk_push() returns the number of items on the
+                  stack, not the location of the pushed item, we need
+                  to transform the returned number into a position,
+                  by decreasing it.  */
+               i=sk_CRYPTO_dynlock_push(dyn_locks,pointer) - 1;
+       else
+               /* If we found a place with a NULL pointer, put our pointer
+                  in it.  */
+               sk_CRYPTO_dynlock_set(dyn_locks,i,pointer);
        CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
 
-       if (!i)
+       if (i == -1)
                {
                dynlock_destroy_callback(pointer->data,__FILE__,__LINE__);
                OPENSSL_free(pointer);
@@ -464,15 +474,17 @@ void CRYPTO_lock(int mode, int type, const char *file, int line)
 #endif
        if (type < 0)
                {
-               struct CRYPTO_dynlock_value *pointer
-                       = CRYPTO_get_dynlock_value(type);
-
-               if (pointer && dynlock_lock_callback)
+               if (dynlock_lock_callback != NULL)
                        {
+                       struct CRYPTO_dynlock_value *pointer
+                               = CRYPTO_get_dynlock_value(type);
+
+                       OPENSSL_assert(pointer != NULL);
+
                        dynlock_lock_callback(mode, pointer, file, line);
-                       }
 
-               CRYPTO_destroy_dynlockid(type);
+                       CRYPTO_destroy_dynlockid(type);
+                       }
                }
        else
                if (locking_callback != NULL)
@@ -555,3 +567,11 @@ BOOL WINAPI DLLEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason,
 #endif
 
 #endif
+
+void OpenSSLDie(const char *file,int line,const char *assertion)
+       {
+       fprintf(stderr,
+               "%s(%d): OpenSSL internal error, assertion failed: %s\n",
+               file,line,assertion);
+       abort();
+       }