[gtksourceview/wip/loader-saver] Make BufferOutputStream more robust after dispose
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/loader-saver] Make BufferOutputStream more robust after dispose
- Date: Mon, 23 Jun 2014 10:41:54 +0000 (UTC)
commit 7d46184cadf514cb4b2cc09c935c2898981375e5
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon Jun 23 12:37:45 2014 +0200
Make BufferOutputStream more robust after dispose
Some code can be executed after dispose(), like
gtk_source_buffer_output_stream_close(). After dispose(), the
source_buffer is NULL.
gtksourceview/gtksourcebufferoutputstream.c | 38 +++++++++++++++++++++++---
1 files changed, 33 insertions(+), 5 deletions(-)
---
diff --git a/gtksourceview/gtksourcebufferoutputstream.c b/gtksourceview/gtksourcebufferoutputstream.c
index 883238f..235d7e3 100644
--- a/gtksourceview/gtksourcebufferoutputstream.c
+++ b/gtksourceview/gtksourcebufferoutputstream.c
@@ -496,6 +496,11 @@ gtk_source_buffer_output_stream_detect_newline_type (GtkSourceBufferOutputStream
g_return_val_if_fail (GTK_SOURCE_IS_BUFFER_OUTPUT_STREAM (stream),
GTK_SOURCE_NEWLINE_TYPE_DEFAULT);
+ if (stream->priv->source_buffer == NULL)
+ {
+ return GTK_SOURCE_NEWLINE_TYPE_DEFAULT;
+ }
+
type = GTK_SOURCE_NEWLINE_TYPE_DEFAULT;
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (stream->priv->source_buffer),
@@ -542,7 +547,8 @@ apply_error_tag (GtkSourceBufferOutputStream *stream)
{
GtkTextIter start;
- if (stream->priv->error_offset == -1)
+ if (stream->priv->error_offset == -1 ||
+ stream->priv->source_buffer == NULL)
{
return;
}
@@ -565,6 +571,11 @@ insert_fallback (GtkSourceBufferOutputStream *stream,
guint8 v;
const gchar hex[] = "0123456789ABCDEF";
+ if (stream->priv->source_buffer == NULL)
+ {
+ return;
+ }
+
/* If we are here it is because we are pointing to an invalid char so we
* substitute it by an hex value.
*/
@@ -589,6 +600,11 @@ validate_and_insert (GtkSourceBufferOutputStream *stream,
GtkTextIter *iter;
gsize len;
+ if (stream->priv->source_buffer == NULL)
+ {
+ return;
+ }
+
text_buffer = GTK_TEXT_BUFFER (stream->priv->source_buffer);
iter = &stream->priv->pos;
len = count;
@@ -671,6 +687,11 @@ remove_trailing_newline (GtkSourceBufferOutputStream *stream)
GtkTextIter end;
GtkTextIter start;
+ if (stream->priv->source_buffer == NULL)
+ {
+ return;
+ }
+
gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (stream->priv->source_buffer), &end);
start = end;
@@ -693,6 +714,11 @@ remove_trailing_newline (GtkSourceBufferOutputStream *stream)
static void
end_append_text_to_document (GtkSourceBufferOutputStream *stream)
{
+ if (stream->priv->source_buffer == NULL)
+ {
+ return;
+ }
+
if (stream->priv->remove_trailing_newline)
{
remove_trailing_newline (stream);
@@ -812,13 +838,14 @@ gtk_source_buffer_output_stream_write (GOutputStream *stream,
gsize len;
gboolean freetext = FALSE;
- if (g_cancellable_set_error_if_cancelled (cancellable, error))
+ ostream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (stream);
+
+ if (g_cancellable_set_error_if_cancelled (cancellable, error) ||
+ ostream->priv->source_buffer == NULL)
{
return -1;
}
- ostream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (stream);
-
if (!ostream->priv->is_initialized)
{
ostream->priv->charset_conv = guess_encoding (ostream, buffer, count);
@@ -992,7 +1019,8 @@ gtk_source_buffer_output_stream_flush (GOutputStream *stream,
ostream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (stream);
- if (ostream->priv->is_closed)
+ if (ostream->priv->is_closed ||
+ ostream->priv->source_buffer == NULL)
{
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]