+2001-08-15 Gary V. Vaughan <gary@gnu.org>
+
+ * 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.
+
2001-08-14 Gary V. Vaughan <gary@gnu.org>
* libltdl/ltdl.c (lt_dlcaller_register): Caller ids are allocated
return result;
}
-#define N_ELEMENTS(a) (sizeof(a) / sizeof(*(a)))
-
lt_ptr
lt_dlcaller_set_data (key, handle, data)
lt_dlcaller_id key;
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)
{
}
/* 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)
{
/* 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;
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)
{