[glib/wip/smcv/none-flags: 1/3] gobject: Add a NONE or DEFAULT member to all flags-sets




commit eee17df5ed3389c1a06f1de7f9235b196262448c
Author: Simon McVittie <smcv collabora com>
Date:   Thu Mar 31 13:58:36 2022 +0100

    gobject: Add a NONE or DEFAULT member to all flags-sets
    
    This makes code that sets no flags a bit more self-documenting:
    for example, G_CONNECT_DEFAULT makes it clearer that no special
    behaviour is required than literal 0, and clearer that there is no
    weird casting between types than (GConnectFlags) 0.
    
    Signed-off-by: Simon McVittie <smcv collabora com>

 gobject/gparam.h  |  2 ++
 gobject/gsignal.h | 16 ++++++++++++----
 gobject/gtype.h   |  6 +++++-
 3 files changed, 19 insertions(+), 5 deletions(-)
---
diff --git a/gobject/gparam.h b/gobject/gparam.h
index e0f316682d..1e78b4d860 100644
--- a/gobject/gparam.h
+++ b/gobject/gparam.h
@@ -115,6 +115,7 @@ G_BEGIN_DECLS
 /* --- flags --- */
 /**
  * GParamFlags:
+ * @G_PARAM_DEFAULT: no flags set. Since: 2.74.
  * @G_PARAM_READABLE: the parameter is readable
  * @G_PARAM_WRITABLE: the parameter is writable
  * @G_PARAM_READWRITE: alias for %G_PARAM_READABLE | %G_PARAM_WRITABLE
@@ -151,6 +152,7 @@ G_BEGIN_DECLS
  */
 typedef enum
 {
+  G_PARAM_DEFAULT GLIB_AVAILABLE_ENUMERATOR_IN_2_74 = 0,
   G_PARAM_READABLE            = 1 << 0,
   G_PARAM_WRITABLE            = 1 << 1,
   G_PARAM_READWRITE           = (G_PARAM_READABLE | G_PARAM_WRITABLE),
diff --git a/gobject/gsignal.h b/gobject/gsignal.h
index 04f1344343..812d30034a 100644
--- a/gobject/gsignal.h
+++ b/gobject/gsignal.h
@@ -107,6 +107,7 @@ typedef gboolean (*GSignalAccumulator)      (GSignalInvocationHint *ihint,
 /* --- run, match and connect types --- */
 /**
  * GSignalFlags:
+ * @G_SIGNAL_DEFAULT: Default behaviour (no special flags)
  * @G_SIGNAL_RUN_FIRST: Invoke the object method handler in the first emission stage.
  * @G_SIGNAL_RUN_LAST: Invoke the object method handler in the third emission stage.
  * @G_SIGNAL_RUN_CLEANUP: Invoke the object method handler in the last emission stage.
@@ -135,6 +136,7 @@ typedef gboolean (*GSignalAccumulator)      (GSignalInvocationHint *ihint,
  */
 typedef enum
 {
+  G_SIGNAL_DEFAULT GLIB_AVAILABLE_ENUMERATOR_IN_2_74 = 0,
   G_SIGNAL_RUN_FIRST   = 1 << 0,
   G_SIGNAL_RUN_LAST    = 1 << 1,
   G_SIGNAL_RUN_CLEANUP = 1 << 2,
@@ -155,9 +157,11 @@ typedef enum
 #define G_SIGNAL_FLAGS_MASK  0x1ff
 /**
  * GConnectFlags:
- * @G_CONNECT_AFTER: whether the handler should be called before or after the
- *  default handler of the signal.
- * @G_CONNECT_SWAPPED: whether the instance and data should be swapped when
+ * @G_CONNECT_DEFAULT: Default behaviour (no special flags). Since: 2.74
+ * @G_CONNECT_AFTER: If set, the handler should be called after the
+ *  default handler of the signal. Normally, the handler is called before
+ *  the default handler.
+ * @G_CONNECT_SWAPPED: If set, the instance and data should be swapped when
  *  calling the handler; see g_signal_connect_swapped() for an example.
  * 
  * The connection flags are used to specify the behaviour of a signal's 
@@ -165,11 +169,14 @@ typedef enum
  */
 typedef enum
 {
+  G_CONNECT_DEFAULT GLIB_AVAILABLE_ENUMERATOR_IN_2_74 = 0,
   G_CONNECT_AFTER      = 1 << 0,
   G_CONNECT_SWAPPED    = 1 << 1
 } GConnectFlags;
 /**
  * GSignalMatchType:
+ * @G_SIGNAL_MATCH_NONE: All signals are matched (not practically useful,
+ *  included for completeness). Since: 2.74
  * @G_SIGNAL_MATCH_ID: The signal id must be equal.
  * @G_SIGNAL_MATCH_DETAIL: The signal detail must be equal.
  * @G_SIGNAL_MATCH_CLOSURE: The closure must be the same.
@@ -183,6 +190,7 @@ typedef enum
  */
 typedef enum
 {
+  G_SIGNAL_MATCH_NONE GLIB_AVAILABLE_ENUMERATOR_IN_2_74 = 0,
   G_SIGNAL_MATCH_ID       = 1 << 0,
   G_SIGNAL_MATCH_DETAIL           = 1 << 1,
   G_SIGNAL_MATCH_CLOSURE   = 1 << 2,
@@ -505,7 +513,7 @@ void   g_signal_chain_from_overridden_handler (gpointer           instance,
  * Returns: the handler ID, of type #gulong (always greater than 0 for successful connections)
  */
 #define g_signal_connect(instance, detailed_signal, c_handler, data) \
-    g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
+    g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_DEFAULT)
 /**
  * g_signal_connect_after:
  * @instance: the instance to connect to.
diff --git a/gobject/gtype.h b/gobject/gtype.h
index 2aa5e13163..1bd463ef2d 100644
--- a/gobject/gtype.h
+++ b/gobject/gtype.h
@@ -1026,6 +1026,8 @@ typedef void     (*GTypeInterfaceCheckFunc)  (gpointer           check_data,
  */
 typedef enum    /*< skip >*/
 {
+  /* There is no G_TYPE_FUNDAMENTAL_FLAGS_NONE: this is implemented to use
+   * the same bits as GTypeFlags */
   G_TYPE_FLAG_CLASSED           = (1 << 0),
   G_TYPE_FLAG_INSTANTIATABLE    = (1 << 1),
   G_TYPE_FLAG_DERIVABLE         = (1 << 2),
@@ -1033,6 +1035,7 @@ typedef enum    /*< skip >*/
 } GTypeFundamentalFlags;
 /**
  * GTypeFlags:
+ * @G_TYPE_FLAG_NONE: No special flags. Since: 2.74
  * @G_TYPE_FLAG_ABSTRACT: Indicates an abstract type. No instances can be
  *  created for an abstract type
  * @G_TYPE_FLAG_VALUE_ABSTRACT: Indicates an abstract value type, i.e. a type
@@ -1045,6 +1048,7 @@ typedef enum    /*< skip >*/
  */
 typedef enum    /*< skip >*/
 {
+  G_TYPE_FLAG_NONE GLIB_AVAILABLE_ENUMERATOR_IN_2_74 = 0,
   G_TYPE_FLAG_ABSTRACT = (1 << 4),
   G_TYPE_FLAG_VALUE_ABSTRACT = (1 << 5),
   G_TYPE_FLAG_FINAL GLIB_AVAILABLE_ENUMERATOR_IN_2_70 = (1 << 6)
@@ -2193,7 +2197,7 @@ type_name##_get_type (void) \
                                        (GClassInitFunc)(void (*)(void)) type_name##_default_init, \
                                        0, \
                                        (GInstanceInitFunc)NULL, \
-                                       (GTypeFlags) 0); \
+                                       G_TYPE_FLAG_NONE); \
       if (TYPE_PREREQ != G_TYPE_INVALID) \
         g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ); \
       { /* custom code follows */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]