summaryrefslogtreecommitdiff
path: root/src/glibext
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-06-18 21:45:14 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-07-08 18:34:43 (GMT)
commit6aa139281feca7cbe806efffe4ee787891d87d00 (patch)
treee1871fd21a210ced8b0ad5da67ffdd5c59790e77 /src/glibext
parent24f4b449d22c918d8f0e6c8fc059e0fa1fa485ff (diff)
Improved reference tracking for widget disposing.
Diffstat (limited to 'src/glibext')
-rw-r--r--src/glibext/gbufferview.c38
-rw-r--r--src/glibext/gwidthtracker.c2
2 files changed, 36 insertions, 4 deletions
diff --git a/src/glibext/gbufferview.c b/src/glibext/gbufferview.c
index cfe215d..c59c9e8 100644
--- a/src/glibext/gbufferview.c
+++ b/src/glibext/gbufferview.c
@@ -143,11 +143,23 @@ static void g_buffer_view_class_init(GBufferViewClass *class)
static void g_buffer_view_init(GBufferView *view)
{
+ view->cache = NULL;
+
+ view->highlighted = NULL;
+
/**
* Inversion du statut pour forcer l'actualisation lors de la création.
*/
view->unrestricted = false;
+ view->start = NULL;
+ view->end = NULL;
+
+ view->first = 0;
+ view->last = 0;
+
+ view->tracker = NULL;
+
}
@@ -165,9 +177,12 @@ static void g_buffer_view_init(GBufferView *view)
static void g_buffer_view_dispose(GBufferView *view)
{
- g_object_unref(G_OBJECT(view->cache));
+ g_clear_object(&view->cache);
+
+ g_clear_object(&view->start);
+ g_clear_object(&view->end);
- g_object_unref(G_OBJECT(view->tracker));
+ g_clear_object(&view->tracker);
G_OBJECT_CLASS(g_buffer_view_parent_class)->dispose(G_OBJECT(view));
@@ -188,7 +203,8 @@ static void g_buffer_view_dispose(GBufferView *view)
static void g_buffer_view_finalize(GBufferView *view)
{
- unref_segment_content_list(view->highlighted);
+ if (view->highlighted != NULL)
+ unref_segment_content_list(view->highlighted);
G_OBJECT_CLASS(g_buffer_view_parent_class)->finalize(G_OBJECT(view));
@@ -215,6 +231,7 @@ GBufferView *g_buffer_view_new(GBufferCache *cache, segcnt_list *highlighted)
result = g_object_new(G_TYPE_BUFFER_VIEW, NULL);
result->cache = cache;
+ g_object_ref_sink(G_OBJECT(cache));
g_buffer_view_restrict(result, NULL, NULL);
@@ -418,6 +435,9 @@ void g_buffer_view_restrict(GBufferView *view, GLineCursor *start, GLineCursor *
else
{
+ g_object_ref_sink(G_OBJECT(start));
+ g_object_ref_sink(G_OBJECT(end));
+
view->start = start;
view->end = end;
@@ -822,8 +842,11 @@ bool g_buffer_view_move_caret(GBufferView *view, bool ctrl, GdkScrollDirection d
index--;
other = g_buffer_cache_find_line_by_index(view->cache, index);
+ assert(other != NULL);
+
result = _g_buffer_view_compute_caret_full(view, caret->x, other, index,
options, offsets, caret, cursor);
+
g_object_unref(G_OBJECT(other));
}
@@ -837,8 +860,11 @@ bool g_buffer_view_move_caret(GBufferView *view, bool ctrl, GdkScrollDirection d
index++;
other = g_buffer_cache_find_line_by_index(view->cache, index);
+ assert(other != NULL);
+
result = _g_buffer_view_compute_caret_full(view, caret->x, other, index,
options, offsets, caret, cursor);
+
g_object_unref(G_OBJECT(other));
}
@@ -860,8 +886,11 @@ bool g_buffer_view_move_caret(GBufferView *view, bool ctrl, GdkScrollDirection d
index--;
other = g_buffer_cache_find_line_by_index(view->cache, index);
+ assert(other != NULL);
+
result = _g_buffer_view_compute_caret_full(view, INT_MAX, other, index,
options, offsets, caret, cursor);
+
g_object_unref(G_OBJECT(other));
}
@@ -885,8 +914,11 @@ bool g_buffer_view_move_caret(GBufferView *view, bool ctrl, GdkScrollDirection d
text_pos = g_buffer_cache_get_text_position(view->cache);
other = g_buffer_cache_find_line_by_index(view->cache, index);
+ assert(other != NULL);
+
result = _g_buffer_view_compute_caret_full(view, text_pos, other, index,
options, offsets, caret, cursor);
+
g_object_unref(G_OBJECT(other));
}
diff --git a/src/glibext/gwidthtracker.c b/src/glibext/gwidthtracker.c
index 50b99eb..3d39316 100644
--- a/src/glibext/gwidthtracker.c
+++ b/src/glibext/gwidthtracker.c
@@ -239,7 +239,7 @@ static void g_width_update_init(GWidthUpdate *update)
static void g_width_update_dispose(GWidthUpdate *update)
{
- g_object_unref(G_OBJECT(update->tracker));
+ g_clear_object(&update->tracker);
G_OBJECT_CLASS(g_width_update_parent_class)->dispose(G_OBJECT(update));