[gtksourceview/wip/loader-saver] Make BufferInputStream more robust after dispose



commit c6aac2c35ef2ca4bfce6f59ff7e447b562340c91
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Jun 30 14:09:30 2014 +0200

    Make BufferInputStream more robust after dispose

 gtksourceview/gtksourcebufferinputstream.c |   21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/gtksourceview/gtksourcebufferinputstream.c b/gtksourceview/gtksourcebufferinputstream.c
index 7f4fc50..7c866db 100644
--- a/gtksourceview/gtksourcebufferinputstream.c
+++ b/gtksourceview/gtksourcebufferinputstream.c
@@ -110,6 +110,11 @@ read_line (GtkSourceBufferInputStream *stream,
        const gchar *newline;
        gboolean is_last;
 
+       if (stream->priv->buffer == NULL)
+       {
+               return 0;
+       }
+
        gtk_text_buffer_get_iter_at_mark (stream->priv->buffer,
                                          &start,
                                          stream->priv->pos);
@@ -244,6 +249,11 @@ _gtk_source_buffer_input_stream_read (GInputStream  *input_stream,
                return -1;
        }
 
+       if (stream->priv->buffer == NULL)
+       {
+               return 0;
+       }
+
        /* Initialize the mark to the first char in the text buffer */
        if (!stream->priv->is_initialized)
        {
@@ -306,7 +316,8 @@ _gtk_source_buffer_input_stream_close (GInputStream  *input_stream,
 
        stream->priv->newline_added = FALSE;
 
-       if (stream->priv->is_initialized)
+       if (stream->priv->is_initialized &&
+           stream->priv->buffer != NULL)
        {
                gtk_text_buffer_delete_mark (stream->priv->buffer, stream->priv->pos);
        }
@@ -471,6 +482,11 @@ _gtk_source_buffer_input_stream_get_total_size (GtkSourceBufferInputStream *stre
 {
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER_INPUT_STREAM (stream), 0);
 
+       if (stream->priv->buffer == NULL)
+       {
+               return 0;
+       }
+
        return gtk_text_buffer_get_char_count (stream->priv->buffer);
 }
 
@@ -482,7 +498,8 @@ _gtk_source_buffer_input_stream_tell (GtkSourceBufferInputStream *stream)
        /* FIXME: is this potentially inefficient? If yes, we could keep
           track of the offset internally, assuming the mark doesn't move
           during the operation */
-       if (!stream->priv->is_initialized)
+       if (!stream->priv->is_initialized ||
+           stream->priv->buffer == NULL)
        {
                return 0;
        }


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