>From 664c3ebe3a5b056840691c35f17273945400a4b6 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 7 Jun 2018 19:12:27 -0700 Subject: [PATCH 04/10] Use record_unwind_protect_ptr to avoid allocation * src/term.c (struct tty_pop_down_menu): New type. (tty_pop_down_menu, tty_menu_show): Use it, along with record_unwind_protect_ptr, to avoid allocating a Lisp_Misc. * src/xmenu.c (struct pop_down_menu): New type. (pop_down_menu, x_menu_show): Use it, likewise. * src/xterm.c (x_cr_destroy, x_cr_export_frames): Use record_unwind_protect_pointer to avoid possibly allocating a Lisp_Misc. --- src/term.c | 20 +++++++++++++------- src/xmenu.c | 16 ++++++++++++---- src/xterm.c | 6 ++---- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/term.c b/src/term.c index 08d483f4fa..8c5085f016 100644 --- a/src/term.c +++ b/src/term.c @@ -3408,15 +3408,20 @@ tty_menu_help_callback (char const *help_string, int pane, int item) Qnil, menu_object, make_number (item)); } +struct tty_pop_down_menu +{ + tty_menu *menu; + struct buffer *buffer; +}; + static void -tty_pop_down_menu (Lisp_Object arg) +tty_pop_down_menu (void *arg) { - tty_menu *menu = XSAVE_POINTER (arg, 0); - struct buffer *orig_buffer = XSAVE_POINTER (arg, 1); + struct tty_pop_down_menu *data = arg; block_input (); - tty_menu_destroy (menu); - set_buffer_internal (orig_buffer); + tty_menu_destroy (data->menu); + set_buffer_internal (data->buffer); unblock_input (); } @@ -3697,8 +3702,9 @@ tty_menu_show (struct frame *f, int x, int y, int menuflags, /* We save and restore the current buffer because tty_menu_activate triggers redisplay, which switches buffers at will. */ - record_unwind_protect (tty_pop_down_menu, - make_save_ptr_ptr (menu, current_buffer)); + record_unwind_protect_ptr (tty_pop_down_menu, + &((struct tty_pop_down_menu) + {menu, current_buffer})); specbind (Qoverriding_terminal_local_map, Fsymbol_value (Qtty_menu_navigation_map)); diff --git a/src/xmenu.c b/src/xmenu.c index a5865a6ec2..2fbf9e8bf6 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -2033,11 +2033,18 @@ menu_help_callback (char const *help_string, int pane, int item) Qnil, menu_object, make_number (item)); } +struct pop_down_menu +{ + struct frame *frame; + XMenu *menu; +}; + static void -pop_down_menu (Lisp_Object arg) +pop_down_menu (void *arg) { - struct frame *f = XSAVE_POINTER (arg, 0); - XMenu *menu = XSAVE_POINTER (arg, 1); + union pop_down_menu *data = arg; + struct frame *f = data->frame; + XMenu *menu = data->menu; block_input (); #ifndef MSDOS @@ -2283,7 +2290,8 @@ x_menu_show (struct frame *f, int x, int y, int menuflags, XMenuActivateSetWaitFunction (x_menu_wait_for_event, FRAME_X_DISPLAY (f)); #endif - record_unwind_protect (pop_down_menu, make_save_ptr_ptr (f, menu)); + record_unwind_protect_pointer (pop_down_menu, + &(struct pop_down_menu) {f, menu}); /* Help display under X won't work because XMenuActivate contains a loop that doesn't give Emacs a chance to process it. */ diff --git a/src/xterm.c b/src/xterm.c index 86d6068539..0efced3313 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -544,10 +544,8 @@ x_cr_accumulate_data (void *closure, const unsigned char *data, } static void -x_cr_destroy (Lisp_Object arg) +x_cr_destroy (void *cr); { - cairo_t *cr = xmint_pointer (arg); - block_input (); cairo_destroy (cr); unblock_input (); @@ -606,7 +604,7 @@ x_cr_export_frames (Lisp_Object frames, cairo_surface_type_t surface_type) cr = cairo_create (surface); cairo_surface_destroy (surface); - record_unwind_protect (x_cr_destroy, make_mint_ptr (cr)); + record_unwind_protect_pointer (x_cr_destroy, cr); while (1) { -- 2.17.1