aboutsummaryrefslogtreecommitdiffstats
path: root/src/menu.c
diff options
context:
space:
mode:
authorJoakim Verona2012-05-30 14:08:12 +0200
committerJoakim Verona2012-05-30 14:08:12 +0200
commit70700d8c47a35b19e29607ac5f0ed322bdd78249 (patch)
tree4fa00d3fac00025354f0b6e23dcda1b58689a094 /src/menu.c
parent44fce8ffe7198991c41c985ff4e67ec7d407907e (diff)
parent72cb32cf2f0938dd7dc733eed77b1ed1e497b053 (diff)
downloademacs-70700d8c47a35b19e29607ac5f0ed322bdd78249.tar.gz
emacs-70700d8c47a35b19e29607ac5f0ed322bdd78249.zip
upstream
Diffstat (limited to 'src/menu.c')
-rw-r--r--src/menu.c71
1 files changed, 37 insertions, 34 deletions
diff --git a/src/menu.c b/src/menu.c
index df86208c7ef..9ccfffd768c 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -175,15 +175,17 @@ save_menu_items (void)
175} 175}
176 176
177 177
178/* Make the menu_items vector twice as large. */ 178/* Ensure that there is room for ITEMS items in the menu_items vector. */
179 179
180static void 180static void
181grow_menu_items (void) 181ensure_menu_items (int items)
182{ 182{
183 if ((INT_MAX - MENU_ITEMS_PANE_LENGTH) / 2 < menu_items_allocated) 183 int incr = items - (menu_items_allocated - menu_items_used);
184 memory_full (SIZE_MAX); 184 if (0 < incr)
185 menu_items_allocated *= 2; 185 {
186 menu_items = larger_vector (menu_items, menu_items_allocated, Qnil); 186 menu_items = larger_vector (menu_items, incr, INT_MAX);
187 menu_items_allocated = ASIZE (menu_items);
188 }
187} 189}
188 190
189#if (defined USE_X_TOOLKIT || defined USE_GTK || defined HAVE_NS \ 191#if (defined USE_X_TOOLKIT || defined USE_GTK || defined HAVE_NS \
@@ -194,9 +196,7 @@ grow_menu_items (void)
194static void 196static void
195push_submenu_start (void) 197push_submenu_start (void)
196{ 198{
197 if (menu_items_used + 1 > menu_items_allocated) 199 ensure_menu_items (1);
198 grow_menu_items ();
199
200 XVECTOR (menu_items)->contents[menu_items_used++] = Qnil; 200 XVECTOR (menu_items)->contents[menu_items_used++] = Qnil;
201 menu_items_submenu_depth++; 201 menu_items_submenu_depth++;
202} 202}
@@ -206,9 +206,7 @@ push_submenu_start (void)
206static void 206static void
207push_submenu_end (void) 207push_submenu_end (void)
208{ 208{
209 if (menu_items_used + 1 > menu_items_allocated) 209 ensure_menu_items (1);
210 grow_menu_items ();
211
212 XVECTOR (menu_items)->contents[menu_items_used++] = Qlambda; 210 XVECTOR (menu_items)->contents[menu_items_used++] = Qlambda;
213 menu_items_submenu_depth--; 211 menu_items_submenu_depth--;
214} 212}
@@ -220,9 +218,7 @@ push_submenu_end (void)
220static void 218static void
221push_left_right_boundary (void) 219push_left_right_boundary (void)
222{ 220{
223 if (menu_items_used + 1 > menu_items_allocated) 221 ensure_menu_items (1);
224 grow_menu_items ();
225
226 XVECTOR (menu_items)->contents[menu_items_used++] = Qquote; 222 XVECTOR (menu_items)->contents[menu_items_used++] = Qquote;
227} 223}
228 224
@@ -232,9 +228,7 @@ push_left_right_boundary (void)
232static void 228static void
233push_menu_pane (Lisp_Object name, Lisp_Object prefix_vec) 229push_menu_pane (Lisp_Object name, Lisp_Object prefix_vec)
234{ 230{
235 if (menu_items_used + MENU_ITEMS_PANE_LENGTH > menu_items_allocated) 231 ensure_menu_items (MENU_ITEMS_PANE_LENGTH);
236 grow_menu_items ();
237
238 if (menu_items_submenu_depth == 0) 232 if (menu_items_submenu_depth == 0)
239 menu_items_n_panes++; 233 menu_items_n_panes++;
240 XVECTOR (menu_items)->contents[menu_items_used++] = Qt; 234 XVECTOR (menu_items)->contents[menu_items_used++] = Qt;
@@ -253,8 +247,7 @@ push_menu_pane (Lisp_Object name, Lisp_Object prefix_vec)
253static void 247static void
254push_menu_item (Lisp_Object name, Lisp_Object enable, Lisp_Object key, Lisp_Object def, Lisp_Object equiv, Lisp_Object type, Lisp_Object selected, Lisp_Object help) 248push_menu_item (Lisp_Object name, Lisp_Object enable, Lisp_Object key, Lisp_Object def, Lisp_Object equiv, Lisp_Object type, Lisp_Object selected, Lisp_Object help)
255{ 249{
256 if (menu_items_used + MENU_ITEMS_ITEM_LENGTH > menu_items_allocated) 250 ensure_menu_items (MENU_ITEMS_ITEM_LENGTH);
257 grow_menu_items ();
258 251
259 ASET (menu_items, menu_items_used + MENU_ITEMS_ITEM_NAME, name); 252 ASET (menu_items, menu_items_used + MENU_ITEMS_ITEM_NAME, name);
260 ASET (menu_items, menu_items_used + MENU_ITEMS_ITEM_ENABLE, enable); 253 ASET (menu_items, menu_items_used + MENU_ITEMS_ITEM_ENABLE, enable);
@@ -458,9 +451,9 @@ single_menu_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy, void *sk
458 and generate menu panes for them in menu_items. */ 451 and generate menu panes for them in menu_items. */
459 452
460static void 453static void
461keymap_panes (Lisp_Object *keymaps, int nmaps) 454keymap_panes (Lisp_Object *keymaps, ptrdiff_t nmaps)
462{ 455{
463 int mapno; 456 ptrdiff_t mapno;
464 457
465 init_menu_items (); 458 init_menu_items ();
466 459
@@ -532,16 +525,17 @@ int
532parse_single_submenu (Lisp_Object item_key, Lisp_Object item_name, Lisp_Object maps) 525parse_single_submenu (Lisp_Object item_key, Lisp_Object item_name, Lisp_Object maps)
533{ 526{
534 Lisp_Object length; 527 Lisp_Object length;
535 int len; 528 EMACS_INT len;
536 Lisp_Object *mapvec; 529 Lisp_Object *mapvec;
537 int i; 530 ptrdiff_t i;
538 int top_level_items = 0; 531 int top_level_items = 0;
532 USE_SAFE_ALLOCA;
539 533
540 length = Flength (maps); 534 length = Flength (maps);
541 len = XINT (length); 535 len = XINT (length);
542 536
543 /* Convert the list MAPS into a vector MAPVEC. */ 537 /* Convert the list MAPS into a vector MAPVEC. */
544 mapvec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); 538 SAFE_ALLOCA_LISP (mapvec, len);
545 for (i = 0; i < len; i++) 539 for (i = 0; i < len; i++)
546 { 540 {
547 mapvec[i] = Fcar (maps); 541 mapvec[i] = Fcar (maps);
@@ -571,6 +565,7 @@ parse_single_submenu (Lisp_Object item_key, Lisp_Object item_name, Lisp_Object m
571 } 565 }
572 } 566 }
573 567
568 SAFE_FREE ();
574 return top_level_items; 569 return top_level_items;
575} 570}
576 571
@@ -1006,7 +1001,7 @@ find_and_return_menu_selection (FRAME_PTR f, int keymaps, void *client_data)
1006 { 1001 {
1007 entry 1002 entry
1008 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_VALUE]; 1003 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_VALUE];
1009 if ((EMACS_INT)client_data == (EMACS_INT)(&XVECTOR (menu_items)->contents[i])) 1004 if (&XVECTOR (menu_items)->contents[i] == client_data)
1010 { 1005 {
1011 if (keymaps != 0) 1006 if (keymaps != 0)
1012 { 1007 {
@@ -1082,7 +1077,7 @@ no quit occurs and `x-popup-menu' returns nil. */)
1082 Lisp_Object x, y, window; 1077 Lisp_Object x, y, window;
1083 int keymaps = 0; 1078 int keymaps = 0;
1084 int for_click = 0; 1079 int for_click = 0;
1085 int specpdl_count = SPECPDL_INDEX (); 1080 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
1086 struct gcpro gcpro1; 1081 struct gcpro gcpro1;
1087 1082
1088 if (NILP (position)) 1083 if (NILP (position))
@@ -1175,9 +1170,6 @@ no quit occurs and `x-popup-menu' returns nil. */)
1175 } 1170 }
1176 } 1171 }
1177 1172
1178 CHECK_NUMBER (x);
1179 CHECK_NUMBER (y);
1180
1181 /* Decode where to put the menu. */ 1173 /* Decode where to put the menu. */
1182 1174
1183 if (FRAMEP (window)) 1175 if (FRAMEP (window))
@@ -1200,6 +1192,14 @@ no quit occurs and `x-popup-menu' returns nil. */)
1200 but I don't want to make one now. */ 1192 but I don't want to make one now. */
1201 CHECK_WINDOW (window); 1193 CHECK_WINDOW (window);
1202 1194
1195 CHECK_RANGED_INTEGER ((xpos < INT_MIN - MOST_NEGATIVE_FIXNUM
1196 ? (EMACS_INT) INT_MIN - xpos
1197 : MOST_NEGATIVE_FIXNUM),
1198 x, INT_MAX - xpos);
1199 CHECK_RANGED_INTEGER ((ypos < INT_MIN - MOST_NEGATIVE_FIXNUM
1200 ? (EMACS_INT) INT_MIN - ypos
1201 : MOST_NEGATIVE_FIXNUM),
1202 y, INT_MAX - ypos);
1203 xpos += XINT (x); 1203 xpos += XINT (x);
1204 ypos += XINT (y); 1204 ypos += XINT (y);
1205 1205
@@ -1248,11 +1248,12 @@ no quit occurs and `x-popup-menu' returns nil. */)
1248 else if (CONSP (menu) && KEYMAPP (XCAR (menu))) 1248 else if (CONSP (menu) && KEYMAPP (XCAR (menu)))
1249 { 1249 {
1250 /* We were given a list of keymaps. */ 1250 /* We were given a list of keymaps. */
1251 int nmaps = XFASTINT (Flength (menu)); 1251 EMACS_INT nmaps = XFASTINT (Flength (menu));
1252 Lisp_Object *maps 1252 Lisp_Object *maps;
1253 = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); 1253 ptrdiff_t i;
1254 int i; 1254 USE_SAFE_ALLOCA;
1255 1255
1256 SAFE_ALLOCA_LISP (maps, nmaps);
1256 title = Qnil; 1257 title = Qnil;
1257 1258
1258 /* The first keymap that has a prompt string 1259 /* The first keymap that has a prompt string
@@ -1276,6 +1277,8 @@ no quit occurs and `x-popup-menu' returns nil. */)
1276 ASET (menu_items, MENU_ITEMS_PANE_NAME, title); 1277 ASET (menu_items, MENU_ITEMS_PANE_NAME, title);
1277 1278
1278 keymaps = 1; 1279 keymaps = 1;
1280
1281 SAFE_FREE ();
1279 } 1282 }
1280 else 1283 else
1281 { 1284 {