Skip to content

Commit 56e8c08

Browse files
authored
Merge pull request #11061 from jywangx/fix_for_issue#11058
opal/list: Fix the bug in function opal_list_insert
2 parents 8113e7c + aaf4363 commit 56e8c08

File tree

4 files changed

+1
-103
lines changed

4 files changed

+1
-103
lines changed

contrib/check_unnecessary_headers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ SEARCH_HEADER[2]="opal/class/opal_bitmap.h opal_bitmap_t opal_bitmap_set_max_siz
8989
SEARCH_HEADER[3]="opal/class/opal_free_list.h opal_free_list_t opal_free_list_item_t opal_free_list_init opal_free_list_grow OPAL_FREE_LIST_GET OPAL_FREE_LIST_WAIT OPAL_FREE_LIST_RETURN"
9090
SEARCH_HEADER[4]="opal/class/opal_graph.h opal_graph_vertex_t opal_graph_edge_t opal_adjacency_list_t opal_graph_t opal_graph_copy_vertex_data opal_graph_free_vertex_data opal_graph_alloc_vertex_data vertex_distance_from_t opal_graph_add_vertex opal_graph_remove_vertex opal_graph_add_edge opal_graph_remove_edge opal_graph_adjacent opal_graph_get_order opal_graph_get_size opal_graph_find_vertex opal_graph_get_graph_vertices opal_graph_get_adjacent_vertices opal_graph_duplicate opal_graph_spf opal_graph_dijkstra opal_graph_print"
9191
SEARCH_HEADER[5]="opal/class/opal_hash_table.h opal_hash_table_t opal_hash_table_init opal_hash_table_get_size opal_hash_table_remove_all opal_hash_table_get_value_uint32 opal_hash_table_set_value_uint32 opal_hash_table_remove_value_uint32 opal_hash_table_get_value_uint64 opal_hash_table_set_value_uint64 opal_hash_table_remove_value_uint64 opal_hash_table_get_value_ptr opal_hash_table_set_value_ptr opal_hash_table_remove_value_ptr opal_hash_table_get_first_key_uint32 opal_hash_table_get_next_key_uint32 opal_hash_table_get_first_key_uint64 opal_hash_table_get_next_key_uint64"
92-
SEARCH_HEADER[6]="opal/class/opal_list.h opal_list_t opal_list_item_t opal_list_get_next opal_list_get_prev opal_list_is_empty opal_list_get_first opal_list_get_last opal_list_get_begin opal_list_get_end opal_list_get_size opal_list_remove_item opal_list_append opal_list_prepend opal_list_remove_first opal_list_remove_last opal_list_insert_pos opal_list_insert opal_list_join opal_list_splice opal_list_sort opal_list_item_compare_fn_t"
92+
SEARCH_HEADER[6]="opal/class/opal_list.h opal_list_t opal_list_item_t opal_list_get_next opal_list_get_prev opal_list_is_empty opal_list_get_first opal_list_get_last opal_list_get_begin opal_list_get_end opal_list_get_size opal_list_remove_item opal_list_append opal_list_prepend opal_list_remove_first opal_list_remove_last opal_list_insert_pos opal_list_join opal_list_splice opal_list_sort opal_list_item_compare_fn_t"
9393
SEARCH_HEADER[7]="opal/class/opal_object.h opal_object_t opal_class_t opal_construct_t opal_destruct_t OPAL_OBJ_STATIC_INIT OBJ_CLASS OBJ_CLASS_INSTANCE OBJ_CLASS_DECLARATION OBJ_NEW OBJ_RETAIN OBJ_RELEASE OBJ_CONSTRUCT OBJ_DESTRUCT opal_class_initialize opal_class_finalize opal_obj_run_constructors opal_obj_run_destructors opal_obj_new opal_obj_update"
9494
SEARCH_HEADER[8]="opal/class/opal_pointer_array.h opal_pointer_array_t opal_pointer_array_init opal_pointer_array_add opal_pointer_array_set_item opal_pointer_array_get_item opal_pointer_array_get_size opal_pointer_array_set_size opal_pointer_array_test_and_set_item opal_pointer_array_remove_all"
9595
SEARCH_HEADER[9]="opal/class/opal_value_array.h opal_value_array_t opal_value_array_init opal_value_array_reserve opal_value_array_get_size opal_value_array_set_size OPAL_VALUE_ARRAY_GET_ITEM opal_value_array_get_item OPAL_VALUE_ARRAY_SET_ITEM opal_value_array_set_item opal_value_array_append_item opal_value_array_remove_item OPAL_VALUE_ARRAY_GET_BASE"

opal/class/opal_list.c

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -93,54 +93,6 @@ static void opal_list_destruct(opal_list_t *list)
9393
opal_list_construct(list);
9494
}
9595

96-
/*
97-
* Insert an item at a specific place in a list
98-
*/
99-
bool opal_list_insert(opal_list_t *list, opal_list_item_t *item, long long idx)
100-
{
101-
/* Adds item to list at index and retains item. */
102-
int i;
103-
volatile opal_list_item_t *ptr, *next;
104-
105-
if (idx >= (long long) list->opal_list_length) {
106-
return false;
107-
}
108-
109-
if (0 == idx) {
110-
opal_list_prepend(list, item);
111-
} else {
112-
#if OPAL_ENABLE_DEBUG
113-
/* Spot check: ensure that this item is previously on no
114-
lists */
115-
116-
assert(0 == item->opal_list_item_refcount);
117-
#endif
118-
/* pointer to element 0 */
119-
ptr = list->opal_list_sentinel.opal_list_next;
120-
for (i = 0; i < idx - 1; i++) {
121-
ptr = ptr->opal_list_next;
122-
}
123-
124-
next = ptr->opal_list_next;
125-
item->opal_list_next = next;
126-
item->opal_list_prev = ptr;
127-
next->opal_list_prev = item;
128-
ptr->opal_list_next = item;
129-
130-
#if OPAL_ENABLE_DEBUG
131-
/* Spot check: ensure this item is only on the list that we
132-
just inserted it into */
133-
134-
opal_atomic_add(&(item->opal_list_item_refcount), 1);
135-
assert(1 == item->opal_list_item_refcount);
136-
item->opal_list_item_belong_to = list;
137-
#endif
138-
}
139-
140-
list->opal_list_length++;
141-
return true;
142-
}
143-
14496
static void opal_list_transfer(opal_list_item_t *pos, opal_list_item_t *begin,
14597
opal_list_item_t *end)
14698
{

opal/class/opal_list.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -783,26 +783,6 @@ static inline void opal_list_insert_pos(opal_list_t *list, opal_list_item_t *pos
783783
#endif
784784
}
785785

786-
/**
787-
* Add an item to the list at a specific index location in the list.
788-
*
789-
* @param list The list container
790-
* @param item The item to insert
791-
* @param index Location to add the item
792-
*
793-
* @returns true if insertion succeeded; otherwise false
794-
*
795-
* This is potentially an O(N) operation to traverse down to the
796-
* correct location in the list and add an item.
797-
*
798-
* Example: if idx = 2 and list = item1->item2->item3->item4, then
799-
* after insert, list = item1->item2->item->item3->item4.
800-
*
801-
* If index is greater than the length of the list, no action is
802-
* performed and false is returned.
803-
*/
804-
OPAL_DECLSPEC bool opal_list_insert(opal_list_t *list, opal_list_item_t *item, long long idx);
805-
806786
/**
807787
* Join a list into another list
808788
*

test/class/opal_list.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -276,40 +276,6 @@ int main(int argc, char **argv)
276276
test_failure(" error in opal_list_remove - list size changed incorrectly");
277277
}
278278

279-
/* test the insert function */
280-
i = opal_list_insert(&list, (opal_list_item_t *) (elements + indx), indx);
281-
if (1 == i) {
282-
test_success();
283-
} else {
284-
test_failure(" error in opal_list_remove_item \n");
285-
}
286-
287-
i = 0;
288-
for (ele = (test_data_t *) opal_list_get_first(&list);
289-
ele != (test_data_t *) opal_list_get_end(&list);
290-
ele = (test_data_t *) ((opal_list_item_t *) ele)->opal_list_next) {
291-
i++;
292-
}
293-
if (size_elements == i) {
294-
test_success();
295-
} else {
296-
test_failure(" error in opal_list_insert - incorrect list length");
297-
}
298-
i = 0;
299-
error_cnt = 0;
300-
for (ele = (test_data_t *) opal_list_get_first(&list);
301-
ele != (test_data_t *) opal_list_get_end(&list);
302-
ele = (test_data_t *) ((opal_list_item_t *) ele)->opal_list_next) {
303-
if (ele->data != i)
304-
error_cnt++;
305-
i++;
306-
}
307-
if (0 == error_cnt) {
308-
test_success();
309-
} else {
310-
test_failure(" error in list order - opal_list_remove_item ");
311-
}
312-
313279
/* test the splice and join functions */
314280
list_size = opal_list_get_size(&list);
315281
for (i = 0, item = opal_list_get_first(&list); i < list_size / 2;

0 commit comments

Comments
 (0)