[glib/gobject-speedups2: 3/4] value: Add G_VALUE_COLLECT_INIT2




commit aaef7f30b35464956a478b5c07abbaedd42e4664
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri May 20 07:53:42 2022 -0400

    value: Add G_VALUE_COLLECT_INIT2
    
    Add a variant of the G_VALUE_COLLECT_INIT() macro
    that provides the GTypeValueTable to the caller.

 docs/reference/gobject/gobject-sections.txt |  1 +
 gobject/gvaluecollector.h                   | 31 +++++++++++++++++++++++++----
 2 files changed, 28 insertions(+), 4 deletions(-)
---
diff --git a/docs/reference/gobject/gobject-sections.txt b/docs/reference/gobject/gobject-sections.txt
index 278c756104..c742de9f63 100644
--- a/docs/reference/gobject/gobject-sections.txt
+++ b/docs/reference/gobject/gobject-sections.txt
@@ -813,6 +813,7 @@ g_param_spec_types
 <INCLUDE>glib-object.h,gobject/gvaluecollector.h</INCLUDE>
 GTypeCValue
 G_VALUE_COLLECT_INIT
+G_VALUE_COLLECT_INIT2
 G_VALUE_COLLECT
 G_VALUE_COLLECT_SKIP
 G_VALUE_LCOPY
diff --git a/gobject/gvaluecollector.h b/gobject/gvaluecollector.h
index 82e675cdd9..5846d77a76 100644
--- a/gobject/gvaluecollector.h
+++ b/gobject/gvaluecollector.h
@@ -87,15 +87,38 @@ union _GTypeCValue
  *
  * Since: 2.24
  */
-#define G_VALUE_COLLECT_INIT(value, _value_type, var_args, flags, __error)             \
+#define G_VALUE_COLLECT_INIT(value, _value_type, var_args, flags, __error) \
+  G_STMT_START { \
+    GTypeValueTable *g_vci_vtab; \
+    G_VALUE_COLLECT_INIT2(value, g_vci_vtab, _value_type, var_args, flags, __error); \
+} G_STMT_END
+
+/**
+ * G_VALUE_COLLECT_INIT2:
+ * @value: a #GValue return location. @value must contain only 0 bytes.
+ * @g_vci_vtab: a #GTypeValueTable pointer that will be set to the value table
+ *   for @_value_type
+ * @_value_type: the #GType to use for @value.
+ * @var_args: the va_list variable; it may be evaluated multiple times
+ * @flags: flags which are passed on to the collect_value() function of
+ *  the #GTypeValueTable of @value.
+ * @__error: a #gchar** variable that will be modified to hold a g_new()
+ *  allocated error messages if something fails
+ *
+ * A variant of G_VALUE_COLLECT_INIT() that provides the #GTypeValueTable
+ * to the caller.
+ *
+ * Since: 2.74
+ */
+#define G_VALUE_COLLECT_INIT2(value, g_vci_vtab, _value_type, var_args, flags, __error)                \
 G_STMT_START {                                                                         \
   GValue *g_vci_val = (value);                                                         \
   guint g_vci_flags = (flags);                                                         \
-  GTypeValueTable *g_vci_vtab = g_type_value_table_peek (_value_type);                 \
-  const gchar *g_vci_collect_format = g_vci_vtab->collect_format;                                      \
+  const gchar *g_vci_collect_format; \
   GTypeCValue g_vci_cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, };          \
   guint g_vci_n_values = 0;                                                                    \
-                                                                                        \
+  g_vci_vtab = g_type_value_table_peek (_value_type);                  \
+  g_vci_collect_format = g_vci_vtab->collect_format;                                   \
   g_vci_val->g_type = _value_type;             /* value_meminit() from gvalue.c */             \
   while (*g_vci_collect_format)                                                                \
     {                                                                                  \


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