From 28be1ada0fb9a4b51cf361dc45208e764bd34143 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Tue, 19 Jun 2012 20:56:28 +0400 Subject: * alloc.c, bytecode.c, ccl.c, coding.c, composite.c, data.c, dosfns.c: * font.c, image.c, keyboard.c, lread.c, menu.c, minibuf.c, msdos.c: * print.c, syntax.c, window.c, xmenu.c, xselect.c: Replace direct access to `contents' member of Lisp_Vector objects with AREF and ASET where appropriate. --- src/coding.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 64826ae16b9..b0359b89cb5 100644 --- a/src/coding.c +++ b/src/coding.c @@ -3189,7 +3189,7 @@ detect_coding_iso_2022 (struct coding_system *coding, break; check_extra_latin: if (! VECTORP (Vlatin_extra_code_table) - || NILP (XVECTOR (Vlatin_extra_code_table)->contents[c])) + || NILP (AREF (Vlatin_extra_code_table, c))) { rejected = CATEGORY_MASK_ISO; break; @@ -5464,7 +5464,7 @@ detect_coding_charset (struct coding_system *coding, if (c < 0xA0 && check_latin_extra && (!VECTORP (Vlatin_extra_code_table) - || NILP (XVECTOR (Vlatin_extra_code_table)->contents[c]))) + || NILP (AREF (Vlatin_extra_code_table, c)))) break; found = CATEGORY_MASK_CHARSET; } @@ -10560,7 +10560,7 @@ Don't modify this variable directly, but use `set-coding-system-priority'. */); Vcoding_category_list = Qnil; for (i = coding_category_max - 1; i >= 0; i--) Vcoding_category_list - = Fcons (XVECTOR (Vcoding_category_table)->contents[i], + = Fcons (AREF (Vcoding_category_table, i), Vcoding_category_list); } -- cgit v1.2.1 From 23f86fce48e1cc8118f0ea5cce49d1acfd4364c4 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Thu, 5 Jul 2012 10:32:41 +0400 Subject: Cleanup xmalloc. * admin/coccinelle/xzalloc.cocci: Semantic patch to convert calls to xmalloc with following memset to xzalloc. * src/lisp.h (xzalloc): New prototype. Omit needless casts. * src/alloc.c (xzalloc): New function. Omit needless casts. * src/charset.c: Omit needless casts. Convert all calls to malloc with following memset to xzalloc. * src/dispnew.c: Likewise. * src/fringe.c: Likewise. * src/image.c: Likewise. * src/sound.c: Likewise. * src/term.c: Likewise. * src/w32fns.c: Likewise. * src/w32font.c: Likewise. * src/w32term.c: Likewise. * src/xfaces.c: Likewise. * src/xfns.c: Likewise. * src/xterm.c: Likewise. * src/atimer.c: Omit needless casts. * src/buffer.c: Likewise. * src/callproc.c: Likewise. * src/ccl.c: Likewise. * src/coding.c: Likewise. * src/composite.c: Likewise. * src/doc.c: Likewise. * src/doprnt.c: Likewise. * src/editfns.c: Likewise. * src/emacs.c: Likewise. * src/eval.c: Likewise. * src/filelock.c: Likewise. * src/fns.c: Likewise. * src/gtkutil.c: Likewise. * src/keyboard.c: Likewise. * src/lisp.h: Likewise. * src/lread.c: Likewise. * src/minibuf.c: Likewise. * src/msdos.c: Likewise. * src/print.c: Likewise. * src/process.c: Likewise. * src/region-cache.c: Likewise. * src/search.c: Likewise. * src/sysdep.c: Likewise. * src/termcap.c: Likewise. * src/terminal.c: Likewise. * src/tparam.c: Likewise. * src/w16select.c: Likewise. * src/w32.c: Likewise. * src/w32reg.c: Likewise. * src/w32select.c: Likewise. * src/w32uniscribe.c: Likewise. * src/widget.c: Likewise. * src/xdisp.c: Likewise. * src/xmenu.c: Likewise. * src/xrdb.c: Likewise. * src/xselect.c: Likewise. --- src/coding.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index b0359b89cb5..891fea09abf 100644 --- a/src/coding.c +++ b/src/coding.c @@ -8006,7 +8006,7 @@ encode_coding_object (struct coding_system *coding, { ptrdiff_t dst_bytes = max (1, coding->src_chars); coding->dst_object = Qnil; - coding->destination = (unsigned char *) xmalloc (dst_bytes); + coding->destination = xmalloc (dst_bytes); coding->dst_bytes = dst_bytes; coding->dst_multibyte = 0; } -- cgit v1.2.1 From 38182d901d030c7d65f4aa7a49b583afb30eb9b7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 5 Jul 2012 11:35:48 -0700 Subject: More xmalloc and related cleanup. * alloc.c, bidi.c, buffer.c, buffer.h, bytecode.c, callint.c: * callproc.c, charset.c, coding.c, composite.c, data.c, dispnew.c: * doc.c, editfns.c, emacs.c, eval.c, fileio.c, filelock.c, fns.c: * font.c, fontset.c, frame.c, fringe.c, ftfont.c, ftxfont.c, gmalloc.c: * gtkutil.c, image.c, keyboard.c, keymap.c, lread.c, macros.c, menu.c: * nsfns.m, nsfont.m, nsmenu.m, nsterm.m, print.c, process.c, ralloc.c: * regex.c, region-cache.c, scroll.c, search.c, sound.c, syntax.c: * sysdep.c, term.c, termcap.c, unexmacosx.c, window.c, xdisp.c: * xfaces.c, xfns.c, xftfont.c, xgselect.c, xmenu.c, xrdb.c, xselect.c: * xterm.c: Omit needless casts involving void * pointers and allocation. Prefer "P = xmalloc (sizeof *P)" to "P = xmalloc (sizeof (TYPE_OF_P))", as the former is more robust if P's type is changed. Prefer xzalloc to xmalloc + memset 0. Simplify malloc-or-realloc to realloc. Don't worry about xmalloc returning a null pointer. Prefer xstrdup to xmalloc + strcpy. * editfns.c (Fmessage_box): Grow message_text by at least 80 when growing it. * keyboard.c (apply_modifiers_uncached): Prefer local array to alloca of a constant. --- src/coding.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 891fea09abf..4b2a9740121 100644 --- a/src/coding.c +++ b/src/coding.c @@ -1145,8 +1145,8 @@ coding_alloc_by_realloc (struct coding_system *coding, ptrdiff_t bytes) { if (STRING_BYTES_BOUND - coding->dst_bytes < bytes) string_overflow (); - coding->destination = (unsigned char *) xrealloc (coding->destination, - coding->dst_bytes + bytes); + coding->destination = xrealloc (coding->destination, + coding->dst_bytes + bytes); coding->dst_bytes += bytes; } @@ -7010,7 +7010,7 @@ produce_charset (struct coding_system *coding, int *charbuf, ptrdiff_t pos) coding->charbuf = NULL; \ while (size > 1024) \ { \ - coding->charbuf = (int *) alloca (sizeof (int) * size); \ + coding->charbuf = alloca (sizeof (int) * size); \ if (coding->charbuf) \ break; \ size >>= 1; \ @@ -9568,7 +9568,7 @@ make_subsidiaries (Lisp_Object base) { Lisp_Object subsidiaries; ptrdiff_t base_name_len = SBYTES (SYMBOL_NAME (base)); - char *buf = (char *) alloca (base_name_len + 6); + char *buf = alloca (base_name_len + 6); int i; memcpy (buf, SDATA (SYMBOL_NAME (base)), base_name_len); -- cgit v1.2.1 From 2a0213a6d0a9e36a388994445837e051d0bbe5f9 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Tue, 10 Jul 2012 12:43:46 +0400 Subject: Optimize pure C strings initialization. * lisp.h (make_pure_string): Fix prototype. (build_pure_c_string): New function, defined as static inline. This provides a better opportunity to optimize away calls to strlen when the function is called with compile-time constant argument. * alloc.c (make_pure_c_string): Fix comment. Change to add nchars argument, adjust users accordingly. Use build_pure_c_string where appropriate. * buffer.c, coding.c, data.c, dbusbind.c, fileio.c, fontset.c, frame.c, * keyboard.c, keymap.c, lread.c, search.c, syntax.c, w32fns.c, xdisp.c, * xfaces.c, xfns.c, xterm.c: Use build_pure_c_string where appropriate. --- src/coding.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 4b2a9740121..8210cacc4d8 100644 --- a/src/coding.c +++ b/src/coding.c @@ -10350,7 +10350,7 @@ syms_of_coding (void) Vcode_conversion_reused_workbuf = Qnil; staticpro (&Vcode_conversion_workbuf_name); - Vcode_conversion_workbuf_name = make_pure_c_string (" *code-conversion-work*"); + Vcode_conversion_workbuf_name = build_pure_c_string (" *code-conversion-work*"); reused_workbuf_in_use = 0; @@ -10413,7 +10413,7 @@ syms_of_coding (void) Fput (Qcoding_system_error, Qerror_conditions, pure_cons (Qcoding_system_error, pure_cons (Qerror, Qnil))); Fput (Qcoding_system_error, Qerror_message, - make_pure_c_string ("Invalid coding system")); + build_pure_c_string ("Invalid coding system")); /* Intern this now in case it isn't already done. Setting this variable twice is harmless. @@ -10686,22 +10686,22 @@ Also used for decoding keyboard input on X Window system. */); DEFVAR_LISP ("eol-mnemonic-unix", eol_mnemonic_unix, doc: /* *String displayed in mode line for UNIX-like (LF) end-of-line format. */); - eol_mnemonic_unix = make_pure_c_string (":"); + eol_mnemonic_unix = build_pure_c_string (":"); DEFVAR_LISP ("eol-mnemonic-dos", eol_mnemonic_dos, doc: /* *String displayed in mode line for DOS-like (CRLF) end-of-line format. */); - eol_mnemonic_dos = make_pure_c_string ("\\"); + eol_mnemonic_dos = build_pure_c_string ("\\"); DEFVAR_LISP ("eol-mnemonic-mac", eol_mnemonic_mac, doc: /* *String displayed in mode line for MAC-like (CR) end-of-line format. */); - eol_mnemonic_mac = make_pure_c_string ("/"); + eol_mnemonic_mac = build_pure_c_string ("/"); DEFVAR_LISP ("eol-mnemonic-undecided", eol_mnemonic_undecided, doc: /* *String displayed in mode line when end-of-line format is not yet determined. */); - eol_mnemonic_undecided = make_pure_c_string (":"); + eol_mnemonic_undecided = build_pure_c_string (":"); DEFVAR_LISP ("enable-character-translation", Venable_character_translation, doc: /* @@ -10839,7 +10839,7 @@ internal character representation. */); plist[10] = intern_c_string (":for-unibyte"); plist[11] = args[coding_arg_for_unibyte] = Qt; plist[12] = intern_c_string (":docstring"); - plist[13] = make_pure_c_string ("Do no conversion.\n\ + plist[13] = build_pure_c_string ("Do no conversion.\n\ \n\ When you visit a file with this coding, the file is read into a\n\ unibyte buffer as is, thus each byte of a file is treated as a\n\ @@ -10857,7 +10857,7 @@ character."); plist[8] = intern_c_string (":charset-list"); plist[9] = args[coding_arg_charset_list] = Fcons (Qascii, Qnil); plist[11] = args[coding_arg_for_unibyte] = Qnil; - plist[13] = make_pure_c_string ("No conversion on encoding, automatic conversion on decoding."); + plist[13] = build_pure_c_string ("No conversion on encoding, automatic conversion on decoding."); plist[15] = args[coding_arg_eol_type] = Qnil; args[coding_arg_plist] = Flist (16, plist); Fdefine_coding_system_internal (coding_arg_max, args); -- cgit v1.2.1 From 7d7bbefd049fc22cf3bf333592abf57a3bde8766 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Tue, 10 Jul 2012 20:53:26 +0400 Subject: Use XCAR and XCDR instead of Fcar and Fcdr where possible. * admin/coccinelle/list_loop.cocci: Semantic patch to convert from Fcdr to XCDR and consistently use CONSP in the list iteration loops. * admin/coccinelle/vector_contents.cocci: Fix indentation. * src/callint.c, src/coding.c, src/doc.c, src/editfns.c, src/eval.c, * src/font.c, src/fontset.c, src/frame.c, src/gnutls.c, src/minibuf.c, * src/msdos.c, src/textprop.c, src/w32fns.c, src/w32menu.c, src/window.c, * src/xmenu.c: Changed to use XCAR and XCDR where argument type is known to be a Lisp_Cons. --- src/coding.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 8210cacc4d8..134ebf2ab73 100644 --- a/src/coding.c +++ b/src/coding.c @@ -9791,7 +9791,7 @@ usage: (define-coding-system-internal ...) */) val = args[coding_arg_ccl_valids]; valids = Fmake_string (make_number (256), make_number (0)); - for (tail = val; !NILP (tail); tail = Fcdr (tail)) + for (tail = val; CONSP (tail); tail = XCDR (tail)) { int from, to; @@ -9892,7 +9892,7 @@ usage: (define-coding-system-internal ...) */) CHECK_NUMBER_CDR (reg_usage); request = Fcopy_sequence (args[coding_arg_iso2022_request]); - for (tail = request; ! NILP (tail); tail = Fcdr (tail)) + for (tail = request; CONSP (tail); tail = XCDR (tail)) { int id; Lisp_Object tmp1; -- cgit v1.2.1 From 34348bd4e5c89fa0e440e37efa20be2a00c8fd9c Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Wed, 11 Jul 2012 09:19:44 +0200 Subject: * coding.c (Fdefine_coding_system_internal): Use XCAR/XCDR instead of Fcar/Fcdr if possible. * font.c (check_otf_features): Likewise. * fontset.c (Fnew_fontset): Likewise. * gnutls.c (Fgnutls_boot): Likewise. * minibuf.c (read_minibuf): Likewise. * msdos.c (IT_set_frame_parameters): Likewise. * xmenu.c (Fx_popup_dialog): Likewise. * w32menu.c (Fx_popup_dialog): Likewise. --- src/coding.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 134ebf2ab73..d9fcc634b77 100644 --- a/src/coding.c +++ b/src/coding.c @@ -9795,7 +9795,7 @@ usage: (define-coding-system-internal ...) */) { int from, to; - val = Fcar (tail); + val = XCAR (tail); if (INTEGERP (val)) { if (! (0 <= XINT (val) && XINT (val) <= 255)) @@ -9897,7 +9897,7 @@ usage: (define-coding-system-internal ...) */) int id; Lisp_Object tmp1; - val = Fcar (tail); + val = XCAR (tail); CHECK_CONS (val); tmp1 = XCAR (val); CHECK_CHARSET_GET_ID (tmp1, id); -- cgit v1.2.1 From d17337e501a189c1d46f758e10c6c2842cafff17 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Thu, 19 Jul 2012 07:55:59 +0400 Subject: New macro to iterate over all buffers, miscellaneous cleanups. * lisp.h (all_buffers): Remove declaration. * buffer.h (all_buffers): Add declaration, with comment. (for_each_buffer): New macro. * alloc.c (Fgarbage_collect, mark_object): Use it. * buffer.c (Fkill_buffer, Fbuffer_swap_text, Fset_buffer_multibyte) (init_buffer): Likewise. * data.c (Fset_default): Likewise. * coding.c (code_conversion_restore): Remove redundant check for dead buffer. * buffer.c (Fkill_buffer): Likewise. Remove obsolete comment. --- src/coding.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index d9fcc634b77..212eb8275fe 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7588,7 +7588,7 @@ code_conversion_restore (Lisp_Object arg) { if (EQ (workbuf, Vcode_conversion_reused_workbuf)) reused_workbuf_in_use = 0; - else if (! NILP (Fbuffer_live_p (workbuf))) + else Fkill_buffer (workbuf); } set_buffer_internal (XBUFFER (current)); -- cgit v1.2.1