From e9d5cb733db1993d0afd16ae301c7b3ccba612d4 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 25 Apr 2023 16:19:54 -0700 Subject: [PATCH] libsysprof-analyze: move to internal types for documents We want to have an object hierarchy, but we don't want to expose our class or other internal details to the public API/ABI. This uses the old form of class definition so we can maintain that. An alternative would be to do what GDK does for internal types, should we find that easier to maintain going forward. --- .../sysprof-document-frame-private.h | 8 ++++ .../sysprof-document-frame.c | 45 +++++++------------ .../sysprof-document-frame.h | 11 +++-- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/libsysprof-analyze/sysprof-document-frame-private.h b/src/libsysprof-analyze/sysprof-document-frame-private.h index 9e0ea4c5..f2786c1d 100644 --- a/src/libsysprof-analyze/sysprof-document-frame-private.h +++ b/src/libsysprof-analyze/sysprof-document-frame-private.h @@ -26,6 +26,14 @@ G_BEGIN_DECLS +struct _SysprofDocumentFrame +{ + GObject parent_instance; + GMappedFile *mapped_file; + const SysprofCaptureFrame *frame; + guint needs_swap : 1; +}; + struct _SysprofDocumentFrameClass { GObjectClass parent_class; diff --git a/src/libsysprof-analyze/sysprof-document-frame.c b/src/libsysprof-analyze/sysprof-document-frame.c index e3e8bad5..fdd773ee 100644 --- a/src/libsysprof-analyze/sysprof-document-frame.c +++ b/src/libsysprof-analyze/sysprof-document-frame.c @@ -22,14 +22,7 @@ #include "sysprof-document-frame-private.h" -typedef struct _SysprofDocumentFramePrivate -{ - GMappedFile *mapped_file; - const SysprofCaptureFrame *frame; - guint needs_swap : 1; -} SysprofDocumentFramePrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (SysprofDocumentFrame, sysprof_document_frame, G_TYPE_OBJECT) +G_DEFINE_TYPE (SysprofDocumentFrame, sysprof_document_frame, G_TYPE_OBJECT) enum { PROP_0, @@ -45,12 +38,11 @@ static void sysprof_document_frame_finalize (GObject *object) { SysprofDocumentFrame *self = (SysprofDocumentFrame *)object; - SysprofDocumentFramePrivate *priv = sysprof_document_frame_get_instance_private (self); - g_clear_pointer (&priv->mapped_file, g_mapped_file_unref); + g_clear_pointer (&self->mapped_file, g_mapped_file_unref); - priv->frame = NULL; - priv->needs_swap = 0; + self->frame = NULL; + self->needs_swap = 0; G_OBJECT_CLASS (sysprof_document_frame_parent_class)->finalize (object); } @@ -125,14 +117,12 @@ _sysprof_document_frame_new (GMappedFile *mapped_file, gboolean needs_swap) { SysprofDocumentFrame *self; - SysprofDocumentFramePrivate *priv; self = g_object_new (SYSPROF_TYPE_DOCUMENT_FRAME, NULL); - priv = sysprof_document_frame_get_instance_private (self); - priv->mapped_file = g_mapped_file_ref (mapped_file); - priv->frame = frame; - priv->needs_swap = !!needs_swap; + self->mapped_file = g_mapped_file_ref (mapped_file); + self->frame = frame; + self->needs_swap = !!needs_swap; return self; } @@ -140,15 +130,14 @@ _sysprof_document_frame_new (GMappedFile *mapped_file, int sysprof_document_frame_get_cpu (SysprofDocumentFrame *self) { - SysprofDocumentFramePrivate *priv = sysprof_document_frame_get_instance_private (self); int ret; g_return_val_if_fail (SYSPROF_IS_DOCUMENT_FRAME (self), 0); - if G_LIKELY (priv->needs_swap) - ret = priv->frame->cpu; + if G_LIKELY (self->needs_swap) + ret = self->frame->cpu; else - ret = GUINT32_SWAP_LE_BE (priv->frame->cpu); + ret = GUINT32_SWAP_LE_BE (self->frame->cpu); return ret; } @@ -156,15 +145,14 @@ sysprof_document_frame_get_cpu (SysprofDocumentFrame *self) int sysprof_document_frame_get_pid (SysprofDocumentFrame *self) { - SysprofDocumentFramePrivate *priv = sysprof_document_frame_get_instance_private (self); int ret; g_return_val_if_fail (SYSPROF_IS_DOCUMENT_FRAME (self), 0); - if G_LIKELY (priv->needs_swap) - ret = priv->frame->pid; + if G_LIKELY (self->needs_swap) + ret = self->frame->pid; else - ret = GUINT32_SWAP_LE_BE (priv->frame->pid); + ret = GUINT32_SWAP_LE_BE (self->frame->pid); return ret; } @@ -172,15 +160,14 @@ sysprof_document_frame_get_pid (SysprofDocumentFrame *self) gint64 sysprof_document_frame_get_time (SysprofDocumentFrame *self) { - SysprofDocumentFramePrivate *priv = sysprof_document_frame_get_instance_private (self); gint64 ret; g_return_val_if_fail (SYSPROF_IS_DOCUMENT_FRAME (self), 0); - if G_LIKELY (priv->needs_swap) - ret = priv->frame->time; + if G_LIKELY (self->needs_swap) + ret = self->frame->time; else - ret = GUINT32_SWAP_LE_BE (priv->frame->time); + ret = GUINT32_SWAP_LE_BE (self->frame->time); return ret; } diff --git a/src/libsysprof-analyze/sysprof-document-frame.h b/src/libsysprof-analyze/sysprof-document-frame.h index c8e81b6e..ffc31120 100644 --- a/src/libsysprof-analyze/sysprof-document-frame.h +++ b/src/libsysprof-analyze/sysprof-document-frame.h @@ -24,11 +24,16 @@ G_BEGIN_DECLS -#define SYSPROF_TYPE_DOCUMENT_FRAME (sysprof_document_frame_get_type()) +#define SYSPROF_TYPE_DOCUMENT_FRAME (sysprof_document_frame_get_type()) +#define SYSPROF_IS_DOCUMENT_FRAME(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, SYSPROF_TYPE_DOCUMENT_FRAME) +#define SYSPROF_DOCUMENT_FRAME(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, SYSPROF_TYPE_DOCUMENT_FRAME, SysprofDocumentFrame) +#define SYSPROF_DOCUMENT_FRAME_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, SYSPROF_TYPE_DOCUMENT_FRAME, SysprofDocumentFrameClass) + +typedef struct _SysprofDocumentFrame SysprofDocumentFrame; +typedef struct _SysprofDocumentFrameClass SysprofDocumentFrameClass; SYSPROF_AVAILABLE_IN_ALL -G_DECLARE_DERIVABLE_TYPE (SysprofDocumentFrame, sysprof_document_frame, SYSPROF, DOCUMENT_FRAME, GObject) - +GType sysprof_document_frame_get_type (void) G_GNUC_CONST; SYSPROF_AVAILABLE_IN_ALL int sysprof_document_frame_get_cpu (SysprofDocumentFrame *self); SYSPROF_AVAILABLE_IN_ALL