summaryrefslogtreecommitdiff
path: root/lwlib/lwlib.c
diff options
context:
space:
mode:
authorDmitry Antipov <dmantipov@yandex.ru>2014-06-02 22:01:21 +0400
committerDmitry Antipov <dmantipov@yandex.ru>2014-06-02 22:01:21 +0400
commit5668fb88bf3731d39c4e958c8e79a549f789ce1e (patch)
treeb0d3fd3555fca3b34c47b803a633da2f36d31165 /lwlib/lwlib.c
parentda11196a248b530c3b3a8329497d71332f8c71a3 (diff)
downloademacs-5668fb88bf3731d39c4e958c8e79a549f789ce1e.tar.gz
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/lwlib.c')
-rw-r--r--lwlib/lwlib.c50
1 files changed, 3 insertions, 47 deletions
diff --git a/lwlib/lwlib.c b/lwlib/lwlib.c
index eccf58046de..7f2f753c1d4 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;