diff options
| author | Dmitry Antipov | 2014-06-02 22:01:21 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2014-06-02 22:01:21 +0400 |
| commit | 5668fb88bf3731d39c4e958c8e79a549f789ce1e (patch) | |
| tree | b0d3fd3555fca3b34c47b803a633da2f36d31165 /src/menu.c | |
| parent | da11196a248b530c3b3a8329497d71332f8c71a3 (diff) | |
| download | emacs-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 'src/menu.c')
| -rw-r--r-- | src/menu.c | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/src/menu.c b/src/menu.c index 468f2814eb4..0cd886f55d1 100644 --- a/src/menu.c +++ b/src/menu.c | |||
| @@ -576,21 +576,26 @@ parse_single_submenu (Lisp_Object item_key, Lisp_Object item_name, | |||
| 576 | 576 | ||
| 577 | #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (HAVE_NTGUI) | 577 | #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (HAVE_NTGUI) |
| 578 | 578 | ||
| 579 | /* Allocate a widget_value, blocking input. */ | 579 | /* Allocate and basically initialize widget_value, blocking input. */ |
| 580 | 580 | ||
| 581 | widget_value * | 581 | widget_value * |
| 582 | xmalloc_widget_value (void) | 582 | make_widget_value (const char *name, char *value, |
| 583 | bool enabled, Lisp_Object help) | ||
| 583 | { | 584 | { |
| 584 | widget_value *value; | 585 | widget_value *wv; |
| 585 | 586 | ||
| 586 | block_input (); | 587 | block_input (); |
| 587 | value = malloc_widget_value (); | 588 | wv = xzalloc (sizeof (widget_value)); |
| 588 | unblock_input (); | 589 | unblock_input (); |
| 589 | 590 | ||
| 590 | return value; | 591 | wv->name = (char *) name; |
| 592 | wv->value = value; | ||
| 593 | wv->enabled = enabled; | ||
| 594 | wv->help = help; | ||
| 595 | return wv; | ||
| 591 | } | 596 | } |
| 592 | 597 | ||
| 593 | /* This recursively calls free_widget_value on the tree of widgets. | 598 | /* This recursively calls xfree on the tree of widgets. |
| 594 | It must free all data that was malloc'ed for these widget_values. | 599 | It must free all data that was malloc'ed for these widget_values. |
| 595 | In Emacs, many slots are pointers into the data of Lisp_Strings, and | 600 | In Emacs, many slots are pointers into the data of Lisp_Strings, and |
| 596 | must be left alone. */ | 601 | must be left alone. */ |
| @@ -613,7 +618,7 @@ free_menubar_widget_value_tree (widget_value *wv) | |||
| 613 | wv->next = (widget_value *) 0xDEADBEEF; | 618 | wv->next = (widget_value *) 0xDEADBEEF; |
| 614 | } | 619 | } |
| 615 | block_input (); | 620 | block_input (); |
| 616 | free_widget_value (wv); | 621 | xfree (wv); |
| 617 | unblock_input (); | 622 | unblock_input (); |
| 618 | } | 623 | } |
| 619 | 624 | ||
| @@ -632,12 +637,8 @@ digest_single_submenu (int start, int end, bool top_level_items) | |||
| 632 | struct frame *f = XFRAME (Vmenu_updating_frame); | 637 | struct frame *f = XFRAME (Vmenu_updating_frame); |
| 633 | 638 | ||
| 634 | submenu_stack = alloca (menu_items_used * sizeof *submenu_stack); | 639 | submenu_stack = alloca (menu_items_used * sizeof *submenu_stack); |
| 635 | wv = xmalloc_widget_value (); | 640 | wv = make_widget_value ("menu", NULL, true, Qnil); |
| 636 | wv->name = "menu"; | ||
| 637 | wv->value = 0; | ||
| 638 | wv->enabled = 1; | ||
| 639 | wv->button_type = BUTTON_TYPE_NONE; | 641 | wv->button_type = BUTTON_TYPE_NONE; |
| 640 | wv->help = Qnil; | ||
| 641 | first_wv = wv; | 642 | first_wv = wv; |
| 642 | save_wv = 0; | 643 | save_wv = 0; |
| 643 | prev_wv = 0; | 644 | prev_wv = 0; |
| @@ -721,17 +722,14 @@ digest_single_submenu (int start, int end, bool top_level_items) | |||
| 721 | with its items as a submenu beneath it. */ | 722 | with its items as a submenu beneath it. */ |
| 722 | if (strcmp (pane_string, "")) | 723 | if (strcmp (pane_string, "")) |
| 723 | { | 724 | { |
| 724 | wv = xmalloc_widget_value (); | 725 | /* Set value to 1 so update_submenu_strings can handle '@'. */ |
| 726 | wv = make_widget_value (NULL, (char *) 1, true, Qnil); | ||
| 725 | if (save_wv) | 727 | if (save_wv) |
| 726 | save_wv->next = wv; | 728 | save_wv->next = wv; |
| 727 | else | 729 | else |
| 728 | first_wv->contents = wv; | 730 | first_wv->contents = wv; |
| 729 | wv->lname = pane_name; | 731 | wv->lname = pane_name; |
| 730 | /* Set value to 1 so update_submenu_strings can handle '@' */ | ||
| 731 | wv->value = (char *)1; | ||
| 732 | wv->enabled = 1; | ||
| 733 | wv->button_type = BUTTON_TYPE_NONE; | 732 | wv->button_type = BUTTON_TYPE_NONE; |
| 734 | wv->help = Qnil; | ||
| 735 | save_wv = wv; | 733 | save_wv = wv; |
| 736 | } | 734 | } |
| 737 | else | 735 | else |
| @@ -805,7 +803,8 @@ digest_single_submenu (int start, int end, bool top_level_items) | |||
| 805 | #endif | 803 | #endif |
| 806 | } | 804 | } |
| 807 | 805 | ||
| 808 | wv = xmalloc_widget_value (); | 806 | wv = make_widget_value (NULL, NULL, !NILP (enable), |
| 807 | STRINGP (help) ? help : Qnil); | ||
| 809 | if (prev_wv) | 808 | if (prev_wv) |
| 810 | prev_wv->next = wv; | 809 | prev_wv->next = wv; |
| 811 | else | 810 | else |
| @@ -814,11 +813,9 @@ digest_single_submenu (int start, int end, bool top_level_items) | |||
| 814 | wv->lname = item_name; | 813 | wv->lname = item_name; |
| 815 | if (!NILP (descrip)) | 814 | if (!NILP (descrip)) |
| 816 | wv->lkey = descrip; | 815 | wv->lkey = descrip; |
| 817 | wv->value = 0; | ||
| 818 | /* The intptr_t cast avoids a warning. There's no problem | 816 | /* The intptr_t cast avoids a warning. There's no problem |
| 819 | as long as pointers have enough bits to hold small integers. */ | 817 | as long as pointers have enough bits to hold small integers. */ |
| 820 | wv->call_data = (!NILP (def) ? (void *) (intptr_t) i : 0); | 818 | wv->call_data = (!NILP (def) ? (void *) (intptr_t) i : 0); |
| 821 | wv->enabled = !NILP (enable); | ||
| 822 | 819 | ||
| 823 | if (NILP (type)) | 820 | if (NILP (type)) |
| 824 | wv->button_type = BUTTON_TYPE_NONE; | 821 | wv->button_type = BUTTON_TYPE_NONE; |
| @@ -830,10 +827,6 @@ digest_single_submenu (int start, int end, bool top_level_items) | |||
| 830 | emacs_abort (); | 827 | emacs_abort (); |
| 831 | 828 | ||
| 832 | wv->selected = !NILP (selected); | 829 | wv->selected = !NILP (selected); |
| 833 | if (! STRINGP (help)) | ||
| 834 | help = Qnil; | ||
| 835 | |||
| 836 | wv->help = help; | ||
| 837 | 830 | ||
| 838 | prev_wv = wv; | 831 | prev_wv = wv; |
| 839 | 832 | ||
| @@ -846,7 +839,7 @@ digest_single_submenu (int start, int end, bool top_level_items) | |||
| 846 | if (top_level_items && first_wv->contents && first_wv->contents->next == 0) | 839 | if (top_level_items && first_wv->contents && first_wv->contents->next == 0) |
| 847 | { | 840 | { |
| 848 | wv = first_wv->contents; | 841 | wv = first_wv->contents; |
| 849 | free_widget_value (first_wv); | 842 | xfree (first_wv); |
| 850 | return wv; | 843 | return wv; |
| 851 | } | 844 | } |
| 852 | 845 | ||