/* Returns: (transfer none): the source, if one was found, otherwise NULL  */
GSource* g_main_context_find_source_by_funcs_user_data(GMainContext *context, GSourceFuncs *funcs, gpointer user_data)
/* Returns: (transfer none): the source, if one was found, otherwise NULL  */
GSource* g_main_context_find_source_by_funcs_user_data(GMainContext *context, GSourceFuncs *funcs, gpointer user_data)
{
  GSourceIter iter;
  GSource *source;
  g_return_val_if_fail (funcs != NULL, NULL);
  if (context == NULL)
    context = g_main_context_default ();
  LOCK_CONTEXT (context);
  g_source_iter_init (&iter, context, FALSE);
  while (g_source_iter_next (&iter, &source))
    {
      if (!SOURCE_DESTROYED (source) &&
	  source->source_funcs == funcs &&
	  source->callback_funcs)
	{
	  GSourceFunc callback;
	  gpointer callback_data;
	  source->callback_funcs->get (source->callback_data, source, &callback, &callback_data);
	  if (callback_data == user_data)
	    break;
	}
    }
  g_source_iter_clear (&iter);
  UNLOCK_CONTEXT (context);
  return source;
}