[libgda] dir-blob-op: removed private from object's struct
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] dir-blob-op: removed private from object's struct
- Date: Wed, 12 Sep 2018 11:54:42 +0000 (UTC)
commit 199f810ffcffe2df47a724b41baa71b2d1b0dc09
Author: Daniel Espinosa <esodan gmail com>
Date: Sun Sep 2 19:14:49 2018 -0500
dir-blob-op: removed private from object's struct
libgda/dir-blob-op.c | 56 ++++++++++++++++++++--------------------------------
libgda/dir-blob-op.h | 17 ++--------------
2 files changed, 23 insertions(+), 50 deletions(-)
---
diff --git a/libgda/dir-blob-op.c b/libgda/dir-blob-op.c
index f311bfbe5..d476dd879 100644
--- a/libgda/dir-blob-op.c
+++ b/libgda/dir-blob-op.c
@@ -28,9 +28,10 @@
#include <unistd.h>
#include <glib/gstdio.h>
-struct _GdaDirBlobOpPrivate {
+typedef struct {
gchar *complete_filename;
-};
+} GdaDirBlobOpPrivate;
+#define gda_dir_blob_op_get_instance_private(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, GDA_TYPE_DIR_BLOB_OP,
GdaDirBlobOpPrivate)
static void gda_dir_blob_op_class_init (GdaDirBlobOpClass *klass);
static void gda_dir_blob_op_init (GdaDirBlobOp *blob,
@@ -47,7 +48,7 @@ static GObjectClass *parent_class = NULL;
* Object init and finalize
*/
GType
-_gda_dir_blob_op_get_type (void)
+gda_dir_blob_op_get_type (void)
{
static GType type = 0;
@@ -78,9 +79,9 @@ gda_dir_blob_op_init (GdaDirBlobOp *op,
G_GNUC_UNUSED GdaDirBlobOpClass *klass)
{
g_return_if_fail (GDA_IS_DIR_BLOB_OP (op));
+ GdaDirBlobOpPrivate *priv = gda_dir_blob_op_get_instance_private (op);
- op->priv = g_new0 (GdaDirBlobOpPrivate, 1);
- op->priv->complete_filename = NULL;
+ priv->complete_filename = NULL;
}
static void
@@ -88,30 +89,15 @@ gda_dir_blob_op_class_init (GdaDirBlobOpClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GdaBlobOpClass *blob_class = GDA_BLOB_OP_CLASS (klass);
+ g_type_class_add_private (object_class, sizeof (GdaDirBlobOpPrivate));
parent_class = g_type_class_peek_parent (klass);
- object_class->finalize = gda_dir_blob_op_finalize;
GDA_BLOB_OP_FUNCTIONS (blob_class->functions)->get_length = gda_dir_blob_op_get_length;
GDA_BLOB_OP_FUNCTIONS (blob_class->functions)->read = gda_dir_blob_op_read;
GDA_BLOB_OP_FUNCTIONS (blob_class->functions)->write = gda_dir_blob_op_write;
}
-
-static void
-gda_dir_blob_op_finalize (GObject * object)
-{
- GdaDirBlobOp *pgop = (GdaDirBlobOp *) object;
-
- g_return_if_fail (GDA_IS_DIR_BLOB_OP (pgop));
-
- g_free (pgop->priv->complete_filename);
- g_free (pgop->priv);
- pgop->priv = NULL;
-
- parent_class->finalize (object);
-}
-
/**
* _gda_dir_blob_op_new
*/
@@ -123,7 +109,8 @@ _gda_dir_blob_op_new (const gchar *complete_filename)
g_return_val_if_fail (complete_filename, NULL);
pgop = g_object_new (GDA_TYPE_DIR_BLOB_OP, NULL);
- pgop->priv->complete_filename = g_strdup (complete_filename);
+ GdaDirBlobOpPrivate *priv = gda_dir_blob_op_get_instance_private (pgop);
+ priv->complete_filename = g_strdup (complete_filename);
return GDA_BLOB_OP (pgop);
}
@@ -135,11 +122,11 @@ void
_gda_dir_blob_set_filename (GdaDirBlobOp *blob, const gchar *complete_filename)
{
g_return_if_fail (GDA_IS_DIR_BLOB_OP (blob));
- g_return_if_fail (blob->priv);
g_return_if_fail (complete_filename);
+ GdaDirBlobOpPrivate *priv = gda_dir_blob_op_get_instance_private (blob);
- g_free (blob->priv->complete_filename);
- blob->priv->complete_filename = g_strdup (complete_filename);
+ g_free (priv->complete_filename);
+ priv->complete_filename = g_strdup (complete_filename);
}
/**
@@ -149,9 +136,9 @@ const gchar *
_gda_dir_blob_get_filename (GdaDirBlobOp *blob)
{
g_return_val_if_fail (GDA_IS_DIR_BLOB_OP (blob), NULL);
- g_return_val_if_fail (blob->priv, NULL);
+ GdaDirBlobOpPrivate *priv = gda_dir_blob_op_get_instance_private (blob);
- return blob->priv->complete_filename;
+ return priv->complete_filename;
}
/*
@@ -165,12 +152,11 @@ gda_dir_blob_op_get_length (GdaBlobOp *op)
g_return_val_if_fail (GDA_IS_DIR_BLOB_OP (op), -1);
dirop = GDA_DIR_BLOB_OP (op);
- g_return_val_if_fail (dirop->priv, -1);
+ GdaDirBlobOpPrivate *priv = gda_dir_blob_op_get_instance_private (dirop);
- if (! g_stat (dirop->priv->complete_filename, &filestat))
+ if (! g_stat (priv->complete_filename, &filestat))
return filestat.st_size;
- else
- return -1;
+ return -1;
}
static glong
@@ -184,13 +170,13 @@ gda_dir_blob_op_read (GdaBlobOp *op, GdaBlob *blob, glong offset, glong size)
g_return_val_if_fail (GDA_IS_DIR_BLOB_OP (op), -1);
dirop = GDA_DIR_BLOB_OP (op);
- g_return_val_if_fail (dirop->priv, -1);
+ GdaDirBlobOpPrivate *priv = gda_dir_blob_op_get_instance_private (dirop);
if (offset >= G_MAXINT)
return -1;
g_return_val_if_fail (blob, -1);
/* open file */
- file = fopen (dirop->priv->complete_filename, "rb"); /* Flawfinder: ignore */
+ file = fopen (priv->complete_filename, "rb"); /* Flawfinder: ignore */
if (!file)
return -1;
@@ -220,13 +206,13 @@ gda_dir_blob_op_write (GdaBlobOp *op, GdaBlob *blob, glong offset)
g_return_val_if_fail (GDA_IS_DIR_BLOB_OP (op), -1);
dirop = GDA_DIR_BLOB_OP (op);
- g_return_val_if_fail (dirop->priv, -1);
+ GdaDirBlobOpPrivate *priv = gda_dir_blob_op_get_instance_private (blob);
if (offset >= G_MAXINT)
return -1;
g_return_val_if_fail (blob, -1);
/* open file */
- file = fopen (dirop->priv->complete_filename, "w+b"); /* Flawfinder: ignore */
+ file = fopen (priv->complete_filename, "w+b"); /* Flawfinder: ignore */
if (!file)
return -1;
diff --git a/libgda/dir-blob-op.h b/libgda/dir-blob-op.h
index 1aaa11c70..5f6248481 100644
--- a/libgda/dir-blob-op.h
+++ b/libgda/dir-blob-op.h
@@ -29,26 +29,13 @@
G_BEGIN_DECLS
-#define GDA_TYPE_DIR_BLOB_OP (_gda_dir_blob_op_get_type())
-#define GDA_DIR_BLOB_OP(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GDA_TYPE_DIR_BLOB_OP,
GdaDirBlobOp))
-#define GDA_DIR_BLOB_OP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_DIR_BLOB_OP,
GdaDirBlobOpClass))
-#define GDA_IS_DIR_BLOB_OP(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GDA_TYPE_DIR_BLOB_OP))
-#define GDA_IS_DIR_BLOB_OP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDA_TYPE_DIR_BLOB_OP))
-
-typedef struct _GdaDirBlobOp GdaDirBlobOp;
-typedef struct _GdaDirBlobOpClass GdaDirBlobOpClass;
-typedef struct _GdaDirBlobOpPrivate GdaDirBlobOpPrivate;
-
-struct _GdaDirBlobOp {
- GdaBlobOp parent;
- GdaDirBlobOpPrivate *priv;
-};
+#define GDA_TYPE_DIR_BLOB_OP (gda_dir_blob_op_get_type())
+G_DECLARE_DERIVABLE_TYPE(GdaDirBlobOp, gda_dir_blob_op, GDA, DIR_BLOB_OP, GdaBlobOp)
struct _GdaDirBlobOpClass {
GdaBlobOpClass parent_class;
};
-GType _gda_dir_blob_op_get_type (void) G_GNUC_CONST;
GdaBlobOp *_gda_dir_blob_op_new (const gchar *complete_filename);
void _gda_dir_blob_set_filename (GdaDirBlobOp *blob, const gchar *complete_filename);
const gchar *_gda_dir_blob_get_filename (GdaDirBlobOp *blob);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]