Index: ChangeLog 2001-08-15 Gary V. Vaughan * libltdl/ltdl.c (N_ELEMENTS): Deleted. How come nobody noticed there was no way this could have ever worked? (lt_dlcaller_set_data): Now that valid caller_ids must be non-zero, allocate an addition entry in the caller_data vector and use a zero valued key as the end marker. (lt_dlcaller_get_data): Iterate up to the end marker in one pass. Index: libltdl/ltdl.c =================================================================== RCS file: /cvsroot/libtool/libtool/libltdl/ltdl.c,v retrieving revision 1.148 diff -b -u -r1.148 ltdl.c --- libltdl/ltdl.c 2001/08/14 22:45:21 1.148 +++ libltdl/ltdl.c 2001/08/14 23:25:09 @@ -3548,8 +3548,6 @@ return result; } -#define N_ELEMENTS(a) (sizeof(a) / sizeof(*(a))) - lt_ptr lt_dlcaller_set_data (key, handle, data) lt_dlcaller_id key; @@ -3565,7 +3563,8 @@ LT_DLMUTEX_LOCK (); if (handle->caller_data) - n_elements = N_ELEMENTS (handle->caller_data); + while (handle->caller_data[n_elements].key) + ++n_elements; for (i = 0; i < n_elements; ++i) { @@ -3577,11 +3576,11 @@ } /* Ensure that there is enough room in this handle's caller_data - array to accept a new element. */ + array to accept a new element (and an empty end marker). */ if (i == n_elements) { lt_caller_data *temp - = LT_DLREALLOC (lt_caller_data, handle->caller_data, 1+ n_elements); + = LT_DLREALLOC (lt_caller_data, handle->caller_data, 2+ n_elements); if (!temp) { @@ -3593,6 +3592,7 @@ /* We only need this if we needed to allocate a new caller_data. */ handle->caller_data[i].key = key; + handle->caller_data[1+ i].key = 0; } handle->caller_data[i].data = data; @@ -3609,19 +3609,15 @@ lt_dlhandle handle; { lt_ptr result = (lt_ptr) 0; - int n_elements = 0; /* This needs to be locked so that the caller data isn't updated by another thread part way through this function. */ LT_DLMUTEX_LOCK (); - if (handle->caller_data) - n_elements = N_ELEMENTS (handle->caller_data); - /* Locate the index of the element with a matching KEY. */ { int i; - for (i = 0; i < n_elements; ++i) + for (i = 0; handle->caller_data[i].key; ++i) { if (handle->caller_data[i].key == key) {