linked-list: invoke_offset() doesn't take any additional arguments anymore

This commit is contained in:
Tobias Brunner
2017-05-26 13:56:44 +02:00
parent 525cc46cab
commit 5cafea6edd
3 changed files with 16 additions and 18 deletions
+4 -5
View File
@@ -394,16 +394,15 @@ METHOD(linked_list_t, find_first, status_t,
} }
METHOD(linked_list_t, invoke_offset, void, METHOD(linked_list_t, invoke_offset, void,
private_linked_list_t *this, size_t offset, private_linked_list_t *this, size_t offset)
void *d1, void *d2, void *d3, void *d4, void *d5)
{ {
element_t *current = this->first; element_t *current = this->first;
linked_list_invoke_t *method; void (**method)(void*);
while (current) while (current)
{ {
method = current->value + offset; method = current->value + offset;
(*method)(current->value, d1, d2, d3, d4, d5); (*method)(current->value);
current = current->next; current = current->next;
} }
} }
@@ -555,7 +554,7 @@ linked_list_t *linked_list_create()
.remove_last = _remove_last, .remove_last = _remove_last,
.remove = _remove_, .remove = _remove_,
.remove_at = (void*)_remove_at, .remove_at = (void*)_remove_at,
.invoke_offset = (void*)_invoke_offset, .invoke_offset = _invoke_offset,
.invoke_function = (void*)_invoke_function, .invoke_function = (void*)_invoke_function,
.clone_offset = _clone_offset, .clone_offset = _clone_offset,
.equals_offset = _equals_offset, .equals_offset = _equals_offset,
+1 -4
View File
@@ -192,12 +192,9 @@ struct linked_list_t {
* which can be evalutated at compile time using the offsetof * which can be evalutated at compile time using the offsetof
* macro, e.g.: list->invoke(list, offsetof(object_t, method)); * macro, e.g.: list->invoke(list, offsetof(object_t, method));
* *
* @warning Only use pointers as user supplied data.
*
* @param offset offset of the method to invoke on objects * @param offset offset of the method to invoke on objects
* @param ... user data to supply to called function (limited to 5 arguments)
*/ */
void (*invoke_offset) (linked_list_t *this, size_t offset, ...); void (*invoke_offset)(linked_list_t *this, size_t offset);
/** /**
* Invoke a function on all of the contained objects. * Invoke a function on all of the contained objects.
@@ -241,7 +241,7 @@ typedef struct invoke_t invoke_t;
struct invoke_t { struct invoke_t {
int val; int val;
void (*invoke)(invoke_t *item, void *a, void *b, void *c, void *d, int *sum); void (*invoke)(invoke_t *item);
}; };
static void invoke(intptr_t item, void *a, void *b, void *c, void *d, int *sum) static void invoke(intptr_t item, void *a, void *b, void *c, void *d, int *sum)
@@ -253,9 +253,9 @@ static void invoke(intptr_t item, void *a, void *b, void *c, void *d, int *sum)
*sum += item; *sum += item;
} }
static void invoke_offset(invoke_t *item, void *a, void *b, void *c, void *d, int *sum) static void invoke_offset(invoke_t *item)
{ {
invoke(item->val, a, b, c, d, sum); item->val++;
} }
START_TEST(test_invoke_function) START_TEST(test_invoke_function)
@@ -282,17 +282,19 @@ START_TEST(test_invoke_offset)
{ .val = 3, .invoke = invoke_offset, }, { .val = 3, .invoke = invoke_offset, },
{ .val = 4, .invoke = invoke_offset, }, { .val = 4, .invoke = invoke_offset, },
{ .val = 5, .invoke = invoke_offset, }, { .val = 5, .invoke = invoke_offset, },
}; }, *item;
int i, sum = 0; int i;
for (i = 0; i < countof(items); i++) for (i = 0; i < countof(items); i++)
{ {
list->insert_last(list, &items[i]); list->insert_last(list, &items[i]);
} }
list->invoke_offset(list, offsetof(invoke_t, invoke), list->invoke_offset(list, offsetof(invoke_t, invoke));
(uintptr_t)1, (uintptr_t)2, i = 2;
(uintptr_t)3, (uintptr_t)4, &sum); while (list->remove_first(list, (void**)&item) == SUCCESS)
ck_assert_int_eq(sum, 15); {
ck_assert_int_eq(item->val, i++);
}
} }
END_TEST END_TEST