aboutsummaryrefslogtreecommitdiffstats
path: root/lwlib
diff options
context:
space:
mode:
authorDmitry Antipov <[email protected]>2014-06-02 22:01:21 +0400
committerDmitry Antipov <[email protected]>2014-06-02 22:01:21 +0400
commit5668fb88bf3731d39c4e958c8e79a549f789ce1e (patch)
treeb0d3fd3555fca3b34c47b803a633da2f36d31165 /lwlib
parentda11196a248b530c3b3a8329497d71332f8c71a3 (diff)
Use common memory management functions for lwlib and refactor users.
* lwlib/lwlib.h (widget_value): Do not maintain a free list any more. (malloc_widget_value, free_widget_value): Remove prototypes. * lwlib/lwlib.c (malloc_widget_value, free_widget_value): (widget_value_free_list, malloc_cpt): Remove. (free_widget_value_tree, copy_widget_value_tree): Adjust users. * src/menu.h (xmalloc_widget_value): Replaced by ... (make_widget_value): ... new prototype. * src/menu.c (xmalloc_widget_value): Replaced by ... (make_widget_value): ... new function. (free_menubar_widget_value_tree, digest_single_submenu): Adjust users. * src/gtkutil.c (malloc_widget_value, free_widget_value): (widget_value_free_list, malloc_cpt): Remove old lwlib-compatible code. * src/keyboard.h (enum button_type, struct _widget_value): * src/gtkutil.h, src/nsgui.h, src/w32gui.h (malloc_widget_value): (free_widget_value): Likewise. * src/nsmenu.m (ns_update_menubar, ns_menu_show): * src/w32menu.c (set_frame_menubar, w32_menu_show, w32_dialog_show): * src/xmenu.c (set_frame_menubar, xmenu_show, x_dialog_show): Adjust users. * src/xterm.h (XtParent) [USE_GTK]: Remove unused macro.
Diffstat (limited to 'lwlib')
-rw-r--r--lwlib/ChangeLog9
-rw-r--r--lwlib/lwlib.c50
-rw-r--r--lwlib/lwlib.h7
3 files changed, 12 insertions, 54 deletions
diff --git a/lwlib/ChangeLog b/lwlib/ChangeLog
index 6444498e1a..294bb10ef0 100644
--- a/lwlib/ChangeLog
+++ b/lwlib/ChangeLog
@@ -1,3 +1,12 @@
+2014-06-02 Dmitry Antipov <[email protected]>
+
+ Use common memory management functions for widgets.
+ * lwlib.h (widget_value): Do not maintain a free list any more.
+ (malloc_widget_value, free_widget_value): Remove prototypes.
+ * lwlib.c (malloc_widget_value, free_widget_value):
+ (widget_value_free_list, malloc_cpt): Remove.
+ (free_widget_value_tree, copy_widget_value_tree): Adjust users.
+
2014-05-30 Dmitry Antipov <[email protected]>
Use common string allocation and freeing functions where applicable.
diff --git a/lwlib/lwlib.c b/lwlib/lwlib.c
index eccf58046d..7f2f753c1d 100644
--- a/lwlib/lwlib.c
+++ b/lwlib/lwlib.c
@@ -99,51 +99,6 @@ static void lw_pop_all_widgets (LWLIB_ID, Boolean);
static Boolean get_one_value (widget_instance *, widget_value *);
static void show_one_widget_busy (Widget, Boolean);
-static widget_value *widget_value_free_list = 0;
-static int malloc_cpt = 0;
-
-widget_value *
-malloc_widget_value (void)
-{
- widget_value *wv;
- if (widget_value_free_list)
- {
- wv = widget_value_free_list;
- widget_value_free_list = wv->free_list;
- wv->free_list = 0;
- }
- else
- {
- wv = (widget_value *) xmalloc (sizeof (widget_value));
- malloc_cpt++;
- }
- memset ((void*) wv, 0, sizeof (widget_value));
- return wv;
-}
-
-/* this is analogous to free(). It frees only what was allocated
- by malloc_widget_value(), and no substructures.
- */
-void
-free_widget_value (widget_value *wv)
-{
- if (wv->free_list)
- abort ();
-
- if (malloc_cpt > 25)
- {
- /* When the number of already allocated cells is too big,
- We free it. */
- xfree (wv);
- malloc_cpt--;
- }
- else
- {
- wv->free_list = widget_value_free_list;
- widget_value_free_list = wv;
- }
-}
-
static void
free_widget_value_tree (widget_value *wv)
{
@@ -172,7 +127,7 @@ free_widget_value_tree (widget_value *wv)
free_widget_value_tree (wv->next);
wv->next = (widget_value *) 0xDEADBEEF;
}
- free_widget_value (wv);
+ xfree (wv);
}
static widget_value *
@@ -185,7 +140,8 @@ copy_widget_value_tree (widget_value *val, change_type change)
if (val == (widget_value *) 1)
return val;
- copy = malloc_widget_value ();
+ copy = xmalloc (sizeof (widget_value));
+ copy->lname = copy->lkey = Qnil;
copy->name = xstrdup (val->name);
copy->value = val->value ? xstrdup (val->value) : NULL;
copy->key = val->key ? xstrdup (val->key) : NULL;
diff --git a/lwlib/lwlib.h b/lwlib/lwlib.h
index 0e646a26b9..563ade8b34 100644
--- a/lwlib/lwlib.h
+++ b/lwlib/lwlib.h
@@ -119,11 +119,6 @@ typedef struct _widget_value
/* tell us if we should free the toolkit data slot when freeing the
widget_value itself. */
Boolean free_toolkit_data;
-
- /* we resource the widget_value structures; this points to the next
- one on the free list if this one has been deallocated.
- */
- struct _widget_value *free_list;
} widget_value;
@@ -153,8 +148,6 @@ widget_value* lw_get_all_values (LWLIB_ID id);
Boolean lw_get_some_values (LWLIB_ID id, widget_value* val);
void lw_pop_up_all_widgets (LWLIB_ID id);
void lw_pop_down_all_widgets (LWLIB_ID id);
-widget_value *malloc_widget_value (void);
-void free_widget_value (widget_value *);
void lw_popup_menu (Widget, XEvent *);
/* Toolkit independent way of focusing on a Widget at the Xt level. */