Fixed a really lame error where g_slist_insert didn't hook the data

in! Reworked the routine a bit too.

-Yosh
This commit is contained in:
Manish Singh 1998-01-27 09:42:41 +00:00
parent 3cefe524dc
commit 8f355e26ef
2 changed files with 30 additions and 20 deletions

View File

@ -1,3 +1,9 @@
Tue Jan 27 01:38:52 PST 1998 Manish Singh <yosh@gimp.org>
* gslist.c: fixed a really, really lame error. g_slist_insert
didn't hook the data in! Reworked the routine to reflect the
functionality of g_list
Wed Jan 21 01:13:25 1998 Tim Janik <timj@psynet.net>
* Applied patch from (Raja R Harinath <harinath@cs.umn.edu>)

View File

@ -110,18 +110,16 @@ g_slist_append (GSList *list,
new_list = g_slist_alloc ();
new_list->data = data;
if (!list)
{
list = new_list;
}
else
if (list)
{
last = g_slist_last (list);
g_assert (last != NULL);
/* g_assert (last != NULL); */
last->next = new_list;
}
return list;
return list;
}
else
return new_list;
}
GSList*
@ -146,30 +144,36 @@ g_slist_insert (GSList *list,
GSList *tmp_list;
GSList *new_list;
if (position < 0)
return g_slist_append (list, data);
else if (position == 0)
return g_slist_prepend (list, data);
new_list = g_slist_alloc ();
new_list->data = data;
if (!list)
return new_list;
prev_list = NULL;
tmp_list = list;
while (tmp_list && (position-- > 0))
while ((position-- > 0) && tmp_list)
{
prev_list = tmp_list;
tmp_list = tmp_list->next;
}
if (!tmp_list && !prev_list)
return list;
new_list = g_slist_alloc ();
if (!prev_list)
{
new_list->next = list;
list = new_list;
}
else
if (prev_list)
{
new_list->next = prev_list->next;
prev_list->next = new_list;
}
else
{
new_list->next = list;
list = new_list;
}
return list;
}