[glib] Add G_PRIVATE_OFFSET



commit d91d114a54bb89d987acb47a6d78fcd5c3ecd2fc
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed Jun 19 20:41:02 2013 +0100

    Add G_PRIVATE_OFFSET
    
    A macro that evaluates to the offset of a field inside an instance
    private data structure.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=700035

 gobject/gtype.h |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/gobject/gtype.h b/gobject/gtype.h
index c275740..c21936d 100644
--- a/gobject/gtype.h
+++ b/gobject/gtype.h
@@ -1582,6 +1582,23 @@ guint     g_type_get_type_registration_serial (void);
     g_type_add_instance_private (g_define_type_id, sizeof (TypeName##Private)); \
 }
 
+/**
+ * G_PRIVATE_OFFSET:
+ * @TypeName: the name of the type in CamelCase
+ * @field: the name of the field in the private data structure
+ *
+ * Evaluates to the offset of the @field inside the instance private data
+ * structure for @TypeName.
+ *
+ * Note that this macro can only be used together with the G_DEFINE_TYPE_*
+ * and G_ADD_PRIVATE() macros, since it depends on variable names from
+ * those macros.
+ *
+ * Since: 2.38
+ */
+#define G_PRIVATE_OFFSET(TypeName, field) \
+  (TypeName##_private_offset + (G_STRUCT_OFFSET (TypeName##Private, field)))
+
 #define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \
 \
 static void     type_name##_init              (TypeName        *self); \


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