Add G_GNUC_DEPRECATED to deprecated functions in gobject
[platform/upstream/glib.git] / gobject / gsignal.c
index a5d35eb..98534be 100644 (file)
 #include <signal.h>
 
 #include "gsignal.h"
+#include "gtype-private.h"
 #include "gbsearcharray.h"
 #include "gvaluecollector.h"
 #include "gvaluetypes.h"
-#include "gboxed.h"
 #include "gobject.h"
 #include "genums.h"
-#include "gobjectalias.h"
+#include "gobject_trace.h"
 
 
 /**
@@ -765,7 +765,7 @@ signal_key_cmp (gconstpointer node1,
 }
 
 void
-g_signal_init (void)
+_g_signal_init (void)
 {
   SIGNAL_LOCK ();
   if (!g_n_signal_nodes)
@@ -1017,8 +1017,8 @@ signal_parse_name (const gchar *name,
  * g_signal_parse_name:
  * @detailed_signal: a string of the form "signal-name::detail".
  * @itype: The interface/instance type that introduced "signal-name".
- * @signal_id_p: Location to store the signal id.
- * @detail_p: Location to store the detail quark.
+ * @signal_id_p: (out): Location to store the signal id.
+ * @detail_p: (out): Location to store the detail quark.
  * @force_detail_quark: %TRUE forces creation of a #GQuark for the detail.
  *
  * Internal function to parse a signal name into its @signal_id
@@ -1164,7 +1164,7 @@ g_signal_lookup (const gchar *name,
  * created. Further information about the signals can be acquired through
  * g_signal_query().
  *
- * Returns: Newly allocated array of signal IDs.
+ * Returns: (array length=n_ids): Newly allocated array of signal IDs.
  */
 guint*
 g_signal_list_ids (GType  itype,
@@ -1223,7 +1223,7 @@ g_signal_list_ids (GType  itype,
  *
  * Returns: the signal name, or %NULL if the signal number was invalid.
  */
-G_CONST_RETURN gchar*
+const gchar *
 g_signal_name (guint signal_id)
 {
   SignalNode *node;
@@ -1240,8 +1240,8 @@ g_signal_name (guint signal_id)
 /**
  * g_signal_query:
  * @signal_id: The signal id of the signal to query information for.
- * @query: A user provided structure that is filled in with constant
- *  values upon success.
+ * @query: (out caller-allocates): A user provided structure that is
+ *  filled in with constant values upon success.
  *
  * Queries the signal system for in-depth information about a
  * specific signal. This function will fill in a user-provided
@@ -1288,8 +1288,8 @@ g_signal_query (guint         signal_id,
  *  not associate a class method slot with this signal.
  * @accumulator: the accumulator for this signal; may be %NULL.
  * @accu_data: user data for the @accumulator.
- * @c_marshaller: the function to translate arrays of parameter values to
- *  signal emissions into C language callback invocations.
+ * @c_marshaller: (allow-none): the function to translate arrays of parameter
+ *  values to signal emissions into C language callback invocations or %NULL.
  * @return_type: the type of return value, or #G_TYPE_NONE for a signal
  *  without a return value.
  * @n_params: the number of parameter types to follow.
@@ -1310,6 +1310,9 @@ g_signal_query (guint         signal_id,
  * <code>super_class->signal_handler = my_signal_handler</code>. Instead they
  * will have to use g_signal_override_class_handler().
  *
+ * If c_marshaller is %NULL, g_cclosure_marshal_generic() will be used as
+ * the marshaller for this signal.
+ *
  * Returns: the signal id
  */
 guint
@@ -1340,7 +1343,8 @@ g_signal_new (const gchar  *signal_name,
 
   /* optimize NOP emissions with NULL class handlers */
   if (signal_id && G_TYPE_IS_INSTANTIATABLE (itype) && return_type == G_TYPE_NONE &&
-      class_offset && class_offset < MAX_TEST_CLASS_OFFSET)
+      class_offset && class_offset < MAX_TEST_CLASS_OFFSET &&
+      ~signal_flags & G_SIGNAL_MUST_COLLECT)
     {
       SignalNode *node;
 
@@ -1366,8 +1370,8 @@ g_signal_new (const gchar  *signal_name,
  *  not associate a class method with this signal.
  * @accumulator: the accumulator for this signal; may be %NULL.
  * @accu_data: user data for the @accumulator.
- * @c_marshaller: the function to translate arrays of parameter values to
- *  signal emissions into C language callback invocations.
+ * @c_marshaller: (allow-none): the function to translate arrays of parameter
+ *  values to signal emissions into C language callback invocations or %NULL.
  * @return_type: the type of return value, or #G_TYPE_NONE for a signal
  *  without a return value.
  * @n_params: the number of parameter types to follow.
@@ -1387,6 +1391,9 @@ g_signal_new (const gchar  *signal_name,
  *
  * See g_signal_new() for information about signal names.
  *
+ * If c_marshaller is %NULL @g_cclosure_marshal_generic will be used as
+ * the marshaller for this signal.
+ *
  * Returns: the signal id
  *
  * Since: 2.18
@@ -1492,20 +1499,26 @@ signal_add_class_closure (SignalNode *node,
  * @signal_flags: a combination of #GSignalFlags specifying detail of when
  *     the default handler is to be invoked. You should at least specify
  *     %G_SIGNAL_RUN_FIRST or %G_SIGNAL_RUN_LAST
- * @class_closure: The closure to invoke on signal emission; may be %NULL
- * @accumulator: the accumulator for this signal; may be %NULL
+ * @class_closure: (allow-none): The closure to invoke on signal emission;
+ *     may be %NULL
+ * @accumulator: (allow-none): the accumulator for this signal; may be %NULL
  * @accu_data: user data for the @accumulator
- * @c_marshaller: the function to translate arrays of parameter values to
- *     signal emissions into C language callback invocations
+ * @c_marshaller: (allow-none): the function to translate arrays of
+ *     parameter values to signal emissions into C language callback
+ *     invocations or %NULL
  * @return_type: the type of return value, or #G_TYPE_NONE for a signal
  *     without a return value
  * @n_params: the length of @param_types
- * @param_types: an array of types, one for each parameter
+ * @param_types: (array length=n_params): an array of types, one for
+ *     each parameter
  *
  * Creates a new signal. (This is usually done in the class initializer.)
  *
  * See g_signal_new() for details on allowed signal names.
  *
+ * If c_marshaller is %NULL @g_cclosure_marshal_generic will be used as
+ * the marshaller for this signal.
+ *
  * Returns: the signal id
  */
 guint
@@ -1608,6 +1621,8 @@ g_signal_newv (const gchar       *signal_name,
       node->name = g_intern_string (name);
       key.quark = g_quark_from_string (name);
       g_signal_key_bsa = g_bsearch_array_insert (g_signal_key_bsa, &g_signal_key_bconfig, &key);
+
+      TRACE(GOBJECT_SIGNAL_NEW(signal_id, name, itype));
     }
   node->destroyed = FALSE;
   node->test_class_offset = 0;
@@ -1626,11 +1641,15 @@ g_signal_newv (const gchar       *signal_name,
     }
   else
     node->accumulator = NULL;
+  if (c_marshaller == NULL)
+      c_marshaller = g_cclosure_marshal_generic;
   node->c_marshaller = c_marshaller;
   node->emission_hooks = NULL;
   if (class_closure)
     signal_add_class_closure (node, 0, class_closure);
-  else if (G_TYPE_IS_INSTANTIATABLE (itype) && return_type == G_TYPE_NONE)
+  else if (G_TYPE_IS_INSTANTIATABLE (itype) &&
+           return_type == G_TYPE_NONE &&
+           ~signal_flags & G_SIGNAL_MUST_COLLECT)
     {
       /* optimize NOP emissions */
       node->test_class_offset = TEST_CLASS_MAGIC;
@@ -1653,8 +1672,8 @@ g_signal_newv (const gchar       *signal_name,
  * @class_closure: The closure to invoke on signal emission; may be %NULL.
  * @accumulator: the accumulator for this signal; may be %NULL.
  * @accu_data: user data for the @accumulator.
- * @c_marshaller: the function to translate arrays of parameter values to
- *  signal emissions into C language callback invocations.
+ * @c_marshaller: (allow-none): the function to translate arrays of parameter
+ *  values to signal emissions into C language callback invocations or %NULL.
  * @return_type: the type of return value, or #G_TYPE_NONE for a signal
  *  without a return value.
  * @n_params: the number of parameter types in @args.
@@ -1664,6 +1683,9 @@ g_signal_newv (const gchar       *signal_name,
  *
  * See g_signal_new() for details on allowed signal names.
  *
+ * If c_marshaller is %NULL, g_cclosure_marshal_generic() will be used as
+ * the marshaller for this signal.
+ *
  * Returns: the signal id
  */
 guint
@@ -1838,9 +1860,9 @@ g_signal_override_class_handler (const gchar *signal_name,
 
 /**
  * g_signal_chain_from_overridden:
- * @instance_and_params: the argument list of the signal emission. The first
- *  element in the array is a #GValue for the instance the signal is being
- *  emitted on. The rest are any arguments to be passed to the signal.
+ * @instance_and_params: (array) the argument list of the signal emission.
+ *  The first element in the array is a #GValue for the instance the signal
+ *  is being emitted on. The rest are any arguments to be passed to the signal.
  * @return_value: Location for the return value.
  *
  * Calls the original class closure of a signal. This function should only
@@ -2054,7 +2076,7 @@ g_signal_chain_from_overridden_handler (gpointer instance,
               g_free (error);
 
               /* we purposely leak the value here, it might not be
-               * in a sane state if an error condition occured
+               * in a sane state if an error condition occurred
                */
             }
         }
@@ -2078,7 +2100,7 @@ g_signal_chain_from_overridden_handler (gpointer instance,
  *
  * Returns the invocation hint of the innermost signal emission of instance.
  *
- * Returns: the invocation hint of the innermost signal emission.
+ * Returns: (transfer none): the invocation hint of the innermost signal  emission.
  */
 GSignalInvocationHint*
 g_signal_get_invocation_hint (gpointer instance)
@@ -2466,7 +2488,7 @@ g_signal_handlers_destroy (gpointer instance)
  *  and/or @data the handler has to match.
  * @signal_id: Signal the handler has to be connected to.
  * @detail: Signal detail the handler has to be connected to.
- * @closure: The closure the handler will invoke.
+ * @closure: (allow-none): The closure the handler will invoke.
  * @func: The C closure callback of the handler (useless for non-C closures).
  * @data: The closure data of the handler's closure.
  *
@@ -2546,7 +2568,7 @@ signal_handlers_foreach_matched_R (gpointer         instance,
  *  and/or @data the handlers have to match.
  * @signal_id: Signal the handlers have to be connected to.
  * @detail: Signal detail the handlers have to be connected to.
- * @closure: The closure the handlers will invoke.
+ * @closure: (allow-none): The closure the handlers will invoke.
  * @func: The C closure callback of the handlers (useless for non-C closures).
  * @data: The closure data of the handlers' closures.
  *
@@ -2593,7 +2615,7 @@ g_signal_handlers_block_matched (gpointer         instance,
  *  and/or @data the handlers have to match.
  * @signal_id: Signal the handlers have to be connected to.
  * @detail: Signal detail the handlers have to be connected to.
- * @closure: The closure the handlers will invoke.
+ * @closure: (allow-none): The closure the handlers will invoke.
  * @func: The C closure callback of the handlers (useless for non-C closures).
  * @data: The closure data of the handlers' closures.
  *
@@ -2641,7 +2663,7 @@ g_signal_handlers_unblock_matched (gpointer         instance,
  *  and/or @data the handlers have to match.
  * @signal_id: Signal the handlers have to be connected to.
  * @detail: Signal detail the handlers have to be connected to.
- * @closure: The closure the handlers will invoke.
+ * @closure: (allow-none): The closure the handlers will invoke.
  * @func: The C closure callback of the handlers (useless for non-C closures).
  * @data: The closure data of the handlers' closures.
  *
@@ -2785,10 +2807,9 @@ signal_check_skip_emission (SignalNode *node,
 
 /**
  * g_signal_emitv:
- * @instance_and_params: argument list for the signal emission. The first
- *  element in the array is a #GValue for the instance the signal is
- *  being emitted on. The rest are any arguments to be passed to the
- *  signal.
+ * @instance_and_params: (array): argument list for the signal emission.
+ *  The first element in the array is a #GValue for the instance the signal
+ *  is being emitted on. The rest are any arguments to be passed to the signal.
  * @signal_id: the signal id
  * @detail: the detail
  * @return_value: Location to store the return value of the signal emission.
@@ -2911,7 +2932,7 @@ g_signal_emit_valist (gpointer instance,
   GValue *param_values;
   SignalNode *node;
   guint i, n_params;
-  
+
   g_return_if_fail (G_TYPE_CHECK_INSTANCE (instance));
   g_return_if_fail (signal_id > 0);
 
@@ -2974,6 +2995,7 @@ g_signal_emit_valist (gpointer instance,
       SIGNAL_LOCK ();
     }
   SIGNAL_UNLOCK ();
+
   instance_and_params->g_type = 0;
   g_value_init (instance_and_params, G_TYPE_FROM_INSTANCE (instance));
   g_value_set_instance (instance_and_params, instance);
@@ -3002,7 +3024,7 @@ g_signal_emit_valist (gpointer instance,
          g_free (error);
          
          /* we purposely leak the value here, it might not be
-          * in a sane state if an error condition occured
+          * in a sane state if an error condition occurred
           */
        }
     }
@@ -3124,7 +3146,9 @@ signal_emit_unlocked_R (SignalNode   *node,
        G_BREAKPOINT ();
     }
 #endif /* G_ENABLE_DEBUG */
-  
+
+  TRACE(GOBJECT_SIGNAL_EMIT(node->signal_id, detail, instance, G_TYPE_FROM_INSTANCE (instance)));
+
   SIGNAL_LOCK ();
   signal_id = node->signal_id;
   if (node->flags & G_SIGNAL_NO_RECURSE)
@@ -3382,7 +3406,9 @@ signal_emit_unlocked_R (SignalNode   *node,
   SIGNAL_UNLOCK ();
   if (accumulator)
     g_value_unset (&accu);
-  
+
+  TRACE(GOBJECT_SIGNAL_EMIT_END(node->signal_id, detail, instance, G_TYPE_FROM_INSTANCE (instance)));
+
   return return_value_altered;
 }
 
@@ -3409,7 +3435,7 @@ type_debug_name (GType type)
  * boolean values. The behavior that this accumulator gives is
  * that a return of %TRUE stops the signal emission: no further
  * callbacks will be invoked, while a return of %FALSE allows
- * the emission to coninue. The idea here is that a %TRUE return
+ * the emission to continue. The idea here is that a %TRUE return
  * indicates that the callback <emphasis>handled</emphasis> the signal,
  * and no further handling is needed.
  *
@@ -3433,8 +3459,34 @@ g_signal_accumulator_true_handled (GSignalInvocationHint *ihint,
   return continue_emission;
 }
 
-/* --- compile standard marshallers --- */
-#include "gmarshal.c"
-
-#define __G_SIGNAL_C__
-#include "gobjectaliasdef.c"
+/**
+ * g_signal_accumulator_first_wins:
+ * @ihint: standard #GSignalAccumulator parameter
+ * @return_accu: standard #GSignalAccumulator parameter
+ * @handler_return: standard #GSignalAccumulator parameter
+ * @dummy: standard #GSignalAccumulator parameter
+ *
+ * A predefined #GSignalAccumulator for signals intended to be used as a
+ * hook for application code to provide a particular value.  Usually
+ * only one such value is desired and multiple handlers for the same
+ * signal don't make much sense (except for the case of the default
+ * handler defined in the class structure, in which case you will
+ * usually want the signal connection to override the class handler).
+ *
+ * This accumulator will use the return value from the first signal
+ * handler that is run as the return value for the signal and not run
+ * any further handlers (ie: the first handler "wins").
+ *
+ * Returns: standard #GSignalAccumulator result
+ *
+ * Since: 2.28
+ **/
+gboolean
+g_signal_accumulator_first_wins (GSignalInvocationHint *ihint,
+                                 GValue                *return_accu,
+                                 const GValue          *handler_return,
+                                 gpointer               dummy)
+{
+  g_value_copy (handler_return, return_accu);
+  return FALSE;
+}