There are two problems with list_remove_elem function in objc/objc-list.h file: - function dumps core when remove first element of the list, - if element is in the list more than once and copy of the element are one by one they do not be removed all. struct objc_list *list = 0; int elem_1 = 1; int elem_2 = 2; int elem_3 = 3; list = list_cons((void *)&elem_1, list); list = list_cons((void *)&elem_2, list); list = list_cons((void *)&elem_2, list); list = list_cons((void *)&elem_2, list); list = list_cons((void *)&elem_3, list); list_remove_elem(&list, (void *)&elem_2); // Remove only 2 elem_2! list_remove_elem(&list, (void *)&elem_1); // Core dumps! After list_remove_head should have not changed pointer to tail. The following patch repair both problems. --- /usr/include/objc/objc-list.h 2006-04-20 11:55:22.000000000 +0200 +++ objc-list.h 2009-01-16 21:05:04.000000000 +0100 @@ -106,7 +106,11 @@ { while (*list) { if ((*list)->head == elem) - list_remove_head(list); + { + list_remove_head(list); + continue; + } + list = &((*list)->tail); } }
Thanks well spotted :-) Unfortunately, the list_remove_elem() function is obsolete (never used inside the runtime itself, and deprecated for usage outside of it as of 4.6.0) so there is not much point in working on it any more. ;-) Thanks