On Friday 21 November 2008 03:01:33 Massimiliano Pala wrote: > Hi David, > > that is really nice.. although.. after I gave it a try... it does not > really work :( > > Actually, it seems that the dynamic functions are never called... :( > > Investigating...
The attached example seems to work. I put it in the top-level directory of the (built) openssl tree and compiled with; gcc -Wall -Iinclude -o foobar foobar.c -L. -lcrypto The output shows that dynamic lockids are negative; About to test Created lock 'dyn_lck.c:257' Created lock 'dyn_lck.c:257' Got new locks -1, -2 Doing mode 9 lock on 'dyn_lck.c:257' from foobar.c:47 Locked the lock Doing mode 10 lock on 'dyn_lck.c:257' from foobar.c:49 Unlocked the lock Destroying lock 'dyn_lck.c:257' from dyn_lck.c:329 Destroying lock 'dyn_lck.c:257' from dyn_lck.c:329 Destroyed the locks, DONE Perhaps that'll help distinguish what's going on in your code? Cheers, Geoff -- Un terrien, c'est un singe avec des clefs de char...
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <openssl/crypto.h> struct CRYPTO_dynlock_value; static struct CRYPTO_dynlock_value *l_create(const char *f, int l) { char *foo = malloc(256); if (!foo) return NULL; snprintf(foo, 255, "%s:%d", f, l); printf("Created lock '%s'\n", foo); return (void *)foo; } static void l_lock(int mode, struct CRYPTO_dynlock_value *v, const char *f, int l) { char *foo = (char *)v; printf("Doing mode %d lock on '%s' from %s:%d\n", mode, foo, f, l); } static void l_destroy(struct CRYPTO_dynlock_value *v, const char *f, int l) { char *foo = (char *)v; printf("Destroying lock '%s' from %s:%d\n", foo, f, l); free(foo); } int main(int argc, char *argv[]) { int lock, lock2; CRYPTO_set_dynlock_create_callback(l_create); CRYPTO_set_dynlock_lock_callback(l_lock); CRYPTO_set_dynlock_destroy_callback(l_destroy); printf("About to test\n"); lock = CRYPTO_get_new_dynlockid(); lock2 = CRYPTO_get_new_dynlockid(); printf("Got new locks %d, %d\n", lock, lock2); CRYPTO_w_lock(lock); printf("Locked the lock\n"); CRYPTO_w_unlock(lock); printf("Unlocked the lock\n"); CRYPTO_destroy_dynlockid(lock); CRYPTO_destroy_dynlockid(lock2); printf("Destroyed the locks, DONE\n"); return 0; }