[libgit2-glib] Port GgitNative to G_DECLARE_DERIVABLE macro
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Port GgitNative to G_DECLARE_DERIVABLE macro
- Date: Tue, 14 Jul 2015 10:55:37 +0000 (UTC)
commit b730f2178983424bd35f62008c34fd2bf337136f
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Tue Jul 14 12:43:40 2015 +0200
Port GgitNative to G_DECLARE_DERIVABLE macro
libgit2-glib/ggit-autocleanup.h | 1 -
libgit2-glib/ggit-native.c | 46 +++++++++++++++++++++++++-------------
libgit2-glib/ggit-native.h | 21 +----------------
libgit2-glib/ggit-types.h | 7 ------
4 files changed, 32 insertions(+), 43 deletions(-)
---
diff --git a/libgit2-glib/ggit-autocleanup.h b/libgit2-glib/ggit-autocleanup.h
index 3670250..f407c5d 100644
--- a/libgit2-glib/ggit-autocleanup.h
+++ b/libgit2-glib/ggit-autocleanup.h
@@ -91,7 +91,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitIndexEntry, ggit_index_entry_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitIndexEntryResolveUndo, ggit_index_entry_resolve_undo_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitIndex, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitMergeOptions, ggit_merge_options_free)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitNative, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitNote, ggit_note_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitObject, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GgitOId, ggit_oid_free)
diff --git a/libgit2-glib/ggit-native.c b/libgit2-glib/ggit-native.c
index 46d1e4f..cd5e226 100644
--- a/libgit2-glib/ggit-native.c
+++ b/libgit2-glib/ggit-native.c
@@ -20,15 +20,19 @@
#include "ggit-native.h"
-#define GGIT_NATIVE_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GGIT_TYPE_NATIVE,
GgitNativePrivate))
+/**
+ * GgitNative:
+ *
+ * Represents a generic native object.
+ */
-struct _GgitNativePrivate
+typedef struct _GgitNativePrivate
{
gpointer native;
GDestroyNotify destroy_notify;
-};
+} GgitNativePrivate;
-G_DEFINE_ABSTRACT_TYPE (GgitNative, ggit_native, GGIT_TYPE_OBJECT_FACTORY_BASE)
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GgitNative, ggit_native, GGIT_TYPE_OBJECT_FACTORY_BASE)
enum
{
@@ -40,12 +44,14 @@ static void
ggit_native_finalize (GObject *object)
{
GgitNative *native;
+ GgitNativePrivate *priv;
native = GGIT_NATIVE (object);
+ priv = ggit_native_get_instance_private (native);
- if (native->priv->native && native->priv->destroy_notify)
+ if (priv->native && priv->destroy_notify)
{
- native->priv->destroy_notify (native->priv->native);
+ priv->destroy_notify (priv->native);
}
G_OBJECT_CLASS (ggit_native_parent_class)->finalize (object);
@@ -57,12 +63,15 @@ ggit_native_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- GgitNative *self = GGIT_NATIVE (object);
+ GgitNative *native = GGIT_NATIVE (object);
+ GgitNativePrivate *priv;
+
+ priv = ggit_native_get_instance_private (native);
switch (prop_id)
{
case PROP_NATIVE:
- self->priv->native = g_value_get_pointer (value);
+ priv->native = g_value_get_pointer (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -79,8 +88,6 @@ ggit_native_class_init (GgitNativeClass *klass)
object_class->set_property = ggit_native_set_property;
- g_type_class_add_private (object_class, sizeof (GgitNativePrivate));
-
g_object_class_install_property (object_class,
PROP_NATIVE,
g_param_spec_pointer ("native",
@@ -92,17 +99,20 @@ ggit_native_class_init (GgitNativeClass *klass)
}
static void
-ggit_native_init (GgitNative *self)
+ggit_native_init (GgitNative *native)
{
- self->priv = GGIT_NATIVE_GET_PRIVATE (self);
}
gpointer
_ggit_native_get (gpointer self)
{
+ GgitNativePrivate *priv;
+
g_return_val_if_fail (GGIT_IS_NATIVE (self), NULL);
- return GGIT_NATIVE (self)->priv->native;
+ priv = ggit_native_get_instance_private (GGIT_NATIVE (self));
+
+ return priv->native;
}
void
@@ -114,7 +124,7 @@ _ggit_native_set (gpointer self,
g_return_if_fail (GGIT_IS_NATIVE (self));
- priv = GGIT_NATIVE (self)->priv;
+ priv = ggit_native_get_instance_private (GGIT_NATIVE (self));
if (priv->native && priv->destroy_notify)
{
@@ -133,7 +143,7 @@ _ggit_native_release (gpointer self)
g_return_val_if_fail (GGIT_IS_NATIVE (self), NULL);
- priv = GGIT_NATIVE (self)->priv;
+ priv = ggit_native_get_instance_private (GGIT_NATIVE (self));
ret = priv->native;
priv->native = NULL;
@@ -146,9 +156,13 @@ void
_ggit_native_set_destroy_func (gpointer self,
GDestroyNotify destroy_notify)
{
+ GgitNativePrivate *priv;
+
g_return_if_fail (GGIT_IS_NATIVE (self));
- GGIT_NATIVE (self)->priv->destroy_notify = destroy_notify;
+ priv = ggit_native_get_instance_private (GGIT_NATIVE (self));
+
+ priv->destroy_notify = destroy_notify;
}
/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-native.h b/libgit2-glib/ggit-native.h
index 321ceb9..551ed4b 100644
--- a/libgit2-glib/ggit-native.h
+++ b/libgit2-glib/ggit-native.h
@@ -26,23 +26,8 @@
G_BEGIN_DECLS
-#define GGIT_TYPE_NATIVE (ggit_native_get_type ())
-#define GGIT_NATIVE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GGIT_TYPE_NATIVE, GgitNative))
-#define GGIT_NATIVE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GGIT_TYPE_NATIVE, GgitNativeClass))
-#define GGIT_IS_NATIVE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GGIT_TYPE_NATIVE))
-#define GGIT_IS_NATIVE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GGIT_TYPE_NATIVE))
-#define GGIT_NATIVE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GGIT_TYPE_NATIVE, GgitNativeClass))
-
-typedef struct _GgitNativeClass GgitNativeClass;
-typedef struct _GgitNativePrivate GgitNativePrivate;
-
-struct _GgitNative
-{
- /*< private >*/
- GgitObjectFactoryBase parent;
-
- GgitNativePrivate *priv;
-};
+#define GGIT_TYPE_NATIVE (ggit_native_get_type ())
+G_DECLARE_DERIVABLE_TYPE (GgitNative, ggit_native, GGIT, NATIVE, GgitObjectFactoryBase)
/**
* GgitNativeClass:
@@ -56,8 +41,6 @@ struct _GgitNativeClass
GgitObjectFactoryBaseClass parent_class;
};
-GType ggit_native_get_type (void) G_GNUC_CONST;
-
gpointer _ggit_native_get (gpointer self);
void _ggit_native_set (gpointer self,
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 6538c45..25233e8 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -257,13 +257,6 @@ typedef struct _GgitIndexEntryResolveUndo GgitIndexEntryResolveUndo;
typedef struct _GgitMergeOptions GgitMergeOptions;
/**
- * GgitNative:
- *
- * Represents a generic native object.
- */
-typedef struct _GgitNative GgitNative;
-
-/**
* GgitNote:
*
* Represents a note object.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]