From: Paul Eggert Date: Mon, 4 Mar 2019 08:00:39 +0000 (-0800) Subject: Simplify list creation in C code X-Git-Tag: emacs-27.0.90~3492 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5c2563a5472cd5580e7af570aa320ac581ad1985;p=emacs.git Simplify list creation in C code The main new thing here is that C code can now say ‘list (a, b, c, d, e, f)’ instead of ‘listn (CONSTYPE_HEAP, 6, a, b, c, d, e, f)’, thus relieving callers of the responsibility of counting arguments (plus, the code feels more like Lisp). The old list1 ... list5 functions remain, as they’re probably a bit faster for small lists. * src/alloc.c (cons_listn, pure_listn): New functions. (listn): Omit enum argument. All callers changed to use either new ‘list’ or ‘pure_list’ macros. * src/charset.c (Fdefine_charset_internal): * src/coding.c (detect_coding_system) (Fset_terminal_coding_system_internal): * src/frame.c (frame_size_history_add, adjust_frame_size): * src/gtkutil.c (xg_frame_set_char_size): * src/keyboard.c (command_loop_1): * src/nsfns.m (frame_geometry): * src/widget.c (set_frame_size): * src/xfaces.c (Fcolor_distance): * src/xfns.c (frame_geometry): * src/xterm.c (x_set_window_size_1): * src/xwidget.c (Fxwidget_size_request): Prefer list1i, list2i, etc. to open-coding them. * src/charset.c (Fset_charset_priority): * src/nsterm.m (append2): * src/window.c (window_list): * src/xfaces.c (Fx_list_fonts): Use nconc2 instead of open-coding it. * src/eval.c (eval_sub, backtrace_frame_apply): * src/kqueue.c (kqueue_generate_event): * src/nsterm.m (performDragOperation:): * src/pdumper.c (Fpdumper_stats): * src/w32.c (init_environment): Prefer list1, list2, etc. to open-coding them. * src/font.c (font_list_entities): Parenthesize to avoid expanding new ‘list’ macro. * src/gtkutil.c (GETSETUP): Rename from MAKE_FLOAT_PAGE_SETUP to get lines to fit. Move outside the ‘list’ call, since it’s now a macro. * src/keymap.c (Fmake_keymap): Simplify. * src/lisp.h (list, pure_list): New macros. (list1i): New function. --- diff --git a/src/alloc.c b/src/alloc.c index 6b366485550..02c55f8ce4c 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -2864,50 +2864,57 @@ list3 (Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3) return Fcons (arg1, Fcons (arg2, Fcons (arg3, Qnil))); } - Lisp_Object list4 (Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, Lisp_Object arg4) { return Fcons (arg1, Fcons (arg2, Fcons (arg3, Fcons (arg4, Qnil)))); } - Lisp_Object -list5 (Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5) +list5 (Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, Lisp_Object arg4, + Lisp_Object arg5) { return Fcons (arg1, Fcons (arg2, Fcons (arg3, Fcons (arg4, Fcons (arg5, Qnil))))); } -/* Make a list of COUNT Lisp_Objects, where ARG is the - first one. Allocate conses from pure space if TYPE - is CONSTYPE_PURE, or allocate as usual if type is CONSTYPE_HEAP. */ - -Lisp_Object -listn (enum constype type, ptrdiff_t count, Lisp_Object arg, ...) +/* Make a list of COUNT Lisp_Objects, where ARG is the first one. + Use CONS to construct the pairs. AP has any remaining args. */ +static Lisp_Object +cons_listn (ptrdiff_t count, Lisp_Object arg, + Lisp_Object (*cons) (Lisp_Object, Lisp_Object), va_list ap) { - Lisp_Object (*cons) (Lisp_Object, Lisp_Object); - switch (type) - { - case CONSTYPE_PURE: cons = pure_cons; break; - case CONSTYPE_HEAP: cons = Fcons; break; - default: emacs_abort (); - } - eassume (0 < count); Lisp_Object val = cons (arg, Qnil); Lisp_Object tail = val; - - va_list ap; - va_start (ap, arg); for (ptrdiff_t i = 1; i < count; i++) { Lisp_Object elem = cons (va_arg (ap, Lisp_Object), Qnil); XSETCDR (tail, elem); tail = elem; } + return val; +} + +/* Make a list of COUNT Lisp_Objects, where ARG1 is the first one. */ +Lisp_Object +listn (ptrdiff_t count, Lisp_Object arg1, ...) +{ + va_list ap; + va_start (ap, arg1); + Lisp_Object val = cons_listn (count, arg1, Fcons, ap); va_end (ap); + return val; +} +/* Make a pure list of COUNT Lisp_Objects, where ARG1 is the first one. */ +Lisp_Object +pure_listn (ptrdiff_t count, Lisp_Object arg1, ...) +{ + va_list ap; + va_start (ap, arg1); + Lisp_Object val = cons_listn (count, arg1, pure_cons, ap); + va_end (ap); return val; } @@ -7283,8 +7290,7 @@ Frames, windows, buffers, and subprocesses count as vectors (but the contents of a buffer's text do not count here). */) (void) { - return listn (CONSTYPE_HEAP, 7, - make_int (cons_cells_consed), + return list (make_int (cons_cells_consed), make_int (floats_consed), make_int (vector_cells_consed), make_int (symbols_consed), @@ -7584,8 +7590,10 @@ do hash-consing of the objects allocated to pure space. */); /* We build this in advance because if we wait until we need it, we might not be able to allocate the memory to hold it. */ Vmemory_signal_data - = listn (CONSTYPE_PURE, 2, Qerror, - build_pure_c_string ("Memory exhausted--use M-x save-some-buffers then exit and restart Emacs")); + = pure_list (Qerror, + build_pure_c_string ("Memory exhausted--use" + " M-x save-some-buffers then" + " exit and restart Emacs")); DEFVAR_LISP ("memory-full", Vmemory_full, doc: /* Non-nil means Emacs cannot get much more Lisp memory. */); diff --git a/src/buffer.c b/src/buffer.c index e5cc5f367f0..44b33f5b60d 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -5487,7 +5487,7 @@ syms_of_buffer (void) Qoverwrite_mode_binary)); Fput (Qprotected_field, Qerror_conditions, - listn (CONSTYPE_PURE, 2, Qprotected_field, Qerror)); + pure_list (Qprotected_field, Qerror)); Fput (Qprotected_field, Qerror_message, build_pure_c_string ("Attempt to modify a protected field")); diff --git a/src/callint.c b/src/callint.c index ba6e3350a50..9993e732fb4 100644 --- a/src/callint.c +++ b/src/callint.c @@ -814,11 +814,10 @@ syms_of_callint (void) callint_message = Qnil; staticpro (&callint_message); - preserved_fns = listn (CONSTYPE_PURE, 4, - intern_c_string ("region-beginning"), - intern_c_string ("region-end"), - intern_c_string ("point"), - intern_c_string ("mark")); + preserved_fns = pure_list (intern_c_string ("region-beginning"), + intern_c_string ("region-end"), + intern_c_string ("point"), + intern_c_string ("mark")); staticpro (&preserved_fns); DEFSYM (Qlist, "list"); diff --git a/src/charset.c b/src/charset.c index 7e2e657c7fc..56ab8d70181 100644 --- a/src/charset.c +++ b/src/charset.c @@ -1175,8 +1175,7 @@ usage: (define-charset-internal ...) */) ISO_CHARSET_TABLE (charset.dimension, charset.iso_chars_96, charset.iso_final) = id; if (new_definition_p) - Viso_2022_charset_list = nconc2 (Viso_2022_charset_list, - list1 (make_fixnum (id))); + Viso_2022_charset_list = nconc2 (Viso_2022_charset_list, list1i (id)); if (ISO_CHARSET_TABLE (1, 0, 'J') == id) charset_jisx0201_roman = id; else if (ISO_CHARSET_TABLE (2, 0, '@') == id) @@ -1196,15 +1195,14 @@ usage: (define-charset-internal ...) */) emacs_mule_bytes[charset.emacs_mule_id] = charset.dimension + 2; if (new_definition_p) Vemacs_mule_charset_list = nconc2 (Vemacs_mule_charset_list, - list1 (make_fixnum (id))); + list1i (id)); } if (new_definition_p) { Vcharset_list = Fcons (args[charset_arg_name], Vcharset_list); if (charset.supplementary_p) - Vcharset_ordered_list = nconc2 (Vcharset_ordered_list, - list1 (make_fixnum (id))); + Vcharset_ordered_list = nconc2 (Vcharset_ordered_list, list1i (id)); else { Lisp_Object tail; @@ -1221,7 +1219,7 @@ usage: (define-charset-internal ...) */) Vcharset_ordered_list); else if (NILP (tail)) Vcharset_ordered_list = nconc2 (Vcharset_ordered_list, - list1 (make_fixnum (id))); + list1i (id)); else { val = Fcons (XCAR (tail), XCDR (tail)); @@ -1278,8 +1276,7 @@ define_charset_internal (Lisp_Object name, args[charset_arg_unify_map] = Qnil; args[charset_arg_plist] = - listn (CONSTYPE_HEAP, 14, - QCname, + list (QCname, args[charset_arg_name], intern_c_string (":dimension"), args[charset_arg_dimension], @@ -2180,7 +2177,7 @@ usage: (set-charset-priority &rest charsets) */) } } Vcharset_non_preferred_head = old_list; - Vcharset_ordered_list = CALLN (Fnconc, Fnreverse (new_head), old_list); + Vcharset_ordered_list = nconc2 (Fnreverse (new_head), old_list); charset_ordered_list_tick++; diff --git a/src/coding.c b/src/coding.c index e470757f92e..a216460fc2c 100644 --- a/src/coding.c +++ b/src/coding.c @@ -8720,20 +8720,20 @@ detect_coding_system (const unsigned char *src, { detect_info.found = CATEGORY_MASK_RAW_TEXT; id = CODING_SYSTEM_ID (Qno_conversion); - val = list1 (make_fixnum (id)); + val = list1i (id); } else if (! detect_info.rejected && ! detect_info.found) { detect_info.found = CATEGORY_MASK_ANY; id = coding_categories[coding_category_undecided].id; - val = list1 (make_fixnum (id)); + val = list1i (id); } else if (highest) { if (detect_info.found) { detect_info.found = 1 << category; - val = list1 (make_fixnum (this->id)); + val = list1i (this->id); } else for (i = 0; i < coding_category_raw_text; i++) @@ -8741,7 +8741,7 @@ detect_coding_system (const unsigned char *src, { detect_info.found = 1 << coding_priorities[i]; id = coding_categories[coding_priorities[i]].id; - val = list1 (make_fixnum (id)); + val = list1i (id); break; } } @@ -8758,7 +8758,7 @@ detect_coding_system (const unsigned char *src, found |= 1 << category; id = coding_categories[category].id; if (id >= 0) - val = list1 (make_fixnum (id)); + val = list1i (id); } } for (i = coding_category_raw_text - 1; i >= 0; i--) @@ -8783,7 +8783,7 @@ detect_coding_system (const unsigned char *src, this = coding_categories + coding_category_utf_8_sig; else this = coding_categories + coding_category_utf_8_nosig; - val = list1 (make_fixnum (this->id)); + val = list1i (this->id); } } else if (base_category == coding_category_utf_16_auto) @@ -8800,13 +8800,13 @@ detect_coding_system (const unsigned char *src, this = coding_categories + coding_category_utf_16_be_nosig; else this = coding_categories + coding_category_utf_16_le_nosig; - val = list1 (make_fixnum (this->id)); + val = list1i (this->id); } } else { detect_info.found = 1 << XFIXNUM (CODING_ATTR_CATEGORY (attrs)); - val = list1 (make_fixnum (coding.id)); + val = list1i (coding.id); } /* Then, detect eol-format if necessary. */ @@ -9749,7 +9749,7 @@ DEFUN ("set-terminal-coding-system-internal", Fset_terminal_coding_system_intern tset_charset_list (term, (terminal_coding->common_flags & CODING_REQUIRE_ENCODING_MASK ? coding_charset_list (terminal_coding) - : list1 (make_fixnum (charset_ascii)))); + : list1i (charset_ascii))); return Qnil; } @@ -10856,7 +10856,7 @@ syms_of_coding (void) /* Error signaled when there's a problem with detecting a coding system. */ DEFSYM (Qcoding_system_error, "coding-system-error"); Fput (Qcoding_system_error, Qerror_conditions, - listn (CONSTYPE_PURE, 2, Qcoding_system_error, Qerror)); + pure_list (Qcoding_system_error, Qerror)); Fput (Qcoding_system_error, Qerror_message, build_pure_c_string ("Invalid coding system")); @@ -11298,7 +11298,7 @@ internal character representation. */); /* This is already set. plist[7] = args[coding_arg_ascii_compatible_p] = Qt; */ plist[8] = intern_c_string (":charset-list"); - plist[9] = args[coding_arg_charset_list] = Fcons (Qascii, Qnil); + plist[9] = args[coding_arg_charset_list] = list1 (Qascii); plist[11] = args[coding_arg_for_unibyte] = Qnil; plist[13] = build_pure_c_string ("No conversion on encoding, " "automatic conversion on decoding."); diff --git a/src/emacs-module.c b/src/emacs-module.c index b70d6cea812..4e2411cb295 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -1234,42 +1234,38 @@ syms_of_module (void) DEFSYM (Qmodule_load_failed, "module-load-failed"); Fput (Qmodule_load_failed, Qerror_conditions, - listn (CONSTYPE_PURE, 2, Qmodule_load_failed, Qerror)); + pure_list (Qmodule_load_failed, Qerror)); Fput (Qmodule_load_failed, Qerror_message, build_pure_c_string ("Module load failed")); DEFSYM (Qmodule_open_failed, "module-open-failed"); Fput (Qmodule_open_failed, Qerror_conditions, - listn (CONSTYPE_PURE, 3, - Qmodule_open_failed, Qmodule_load_failed, Qerror)); + pure_list (Qmodule_open_failed, Qmodule_load_failed, Qerror)); Fput (Qmodule_open_failed, Qerror_message, build_pure_c_string ("Module could not be opened")); DEFSYM (Qmodule_not_gpl_compatible, "module-not-gpl-compatible"); Fput (Qmodule_not_gpl_compatible, Qerror_conditions, - listn (CONSTYPE_PURE, 3, - Qmodule_not_gpl_compatible, Qmodule_load_failed, Qerror)); + pure_list (Qmodule_not_gpl_compatible, Qmodule_load_failed, Qerror)); Fput (Qmodule_not_gpl_compatible, Qerror_message, build_pure_c_string ("Module is not GPL compatible")); DEFSYM (Qmissing_module_init_function, "missing-module-init-function"); Fput (Qmissing_module_init_function, Qerror_conditions, - listn (CONSTYPE_PURE, 3, - Qmissing_module_init_function, Qmodule_load_failed, Qerror)); + pure_list (Qmissing_module_init_function, Qmodule_load_failed, + Qerror)); Fput (Qmissing_module_init_function, Qerror_message, build_pure_c_string ("Module does not export an " "initialization function")); DEFSYM (Qmodule_init_failed, "module-init-failed"); Fput (Qmodule_init_failed, Qerror_conditions, - listn (CONSTYPE_PURE, 3, - Qmodule_init_failed, Qmodule_load_failed, Qerror)); + pure_list (Qmodule_init_failed, Qmodule_load_failed, Qerror)); Fput (Qmodule_init_failed, Qerror_message, build_pure_c_string ("Module initialization failed")); DEFSYM (Qinvalid_arity, "invalid-arity"); - Fput (Qinvalid_arity, Qerror_conditions, - listn (CONSTYPE_PURE, 2, Qinvalid_arity, Qerror)); + Fput (Qinvalid_arity, Qerror_conditions, pure_list (Qinvalid_arity, Qerror)); Fput (Qinvalid_arity, Qerror_message, build_pure_c_string ("Invalid function arity")); diff --git a/src/eval.c b/src/eval.c index e162725f03d..09e8fdf4c2a 100644 --- a/src/eval.c +++ b/src/eval.c @@ -2246,7 +2246,7 @@ eval_sub (Lisp_Object form) /* Optimize for no indirection. */ fun = original_fun; if (!SYMBOLP (fun)) - fun = Ffunction (Fcons (fun, Qnil)); + fun = Ffunction (list1 (fun)); else if (!NILP (fun) && (fun = XSYMBOL (fun)->u.s.function, SYMBOLP (fun))) fun = indirect_function (fun); @@ -3690,7 +3690,7 @@ backtrace_frame_apply (Lisp_Object function, union specbinding *pdl) Lisp_Object flags = Qnil; if (backtrace_debug_on_exit (pdl)) - flags = Fcons (QCdebug_on_exit, Fcons (Qt, Qnil)); + flags = list2 (QCdebug_on_exit, Qt); if (backtrace_nargs (pdl) == UNEVALLED) return call4 (function, Qnil, backtrace_function (pdl), *backtrace_args (pdl), flags); diff --git a/src/fns.c b/src/fns.c index d55158e72f1..6573124a935 100644 --- a/src/fns.c +++ b/src/fns.c @@ -4914,13 +4914,7 @@ DEFUN ("secure-hash-algorithms", Fsecure_hash_algorithms, doc: /* Return a list of all the supported `secure_hash' algorithms. */) (void) { - return listn (CONSTYPE_HEAP, 6, - Qmd5, - Qsha1, - Qsha224, - Qsha256, - Qsha384, - Qsha512); + return list (Qmd5, Qsha1, Qsha224, Qsha256, Qsha384, Qsha512); } /* Extract data from a string or a buffer. SPEC is a list of diff --git a/src/font.c b/src/font.c index 4ca44942fde..9220fb1cd24 100644 --- a/src/font.c +++ b/src/font.c @@ -2781,7 +2781,7 @@ font_list_entities (struct frame *f, Lisp_Object spec) { Lisp_Object copy; - val = driver_list->driver->list (f, scratch_font_spec); + val = (driver_list->driver->list) (f, scratch_font_spec); /* We put zero_vector in the font-cache to indicate that no fonts matching SPEC were found on the system. Failure to have this indication in the font cache can diff --git a/src/frame.c b/src/frame.c index d1d6993e94b..c7108d6a902 100644 --- a/src/frame.c +++ b/src/frame.c @@ -163,10 +163,8 @@ frame_size_history_add (struct frame *f, Lisp_Object fun_symbol, Fcons (list4 (frame, fun_symbol, ((width > 0) - ? list4 (make_fixnum (FRAME_TEXT_WIDTH (f)), - make_fixnum (FRAME_TEXT_HEIGHT (f)), - make_fixnum (width), - make_fixnum (height)) + ? list4i (FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), + width, height) : Qnil), rest), XCDR (frame_size_history))); @@ -744,8 +742,8 @@ adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit, frame_size_history_add (f, Qadjust_frame_size_3, new_text_width, new_text_height, - list4 (make_fixnum (old_pixel_width), make_fixnum (old_pixel_height), - make_fixnum (new_pixel_width), make_fixnum (new_pixel_height))); + list4i (old_pixel_width, old_pixel_height, + new_pixel_width, new_pixel_height)); /* Assign new sizes. */ FRAME_TEXT_WIDTH (f) = new_text_width; diff --git a/src/gnutls.c b/src/gnutls.c index 2951c8d074c..1afbb2bd4e5 100644 --- a/src/gnutls.c +++ b/src/gnutls.c @@ -1998,7 +1998,7 @@ The alist key is the cipher name. */) ptrdiff_t cipher_tag_size = gnutls_cipher_get_tag_size (gca); Lisp_Object cp - = listn (CONSTYPE_HEAP, 15, cipher_symbol, + = list (cipher_symbol, QCcipher_id, make_fixnum (gca), QCtype, Qgnutls_type_cipher, QCcipher_aead_capable, cipher_tag_size == 0 ? Qnil : Qt, @@ -2329,7 +2329,7 @@ name. */) # ifdef HAVE_GNUTLS_MAC_GET_NONCE_SIZE nonce_size = gnutls_mac_get_nonce_size (gma); # endif - Lisp_Object mp = listn (CONSTYPE_HEAP, 11, gma_symbol, + Lisp_Object mp = list (gma_symbol, QCmac_algorithm_id, make_fixnum (gma), QCtype, Qgnutls_type_mac_algorithm, @@ -2364,7 +2364,7 @@ method name. */) /* A symbol representing the GnuTLS digest algorithm. */ Lisp_Object gda_symbol = intern (gnutls_digest_get_name (gda)); - Lisp_Object mp = listn (CONSTYPE_HEAP, 7, gda_symbol, + Lisp_Object mp = list (gda_symbol, QCdigest_algorithm_id, make_fixnum (gda), QCtype, Qgnutls_type_digest_algorithm, diff --git a/src/gtkutil.c b/src/gtkutil.c index 75fc9ea5477..58e95a46796 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -967,7 +967,7 @@ xg_frame_set_char_size (struct frame *f, int width, int height) { frame_size_history_add (f, Qxg_frame_set_char_size_1, width, height, - list2 (make_fixnum (gheight), make_fixnum (totalheight))); + list2i (gheight, totalheight)); gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), gwidth, totalheight); @@ -976,7 +976,7 @@ xg_frame_set_char_size (struct frame *f, int width, int height) { frame_size_history_add (f, Qxg_frame_set_char_size_2, width, height, - list2 (make_fixnum (gwidth), make_fixnum (totalwidth))); + list2i (gwidth, totalwidth)); gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), totalwidth, gheight); @@ -985,7 +985,7 @@ xg_frame_set_char_size (struct frame *f, int width, int height) { frame_size_history_add (f, Qxg_frame_set_char_size_3, width, height, - list2 (make_fixnum (totalwidth), make_fixnum (totalheight))); + list2i (totalwidth, totalheight)); gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), totalwidth, totalheight); @@ -4260,23 +4260,16 @@ xg_get_page_setup (void) eassume (false); } - return listn (CONSTYPE_HEAP, 7, - Fcons (Qorientation, orientation_symbol), -#define MAKE_FLOAT_PAGE_SETUP(f) make_float (f (page_setup, GTK_UNIT_POINTS)) - Fcons (Qwidth, - MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_page_width)), - Fcons (Qheight, - MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_page_height)), - Fcons (Qleft_margin, - MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_left_margin)), - Fcons (Qright_margin, - MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_right_margin)), - Fcons (Qtop_margin, - MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_top_margin)), - Fcons (Qbottom_margin, - MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_bottom_margin)) -#undef MAKE_FLOAT_PAGE_SETUP - ); +#define GETSETUP(f) make_float (f (page_setup, GTK_UNIT_POINTS)) + return + list (Fcons (Qorientation, orientation_symbol), + Fcons (Qwidth, GETSETUP (gtk_page_setup_get_page_width)), + Fcons (Qheight, GETSETUP (gtk_page_setup_get_page_height)), + Fcons (Qleft_margin, GETSETUP (gtk_page_setup_get_left_margin)), + Fcons (Qright_margin, GETSETUP (gtk_page_setup_get_right_margin)), + Fcons (Qtop_margin, GETSETUP (gtk_page_setup_get_top_margin)), + Fcons (Qbottom_margin, GETSETUP (gtk_page_setup_get_bottom_margin))); +#undef GETSETUP } static void diff --git a/src/keyboard.c b/src/keyboard.c index 38074458373..1bde3a13ba5 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -1328,7 +1328,7 @@ command_loop_1 (void) if (!NILP (Vquit_flag)) { Vquit_flag = Qnil; - Vunread_command_events = list1 (make_fixnum (quit_char)); + Vunread_command_events = list1i (quit_char); } } diff --git a/src/keymap.c b/src/keymap.c index dda552ba471..2ac3d33460c 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -120,11 +120,7 @@ The optional arg STRING supplies a menu name for the keymap in case you use it as a menu with `x-popup-menu'. */) (Lisp_Object string) { - Lisp_Object tail; - if (!NILP (string)) - tail = list1 (string); - else - tail = Qnil; + Lisp_Object tail = !NILP (string) ? list1 (string) : Qnil; return Fcons (Qkeymap, Fcons (Fmake_char_table (Qkeymap, Qnil), tail)); } @@ -3608,12 +3604,12 @@ syms_of_keymap (void) Fset (intern_c_string ("ctl-x-map"), control_x_map); Ffset (intern_c_string ("Control-X-prefix"), control_x_map); - exclude_keys = listn (CONSTYPE_PURE, 5, - pure_cons (build_pure_c_string ("DEL"), build_pure_c_string ("\\d")), - pure_cons (build_pure_c_string ("TAB"), build_pure_c_string ("\\t")), - pure_cons (build_pure_c_string ("RET"), build_pure_c_string ("\\r")), - pure_cons (build_pure_c_string ("ESC"), build_pure_c_string ("\\e")), - pure_cons (build_pure_c_string ("SPC"), build_pure_c_string (" "))); + exclude_keys = pure_list + (pure_cons (build_pure_c_string ("DEL"), build_pure_c_string ("\\d")), + pure_cons (build_pure_c_string ("TAB"), build_pure_c_string ("\\t")), + pure_cons (build_pure_c_string ("RET"), build_pure_c_string ("\\r")), + pure_cons (build_pure_c_string ("ESC"), build_pure_c_string ("\\e")), + pure_cons (build_pure_c_string ("SPC"), build_pure_c_string (" "))); staticpro (&exclude_keys); DEFVAR_LISP ("define-key-rebound-commands", Vdefine_key_rebound_commands, @@ -3669,16 +3665,12 @@ be preferred. */); DEFSYM (Qmode_line, "mode-line"); staticpro (&Vmouse_events); - Vmouse_events = listn (CONSTYPE_PURE, 9, - Qmenu_bar, - Qtool_bar, - Qheader_line, - Qmode_line, - intern_c_string ("mouse-1"), - intern_c_string ("mouse-2"), - intern_c_string ("mouse-3"), - intern_c_string ("mouse-4"), - intern_c_string ("mouse-5")); + Vmouse_events = pure_list (Qmenu_bar, Qtool_bar, Qheader_line, Qmode_line, + intern_c_string ("mouse-1"), + intern_c_string ("mouse-2"), + intern_c_string ("mouse-3"), + intern_c_string ("mouse-4"), + intern_c_string ("mouse-5")); /* Keymap used for minibuffers when doing completion. */ /* Keymap used for minibuffers when doing completion and require a match. */ diff --git a/src/kqueue.c b/src/kqueue.c index 43e75cac310..48121bd663a 100644 --- a/src/kqueue.c +++ b/src/kqueue.c @@ -99,7 +99,7 @@ kqueue_generate_event (Lisp_Object watch_object, Lisp_Object actions, event.arg = list2 (Fcons (XCAR (watch_object), Fcons (actions, NILP (file1) - ? Fcons (file, Qnil) + ? list1 (file) : list2 (file, file1))), Fnth (make_fixnum (3), watch_object)); kbd_buffer_store_event (&event); diff --git a/src/lisp.h b/src/lisp.h index 2a3eaf38122..4391e173741 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3782,8 +3782,12 @@ extern Lisp_Object list3 (Lisp_Object, Lisp_Object, Lisp_Object); extern Lisp_Object list4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object); extern Lisp_Object list5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object); -enum constype {CONSTYPE_HEAP, CONSTYPE_PURE}; -extern Lisp_Object listn (enum constype, ptrdiff_t, Lisp_Object, ...); +extern Lisp_Object listn (ptrdiff_t, Lisp_Object, ...); +extern Lisp_Object pure_listn (ptrdiff_t, Lisp_Object, ...); +#define list(...) \ + listn (ARRAYELTS (((Lisp_Object []) {__VA_ARGS__})), __VA_ARGS__) +#define pure_list(...) \ + pure_listn (ARRAYELTS (((Lisp_Object []) {__VA_ARGS__})), __VA_ARGS__) enum gc_root_type { GC_ROOT_STATICPRO, @@ -3800,7 +3804,13 @@ struct gc_root_visitor { }; extern void visit_static_gc_roots (struct gc_root_visitor visitor); -/* Build a frequently used 2/3/4-integer lists. */ +/* Build a frequently used 1/2/3/4-integer lists. */ + +INLINE Lisp_Object +list1i (EMACS_INT x) +{ + return list1 (make_fixnum (x)); +} INLINE Lisp_Object list2i (EMACS_INT x, EMACS_INT y) diff --git a/src/nsfns.m b/src/nsfns.m index 60d62310bb0..ee7598a1c7e 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -2811,23 +2811,20 @@ frame_geometry (Lisp_Object frame, Lisp_Object attribute) /* Construct list. */ if (EQ (attribute, Qouter_edges)) - return list4 (make_fixnum (f->left_pos), make_fixnum (f->top_pos), - make_fixnum (f->left_pos + outer_width), - make_fixnum (f->top_pos + outer_height)); + return list4i (f->left_pos, f->top_pos, + f->left_pos + outer_width, + f->top_pos + outer_height); else if (EQ (attribute, Qnative_edges)) - return list4 (make_fixnum (native_left), make_fixnum (native_top), - make_fixnum (native_right), make_fixnum (native_bottom)); + return list4i (native_left, native_top, + native_right, native_bottom); else if (EQ (attribute, Qinner_edges)) - return list4 (make_fixnum (native_left + internal_border_width), - make_fixnum (native_top - + tool_bar_height - + internal_border_width), - make_fixnum (native_right - internal_border_width), - make_fixnum (native_bottom - internal_border_width)); + return list4i (native_left + internal_border_width, + native_top + tool_bar_height + internal_border_width, + native_right - internal_border_width, + native_bottom - internal_border_width); else return - listn (CONSTYPE_HEAP, 10, - Fcons (Qouter_position, + list (Fcons (Qouter_position, Fcons (make_fixnum (f->left_pos), make_fixnum (f->top_pos))), Fcons (Qouter_size, diff --git a/src/nsterm.m b/src/nsterm.m index d0fe206d2e3..ccf8ecc4d26 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -500,7 +500,7 @@ append2 (Lisp_Object list, Lisp_Object item) Utility to append to a list -------------------------------------------------------------------------- */ { - return CALLN (Fnconc, list, list1 (item)); + return nconc2 (list, list (item)); } @@ -8284,7 +8284,7 @@ not_in_argv (NSString *arg) type_sym = Qurl; - strings = Fcons (build_string ([[url absoluteString] UTF8String]), Qnil); + strings = list1 (build_string ([[url absoluteString] UTF8String])); } else if ([type isEqualToString: NSStringPboardType] || [type isEqualToString: NSTabularTextPboardType]) @@ -8296,7 +8296,7 @@ not_in_argv (NSString *arg) type_sym = Qnil; - strings = Fcons (build_string ([data UTF8String]), Qnil); + strings = list1 (build_string ([data UTF8String])); } else { diff --git a/src/pdumper.c b/src/pdumper.c index bba43370a14..dd272a0389d 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -5580,8 +5580,7 @@ Value is nil if this session was not started using a portable dump file.*/) dump_fn = Fexpand_file_name (dump_fn, Qnil); - return CALLN (Flist, - Fcons (Qdumped_with_pdumper, Qt), + return list3 (Fcons (Qdumped_with_pdumper, Qt), Fcons (Qload_time, make_float (dump_private.load_time)), Fcons (Qdump_file_name, dump_fn)); } diff --git a/src/search.c b/src/search.c index 17bc8d0c948..a1e0b0976ed 100644 --- a/src/search.c +++ b/src/search.c @@ -3402,18 +3402,17 @@ syms_of_search (void) DEFSYM (Qinvalid_regexp, "invalid-regexp"); Fput (Qsearch_failed, Qerror_conditions, - listn (CONSTYPE_PURE, 2, Qsearch_failed, Qerror)); + pure_list (Qsearch_failed, Qerror)); Fput (Qsearch_failed, Qerror_message, build_pure_c_string ("Search failed")); Fput (Quser_search_failed, Qerror_conditions, - listn (CONSTYPE_PURE, 4, - Quser_search_failed, Quser_error, Qsearch_failed, Qerror)); + pure_list (Quser_search_failed, Quser_error, Qsearch_failed, Qerror)); Fput (Quser_search_failed, Qerror_message, build_pure_c_string ("Search failed")); Fput (Qinvalid_regexp, Qerror_conditions, - listn (CONSTYPE_PURE, 2, Qinvalid_regexp, Qerror)); + pure_list (Qinvalid_regexp, Qerror)); Fput (Qinvalid_regexp, Qerror_message, build_pure_c_string ("Invalid regexp")); diff --git a/src/syntax.c b/src/syntax.c index 32103c8657c..5c38e92026e 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -3719,7 +3719,7 @@ syms_of_syntax (void) DEFSYM (Qscan_error, "scan-error"); Fput (Qscan_error, Qerror_conditions, - listn (CONSTYPE_PURE, 2, Qscan_error, Qerror)); + pure_list (Qscan_error, Qerror)); Fput (Qscan_error, Qerror_message, build_pure_c_string ("Scan error")); diff --git a/src/w32.c b/src/w32.c index 197f6ddee2f..f3e88afd5bf 100644 --- a/src/w32.c +++ b/src/w32.c @@ -2982,8 +2982,7 @@ init_environment (char ** argv) if (strcmp (env_vars[i].name, "HOME") == 0 && !appdata) Vdelayed_warnings_list = Fcons - (listn (CONSTYPE_HEAP, 2, - intern ("initialization"), build_string + (list2 (intern ("initialization"), build_string ("Use of `C:\\.emacs' without defining `HOME'\n" "in the environment is deprecated, " "see `Windows HOME' in the Emacs manual.")), diff --git a/src/w32cygwinx.c b/src/w32cygwinx.c index 086dcd15b43..3b994b16b3f 100644 --- a/src/w32cygwinx.c +++ b/src/w32cygwinx.c @@ -115,8 +115,7 @@ The following %-sequences are provided: remain = format_string ("%ld:%02ld", m / 60, m % 60); } - status = listn (CONSTYPE_HEAP, 8, - Fcons (make_fixnum ('L'), line_status), + status = list (Fcons (make_fixnum ('L'), line_status), Fcons (make_fixnum ('B'), battery_status), Fcons (make_fixnum ('b'), battery_status_symbol), Fcons (make_fixnum ('p'), load_percentage), diff --git a/src/w32fns.c b/src/w32fns.c index 29d85c4826c..4a32d496350 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -8787,8 +8787,7 @@ and width values are in pixels. /* A single line menu bar. */ menu_bar_height = single_menu_bar_height; - return listn (CONSTYPE_HEAP, 10, - Fcons (Qouter_position, + return list (Fcons (Qouter_position, Fcons (make_fixnum (left), make_fixnum (top))), Fcons (Qouter_size, Fcons (make_fixnum (right - left), @@ -10257,7 +10256,7 @@ syms_of_w32fns (void) DEFSYM (Qjson, "json"); Fput (Qundefined_color, Qerror_conditions, - listn (CONSTYPE_PURE, 2, Qundefined_color, Qerror)); + pure_list (Qundefined_color, Qerror)); Fput (Qundefined_color, Qerror_message, build_pure_c_string ("Undefined color")); diff --git a/src/widget.c b/src/widget.c index 9db33168a2a..c695bd5f305 100644 --- a/src/widget.c +++ b/src/widget.c @@ -282,7 +282,7 @@ set_frame_size (EmacsFrame ew) frame_size_history_add (f, Qset_frame_size, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), - list2 (make_fixnum (ew->core.width), make_fixnum (ew->core.height))); + list2i (ew->core.width, ew->core.height)); } static void diff --git a/src/window.c b/src/window.c index fe685d5ab09..642c77ba56e 100644 --- a/src/window.c +++ b/src/window.c @@ -2525,7 +2525,7 @@ window_list (void) have to reverse this list at the end. */ foreach_window (XFRAME (frame), add_window_to_list, &arglist); arglist = Fnreverse (arglist); - Vwindow_list = CALLN (Fnconc, Vwindow_list, arglist); + Vwindow_list = nconc2 (Vwindow_list, arglist); } } diff --git a/src/xdisp.c b/src/xdisp.c index 760c31c6768..d728e0f111c 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -32932,14 +32932,12 @@ and is used only on frames for which no explicit name has been set \(see `modify-frame-parameters'). */); Vicon_title_format = Vframe_title_format - = listn (CONSTYPE_PURE, 3, - intern_c_string ("multiple-frames"), - build_pure_c_string ("%b"), - listn (CONSTYPE_PURE, 4, - empty_unibyte_string, - intern_c_string ("invocation-name"), - build_pure_c_string ("@"), - intern_c_string ("system-name"))); + = pure_list (intern_c_string ("multiple-frames"), + build_pure_c_string ("%b"), + pure_list (empty_unibyte_string, + intern_c_string ("invocation-name"), + build_pure_c_string ("@"), + intern_c_string ("system-name"))); DEFVAR_LISP ("message-log-max", Vmessage_log_max, doc: /* Maximum number of lines to keep in the message log buffer. diff --git a/src/xfaces.c b/src/xfaces.c index e397f0b8a03..c6723ebe2c3 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -1597,7 +1597,7 @@ the WIDTH times as wide as FACE on FRAME. */) /* We don't have to check fontsets. */ return fonts; Lisp_Object fontsets = list_fontsets (f, pattern, size); - return CALLN (Fnconc, fonts, fontsets); + return nconc2 (fonts, fontsets); } #endif /* HAVE_WINDOW_SYSTEM */ @@ -4254,12 +4254,8 @@ two lists of the form (RED GREEN BLUE) aforementioned. */) return make_fixnum (color_distance (&cdef1, &cdef2)); else return call2 (metric, - list3 (make_fixnum (cdef1.red), - make_fixnum (cdef1.green), - make_fixnum (cdef1.blue)), - list3 (make_fixnum (cdef2.red), - make_fixnum (cdef2.green), - make_fixnum (cdef2.blue))); + list3i (cdef1.red, cdef1.green, cdef1.blue), + list3i (cdef2.red, cdef2.green, cdef2.blue)); } diff --git a/src/xfns.c b/src/xfns.c index 9cea420a404..a627b7e19e6 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -5185,18 +5185,14 @@ frame_geometry (Lisp_Object frame, Lisp_Object attribute) /* Construct list. */ if (EQ (attribute, Qouter_edges)) - return list4 (make_fixnum (outer_left), make_fixnum (outer_top), - make_fixnum (outer_right), make_fixnum (outer_bottom)); + return list4i (outer_left, outer_top, outer_right, outer_bottom); else if (EQ (attribute, Qnative_edges)) - return list4 (make_fixnum (native_left), make_fixnum (native_top), - make_fixnum (native_right), make_fixnum (native_bottom)); + return list4i (native_left, native_top, native_right, native_bottom); else if (EQ (attribute, Qinner_edges)) - return list4 (make_fixnum (inner_left), make_fixnum (inner_top), - make_fixnum (inner_right), make_fixnum (inner_bottom)); + return list4i (inner_left, inner_top, inner_right, inner_bottom); else return - listn (CONSTYPE_HEAP, 11, - Fcons (Qouter_position, + list (Fcons (Qouter_position, Fcons (make_fixnum (outer_left), make_fixnum (outer_top))), Fcons (Qouter_size, @@ -7675,7 +7671,7 @@ syms_of_xfns (void) #endif Fput (Qundefined_color, Qerror_conditions, - listn (CONSTYPE_PURE, 2, Qundefined_color, Qerror)); + pure_list (Qundefined_color, Qerror)); Fput (Qundefined_color, Qerror_message, build_pure_c_string ("Undefined color")); diff --git a/src/xterm.c b/src/xterm.c index 453669f6e02..73a38de3719 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -11181,8 +11181,7 @@ x_set_window_size_1 (struct frame *f, bool change_gravity, { frame_size_history_add (f, Qx_set_window_size_1, width, height, - list2 (make_fixnum (old_height), - make_fixnum (pixelheight + FRAME_MENUBAR_HEIGHT (f)))); + list2i (old_height, pixelheight + FRAME_MENUBAR_HEIGHT (f))); XResizeWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), old_width, pixelheight + FRAME_MENUBAR_HEIGHT (f)); @@ -11191,7 +11190,7 @@ x_set_window_size_1 (struct frame *f, bool change_gravity, { frame_size_history_add (f, Qx_set_window_size_2, width, height, - list2 (make_fixnum (old_width), make_fixnum (pixelwidth))); + list2i (old_width, pixelwidth)); XResizeWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), pixelwidth, old_height); @@ -11201,10 +11200,10 @@ x_set_window_size_1 (struct frame *f, bool change_gravity, { frame_size_history_add (f, Qx_set_window_size_3, width, height, - list3 (make_fixnum (pixelwidth + FRAME_TOOLBAR_WIDTH (f)), - make_fixnum (pixelheight + FRAME_TOOLBAR_HEIGHT (f) - + FRAME_MENUBAR_HEIGHT (f)), - make_fixnum (FRAME_MENUBAR_HEIGHT (f)))); + list3i (pixelwidth + FRAME_TOOLBAR_WIDTH (f), + (pixelheight + FRAME_TOOLBAR_HEIGHT (f) + + FRAME_MENUBAR_HEIGHT (f)), + FRAME_MENUBAR_HEIGHT (f))); XResizeWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), pixelwidth, pixelheight + FRAME_MENUBAR_HEIGHT (f)); diff --git a/src/xwidget.c b/src/xwidget.c index dcbccdf27c7..c56284928e3 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -831,8 +831,7 @@ Emacs allocated area accordingly. */) CHECK_XWIDGET (xwidget); GtkRequisition requisition; gtk_widget_size_request (XXWIDGET (xwidget)->widget_osr, &requisition); - return list2 (make_fixnum (requisition.width), - make_fixnum (requisition.height)); + return list2i (requisition.width, requisition.height); } DEFUN ("xwidgetp",