* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __G_TYPE_H__
#define __G_TYPE_H__
* instance data to the type. Furthermore, it defines a *_get_type() function. See G_DEFINE_TYPE_EXTENDED()
* for an example.
*
+ * Note that private structs added with this macros must have a struct
+ * name of the form <replaceable>@TN</replaceable>Private.
+ *
* Since: 2.38
*/
#define G_DEFINE_TYPE_WITH_PRIVATE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, G_ADD_PRIVATE (TN))
* @TN: The name of the new type, in Camel case.
* @t_n: The name of the new type, in lowercase, with words
* separated by '_'.
- *
* @T_P: The #GType of the parent type.
+ *
* Similar to G_DEFINE_TYPE_WITH_PRIVATE(), but defines an abstract type.
* See G_DEFINE_TYPE_EXTENDED() for an example.
*
- * Since: 2.4
+ * Since: 2.38
*/
#define G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(TN, t_n, T_P) G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, G_ADD_PRIVATE (TN))
/**
* gint
* my_object_get_foo (MyObject *obj)
* {
- * MyObjectPrivate *priv = my_object_get_private (obj);
+ * MyObjectPrivate *priv = my_object_get_instance_private (obj);
*
* return priv->foo;
* }
* my_object_set_bar (MyObject *obj,
* gint bar)
* {
- * MyObjectPrivate *priv = my_object_get_private (obj);
+ * MyObjectPrivate *priv = my_object_get_instance_private (obj);
*
* if (priv->bar != bar)
* priv->bar = bar;
* Note that this macro can only be used together with the G_DEFINE_TYPE_*
* macros, since it depends on variable names from those macros.
*
+ * Also note that private structs added with these macros must have a struct
+ * name of the form <replaceable>TypeName</replaceable>Private.
+ *
* Since: 2.38
*/
#define G_ADD_PRIVATE(TypeName) { \
g_type_add_instance_private (g_define_type_id, sizeof (TypeName##Private)); \
}
-#define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \
-\
-static void type_name##_init (TypeName *self); \
-static void type_name##_class_init (TypeName##Class *klass); \
-static gpointer type_name##_parent_class = NULL; \
-static gint TypeName##_private_offset; \
+/**
+ * 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)))
+
+/**
+ * G_PRIVATE_FIELD_P:
+ * @TypeName: the name of the type in CamelCase
+ * @inst: the instance of @TypeName you wish to access
+ * @field_name: the name of the field in the private data structure
+ *
+ * Evaluates to a pointer to the @field_name inside the @inst 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_FIELD_P(TypeName, inst, field_name) \
+ G_STRUCT_MEMBER_P (inst, G_PRIVATE_OFFSET (TypeName, field_name))
+
+/**
+ * G_PRIVATE_FIELD:
+ * @TypeName: the name of the type in CamelCase
+ * @inst: the instance of @TypeName you wish to access
+ * @field_type: the type of the field in the private data structure
+ * @field_name: the name of the field in the private data structure
+ *
+ * Evaluates to the @field_name inside the @inst 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_FIELD(TypeName, inst, field_type, field_name) \
+ G_STRUCT_MEMBER (field_type, inst, G_PRIVATE_OFFSET (TypeName, field_name))
+
+/* we need to have this macro under conditional expansion, as it references
+ * a function that has been added in 2.38. see bug:
+ * https://bugzilla.gnome.org/show_bug.cgi?id=703191
+ */
+#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38
+#define _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
static void type_name##_class_intern_init (gpointer klass) \
{ \
type_name##_parent_class = g_type_class_peek_parent (klass); \
if (TypeName##_private_offset != 0) \
g_type_class_adjust_private_offset (klass, &TypeName##_private_offset); \
type_name##_class_init ((TypeName##Class*) klass); \
-} \
+}
+
+#else
+#define _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
+static void type_name##_class_intern_init (gpointer klass) \
+{ \
+ type_name##_parent_class = g_type_class_peek_parent (klass); \
+ type_name##_class_init ((TypeName##Class*) klass); \
+}
+#endif /* GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 */
+
+#define _G_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \
+\
+static void type_name##_init (TypeName *self); \
+static void type_name##_class_init (TypeName##Class *klass); \
+static gpointer type_name##_parent_class = NULL; \
+static gint TypeName##_private_offset; \
+\
+_G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
\
static inline gpointer \
-type_name##_get_private (TypeName *self) \
+type_name##_get_instance_private (TypeName *self) \
{ \
return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \
} \
*/
#define G_DEFINE_BOXED_TYPE_WITH_CODE(TypeName, type_name, copy_func, free_func, _C_) _G_DEFINE_BOXED_TYPE_BEGIN (TypeName, type_name, copy_func, free_func) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
-#if !defined (__cplusplus) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))
+/* Only use this in non-C++ on GCC >= 2.7, except for Darwin/ppc64.
+ * See https://bugzilla.gnome.org/show_bug.cgi?id=647145
+ */
+#if !defined (__cplusplus) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) && !(defined (__APPLE__) && defined (__ppc64__))
#define _G_DEFINE_BOXED_TYPE_BEGIN(TypeName, type_name, copy_func, free_func) \
GType \
type_name##_get_type (void) \