[gtksourceview/wip/loader-saver] BufferInputStream: strong reference to the buffer



commit 33c4216530b4bac081cfd31b0da733297adf5f81
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Mar 25 13:40:14 2014 +0100

    BufferInputStream: strong reference to the buffer
    
    During a file saving, we don't want the buffer to be finalized.

 gtksourceview/gtksourcebufferinputstream.c |   14 +++++++++++++-
 gtksourceview/gtksourcefilesaver.c         |    3 +++
 2 files changed, 16 insertions(+), 1 deletions(-)
---
diff --git a/gtksourceview/gtksourcebufferinputstream.c b/gtksourceview/gtksourcebufferinputstream.c
index 2b6ddc8..f3462fe 100644
--- a/gtksourceview/gtksourcebufferinputstream.c
+++ b/gtksourceview/gtksourcebufferinputstream.c
@@ -325,7 +325,8 @@ _gtk_source_buffer_input_stream_set_property (GObject      *object,
        switch (prop_id)
        {
                case PROP_BUFFER:
-                       stream->priv->buffer = GTK_TEXT_BUFFER (g_value_get_object (value));
+                       g_assert (stream->priv->buffer == NULL);
+                       stream->priv->buffer = g_value_dup_object (value);
                        break;
 
                case PROP_NEWLINE_TYPE:
@@ -371,6 +372,16 @@ _gtk_source_buffer_input_stream_get_property (GObject    *object,
 }
 
 static void
+_gtk_source_buffer_input_stream_dispose (GObject *object)
+{
+       GtkSourceBufferInputStream *stream = GTK_SOURCE_BUFFER_INPUT_STREAM (object);
+
+       g_clear_object (&stream->priv->buffer);
+
+       G_OBJECT_CLASS (_gtk_source_buffer_input_stream_parent_class)->dispose (object);
+}
+
+static void
 _gtk_source_buffer_input_stream_class_init (GtkSourceBufferInputStreamClass *klass)
 {
        GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
@@ -378,6 +389,7 @@ _gtk_source_buffer_input_stream_class_init (GtkSourceBufferInputStreamClass *kla
 
        gobject_class->get_property = _gtk_source_buffer_input_stream_get_property;
        gobject_class->set_property = _gtk_source_buffer_input_stream_set_property;
+       gobject_class->dispose = _gtk_source_buffer_input_stream_dispose;
 
        stream_class->read_fn = _gtk_source_buffer_input_stream_read;
        stream_class->close_fn = _gtk_source_buffer_input_stream_close;
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index 81bf8c9..e789159 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -62,6 +62,9 @@ struct _GtkSourceFileSaverPrivate
         * can have the ownership of the FileSaver. And a FileSaver can be used
         * several times, so the object can be kept around until the subclass of
         * GtkSourceBuffer is disposed.
+        * The GtkSourceBufferInputStream has a strong reference to the
+        * source_buffer, so the buffer will not be finalized when the file is
+        * being saved. So there can be a temporary reference cycle.
         */
        GtkSourceBuffer *source_buffer;
        GFile *file;


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