linked-list: Change interface of callback for invoke_function()

This avoids the unportable five pointer hack.
This commit is contained in:
Tobias Brunner
2017-05-26 13:56:44 +02:00
parent 5cafea6edd
commit 8a2e4d4a8b
9 changed files with 98 additions and 54 deletions
+6 -4
View File
@@ -408,14 +408,16 @@ METHOD(linked_list_t, invoke_offset, void,
}
METHOD(linked_list_t, invoke_function, void,
private_linked_list_t *this, linked_list_invoke_t fn,
void *d1, void *d2, void *d3, void *d4, void *d5)
private_linked_list_t *this, linked_list_invoke_t fn, ...)
{
element_t *current = this->first;
va_list args;
while (current)
{
fn(current->value, d1, d2, d3, d4, d5);
va_start(args, fn);
fn(current->value, args);
va_end(args);
current = current->next;
}
}
@@ -555,7 +557,7 @@ linked_list_t *linked_list_create()
.remove = _remove_,
.remove_at = (void*)_remove_at,
.invoke_offset = _invoke_offset,
.invoke_function = (void*)_invoke_function,
.invoke_function = _invoke_function,
.clone_offset = _clone_offset,
.equals_offset = _equals_offset,
.equals_function = _equals_function,
+8 -9
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2007-2015 Tobias Brunner
* Copyright (C) 2007-2017 Tobias Brunner
* Copyright (C) 2005-2008 Martin Willi
* Copyright (C) 2005 Jan Hutter
* Hochschule fuer Technik Rapperswil
@@ -39,12 +39,12 @@ typedef struct linked_list_t linked_list_t;
typedef bool (*linked_list_match_t)(void *item, ...);
/**
* Method to be invoked on elements in a linked list (used in invoke_* functions)
* Function to be invoked on elements in a linked list
*
* @param item current list item
* @param ... user supplied data (only pointers, at most 5)
* @param args user supplied data
*/
typedef void (*linked_list_invoke_t)(void *item, ...);
typedef void (*linked_list_invoke_t)(void *item, va_list args);
/**
* Class implementing a double linked list.
@@ -199,12 +199,11 @@ struct linked_list_t {
/**
* Invoke a function on all of the contained objects.
*
* @warning Only use pointers as user supplied data.
*
* @param function offset of the method to invoke on objects
* @param ... user data to supply to called function (limited to 5 arguments)
* @param function function to call for each object
* @param ... user data to supply to called function
*/
void (*invoke_function) (linked_list_t *this, linked_list_invoke_t function, ...);
void (*invoke_function)(linked_list_t *this, linked_list_invoke_t function,
...);
/**
* Clones a list and its objects using the objects' clone method.