/* Calls the given function for each data element of the datalist. The function is called with each data element's #GQuark id and data, together with the given @user_data parameter. Note that this function is NOT thread-safe. So unless @datalist can be protected from any modifications during invocation of this function, it should not be called.  */
void g_datalist_foreach(GData **datalist, GDataForeachFunc func, gpointer user_data)
/* Calls the given function for each data element of the datalist. The function is called with each data element's #GQuark id and data, together with the given @user_data parameter. Note that this function is NOT thread-safe. So unless @datalist can be protected from any modifications during invocation of this function, it should not be called.  */
void g_datalist_foreach(GData **datalist, GDataForeachFunc func, gpointer user_data)
{
  GData *d;
  int i, j, len;
  GQuark *keys;
  g_return_if_fail (datalist != NULL);
  g_return_if_fail (func != NULL);
  d = G_DATALIST_GET_POINTER (datalist);
  if (d == NULL) 
    return;
  len = d->len;
  keys = g_new (GQuark, len);
  for (i = 0; i < len; i++)
    keys[i] = d->data[i].key;
  for (i = 0; i < len; i++)
    {
      d = G_DATALIST_GET_POINTER (datalist);
      if (d == NULL)
	break;
      for (j = 0; j < d->len; j++)
	{
	  if (d->data[j].key == keys[i]) {
	    func (d->data[i].key, d->data[i].data, user_data);
	    break;
	  }
	}
    }
  g_free (keys);
}