aboutsummaryrefslogtreecommitdiffstats
path: root/lwlib
diff options
context:
space:
mode:
authorDmitry Antipov2014-06-02 22:01:21 +0400
committerDmitry Antipov2014-06-02 22:01:21 +0400
commit5668fb88bf3731d39c4e958c8e79a549f789ce1e (patch)
treeb0d3fd3555fca3b34c47b803a633da2f36d31165 /lwlib
parentda11196a248b530c3b3a8329497d71332f8c71a3 (diff)
downloademacs-5668fb88bf3731d39c4e958c8e79a549f789ce1e.tar.gz
emacs-5668fb88bf3731d39c4e958c8e79a549f789ce1e.zip
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 6444498e1a5..294bb10ef0a 100644
--- a/lwlib/ChangeLog
+++ b/lwlib/ChangeLog
@@ -1,3 +1,12 @@
12014-06-02 Dmitry Antipov <dmantipov@yandex.ru>
2
3 Use common memory management functions for widgets.
4 * lwlib.h (widget_value): Do not maintain a free list any more.
5 (malloc_widget_value, free_widget_value): Remove prototypes.
6 * lwlib.c (malloc_widget_value, free_widget_value):
7 (widget_value_free_list, malloc_cpt): Remove.
8 (free_widget_value_tree, copy_widget_value_tree): Adjust users.
9
12014-05-30 Dmitry Antipov <dmantipov@yandex.ru> 102014-05-30 Dmitry Antipov <dmantipov@yandex.ru>
2 11
3 Use common string allocation and freeing functions where applicable. 12 Use common string allocation and freeing functions where applicable.
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);
99static Boolean get_one_value (widget_instance *, widget_value *); 99static Boolean get_one_value (widget_instance *, widget_value *);
100static void show_one_widget_busy (Widget, Boolean); 100static void show_one_widget_busy (Widget, Boolean);
101 101
102static widget_value *widget_value_free_list = 0;
103static int malloc_cpt = 0;
104
105widget_value *
106malloc_widget_value (void)
107{
108 widget_value *wv;
109 if (widget_value_free_list)
110 {
111 wv = widget_value_free_list;
112 widget_value_free_list = wv->free_list;
113 wv->free_list = 0;
114 }
115 else
116 {
117 wv = (widget_value *) xmalloc (sizeof (widget_value));
118 malloc_cpt++;
119 }
120 memset ((void*) wv, 0, sizeof (widget_value));
121 return wv;
122}
123
124/* this is analogous to free(). It frees only what was allocated
125 by malloc_widget_value(), and no substructures.
126 */
127void
128free_widget_value (widget_value *wv)
129{
130 if (wv->free_list)
131 abort ();
132
133 if (malloc_cpt > 25)
134 {
135 /* When the number of already allocated cells is too big,
136 We free it. */
137 xfree (wv);
138 malloc_cpt--;
139 }
140 else
141 {
142 wv->free_list = widget_value_free_list;
143 widget_value_free_list = wv;
144 }
145}
146
147static void 102static void
148free_widget_value_tree (widget_value *wv) 103free_widget_value_tree (widget_value *wv)
149{ 104{
@@ -172,7 +127,7 @@ free_widget_value_tree (widget_value *wv)
172 free_widget_value_tree (wv->next); 127 free_widget_value_tree (wv->next);
173 wv->next = (widget_value *) 0xDEADBEEF; 128 wv->next = (widget_value *) 0xDEADBEEF;
174 } 129 }
175 free_widget_value (wv); 130 xfree (wv);
176} 131}
177 132
178static widget_value * 133static widget_value *
@@ -185,7 +140,8 @@ copy_widget_value_tree (widget_value *val, change_type change)
185 if (val == (widget_value *) 1) 140 if (val == (widget_value *) 1)
186 return val; 141 return val;
187 142
188 copy = malloc_widget_value (); 143 copy = xmalloc (sizeof (widget_value));
144 copy->lname = copy->lkey = Qnil;
189 copy->name = xstrdup (val->name); 145 copy->name = xstrdup (val->name);
190 copy->value = val->value ? xstrdup (val->value) : NULL; 146 copy->value = val->value ? xstrdup (val->value) : NULL;
191 copy->key = val->key ? xstrdup (val->key) : NULL; 147 copy->key = val->key ? xstrdup (val->key) : NULL;
diff --git a/lwlib/lwlib.h b/lwlib/lwlib.h
index 0e646a26b99..563ade8b34d 100644
--- a/lwlib/lwlib.h
+++ b/lwlib/lwlib.h
@@ -119,11 +119,6 @@ typedef struct _widget_value
119 /* tell us if we should free the toolkit data slot when freeing the 119 /* tell us if we should free the toolkit data slot when freeing the
120 widget_value itself. */ 120 widget_value itself. */
121 Boolean free_toolkit_data; 121 Boolean free_toolkit_data;
122
123 /* we resource the widget_value structures; this points to the next
124 one on the free list if this one has been deallocated.
125 */
126 struct _widget_value *free_list;
127} widget_value; 122} widget_value;
128 123
129 124
@@ -153,8 +148,6 @@ widget_value* lw_get_all_values (LWLIB_ID id);
153Boolean lw_get_some_values (LWLIB_ID id, widget_value* val); 148Boolean lw_get_some_values (LWLIB_ID id, widget_value* val);
154void lw_pop_up_all_widgets (LWLIB_ID id); 149void lw_pop_up_all_widgets (LWLIB_ID id);
155void lw_pop_down_all_widgets (LWLIB_ID id); 150void lw_pop_down_all_widgets (LWLIB_ID id);
156widget_value *malloc_widget_value (void);
157void free_widget_value (widget_value *);
158void lw_popup_menu (Widget, XEvent *); 151void lw_popup_menu (Widget, XEvent *);
159 152
160/* Toolkit independent way of focusing on a Widget at the Xt level. */ 153/* Toolkit independent way of focusing on a Widget at the Xt level. */