[ghex] gtkhex: roll back usage of slice allocator



commit 9e9cb79763fc7f271cb800ce03bbc3868e644dd5
Author: Logan Rathbone <poprocks gmail com>
Date:   Tue Dec 28 21:56:53 2021 -0500

    gtkhex: roll back usage of slice allocator
    
    I didn't appreciate the impact it would have. It clashes too much with
    the changedata being allocated as static structs in certain functions,
    which causes conflicts and unpredictable crashes.

 src/findreplace.c  |  4 ++--
 src/gtkhex.c       | 36 +++++++-----------------------------
 src/gtkhex.h       |  4 ----
 src/hex-document.c | 20 +++++++-------------
 4 files changed, 16 insertions(+), 48 deletions(-)
---
diff --git a/src/findreplace.c b/src/findreplace.c
index 1831561..fa7be4e 100644
--- a/src/findreplace.c
+++ b/src/findreplace.c
@@ -549,8 +549,8 @@ replace_one_cb (GtkButton *button, gpointer user_data)
        }
 
 clean_up:
-       g_free(find_str);
-       g_free(rep_str);
+       g_free (find_str);
+       g_free (rep_str);
 }
 
 static void
diff --git a/src/gtkhex.c b/src/gtkhex.c
index c574087..63e3113 100644
--- a/src/gtkhex.c
+++ b/src/gtkhex.c
@@ -114,37 +114,15 @@ struct _HexWidgetAutoHighlight
        HexWidgetAutoHighlight *next, *prev;
 };
 
-HexWidgetAutoHighlight *
-hex_widget_autohighlight_new (void)
-{
-       return g_slice_new0 (HexWidgetAutoHighlight);
-}
-
-void
-hex_widget_autohighlight_free (HexWidgetAutoHighlight *ahl)
-{
-       g_free (ahl->search_string);
-       g_free (ahl);
-}
-
-HexWidgetAutoHighlight *
+/* FIXME - only defined to create a boxed type and may be unreliable. */
+static HexWidgetAutoHighlight *
 hex_widget_autohighlight_copy (HexWidgetAutoHighlight *ahl)
 {
-       HexWidgetAutoHighlight *new = g_slice_new0 (HexWidgetAutoHighlight);
-
-       new->search_string = g_strdup (ahl->search_string);
-       new->search_len = ahl->search_len;
-       new->view_min = ahl->view_min;
-       new->view_max = ahl->view_max;
-       new->highlights = ahl->highlights;
-       new->next = ahl->next;
-       new->prev = ahl->prev;
-
-       return new;
+       return ahl;
 }
 
 G_DEFINE_BOXED_TYPE (HexWidgetAutoHighlight, hex_widget_autohighlight,
-               hex_widget_autohighlight_copy, hex_widget_autohighlight_free)
+               hex_widget_autohighlight_copy, g_free)
 
 
 /* ------------------------------
@@ -3394,7 +3372,7 @@ hex_widget_insert_autohighlight (HexWidget *self,
                const char *search,
                int len)
 {
-       HexWidgetAutoHighlight *new = hex_widget_autohighlight_new ();
+       HexWidgetAutoHighlight *new = g_new0 (HexWidgetAutoHighlight, 1);
 
        new->search_string = g_memdup2 (search, len);
        new->search_len = len;
@@ -3427,7 +3405,7 @@ void hex_widget_delete_autohighlight (HexWidget *self,
 
        while (ahl->highlights)
        {
-               hex_widget_delete_highlight(self, ahl, ahl->highlights);
+               hex_widget_delete_highlight (self, ahl, ahl->highlights);
        }
 
        if (ahl->next) ahl->next->prev = ahl->prev;
@@ -3435,7 +3413,7 @@ void hex_widget_delete_autohighlight (HexWidget *self,
 
        if (self->auto_highlight == ahl) self->auto_highlight = ahl->next;
 
-       g_free(ahl);
+       g_free (ahl);
 }
 
 /* FIXME - make this actually work. */
diff --git a/src/gtkhex.h b/src/gtkhex.h
index 07bcbb6..561fb40 100644
--- a/src/gtkhex.h
+++ b/src/gtkhex.h
@@ -69,10 +69,6 @@ G_DECLARE_FINAL_TYPE(HexWidget, hex_widget, HEX, WIDGET, GtkWidget)
 GType hex_widget_autohighlight_get_type (void) G_GNUC_CONST;
 typedef struct _HexWidgetAutoHighlight HexWidgetAutoHighlight;
 
-HexWidgetAutoHighlight *       hex_widget_autohighlight_new (void);
-HexWidgetAutoHighlight *       hex_widget_autohighlight_copy (HexWidgetAutoHighlight *ahl);
-void   hex_widget_autohighlight_free (HexWidgetAutoHighlight *ahl);
-
 /* PUBLIC METHOD DECLARATIONS */
 
 GtkWidget *hex_widget_new (HexDocument *owner);
diff --git a/src/hex-document.c b/src/hex-document.c
index 7c0fcb8..1621e0b 100644
--- a/src/hex-document.c
+++ b/src/hex-document.c
@@ -82,17 +82,11 @@ static guint hex_signals[LAST_SIGNAL];
 
 /* HexDocumentFindData GType Definitions */
 
-static HexDocumentFindData *
-hex_document_find_data_new (void)
-{
-       return g_slice_new0 (HexDocumentFindData);
-}
-
 /* FIXME - unused and could be unreliable. */
 static HexDocumentFindData *
 hex_document_find_data_copy (HexDocumentFindData *data)
 {
-       return g_slice_dup (HexDocumentFindData, data);
+       return data;
 }
 
 G_DEFINE_BOXED_TYPE (HexDocumentFindData, hex_document_find_data,
@@ -105,7 +99,7 @@ G_DEFINE_BOXED_TYPE (HexDocumentFindData, hex_document_find_data,
 static HexChangeData *
 hex_change_data_copy (HexChangeData *data)
 {
-       return g_slice_dup (HexChangeData, data);
+       return data;
 }
 
 G_DEFINE_BOXED_TYPE (HexChangeData, hex_change_data,
@@ -147,9 +141,9 @@ free_stack(GList *stack)
        while(stack) {
                cd = (HexChangeData *)stack->data;
                if(cd->v_string)
-                       g_free(cd->v_string);
+                       g_free (cd->v_string);
                stack = g_list_remove(stack, cd);
-               g_free(cd);
+               g_free (cd);
        }
 }
 
@@ -1111,7 +1105,7 @@ hex_document_find_forward_async (HexDocument *doc,
                gpointer user_data)
 {
        GTask *task;
-       HexDocumentFindData *find_data = hex_document_find_data_new ();
+       HexDocumentFindData *find_data = g_new0 (HexDocumentFindData, 1);
 
        find_data->start = start;
        find_data->what = what;
@@ -1280,7 +1274,7 @@ hex_document_real_undo (HexDocument *doc)
                len = cd->end - cd->start + 1;
                rep_data = hex_buffer_get_data (doc->buffer, cd->start, len);
                hex_document_set_data (doc, cd->start, cd->rep_len, len, cd->v_string, FALSE);
-               g_free(cd->v_string);
+               g_free (cd->v_string);
                cd->end = cd->start + cd->rep_len - 1;
                cd->rep_len = len;
                cd->v_string = rep_data;
@@ -1351,7 +1345,7 @@ hex_document_real_redo(HexDocument *doc)
                len = cd->end - cd->start + 1;
                rep_data = hex_buffer_get_data (doc->buffer, cd->start, len);
                hex_document_set_data (doc, cd->start, cd->rep_len, len, cd->v_string, FALSE);
-               g_free(cd->v_string);
+               g_free (cd->v_string);
                cd->end = cd->start + cd->rep_len - 1;
                cd->rep_len = len;
                cd->v_string = rep_data;


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