From e5560ff7d28c684003ed598a9390e17f9fb92d34 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Sat, 16 Jun 2012 14:24:15 +0200 Subject: * buffer.h (FETCH_MULTIBYTE_CHAR): Define as inline. (BUF_FETCH_MULTIBYTE_CHAR): Likewise. * character.c (_fetch_multibyte_char_p): Remove. * alloc.c: Include "character.h" before "buffer.h". * bidi.c: Likewise. * buffer.c: Likewise. * bytecode.c: Likewise. * callint.c: Likewise. * callproc.c: Likewise. * casefiddle.c: Likewise. * casetab.c: Likewise. * category.c: Likewise. * cmds.c: Likewise. * coding.c: Likewise. * composite.c: Likewise. * dired.c: Likewise. * dispnew.c: Likewise. * doc.c: Likewise. * dosfns.c: Likewise. * editfns.c: Likewise. * emacs.c: Likewise. * fileio.c: Likewise. * filelock.c: Likewise. * font.c: Likewise. * fontset.c: Likewise. * fringe.c: Likewise. * indent.c: Likewise. * insdel.c: Likewise. * intervals.c: Likewise. * keyboard.c: Likewise. * keymap.c: Likewise. * lread.c: Likewise. * macros.c: Likewise. * marker.c: Likewise. * minibuf.c: Likewise. * nsfns.m: Likewise. * nsmenu.m: Likewise. * print.c: Likewise. * process.c: Likewise. * regex.c: Likewise. * region-cache.c: Likewise. * search.c: Likewise. * syntax.c: Likewise. * term.c: Likewise. * textprop.c: Likewise. * undo.c: Likewise. * unexsol.c: Likewise. * w16select.c: Likewise. * w32fns.c: Likewise. * w32menu.c: Likewise. * window.c: Likewise. * xdisp.c: Likewise. * xfns.c: Likewise. * xmenu.c: Likewise. * xml.c: Likewise. * 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 17e342298b9..ab13f0311c0 100644 --- a/src/coding.c +++ b/src/coding.c @@ -288,8 +288,8 @@ encode_coding_XXX (struct coding_system *coding) #include #include "lisp.h" -#include "buffer.h" #include "character.h" +#include "buffer.h" #include "charset.h" #include "ccl.h" #include "composite.h" -- cgit v1.2.1 From 27bb1ca4b00cb47153db3016ced27c0327932fce Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 17 Jun 2012 00:57:28 -0700 Subject: * coding.c (produce_chars): Use ptrdiff_t, not int. --- src/coding.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index ab13f0311c0..64826ae16b9 100644 --- a/src/coding.c +++ b/src/coding.c @@ -6765,7 +6765,8 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table, while (buf < buf_end) { - int c = *buf, i; + int c = *buf; + ptrdiff_t i; if (c >= 0) { -- cgit v1.2.1 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 From 694b6c97ebb8310bc18dd305c2f277bcc11cebca Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Fri, 27 Jul 2012 10:04:35 +0400 Subject: Utility function to make a list from specified amount of objects. * lisp.h (enum constype): New datatype. (listn): New prototype. * alloc.c (listn): New function. (Fmemory_use_count, syms_of_alloc): Use it. * buffer.c (syms_of_buffer): Likewise. * callint.c (syms_of_callint): Likewise. * charset.c (define_charset_internal): Likewise. * coding.c (syms_of_coding): Likewise. * keymap.c (syms_of_keymap): Likewise. * search.c (syms_of_search): Likewise. * syntax.c (syms_of_syntax): Likewise. * w32.c (init_environment): Likewise. * w32fns.c (Fw32_battery_status, syms_of_w32fns): Likewise. * xdisp.c (syms_of_xdisp): Likewise. * xfns.c (syms_of_xfns): 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 212eb8275fe..8b858aa218e 100644 --- a/src/coding.c +++ b/src/coding.c @@ -10411,7 +10411,7 @@ syms_of_coding (void) DEFSYM (Qcoding_system_error, "coding-system-error"); Fput (Qcoding_system_error, Qerror_conditions, - pure_cons (Qcoding_system_error, pure_cons (Qerror, Qnil))); + listn (PURE, 2, Qcoding_system_error, Qerror)); Fput (Qcoding_system_error, Qerror_message, build_pure_c_string ("Invalid coding system")); -- cgit v1.2.1 From 3438fe218c77633ee2c5f106e3a335f906347247 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 27 Jul 2012 12:24:34 +0300 Subject: Fix failure to compile on Windows due to 2012-07-27T06:04:35Z!dmantipov@yandex.ru. src/lisp.h (enum constype): Use CONSTYPE_HEAP and CONSTYPE_PURE for enumeration constants, as PURE and HEAP are too general, and clash with other headers and sources, such as gmalloc.c and the MS-Windows system headers. All users changed. --- 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 8b858aa218e..7b178b0ce14 100644 --- a/src/coding.c +++ b/src/coding.c @@ -10411,7 +10411,7 @@ syms_of_coding (void) DEFSYM (Qcoding_system_error, "coding-system-error"); Fput (Qcoding_system_error, Qerror_conditions, - listn (PURE, 2, Qcoding_system_error, Qerror)); + listn (CONSTYPE_PURE, 2, Qcoding_system_error, Qerror)); Fput (Qcoding_system_error, Qerror_message, build_pure_c_string ("Invalid coding system")); -- cgit v1.2.1 From 6cd7a13902729007a4d1e14a299bad47c9808353 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Mon, 30 Jul 2012 10:43:46 +0400 Subject: Convert safe_call to use variable number of arguments. * xdisp.c (safe_call): Convert to use varargs. Adjust users. (safe_call2): Fix comment. * lisp.h (safe_call): Adjust prototype. * coding.c (encode_coding_object): Change to use safe_call2. * xfaces.c (merge_face_heights): Change to use safe_call1. --- src/coding.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 7b178b0ce14..e4ed65079d9 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7931,15 +7931,12 @@ encode_coding_object (struct coding_system *coding, } { - Lisp_Object args[3]; struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; GCPRO5 (coding->src_object, coding->dst_object, src_object, dst_object, old_deactivate_mark); - args[0] = CODING_ATTR_PRE_WRITE (attrs); - args[1] = make_number (BEG); - args[2] = make_number (Z); - safe_call (3, args); + safe_call2 (CODING_ATTR_PRE_WRITE (attrs), + make_number (BEG), make_number (Z)); UNGCPRO; } if (XBUFFER (coding->src_object) != current_buffer) -- cgit v1.2.1 From 4939150cb43137980c49b318bc70119b9d8ff6f7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 1 Aug 2012 13:51:44 -0700 Subject: Use "ASET (a, i, v)" rather than "AREF (a, i) = v". This how ASET and AREF are supposed to work, and makes it easier to think about future improvements. See . * charset.h (set_charset_attr): New function. All lvalue-style uses of CHARSET_DECODER etc. changed to use it. * lisp.h (ASET): Rewrite so as not to use AREF in an lvalue style. (aref_addr): New function. All uses of &AREF(...) changed. (set_hash_key, set_hash_value, set_hash_next, set_hash_hash) (set_hash_index): New functions. All lvalue-style uses of HASH_KEY etc. changed. * keyboard.c (set_prop): New function. All lvalue-style uses of PROP changed. --- src/coding.c | 89 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 44 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index e4ed65079d9..12a7cf93c46 100644 --- a/src/coding.c +++ b/src/coding.c @@ -2674,8 +2674,8 @@ encode_coding_emacs_mule (struct coding_system *coding) CODING_GET_INFO (coding, attrs, charset_list); if (! EQ (charset_list, Vemacs_mule_charset_list)) { - CODING_ATTR_CHARSET_LIST (attrs) - = charset_list = Vemacs_mule_charset_list; + charset_list = Vemacs_mule_charset_list; + ASET (attrs, coding_attr_charset_list, charset_list); } while (charbuf < charbuf_end) @@ -2967,8 +2967,8 @@ setup_iso_safe_charsets (Lisp_Object attrs) if ((flags & CODING_ISO_FLAG_FULL_SUPPORT) && ! EQ (charset_list, Viso_2022_charset_list)) { - CODING_ATTR_CHARSET_LIST (attrs) - = charset_list = Viso_2022_charset_list; + charset_list = Viso_2022_charset_list; + ASET (attrs, coding_attr_charset_list, charset_list); ASET (attrs, coding_attr_safe_charsets, Qnil); } @@ -9603,16 +9603,16 @@ usage: (define-coding-system-internal ...) */) name = args[coding_arg_name]; CHECK_SYMBOL (name); - CODING_ATTR_BASE_NAME (attrs) = name; + ASET (attrs, coding_attr_base_name, name); val = args[coding_arg_mnemonic]; if (! STRINGP (val)) CHECK_CHARACTER (val); - CODING_ATTR_MNEMONIC (attrs) = val; + ASET (attrs, coding_attr_mnemonic, val); coding_type = args[coding_arg_coding_type]; CHECK_SYMBOL (coding_type); - CODING_ATTR_TYPE (attrs) = coding_type; + ASET (attrs, coding_attr_type, coding_type); charset_list = args[coding_arg_charset_list]; if (SYMBOLP (charset_list)) @@ -9659,49 +9659,49 @@ usage: (define-coding-system-internal ...) */) max_charset_id = charset->id; } } - CODING_ATTR_CHARSET_LIST (attrs) = charset_list; + ASET (attrs, coding_attr_charset_list, charset_list); safe_charsets = make_uninit_string (max_charset_id + 1); memset (SDATA (safe_charsets), 255, max_charset_id + 1); for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) SSET (safe_charsets, XFASTINT (XCAR (tail)), 0); - CODING_ATTR_SAFE_CHARSETS (attrs) = safe_charsets; + ASET (attrs, coding_attr_safe_charsets, safe_charsets); - CODING_ATTR_ASCII_COMPAT (attrs) = args[coding_arg_ascii_compatible_p]; + ASET (attrs, coding_attr_ascii_compat, args[coding_arg_ascii_compatible_p]); val = args[coding_arg_decode_translation_table]; if (! CHAR_TABLE_P (val) && ! CONSP (val)) CHECK_SYMBOL (val); - CODING_ATTR_DECODE_TBL (attrs) = val; + ASET (attrs, coding_attr_decode_tbl, val); val = args[coding_arg_encode_translation_table]; if (! CHAR_TABLE_P (val) && ! CONSP (val)) CHECK_SYMBOL (val); - CODING_ATTR_ENCODE_TBL (attrs) = val; + ASET (attrs, coding_attr_encode_tbl, val); val = args[coding_arg_post_read_conversion]; CHECK_SYMBOL (val); - CODING_ATTR_POST_READ (attrs) = val; + ASET (attrs, coding_attr_post_read, val); val = args[coding_arg_pre_write_conversion]; CHECK_SYMBOL (val); - CODING_ATTR_PRE_WRITE (attrs) = val; + ASET (attrs, coding_attr_pre_write, val); val = args[coding_arg_default_char]; if (NILP (val)) - CODING_ATTR_DEFAULT_CHAR (attrs) = make_number (' '); + ASET (attrs, coding_attr_default_char, make_number (' ')); else { CHECK_CHARACTER (val); - CODING_ATTR_DEFAULT_CHAR (attrs) = val; + ASET (attrs, coding_attr_default_char, val); } val = args[coding_arg_for_unibyte]; - CODING_ATTR_FOR_UNIBYTE (attrs) = NILP (val) ? Qnil : Qt; + ASET (attrs, coding_attr_for_unibyte, NILP (val) ? Qnil : Qt); val = args[coding_arg_plist]; CHECK_LIST (val); - CODING_ATTR_PLIST (attrs) = val; + ASET (attrs, coding_attr_plist, val); if (EQ (coding_type, Qcharset)) { @@ -9726,7 +9726,7 @@ usage: (define-coding-system-internal ...) */) int idx = (dim - 1) * 4; if (CHARSET_ASCII_COMPATIBLE_P (charset)) - CODING_ATTR_ASCII_COMPAT (attrs) = Qt; + ASET (attrs, coding_attr_ascii_compat, Qt); for (i = charset->code_space[idx]; i <= charset->code_space[idx + 1]; i++) @@ -9824,7 +9824,7 @@ usage: (define-coding-system-internal ...) */) { Lisp_Object bom, endian; - CODING_ATTR_ASCII_COMPAT (attrs) = Qnil; + ASET (attrs, coding_attr_ascii_compat, Qnil); if (nargs < coding_arg_utf16_max) goto short_args; @@ -9877,7 +9877,7 @@ usage: (define-coding-system-internal ...) */) CHECK_CHARSET_GET_CHARSET (val, charset); ASET (initial, i, make_number (CHARSET_ID (charset))); if (i == 0 && CHARSET_ASCII_COMPATIBLE_P (charset)) - CODING_ATTR_ASCII_COMPAT (attrs) = Qt; + ASET (attrs, coding_attr_ascii_compat, Qt); } else ASET (initial, i, make_number (-1)); @@ -9938,13 +9938,13 @@ usage: (define-coding-system-internal ...) */) } if (category != coding_category_iso_8_1 && category != coding_category_iso_8_2) - CODING_ATTR_ASCII_COMPAT (attrs) = Qnil; + ASET (attrs, coding_attr_ascii_compat, Qnil); } else if (EQ (coding_type, Qemacs_mule)) { if (EQ (args[coding_arg_charset_list], Qemacs_mule)) ASET (attrs, coding_attr_emacs_mule_full, Qt); - CODING_ATTR_ASCII_COMPAT (attrs) = Qt; + ASET (attrs, coding_attr_ascii_compat, Qt); category = coding_category_emacs_mule; } else if (EQ (coding_type, Qshift_jis)) @@ -9961,7 +9961,7 @@ usage: (define-coding-system-internal ...) */) error ("Dimension of charset %s is not one", SDATA (SYMBOL_NAME (CHARSET_NAME (charset)))); if (CHARSET_ASCII_COMPATIBLE_P (charset)) - CODING_ATTR_ASCII_COMPAT (attrs) = Qt; + ASET (attrs, coding_attr_ascii_compat, Qt); charset_list = XCDR (charset_list); charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); @@ -9999,7 +9999,7 @@ usage: (define-coding-system-internal ...) */) error ("Dimension of charset %s is not one", SDATA (SYMBOL_NAME (CHARSET_NAME (charset)))); if (CHARSET_ASCII_COMPATIBLE_P (charset)) - CODING_ATTR_ASCII_COMPAT (attrs) = Qt; + ASET (attrs, coding_attr_ascii_compat, Qt); charset_list = XCDR (charset_list); charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); @@ -10013,7 +10013,7 @@ usage: (define-coding-system-internal ...) */) else if (EQ (coding_type, Qraw_text)) { category = coding_category_raw_text; - CODING_ATTR_ASCII_COMPAT (attrs) = Qt; + ASET (attrs, coding_attr_ascii_compat, Qt); } else if (EQ (coding_type, Qutf_8)) { @@ -10033,7 +10033,7 @@ usage: (define-coding-system-internal ...) */) } ASET (attrs, coding_attr_utf_bom, bom); if (NILP (bom)) - CODING_ATTR_ASCII_COMPAT (attrs) = Qt; + ASET (attrs, coding_attr_ascii_compat, Qt); category = (CONSP (bom) ? coding_category_utf_8_auto : NILP (bom) ? coding_category_utf_8_nosig @@ -10045,14 +10045,15 @@ usage: (define-coding-system-internal ...) */) error ("Invalid coding system type: %s", SDATA (SYMBOL_NAME (coding_type))); - CODING_ATTR_CATEGORY (attrs) = make_number (category); - CODING_ATTR_PLIST (attrs) - = Fcons (QCcategory, Fcons (AREF (Vcoding_category_table, category), - CODING_ATTR_PLIST (attrs))); - CODING_ATTR_PLIST (attrs) - = Fcons (QCascii_compatible_p, - Fcons (CODING_ATTR_ASCII_COMPAT (attrs), - CODING_ATTR_PLIST (attrs))); + ASET (attrs, coding_attr_category, make_number (category)); + ASET (attrs, coding_attr_plist, + Fcons (QCcategory, + Fcons (AREF (Vcoding_category_table, category), + CODING_ATTR_PLIST (attrs)))); + ASET (attrs, coding_attr_plist, + Fcons (QCascii_compatible_p, + Fcons (CODING_ATTR_ASCII_COMPAT (attrs), + CODING_ATTR_PLIST (attrs)))); eol_type = args[coding_arg_eol_type]; if (! NILP (eol_type) @@ -10126,7 +10127,7 @@ DEFUN ("coding-system-put", Fcoding_system_put, Scoding_system_put, { if (! STRINGP (val)) CHECK_CHARACTER (val); - CODING_ATTR_MNEMONIC (attrs) = val; + ASET (attrs, coding_attr_mnemonic, val); } else if (EQ (prop, QCdefault_char)) { @@ -10134,37 +10135,37 @@ DEFUN ("coding-system-put", Fcoding_system_put, Scoding_system_put, val = make_number (' '); else CHECK_CHARACTER (val); - CODING_ATTR_DEFAULT_CHAR (attrs) = val; + ASET (attrs, coding_attr_default_char, val); } else if (EQ (prop, QCdecode_translation_table)) { if (! CHAR_TABLE_P (val) && ! CONSP (val)) CHECK_SYMBOL (val); - CODING_ATTR_DECODE_TBL (attrs) = val; + ASET (attrs, coding_attr_decode_tbl, val); } else if (EQ (prop, QCencode_translation_table)) { if (! CHAR_TABLE_P (val) && ! CONSP (val)) CHECK_SYMBOL (val); - CODING_ATTR_ENCODE_TBL (attrs) = val; + ASET (attrs, coding_attr_encode_tbl, val); } else if (EQ (prop, QCpost_read_conversion)) { CHECK_SYMBOL (val); - CODING_ATTR_POST_READ (attrs) = val; + ASET (attrs, coding_attr_post_read, val); } else if (EQ (prop, QCpre_write_conversion)) { CHECK_SYMBOL (val); - CODING_ATTR_PRE_WRITE (attrs) = val; + ASET (attrs, coding_attr_pre_write, val); } else if (EQ (prop, QCascii_compatible_p)) { - CODING_ATTR_ASCII_COMPAT (attrs) = val; + ASET (attrs, coding_attr_ascii_compat, val); } - CODING_ATTR_PLIST (attrs) - = Fplist_put (CODING_ATTR_PLIST (attrs), prop, val); + ASET (attrs, coding_attr_plist, + Fplist_put (CODING_ATTR_PLIST (attrs), prop, val)); return val; } -- cgit v1.2.1 From a2752828083a77421efdcd59938eeb21657c39a3 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Thu, 9 Aug 2012 09:14:23 +0400 Subject: Use TSET for write access to Lisp_Object slots of struct terminal. * termhooks.h (TSET): New macro. * coding.c, terminal.c, xselect.c: Adjust users. --- 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 12a7cf93c46..5bed11b8241 100644 --- a/src/coding.c +++ b/src/coding.c @@ -9294,9 +9294,9 @@ DEFUN ("set-terminal-coding-system-internal", Fset_terminal_coding_system_intern terminal_coding->src_multibyte = 1; terminal_coding->dst_multibyte = 0; if (terminal_coding->common_flags & CODING_REQUIRE_ENCODING_MASK) - term->charset_list = coding_charset_list (terminal_coding); + TSET (term, charset_list, coding_charset_list (terminal_coding)); else - term->charset_list = Fcons (make_number (charset_ascii), Qnil); + TSET (term, charset_list, Fcons (make_number (charset_ascii), Qnil)); return Qnil; } -- cgit v1.2.1 From 4c31be6153255dfe29a0231253263ea0d9011ac3 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Mon, 13 Aug 2012 07:39:07 +0400 Subject: Use BSET for write access to Lisp_Object members of struct buffer. * buffer.h (BSET): New macro. * buffer.c, casetab.c, cmds.c, coding.c, data.c, editfns.c: * fileio.c, frame.c, indent.c, insdel.c, intervals.c, keymap.c: * minibuf.c, print.c, process.c, syntax.c, undo.c, w32fns.c: * window.c, xdisp.c, xfns.c: Adjust users. --- 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 5bed11b8241..08633d8bcff 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7103,7 +7103,7 @@ decode_coding (struct coding_system *coding) if (GPT != PT) move_gap_both (PT, PT_BYTE); undo_list = BVAR (current_buffer, undo_list); - BVAR (current_buffer, undo_list) = Qt; + BSET (current_buffer, undo_list, Qt); } coding->consumed = coding->consumed_char = 0; @@ -7200,7 +7200,7 @@ decode_coding (struct coding_system *coding) decode_eol (coding); if (BUFFERP (coding->dst_object)) { - BVAR (current_buffer, undo_list) = undo_list; + BSET (current_buffer, undo_list, undo_list); record_insert (coding->dst_pos, coding->produced_char); } return coding->result; @@ -7568,8 +7568,8 @@ make_conversion_work_buffer (int multibyte) doesn't compile new regexps. */ Fset (Fmake_local_variable (Qinhibit_modification_hooks), Qt); Ferase_buffer (); - BVAR (current_buffer, undo_list) = Qt; - BVAR (current_buffer, enable_multibyte_characters) = multibyte ? Qt : Qnil; + BSET (current_buffer, undo_list, Qt); + BSET (current_buffer, enable_multibyte_characters, multibyte ? Qt : Qnil); set_buffer_internal (current); return workbuf; } -- cgit v1.2.1 From f48b82fd19703c5001c9cceb14b4d8372ce2b083 Mon Sep 17 00:00:00 2001 From: Gergely Risko Date: Tue, 14 Aug 2012 13:09:35 +0800 Subject: Fix for undo recording in decode_coding. * coding.c (decode_coding): Record buffer modification before disabling undo_list. Fixes: debbugs:11773 --- src/coding.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 08633d8bcff..c601a18b26e 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7102,6 +7102,15 @@ decode_coding (struct coding_system *coding) set_buffer_internal (XBUFFER (coding->dst_object)); if (GPT != PT) move_gap_both (PT, PT_BYTE); + + /* We must disable undo_list in order to record the whole insert + transaction via record_insert at the end. But doing so also + disables the recording of the first change to the undo_list. + Therefore we check for first change here and record it via + record_first_change if needed. */ + if (MODIFF <= SAVE_MODIFF) + record_first_change (); + undo_list = BVAR (current_buffer, undo_list); BSET (current_buffer, undo_list, Qt); } -- cgit v1.2.1 From 3f22b86fc7d9b66ff3e332b9a56350e93ddbd0aa Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 17 Aug 2012 17:07:52 -0700 Subject: * termhooks.h (TSET): Remove. Replace all uses with calls to new setter functions. Use INLINE_HEADER_BEGIN, INLINE_HEADER_END. (TERMHOOKS_INLINE): New macro. (tset_charset_list, tset_selection_alist): New setter functions. * terminal.c (TERMHOOKS_INLINE): Define to EXTERN_INLINE, so that the corresponding functions are compiled into code. (tset_param_alist): New setter function. Fixes: debbugs:12215 --- 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 c601a18b26e..290b9a5dbb6 100644 --- a/src/coding.c +++ b/src/coding.c @@ -9302,10 +9302,10 @@ DEFUN ("set-terminal-coding-system-internal", Fset_terminal_coding_system_intern terminal_coding->common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; terminal_coding->src_multibyte = 1; terminal_coding->dst_multibyte = 0; - if (terminal_coding->common_flags & CODING_REQUIRE_ENCODING_MASK) - TSET (term, charset_list, coding_charset_list (terminal_coding)); - else - TSET (term, charset_list, Fcons (make_number (charset_ascii), Qnil)); + tset_charset_list + (term, (terminal_coding->common_flags & CODING_REQUIRE_ENCODING_MASK + ? coding_charset_list (terminal_coding) + : Fcons (make_number (charset_ascii), Qnil))); return Qnil; } -- cgit v1.2.1 From 39eb03f1b023ae3d94e311f6f5d9f913f75c42c4 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 17 Aug 2012 23:06:39 -0700 Subject: * buffer.h (BSET): Remove. Replace all uses with calls to new setter functions. (bset_bidi_paragraph_direction, bset_case_canon_table) (bset_case_eqv_table, bset_directory, bset_display_count) (bset_display_time, bset_downcase_table) (bset_enable_multibyte_characters, bset_filename, bset_keymap) (bset_last_selected_window, bset_local_var_alist) (bset_mark_active, bset_point_before_scroll, bset_read_only) (bset_truncate_lines, bset_undo_list, bset_upcase_table) (bset_width_table): * buffer.c (bset_abbrev_mode, bset_abbrev_table) (bset_auto_fill_function, bset_auto_save_file_format) (bset_auto_save_file_name, bset_backed_up, bset_begv_marker) (bset_bidi_display_reordering, bset_buffer_file_coding_system) (bset_cache_long_line_scans, bset_case_fold_search) (bset_ctl_arrow, bset_cursor_in_non_selected_windows) (bset_cursor_type, bset_display_table, bset_extra_line_spacing) (bset_file_format, bset_file_truename, bset_fringe_cursor_alist) (bset_fringe_indicator_alist, bset_fringes_outside_margins) (bset_header_line_format, bset_indicate_buffer_boundaries) (bset_indicate_empty_lines, bset_invisibility_spec) (bset_left_fringe_width, bset_major_mode, bset_mark) (bset_minor_modes, bset_mode_line_format, bset_mode_name) (bset_name, bset_overwrite_mode, bset_pt_marker) (bset_right_fringe_width, bset_save_length) (bset_scroll_bar_width, bset_scroll_down_aggressively) (bset_scroll_up_aggressively, bset_selective_display) (bset_selective_display_ellipses, bset_vertical_scroll_bar_type) (bset_word_wrap, bset_zv_marker): * category.c (bset_category_table): * syntax.c (bset_syntax_table): New setter functions. Fixes: debbugs:12215 --- 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 290b9a5dbb6..971686dc180 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7112,7 +7112,7 @@ decode_coding (struct coding_system *coding) record_first_change (); undo_list = BVAR (current_buffer, undo_list); - BSET (current_buffer, undo_list, Qt); + bset_undo_list (current_buffer, Qt); } coding->consumed = coding->consumed_char = 0; @@ -7209,7 +7209,7 @@ decode_coding (struct coding_system *coding) decode_eol (coding); if (BUFFERP (coding->dst_object)) { - BSET (current_buffer, undo_list, undo_list); + bset_undo_list (current_buffer, undo_list); record_insert (coding->dst_pos, coding->produced_char); } return coding->result; @@ -7577,8 +7577,8 @@ make_conversion_work_buffer (int multibyte) doesn't compile new regexps. */ Fset (Fmake_local_variable (Qinhibit_modification_hooks), Qt); Ferase_buffer (); - BSET (current_buffer, undo_list, Qt); - BSET (current_buffer, enable_multibyte_characters, multibyte ? Qt : Qnil); + bset_undo_list (current_buffer, Qt); + bset_enable_multibyte_characters (current_buffer, multibyte ? Qt : Qnil); set_buffer_internal (current); return workbuf; } -- cgit v1.2.1 From f10fe38f772c29031a23ef7aa92d2de1b3675461 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 27 Aug 2012 09:19:34 -0700 Subject: * cmds.c, coding.c: Use bool for booleans. * cmds.c (move_point, Fself_insert_command): * coding.h (struct composition status, struct coding_system): * coding.c (detect_coding_utf_8, encode_coding_utf_8) (detect_coding_utf_16, encode_coding_utf_16, detect_coding_emacs_mule) (emacs_mule_char, decode_coding_emacs_mule) (encode_coding_emacs_mule, detect_coding_iso_2022) (decode_coding_iso_2022, encode_invocation_designation) (encode_designation_at_bol, encode_coding_iso_2022) (detect_coding_sjis, detect_coding_big5, decode_coding_sjis) (decode_coding_big5, encode_coding_sjis, encode_coding_big5) (detect_coding_ccl, encode_coding_ccl, decode_coding_raw_text) (encode_coding_raw_text, detect_coding_charset) (decode_coding_charset, encode_coding_charset, detect_eol) (detect_coding, get_translation_table, produce_chars) (consume_chars, reused_workbuf_in_use) (make_conversion_work_buffer, code_conversion_save) (decode_coding_object, encode_coding_object) (detect_coding_system, char_encodable_p) (Funencodable_char_position, code_convert_region) (code_convert_string, code_convert_string_norecord) (Fset_coding_system_priority): * fileio.c (Finsert_file_contents): Use bool for booleans. * coding.h, lisp.h: Reflect above API changes. * coding.c: Remove unnecessary static function decls. (detect_coding): Use unsigned, not signed, to copy an unsigned field. (decode_coding, encode_coding, decode_coding_gap): Return 'void', not a boolean 'int', since callers never look at the return value. (ALLOC_CONVERSION_WORK_AREA): Assume caller returns 'void', not 'int'. * coding.h (decoding_buffer_size, encoding_buffer_size) (emacs_mule_string_char): Remove unused extern decls. (struct iso_2022_spec, struct coding_system): Use 'unsigned int : 1' for boolean fields, since there's more than one. (struct emacs_mule_spec): Remove unused field 'full_support'. All initializations removed. * cmds.c (internal_self_insert): Don't assume EMACS_INT fits in 'int'. --- src/coding.c | 368 ++++++++++++++++++++++------------------------------------- 1 file changed, 137 insertions(+), 231 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 971686dc180..5bfd42c7272 100644 --- a/src/coding.c +++ b/src/coding.c @@ -147,18 +147,18 @@ STRUCT CODING_SYSTEM CODING conforms to the format of XXX, and update the members of DETECT_INFO. - Return 1 if the byte sequence conforms to XXX, otherwise return 0. + Return true if the byte sequence conforms to XXX. Below is the template of these functions. */ #if 0 -static int +static bool detect_coding_XXX (struct coding_system *coding, struct coding_detection_info *detect_info) { const unsigned char *src = coding->source; const unsigned char *src_end = coding->source + coding->src_bytes; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; ptrdiff_t consumed_chars = 0; int found = 0; ...; @@ -212,7 +212,7 @@ decode_coding_XXXX (struct coding_system *coding) /* A buffer to produce decoded characters. */ int *charbuf = coding->charbuf + coding->charbuf_used; int *charbuf_end = coding->charbuf + coding->charbuf_size; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; while (1) { @@ -260,7 +260,7 @@ decode_coding_XXXX (struct coding_system *coding) static void encode_coding_XXX (struct coding_system *coding) { - int multibytep = coding->dst_multibyte; + bool multibytep = coding->dst_multibyte; int *charbuf = coding->charbuf; int *charbuf_end = charbuf->charbuf + coding->charbuf_used; unsigned char *dst = coding->destination + coding->produced; @@ -651,8 +651,8 @@ static struct coding_system coding_categories[coding_category_max]; /* Safely get one byte from the source text pointed by SRC which ends at SRC_END, and set C to that byte. If there are not enough bytes - in the source, it jumps to `no_more_source'. If multibytep is - nonzero, and a multibyte character is found at SRC, set C to the + in the source, it jumps to 'no_more_source'. If MULTIBYTEP, + and a multibyte character is found at SRC, set C to the negative value of the character code. The caller should declare and set these variables appropriately in advance: src, src_end, multibytep */ @@ -685,7 +685,7 @@ static struct coding_system coding_categories[coding_category_max]; /* Safely get two bytes from the source text pointed by SRC which ends at SRC_END, and set C1 and C2 to those bytes while skipping the heading multibyte characters. If there are not enough bytes in the - source, it jumps to `no_more_source'. If multibytep is nonzero and + source, it jumps to 'no_more_source'. If MULTIBYTEP and a multibyte character is found for C2, set C2 to the negative value of the character code. The caller should declare and set these variables appropriately in advance: @@ -746,8 +746,8 @@ static struct coding_system coding_categories[coding_category_max]; /* Store a byte C in the place pointed by DST and increment DST to the - next free point, and increment PRODUCED_CHARS. If MULTIBYTEP is - nonzero, store in an appropriate multibyte from. The caller should + next free point, and increment PRODUCED_CHARS. If MULTIBYTEP, + store in an appropriate multibyte form. The caller should declare and set the variables `dst' and `multibytep' appropriately in advance. */ @@ -806,83 +806,6 @@ static struct coding_system coding_categories[coding_category_max]; } while (0) -/* Prototypes for static functions. */ -static void record_conversion_result (struct coding_system *coding, - enum coding_result_code result); -static int detect_coding_utf_8 (struct coding_system *, - struct coding_detection_info *info); -static void decode_coding_utf_8 (struct coding_system *); -static int encode_coding_utf_8 (struct coding_system *); - -static int detect_coding_utf_16 (struct coding_system *, - struct coding_detection_info *info); -static void decode_coding_utf_16 (struct coding_system *); -static int encode_coding_utf_16 (struct coding_system *); - -static int detect_coding_iso_2022 (struct coding_system *, - struct coding_detection_info *info); -static void decode_coding_iso_2022 (struct coding_system *); -static int encode_coding_iso_2022 (struct coding_system *); - -static int detect_coding_emacs_mule (struct coding_system *, - struct coding_detection_info *info); -static void decode_coding_emacs_mule (struct coding_system *); -static int encode_coding_emacs_mule (struct coding_system *); - -static int detect_coding_sjis (struct coding_system *, - struct coding_detection_info *info); -static void decode_coding_sjis (struct coding_system *); -static int encode_coding_sjis (struct coding_system *); - -static int detect_coding_big5 (struct coding_system *, - struct coding_detection_info *info); -static void decode_coding_big5 (struct coding_system *); -static int encode_coding_big5 (struct coding_system *); - -static int detect_coding_ccl (struct coding_system *, - struct coding_detection_info *info); -static void decode_coding_ccl (struct coding_system *); -static int encode_coding_ccl (struct coding_system *); - -static void decode_coding_raw_text (struct coding_system *); -static int encode_coding_raw_text (struct coding_system *); - -static void coding_set_source (struct coding_system *); -static ptrdiff_t coding_change_source (struct coding_system *); -static void coding_set_destination (struct coding_system *); -static ptrdiff_t coding_change_destination (struct coding_system *); -static void coding_alloc_by_realloc (struct coding_system *, ptrdiff_t); -static void coding_alloc_by_making_gap (struct coding_system *, - ptrdiff_t, ptrdiff_t); -static unsigned char *alloc_destination (struct coding_system *, - ptrdiff_t, unsigned char *); -static void setup_iso_safe_charsets (Lisp_Object); -static ptrdiff_t encode_designation_at_bol (struct coding_system *, - int *, int *, unsigned char *); -static int detect_eol (const unsigned char *, - ptrdiff_t, enum coding_category); -static Lisp_Object adjust_coding_eol_type (struct coding_system *, int); -static void decode_eol (struct coding_system *); -static Lisp_Object get_translation_table (Lisp_Object, int, int *); -static Lisp_Object get_translation (Lisp_Object, int *, int *); -static int produce_chars (struct coding_system *, Lisp_Object, int); -static inline void produce_charset (struct coding_system *, int *, - ptrdiff_t); -static void produce_annotation (struct coding_system *, ptrdiff_t); -static int decode_coding (struct coding_system *); -static inline int *handle_composition_annotation (ptrdiff_t, ptrdiff_t, - struct coding_system *, - int *, ptrdiff_t *); -static inline int *handle_charset_annotation (ptrdiff_t, ptrdiff_t, - struct coding_system *, - int *, ptrdiff_t *); -static void consume_chars (struct coding_system *, Lisp_Object, int); -static int encode_coding (struct coding_system *); -static Lisp_Object make_conversion_work_buffer (int); -static Lisp_Object code_conversion_restore (Lisp_Object); -static inline int char_encodable_p (int, Lisp_Object); -static Lisp_Object make_subsidiaries (Lisp_Object); - static void record_conversion_result (struct coding_system *coding, enum coding_result_code result) @@ -1264,8 +1187,7 @@ alloc_destination (struct coding_system *coding, ptrdiff_t nbytes, /*** 3. UTF-8 ***/ /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". - Check if a text is encoded in UTF-8. If it is, return 1, else - return 0. */ + Return true if a text is encoded in UTF-8. */ #define UTF_8_1_OCTET_P(c) ((c) < 0x80) #define UTF_8_EXTRA_OCTET_P(c) (((c) & 0xC0) == 0x80) @@ -1278,16 +1200,16 @@ alloc_destination (struct coding_system *coding, ptrdiff_t nbytes, #define UTF_8_BOM_2 0xBB #define UTF_8_BOM_3 0xBF -static int +static bool detect_coding_utf_8 (struct coding_system *coding, struct coding_detection_info *detect_info) { const unsigned char *src = coding->source, *src_base; const unsigned char *src_end = coding->source + coding->src_bytes; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; ptrdiff_t consumed_chars = 0; - int bom_found = 0; - int found = 0; + bool bom_found = 0; + bool found = 0; detect_info->checked |= CATEGORY_MASK_UTF_8; /* A coding system of this category is always ASCII compatible. */ @@ -1371,10 +1293,10 @@ decode_coding_utf_8 (struct coding_system *coding) int *charbuf = coding->charbuf + coding->charbuf_used; int *charbuf_end = coding->charbuf + coding->charbuf_size; ptrdiff_t consumed_chars = 0, consumed_chars_base = 0; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; enum utf_bom_type bom = CODING_UTF_8_BOM (coding); - int eol_dos = - !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); + bool eol_dos + = !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); int byte_after_cr = -1; if (bom != utf_without_bom) @@ -1513,10 +1435,10 @@ decode_coding_utf_8 (struct coding_system *coding) } -static int +static bool encode_coding_utf_8 (struct coding_system *coding) { - int multibytep = coding->dst_multibyte; + bool multibytep = coding->dst_multibyte; int *charbuf = coding->charbuf; int *charbuf_end = charbuf + coding->charbuf_used; unsigned char *dst = coding->destination + coding->produced; @@ -1577,8 +1499,7 @@ encode_coding_utf_8 (struct coding_system *coding) /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". - Check if a text is encoded in one of UTF-16 based coding systems. - If it is, return 1, else return 0. */ + Return true if a text is encoded in one of UTF-16 based coding systems. */ #define UTF_16_HIGH_SURROGATE_P(val) \ (((val) & 0xFC00) == 0xD800) @@ -1587,13 +1508,13 @@ encode_coding_utf_8 (struct coding_system *coding) (((val) & 0xFC00) == 0xDC00) -static int +static bool detect_coding_utf_16 (struct coding_system *coding, struct coding_detection_info *detect_info) { const unsigned char *src = coding->source; const unsigned char *src_end = coding->source + coding->src_bytes; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; int c1, c2; detect_info->checked |= CATEGORY_MASK_UTF_16; @@ -1680,12 +1601,12 @@ decode_coding_utf_16 (struct coding_system *coding) /* We may produces at most 3 chars in one loop. */ int *charbuf_end = coding->charbuf + coding->charbuf_size - 2; ptrdiff_t consumed_chars = 0, consumed_chars_base = 0; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; enum utf_bom_type bom = CODING_UTF_16_BOM (coding); enum utf_16_endian_type endian = CODING_UTF_16_ENDIAN (coding); int surrogate = CODING_UTF_16_SURROGATE (coding); - int eol_dos = - !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); + bool eol_dos + = !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); int byte_after_cr1 = -1, byte_after_cr2 = -1; if (bom == utf_with_bom) @@ -1795,17 +1716,17 @@ decode_coding_utf_16 (struct coding_system *coding) coding->charbuf_used = charbuf - coding->charbuf; } -static int +static bool encode_coding_utf_16 (struct coding_system *coding) { - int multibytep = coding->dst_multibyte; + bool multibytep = coding->dst_multibyte; int *charbuf = coding->charbuf; int *charbuf_end = charbuf + coding->charbuf_used; unsigned char *dst = coding->destination + coding->produced; unsigned char *dst_end = coding->destination + coding->dst_bytes; int safe_room = 8; enum utf_bom_type bom = CODING_UTF_16_BOM (coding); - int big_endian = CODING_UTF_16_ENDIAN (coding) == utf_16_big_endian; + bool big_endian = CODING_UTF_16_ENDIAN (coding) == utf_16_big_endian; ptrdiff_t produced_chars = 0; int c; @@ -1930,16 +1851,15 @@ char emacs_mule_bytes[256]; /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". - Check if a text is encoded in `emacs-mule'. If it is, return 1, - else return 0. */ + Return true if a text is encoded in 'emacs-mule'. */ -static int +static bool detect_coding_emacs_mule (struct coding_system *coding, struct coding_detection_info *detect_info) { const unsigned char *src = coding->source, *src_base; const unsigned char *src_end = coding->source + coding->src_bytes; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; ptrdiff_t consumed_chars = 0; int c; int found = 0; @@ -2029,12 +1949,12 @@ emacs_mule_char (struct coding_system *coding, const unsigned char *src, { const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_base = src; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; int charset_ID; unsigned code; int c; int consumed_chars = 0; - int mseq_found = 0; + bool mseq_found = 0; ONE_MORE_BYTE (c); if (c < 0) @@ -2411,12 +2331,12 @@ decode_coding_emacs_mule (struct coding_system *coding) /* We can produce up to 2 characters in a loop. */ - 1; ptrdiff_t consumed_chars = 0, consumed_chars_base; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; ptrdiff_t char_offset = coding->produced_char; ptrdiff_t last_offset = char_offset; int last_id = charset_ascii; - int eol_dos = - !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); + bool eol_dos + = !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); int byte_after_cr = -1; struct composition_status *cmp_status = &coding->spec.emacs_mule.cmp_status; @@ -2657,10 +2577,10 @@ decode_coding_emacs_mule (struct coding_system *coding) } while (0); -static int +static bool encode_coding_emacs_mule (struct coding_system *coding) { - int multibytep = coding->dst_multibyte; + bool multibytep = coding->dst_multibyte; int *charbuf = coding->charbuf; int *charbuf_end = charbuf + coding->charbuf_used; unsigned char *dst = coding->destination + coding->produced; @@ -2722,7 +2642,7 @@ encode_coding_emacs_mule (struct coding_system *coding) if (preferred_charset_id >= 0) { - int result; + bool result; charset = CHARSET_FROM_ID (preferred_charset_id); CODING_CHAR_CHARSET_P (coding, dst, dst_end, c, charset, result); @@ -3017,17 +2937,17 @@ setup_iso_safe_charsets (Lisp_Object attrs) /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". - Check if a text is encoded in one of ISO-2022 based coding systems. - If it is, return 1, else return 0. */ + Return true if a text is encoded in one of ISO-2022 based coding + systems. */ -static int +static bool detect_coding_iso_2022 (struct coding_system *coding, struct coding_detection_info *detect_info) { const unsigned char *src = coding->source, *src_base = src; const unsigned char *src_end = coding->source + coding->src_bytes; - int multibytep = coding->src_multibyte; - int single_shifting = 0; + bool multibytep = coding->src_multibyte; + bool single_shifting = 0; int id; int c, c1; ptrdiff_t consumed_chars = 0; @@ -3390,8 +3310,6 @@ detect_coding_iso_2022 (struct coding_system *coding, /* Finish the current composition as invalid. */ -static int finish_composition (int *, struct composition_status *); - static int finish_composition (int *charbuf, struct composition_status *cmp_status) { @@ -3541,7 +3459,7 @@ decode_coding_iso_2022 (struct coding_system *coding) int *charbuf_end = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 3); ptrdiff_t consumed_chars = 0, consumed_chars_base; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; /* Charsets invoked to graphic plane 0 and 1 respectively. */ int charset_id_0 = CODING_ISO_INVOKED_CHARSET (coding, 0); int charset_id_1 = CODING_ISO_INVOKED_CHARSET (coding, 1); @@ -3553,8 +3471,8 @@ decode_coding_iso_2022 (struct coding_system *coding) ptrdiff_t char_offset = coding->produced_char; ptrdiff_t last_offset = char_offset; int last_id = charset_ascii; - int eol_dos = - !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); + bool eol_dos + = !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); int byte_after_cr = -1; int i; @@ -4282,7 +4200,7 @@ encode_invocation_designation (struct charset *charset, struct coding_system *coding, unsigned char *dst, ptrdiff_t *p_nchars) { - int multibytep = coding->dst_multibyte; + bool multibytep = coding->dst_multibyte; ptrdiff_t produced_chars = *p_nchars; int reg; /* graphic register number */ int id = CHARSET_ID (charset); @@ -4380,7 +4298,7 @@ encode_designation_at_bol (struct coding_system *coding, int r[4]; int c, found = 0, reg; ptrdiff_t produced_chars = 0; - int multibytep = coding->dst_multibyte; + bool multibytep = coding->dst_multibyte; Lisp_Object attrs; Lisp_Object charset_list; @@ -4422,21 +4340,21 @@ encode_designation_at_bol (struct coding_system *coding, /* See the above "GENERAL NOTES on `encode_coding_XXX ()' functions". */ -static int +static bool encode_coding_iso_2022 (struct coding_system *coding) { - int multibytep = coding->dst_multibyte; + bool multibytep = coding->dst_multibyte; int *charbuf = coding->charbuf; int *charbuf_end = charbuf + coding->charbuf_used; unsigned char *dst = coding->destination + coding->produced; unsigned char *dst_end = coding->destination + coding->dst_bytes; int safe_room = 16; - int bol_designation + bool bol_designation = (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATE_AT_BOL && CODING_ISO_BOL (coding)); ptrdiff_t produced_chars = 0; Lisp_Object attrs, eol_type, charset_list; - int ascii_compatible; + bool ascii_compatible; int c; int preferred_charset_id = -1; @@ -4523,8 +4441,9 @@ encode_coding_iso_2022 (struct coding_system *coding) CODING_ISO_DESIGNATION (coding, i) = CODING_ISO_INITIAL (coding, i); } - bol_designation - = CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATE_AT_BOL; + bol_designation = ((CODING_ISO_FLAGS (coding) + & CODING_ISO_FLAG_DESIGNATE_AT_BOL) + != 0); } else if (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_RESET_AT_CNTL) ENCODE_RESET_PLANE_AND_REGISTER (); @@ -4551,7 +4470,7 @@ encode_coding_iso_2022 (struct coding_system *coding) if (preferred_charset_id >= 0) { - int result; + bool result; charset = CHARSET_FROM_ID (preferred_charset_id); CODING_CHAR_CHARSET_P (coding, dst, dst_end, c, charset, result); @@ -4631,16 +4550,15 @@ encode_coding_iso_2022 (struct coding_system *coding) */ /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". - Check if a text is encoded in SJIS. If it is, return - CATEGORY_MASK_SJIS, else return 0. */ + Return true if a text is encoded in SJIS. */ -static int +static bool detect_coding_sjis (struct coding_system *coding, struct coding_detection_info *detect_info) { const unsigned char *src = coding->source, *src_base; const unsigned char *src_end = coding->source + coding->src_bytes; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; ptrdiff_t consumed_chars = 0; int found = 0; int c; @@ -4688,16 +4606,15 @@ detect_coding_sjis (struct coding_system *coding, } /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". - Check if a text is encoded in BIG5. If it is, return - CATEGORY_MASK_BIG5, else return 0. */ + Return true if a text is encoded in BIG5. */ -static int +static bool detect_coding_big5 (struct coding_system *coding, struct coding_detection_info *detect_info) { const unsigned char *src = coding->source, *src_base; const unsigned char *src_end = coding->source + coding->src_bytes; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; ptrdiff_t consumed_chars = 0; int found = 0; int c; @@ -4735,8 +4652,7 @@ detect_coding_big5 (struct coding_system *coding, return 1; } -/* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". - If SJIS_P is 1, decode SJIS text, else decode BIG5 test. */ +/* See the above "GENERAL NOTES on `decode_coding_XXX ()' functions". */ static void decode_coding_sjis (struct coding_system *coding) @@ -4750,15 +4666,15 @@ decode_coding_sjis (struct coding_system *coding) int *charbuf_end = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2); ptrdiff_t consumed_chars = 0, consumed_chars_base; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; struct charset *charset_roman, *charset_kanji, *charset_kana; struct charset *charset_kanji2; Lisp_Object attrs, charset_list, val; ptrdiff_t char_offset = coding->produced_char; ptrdiff_t last_offset = char_offset; int last_id = charset_ascii; - int eol_dos = - !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); + bool eol_dos + = !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); int byte_after_cr = -1; CODING_GET_INFO (coding, attrs, charset_list); @@ -4868,14 +4784,14 @@ decode_coding_big5 (struct coding_system *coding) int *charbuf_end = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2); ptrdiff_t consumed_chars = 0, consumed_chars_base; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; struct charset *charset_roman, *charset_big5; Lisp_Object attrs, charset_list, val; ptrdiff_t char_offset = coding->produced_char; ptrdiff_t last_offset = char_offset; int last_id = charset_ascii; - int eol_dos = - !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); + bool eol_dos + = !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); int byte_after_cr = -1; CODING_GET_INFO (coding, attrs, charset_list); @@ -4957,13 +4873,12 @@ decode_coding_big5 (struct coding_system *coding) `japanese-jisx0208', `chinese-big5-1', and `chinese-big5-2'. We are sure that all these charsets are registered as official charset (i.e. do not have extended leading-codes). Characters of other - charsets are produced without any encoding. If SJIS_P is 1, encode - SJIS text, else encode BIG5 text. */ + charsets are produced without any encoding. */ -static int +static bool encode_coding_sjis (struct coding_system *coding) { - int multibytep = coding->dst_multibyte; + bool multibytep = coding->dst_multibyte; int *charbuf = coding->charbuf; int *charbuf_end = charbuf + coding->charbuf_used; unsigned char *dst = coding->destination + coding->produced; @@ -4971,7 +4886,7 @@ encode_coding_sjis (struct coding_system *coding) int safe_room = 4; ptrdiff_t produced_chars = 0; Lisp_Object attrs, charset_list, val; - int ascii_compatible; + bool ascii_compatible; struct charset *charset_kanji, *charset_kana; struct charset *charset_kanji2; int c; @@ -5054,10 +4969,10 @@ encode_coding_sjis (struct coding_system *coding) return 0; } -static int +static bool encode_coding_big5 (struct coding_system *coding) { - int multibytep = coding->dst_multibyte; + bool multibytep = coding->dst_multibyte; int *charbuf = coding->charbuf; int *charbuf_end = charbuf + coding->charbuf_used; unsigned char *dst = coding->destination + coding->produced; @@ -5065,7 +4980,7 @@ encode_coding_big5 (struct coding_system *coding) int safe_room = 4; ptrdiff_t produced_chars = 0; Lisp_Object attrs, charset_list, val; - int ascii_compatible; + bool ascii_compatible; struct charset *charset_big5; int c; @@ -5130,17 +5045,16 @@ encode_coding_big5 (struct coding_system *coding) /*** 10. CCL handlers ***/ /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". - Check if a text is encoded in a coding system of which - encoder/decoder are written in CCL program. If it is, return - CATEGORY_MASK_CCL, else return 0. */ + Return true if a text is encoded in a coding system of which + encoder/decoder are written in CCL program. */ -static int +static bool detect_coding_ccl (struct coding_system *coding, struct coding_detection_info *detect_info) { const unsigned char *src = coding->source, *src_base; const unsigned char *src_end = coding->source + coding->src_bytes; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; ptrdiff_t consumed_chars = 0; int found = 0; unsigned char *valids; @@ -5182,7 +5096,7 @@ decode_coding_ccl (struct coding_system *coding) int *charbuf = coding->charbuf + coding->charbuf_used; int *charbuf_end = coding->charbuf + coding->charbuf_size; ptrdiff_t consumed_chars = 0; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; struct ccl_program *ccl = &coding->spec.ccl->ccl; int source_charbuf[1024]; int source_byteidx[1025]; @@ -5243,11 +5157,11 @@ decode_coding_ccl (struct coding_system *coding) coding->charbuf_used = charbuf - coding->charbuf; } -static int +static bool encode_coding_ccl (struct coding_system *coding) { struct ccl_program *ccl = &coding->spec.ccl->ccl; - int multibytep = coding->dst_multibyte; + bool multibytep = coding->dst_multibyte; int *charbuf = coding->charbuf; int *charbuf_end = charbuf + coding->charbuf_used; unsigned char *dst = coding->destination + coding->produced; @@ -5308,7 +5222,6 @@ encode_coding_ccl (struct coding_system *coding) return 0; } - /*** 10, 11. no-conversion handlers ***/ @@ -5317,8 +5230,8 @@ encode_coding_ccl (struct coding_system *coding) static void decode_coding_raw_text (struct coding_system *coding) { - int eol_dos = - !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); + bool eol_dos + = !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); coding->chars_at_source = 1; coding->consumed_char = coding->src_chars; @@ -5333,10 +5246,10 @@ decode_coding_raw_text (struct coding_system *coding) record_conversion_result (coding, CODING_RESULT_SUCCESS); } -static int +static bool encode_coding_raw_text (struct coding_system *coding) { - int multibytep = coding->dst_multibyte; + bool multibytep = coding->dst_multibyte; int *charbuf = coding->charbuf; int *charbuf_end = coding->charbuf + coding->charbuf_used; unsigned char *dst = coding->destination + coding->produced; @@ -5414,21 +5327,20 @@ encode_coding_raw_text (struct coding_system *coding) } /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". - Check if a text is encoded in a charset-based coding system. If it - is, return 1, else return 0. */ + Return true if a text is encoded in a charset-based coding system. */ -static int +static bool detect_coding_charset (struct coding_system *coding, struct coding_detection_info *detect_info) { const unsigned char *src = coding->source, *src_base; const unsigned char *src_end = coding->source + coding->src_bytes; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; ptrdiff_t consumed_chars = 0; Lisp_Object attrs, valids, name; int found = 0; ptrdiff_t head_ascii = coding->head_ascii; - int check_latin_extra = 0; + bool check_latin_extra = 0; detect_info->checked |= CATEGORY_MASK_CHARSET; @@ -5532,14 +5444,14 @@ decode_coding_charset (struct coding_system *coding) int *charbuf_end = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2); ptrdiff_t consumed_chars = 0, consumed_chars_base; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; Lisp_Object attrs = CODING_ID_ATTRS (coding->id); Lisp_Object valids; ptrdiff_t char_offset = coding->produced_char; ptrdiff_t last_offset = char_offset; int last_id = charset_ascii; - int eol_dos = - !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); + bool eol_dos + = !inhibit_eol_conversion && EQ (CODING_ID_EOL_TYPE (coding->id), Qdos); int byte_after_cr = -1; valids = AREF (attrs, coding_attr_charset_valids); @@ -5648,10 +5560,10 @@ decode_coding_charset (struct coding_system *coding) coding->charbuf_used = charbuf - coding->charbuf; } -static int +static bool encode_coding_charset (struct coding_system *coding) { - int multibytep = coding->dst_multibyte; + bool multibytep = coding->dst_multibyte; int *charbuf = coding->charbuf; int *charbuf_end = charbuf + coding->charbuf_used; unsigned char *dst = coding->destination + coding->produced; @@ -5659,7 +5571,7 @@ encode_coding_charset (struct coding_system *coding) int safe_room = MAX_MULTIBYTE_LENGTH; ptrdiff_t produced_chars = 0; Lisp_Object attrs, charset_list; - int ascii_compatible; + bool ascii_compatible; int c; CODING_GET_INFO (coding, attrs, charset_list); @@ -5865,7 +5777,6 @@ setup_coding_system (Lisp_Object coding_system, struct coding_system *coding) coding->encoder = encode_coding_emacs_mule; coding->common_flags |= (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_ENCODING_MASK); - coding->spec.emacs_mule.full_support = 1; if (! NILP (AREF (attrs, coding_attr_emacs_mule_full)) && ! EQ (CODING_ATTR_CHARSET_LIST (attrs), Vemacs_mule_charset_list)) { @@ -5883,7 +5794,6 @@ setup_coding_system (Lisp_Object coding_system, struct coding_system *coding) SSET (safe_charsets, XFASTINT (XCAR (tail)), 0); coding->max_charset_id = max_charset_id; coding->safe_charsets = SDATA (safe_charsets); - coding->spec.emacs_mule.full_support = 1; } coding->spec.emacs_mule.cmp_status.state = COMPOSING_NO; coding->spec.emacs_mule.cmp_status.method = COMPOSITION_NO; @@ -6216,11 +6126,9 @@ detect_eol (const unsigned char *source, ptrdiff_t src_bytes, if ((1 << category) & CATEGORY_MASK_UTF_16) { - int msb, lsb; - - msb = category == (coding_category_utf_16_le - | coding_category_utf_16_le_nosig); - lsb = 1 - msb; + bool msb = category == (coding_category_utf_16_le + | coding_category_utf_16_le_nosig); + bool lsb = !msb; while (src + 1 < src_end) { @@ -6335,7 +6243,7 @@ static void detect_coding (struct coding_system *coding) { const unsigned char *src, *src_end; - int saved_mode = coding->mode; + unsigned int saved_mode = coding->mode; coding->consumed = coding->consumed_char = 0; coding->produced = coding->produced_char = 0; @@ -6350,7 +6258,7 @@ detect_coding (struct coding_system *coding) { int c, i; struct coding_detection_info detect_info; - int null_byte_found = 0, eight_bit_found = 0; + bool null_byte_found = 0, eight_bit_found = 0; detect_info.checked = detect_info.found = detect_info.rejected = 0; for (src = coding->source; src < src_end; src++) @@ -6609,11 +6517,11 @@ decode_eol (struct coding_system *coding) /* Return a translation table (or list of them) from coding system - attribute vector ATTRS for encoding (ENCODEP is nonzero) or - decoding (ENCODEP is zero). */ + attribute vector ATTRS for encoding (if ENCODEP) or decoding (if + not ENCODEP). */ static Lisp_Object -get_translation_table (Lisp_Object attrs, int encodep, int *max_lookup) +get_translation_table (Lisp_Object attrs, bool encodep, int *max_lookup) { Lisp_Object standard, translation_table; Lisp_Object val; @@ -6743,7 +6651,7 @@ get_translation (Lisp_Object trans, int *buf, int *buf_end) static int produce_chars (struct coding_system *coding, Lisp_Object translation_table, - int last_block) + bool last_block) { unsigned char *dst = coding->destination + coding->produced; unsigned char *dst_end = coding->destination + coding->dst_bytes; @@ -6846,7 +6754,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table, { if (coding->src_multibyte) { - int multibytep = 1; + bool multibytep = 1; ptrdiff_t consumed_chars = 0; while (1) @@ -6882,7 +6790,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table, else while (src < src_end) { - int multibytep = 1; + bool multibytep = 1; int c = *src++; if (dst >= dst_end - 1) @@ -7018,7 +6926,7 @@ produce_charset (struct coding_system *coding, int *charbuf, ptrdiff_t pos) if (! coding->charbuf) \ { \ record_conversion_result (coding, CODING_RESULT_INSUFFICIENT_MEM); \ - return coding->result; \ + return; \ } \ coding->charbuf_size = size; \ } while (0) @@ -7079,7 +6987,7 @@ produce_annotation (struct coding_system *coding, ptrdiff_t pos) CODING->dst_object. */ -static int +static void decode_coding (struct coding_system *coding) { Lisp_Object attrs; @@ -7212,7 +7120,6 @@ decode_coding (struct coding_system *coding) bset_undo_list (current_buffer, undo_list); record_insert (coding->dst_pos, coding->produced_char); } - return coding->result; } @@ -7341,7 +7248,7 @@ consume_chars (struct coding_system *coding, Lisp_Object translation_table, const unsigned char *src_end = coding->source + coding->src_bytes; ptrdiff_t pos = coding->src_pos + coding->consumed_char; ptrdiff_t end_pos = coding->src_pos + coding->src_chars; - int multibytep = coding->src_multibyte; + bool multibytep = coding->src_multibyte; Lisp_Object eol_type; int c; ptrdiff_t stop, stop_composition, stop_charset; @@ -7488,7 +7395,7 @@ consume_chars (struct coding_system *coding, Lisp_Object translation_table, If CODING->dst_object is nil, the encoded data is placed at the memory area specified by CODING->destination. */ -static int +static void encode_coding (struct coding_system *coding) { Lisp_Object attrs; @@ -7530,8 +7437,6 @@ encode_coding (struct coding_system *coding) if (BUFFERP (coding->dst_object) && coding->produced_char > 0) insert_from_gap (coding->produced_char, coding->produced); - - return (coding->result); } @@ -7545,26 +7450,27 @@ static Lisp_Object Vcode_conversion_workbuf_name; versions of Vcode_conversion_workbuf_name. */ static Lisp_Object Vcode_conversion_reused_workbuf; -/* 1 iff Vcode_conversion_reused_workbuf is already in use. */ -static int reused_workbuf_in_use; +/* True iff Vcode_conversion_reused_workbuf is already in use. */ +static bool reused_workbuf_in_use; /* Return a working buffer of code conversion. MULTIBYTE specifies the multibyteness of returning buffer. */ static Lisp_Object -make_conversion_work_buffer (int multibyte) +make_conversion_work_buffer (bool multibyte) { Lisp_Object name, workbuf; struct buffer *current; - if (reused_workbuf_in_use++) + if (reused_workbuf_in_use) { name = Fgenerate_new_buffer_name (Vcode_conversion_workbuf_name, Qnil); workbuf = Fget_buffer_create (name); } else { + reused_workbuf_in_use = 1; if (NILP (Fbuffer_live_p (Vcode_conversion_reused_workbuf))) Vcode_conversion_reused_workbuf = Fget_buffer_create (Vcode_conversion_workbuf_name); @@ -7606,7 +7512,7 @@ code_conversion_restore (Lisp_Object arg) } Lisp_Object -code_conversion_save (int with_work_buf, int multibyte) +code_conversion_save (bool with_work_buf, bool multibyte) { Lisp_Object workbuf = Qnil; @@ -7617,7 +7523,7 @@ code_conversion_save (int with_work_buf, int multibyte) return workbuf; } -int +void decode_coding_gap (struct coding_system *coding, ptrdiff_t chars, ptrdiff_t bytes) { @@ -7660,7 +7566,6 @@ decode_coding_gap (struct coding_system *coding, } unbind_to (count, Qnil); - return coding->result; } @@ -7706,8 +7611,8 @@ decode_coding_object (struct coding_system *coding, ptrdiff_t chars = to - from; ptrdiff_t bytes = to_byte - from_byte; Lisp_Object attrs; - int saved_pt = -1, saved_pt_byte IF_LINT (= 0); - int need_marker_adjustment = 0; + ptrdiff_t saved_pt = -1, saved_pt_byte IF_LINT (= 0); + bool need_marker_adjustment = 0; Lisp_Object old_deactivate_mark; old_deactivate_mark = Vdeactivate_mark; @@ -7894,9 +7799,9 @@ encode_coding_object (struct coding_system *coding, ptrdiff_t chars = to - from; ptrdiff_t bytes = to_byte - from_byte; Lisp_Object attrs; - int saved_pt = -1, saved_pt_byte IF_LINT (= 0); - int need_marker_adjustment = 0; - int kill_src_buffer = 0; + ptrdiff_t saved_pt = -1, saved_pt_byte IF_LINT (= 0); + bool need_marker_adjustment = 0; + bool kill_src_buffer = 0; Lisp_Object old_deactivate_mark; old_deactivate_mark = Vdeactivate_mark; @@ -8172,10 +8077,10 @@ function `define-coding-system'. */) /* Detect how the bytes at SRC of length SRC_BYTES are encoded. If - HIGHEST is nonzero, return the coding system of the highest + HIGHEST, return the coding system of the highest priority among the detected coding systems. Otherwise return a list of detected coding systems sorted by their priorities. If - MULTIBYTEP is nonzero, it is assumed that the bytes are in correct + MULTIBYTEP, it is assumed that the bytes are in correct multibyte form but contains only ASCII and eight-bit chars. Otherwise, the bytes are raw bytes. @@ -8190,7 +8095,7 @@ function `define-coding-system'. */) Lisp_Object detect_coding_system (const unsigned char *src, ptrdiff_t src_chars, ptrdiff_t src_bytes, - int highest, int multibytep, + bool highest, bool multibytep, Lisp_Object coding_system) { const unsigned char *src_end = src + src_bytes; @@ -8200,7 +8105,7 @@ detect_coding_system (const unsigned char *src, ptrdiff_t id; struct coding_detection_info detect_info; enum coding_category base_category; - int null_byte_found = 0, eight_bit_found = 0; + bool null_byte_found = 0, eight_bit_found = 0; if (NILP (coding_system)) coding_system = Qundecided; @@ -8556,7 +8461,7 @@ highest priority. */) } -static inline int +static inline bool char_encodable_p (int c, Lisp_Object attrs) { Lisp_Object tail; @@ -8728,7 +8633,7 @@ to the string. */) Lisp_Object positions; ptrdiff_t from, to; const unsigned char *p, *stop, *pend; - int ascii_compatible; + bool ascii_compatible; setup_coding_system (Fcheck_coding_system (coding_system), &coding); attrs = CODING_ID_ATTRS (coding.id); @@ -8952,7 +8857,7 @@ is nil. */) static Lisp_Object code_convert_region (Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object dst_object, - int encodep, int norecord) + bool encodep, bool norecord) { struct coding_system coding; ptrdiff_t from, from_byte, to, to_byte; @@ -9040,7 +8945,8 @@ not fully specified.) */) Lisp_Object code_convert_string (Lisp_Object string, Lisp_Object coding_system, - Lisp_Object dst_object, int encodep, int nocopy, int norecord) + Lisp_Object dst_object, bool encodep, bool nocopy, + bool norecord) { struct coding_system coding; ptrdiff_t chars, bytes; @@ -9088,7 +8994,7 @@ code_convert_string (Lisp_Object string, Lisp_Object coding_system, Lisp_Object code_convert_string_norecord (Lisp_Object string, Lisp_Object coding_system, - int encodep) + bool encodep) { return code_convert_string (string, coding_system, Qt, encodep, 0, 1); } @@ -9489,7 +9395,7 @@ usage: (set-coding-system-priority &rest coding-systems) */) (ptrdiff_t nargs, Lisp_Object *args) { ptrdiff_t i, j; - int changed[coding_category_max]; + bool changed[coding_category_max]; enum coding_category priorities[coding_category_max]; memset (changed, 0, sizeof changed); -- cgit v1.2.1 From a3d794a153425b09a0185c660926c241d13e0f2c Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Tue, 28 Aug 2012 09:49:02 +0400 Subject: Fix usage of set_buffer_internal. * buffer.h (set_buffer_internal): Make it BUFFER_INLINE. * buffer.c (set_buffer_if_live): Use set_buffer_internal. * coding.c (decode_coding): Omit redundant test. * fileio.c (decide_coding_unwind): Likewise. * fns.c (secure_hash): Likewise. * insdel.c (modify_region): Likewise. * keyboard.c (command_loop_1): Likewise. * print.c (PRINTFINISH): Likewise. * xdisp.c (run_window_scroll_functions): Use set_buffer_internal. --- src/coding.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 5bfd42c7272..02e7b34695e 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7006,8 +7006,7 @@ decode_coding (struct coding_system *coding) undo_list = Qt; if (BUFFERP (coding->dst_object)) { - if (current_buffer != XBUFFER (coding->dst_object)) - set_buffer_internal (XBUFFER (coding->dst_object)); + set_buffer_internal (XBUFFER (coding->dst_object)); if (GPT != PT) move_gap_both (PT, PT_BYTE); -- cgit v1.2.1 From 1088b9226e7dac7314dab52ef0696a5f540900cd Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 4 Sep 2012 10:34:54 -0700 Subject: Simplify redefinition of 'abort' (Bug#12316). Do not try to redefine the 'abort' function. Instead, redo the code so that it calls 'emacs_abort' rather than 'abort'. This removes the need for the NO_ABORT configure-time macro and makes it easier to change the abort code to do a backtrace. * configure.ac (NO_ABRT): Remove. * admin/CPP-DEFINES (NO_ABORT): Remove. * nt/inc/ms-w32.h (w32_abort) [HAVE_NTGUI]: Remove. * src/.gdbinit: Just stop at emacs_abort, not at w32_abort or abort. * src/emacs.c (abort) [!DOS_NT && !NO_ABORT]: Remove; sysdep.c's emacs_abort now takes its place. * src/lisp.h (emacs_abort): New decl. All calls from Emacs code to 'abort' changed to use 'emacs_abort'. * src/msdos.c (dos_abort) [defined abort]: Remove; not used. (abort) [!defined abort]: Rename to ... (emacs_abort): ... new name. * src/sysdep.c (emacs_abort) [!HAVE_NTGUI]: New function, taking the place of the old 'abort' in emacs.c. * src/w32.c, src/w32fns.c (abort): Do not #undef. * src/w32.c (emacs_abort): Rename from w32_abort. --- src/coding.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 02e7b34695e..94a2d9fea80 100644 --- a/src/coding.c +++ b/src/coding.c @@ -2051,7 +2051,7 @@ emacs_mule_char (struct coding_system *coding, const unsigned char *src, break; default: - abort (); + emacs_abort (); } CODING_DECODE_CHAR (coding, src, src_base, src_end, CHARSET_FROM_ID (charset_ID), code, c); @@ -2345,7 +2345,7 @@ decode_coding_emacs_mule (struct coding_system *coding) int i; if (charbuf_end - charbuf < cmp_status->length) - abort (); + emacs_abort (); for (i = 0; i < cmp_status->length; i++) *charbuf++ = cmp_status->carryover[i]; coding->annotated = 1; @@ -2619,7 +2619,7 @@ encode_coding_emacs_mule (struct coding_system *coding) preferred_charset_id = -1; break; default: - abort (); + emacs_abort (); } charbuf += -c - 1; continue; @@ -3482,7 +3482,7 @@ decode_coding_iso_2022 (struct coding_system *coding) if (cmp_status->state != COMPOSING_NO) { if (charbuf_end - charbuf < cmp_status->length) - abort (); + emacs_abort (); for (i = 0; i < cmp_status->length; i++) *charbuf++ = cmp_status->carryover[i]; coding->annotated = 1; @@ -3864,7 +3864,7 @@ decode_coding_iso_2022 (struct coding_system *coding) break; default: - abort (); + emacs_abort (); } if (cmp_status->state == COMPOSING_NO @@ -4419,7 +4419,7 @@ encode_coding_iso_2022 (struct coding_system *coding) preferred_charset_id = -1; break; default: - abort (); + emacs_abort (); } charbuf += -c - 1; continue; @@ -4933,7 +4933,7 @@ encode_coding_sjis (struct coding_system *coding) } } if (code == CHARSET_INVALID_CODE (charset)) - abort (); + emacs_abort (); if (charset == charset_kanji) { int c1, c2; @@ -5023,7 +5023,7 @@ encode_coding_big5 (struct coding_system *coding) } } if (code == CHARSET_INVALID_CODE (charset)) - abort (); + emacs_abort (); if (charset == charset_big5) { int c1, c2; @@ -7190,7 +7190,7 @@ handle_composition_annotation (ptrdiff_t pos, ptrdiff_t limit, *buf++ = XINT (XCAR (components)); } else - abort (); + emacs_abort (); *head -= len; } } @@ -9428,7 +9428,7 @@ usage: (set-coding-system-priority &rest coding-systems) */) && changed[coding_priorities[j]]) j++; if (j == coding_category_max) - abort (); + emacs_abort (); priorities[i] = coding_priorities[j]; } -- cgit v1.2.1 From 0328b6de4a92676b4ad4616095ce19a4f51d1c4d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 15 Sep 2012 00:06:56 -0700 Subject: Port better to POSIX hosts lacking _setjmp. * configure.ac (HAVE__SETJMP, HAVE_SIGSETJMP): New symbols. (_setjmp, _longjmp): Remove. * src/lisp.h: Include here, since we use its symbols here. All instances of '#include ' removed, if the only reason for the instance was because "lisp.h" was included. (sys_jmp_buf, sys_setjmp, sys_longjmp): New symbols. Unless otherwise specified, replace all uses of jmp_buf, _setjmp, and _longjmp with the new symbols. Emacs already uses _setjmp if available, so this change affects only POSIXish hosts that have sigsetjmp but not _setjmp, such as some versions of Solaris and Unixware. (Also, POSIX-2008 marks _setjmp as obsolescent.) * src/image.c (_setjmp, _longjmp) [HAVE_PNG && !HAVE__SETJMP]: New macros. (png_load_body) [HAVE_PNG]: (PNG_LONGJMP) [HAVE_PNG && PNG_LIBPNG_VER < 10500]: (PNG_JMPBUF) [HAVE_PNG && PNG_LIBPNG_VER >= 10500]: Use _setjmp and _longjmp rather than sys_setjmp and sys_longjmp, since PNG requires jmp_buf. This is the only exception to the general rule that we now use sys_setjmp and sys_longjmp. This exception is OK since this code does not change the signal mask or longjmp out of a signal handler. Fixes: debbugs:12446 --- src/coding.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 94a2d9fea80..4b3d22f956c 100644 --- a/src/coding.c +++ b/src/coding.c @@ -285,7 +285,6 @@ encode_coding_XXX (struct coding_system *coding) #include #include -#include #include "lisp.h" #include "character.h" -- cgit v1.2.1 From eedec3eec8ea42189032fcde9d5f11a048fa837a Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Tue, 25 Sep 2012 14:44:13 +0200 Subject: Followup to not using maybe_unify_char in processing buffers and strings. src/coding.c (CHAR_STRING_ADVANCE_NO_UNIFY): Make it an alias of CHAR_STRING_ADVANCE. (STRING_CHAR_ADVANCE_NO_UNIFY): Make it an alias of STRING_CHAR_ADVANCE. --- src/coding.c | 63 ++++++++---------------------------------------------------- 1 file changed, 8 insertions(+), 55 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 4b3d22f956c..13f53ad5abc 100644 --- a/src/coding.c +++ b/src/coding.c @@ -920,65 +920,18 @@ record_conversion_result (struct coding_system *coding, /* Store multibyte form of the character C in P, and advance P to the - end of the multibyte form. This is like CHAR_STRING_ADVANCE but it - never calls MAYBE_UNIFY_CHAR. */ - -#define CHAR_STRING_ADVANCE_NO_UNIFY(c, p) \ - do { \ - if ((c) <= MAX_1_BYTE_CHAR) \ - *(p)++ = (c); \ - else if ((c) <= MAX_2_BYTE_CHAR) \ - *(p)++ = (0xC0 | ((c) >> 6)), \ - *(p)++ = (0x80 | ((c) & 0x3F)); \ - else if ((c) <= MAX_3_BYTE_CHAR) \ - *(p)++ = (0xE0 | ((c) >> 12)), \ - *(p)++ = (0x80 | (((c) >> 6) & 0x3F)), \ - *(p)++ = (0x80 | ((c) & 0x3F)); \ - else if ((c) <= MAX_4_BYTE_CHAR) \ - *(p)++ = (0xF0 | (c >> 18)), \ - *(p)++ = (0x80 | ((c >> 12) & 0x3F)), \ - *(p)++ = (0x80 | ((c >> 6) & 0x3F)), \ - *(p)++ = (0x80 | (c & 0x3F)); \ - else if ((c) <= MAX_5_BYTE_CHAR) \ - *(p)++ = 0xF8, \ - *(p)++ = (0x80 | ((c >> 18) & 0x0F)), \ - *(p)++ = (0x80 | ((c >> 12) & 0x3F)), \ - *(p)++ = (0x80 | ((c >> 6) & 0x3F)), \ - *(p)++ = (0x80 | (c & 0x3F)); \ - else \ - (p) += BYTE8_STRING ((c) - 0x3FFF80, p); \ - } while (0) + end of the multibyte form. This used to be like CHAR_STRING_ADVANCE + without ever calling MAYBE_UNIFY_CHAR, but nowadays we don't call + MAYBE_UNIFY_CHAR in CHAR_STRING_ADVANCE. */ +#define CHAR_STRING_ADVANCE_NO_UNIFY(c, p) CHAR_STRING_ADVANCE(c, p) /* Return the character code of character whose multibyte form is at - P, and advance P to the end of the multibyte form. This is like - STRING_CHAR_ADVANCE, but it never calls MAYBE_UNIFY_CHAR. */ - -#define STRING_CHAR_ADVANCE_NO_UNIFY(p) \ - (!((p)[0] & 0x80) \ - ? *(p)++ \ - : ! ((p)[0] & 0x20) \ - ? ((p) += 2, \ - ((((p)[-2] & 0x1F) << 6) \ - | ((p)[-1] & 0x3F) \ - | ((unsigned char) ((p)[-2]) < 0xC2 ? 0x3FFF80 : 0))) \ - : ! ((p)[0] & 0x10) \ - ? ((p) += 3, \ - ((((p)[-3] & 0x0F) << 12) \ - | (((p)[-2] & 0x3F) << 6) \ - | ((p)[-1] & 0x3F))) \ - : ! ((p)[0] & 0x08) \ - ? ((p) += 4, \ - ((((p)[-4] & 0xF) << 18) \ - | (((p)[-3] & 0x3F) << 12) \ - | (((p)[-2] & 0x3F) << 6) \ - | ((p)[-1] & 0x3F))) \ - : ((p) += 5, \ - ((((p)[-4] & 0x3F) << 18) \ - | (((p)[-3] & 0x3F) << 12) \ - | (((p)[-2] & 0x3F) << 6) \ - | ((p)[-1] & 0x3F)))) + P, and advance P to the end of the multibyte form. This used to be + like STRING_CHAR_ADVANCE without ever calling MAYBE_UNIFY_CHAR, but + nowadays STRING_CHAR_ADVANCE doesn't call MAYBE_UNIFY_CHAR. */ +#define STRING_CHAR_ADVANCE_NO_UNIFY(p) STRING_CHAR_ADVANCE(p) /* Set coding->source from coding->src_object. */ -- cgit v1.2.1 From 95402d5faa114a311cabfb8c64cf22a93787a066 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Sun, 30 Sep 2012 22:25:11 +0900 Subject: coding.c (decode_coding_ccl, encode_coding_ccl): Pay attention to the buffer relocation which may be caused by ccl_driver. --- src/coding.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 4b3d22f956c..40e67b9a6c8 100644 --- a/src/coding.c +++ b/src/coding.c @@ -5106,6 +5106,7 @@ decode_coding_ccl (struct coding_system *coding) while (1) { const unsigned char *p = src; + ptrdiff_t offset; int i = 0; if (multibytep) @@ -5123,8 +5124,17 @@ decode_coding_ccl (struct coding_system *coding) if (p == src_end && coding->mode & CODING_MODE_LAST_BLOCK) ccl->last_block = 1; + /* As ccl_driver calls DECODE_CHAR, buffer may be relocated. */ + charset_map_loaded = 0; ccl_driver (ccl, source_charbuf, charbuf, i, charbuf_end - charbuf, charset_list); + if (charset_map_loaded + && (offset = coding_change_source (coding))) + { + p += offset; + src += offset; + src_end += offset; + } charbuf += ccl->produced; if (multibytep) src += source_byteidx[ccl->consumed]; @@ -5177,8 +5187,15 @@ encode_coding_ccl (struct coding_system *coding) do { + ptrdiff_t offset; + + /* As ccl_driver calls DECODE_CHAR, buffer may be relocated. */ + charset_map_loaded = 0; ccl_driver (ccl, charbuf, destination_charbuf, charbuf_end - charbuf, 1024, charset_list); + if (charset_map_loaded + && (offset = coding_change_destination (coding))) + dst += offset; if (multibytep) { ASSURE_DESTINATION (ccl->produced * 2); -- cgit v1.2.1 From b0ab8123df78b7149d1f55b2ef0d3095c3f10628 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 30 Sep 2012 23:36:54 -0700 Subject: Prefer plain 'static' to 'static inline'. With static functions, modern compilers inline pretty well by themselves; advice from programmers often hurts as much as it helps. On my host (x86-64, Fedora 17, GCC 4.7.2, default 'configure'), this change shrinks the text size of the Emacs executable by 1.1% without affecting CPU significantly in my benchmark. * alloc.c (mem_find, live_string_p, live_cons_p, live_symbol_p) (live_float_p, live_misc_p, live_vector_p, live_buffer_p) (mark_maybe_object, mark_maybe_pointer, bounded_number): * buffer.c (bset_abbrev_mode, bset_abbrev_table) (bset_auto_fill_function, bset_auto_save_file_format) (bset_auto_save_file_name, bset_backed_up, bset_begv_marker) (bset_bidi_display_reordering, bset_buffer_file_coding_system) (bset_cache_long_line_scans, bset_case_fold_search) (bset_ctl_arrow, bset_cursor_in_non_selected_windows) (bset_cursor_type, bset_display_table, bset_extra_line_spacing) (bset_file_format, bset_file_truename, bset_fringe_cursor_alist) (bset_fringe_indicator_alist, bset_fringes_outside_margins) (bset_header_line_format, bset_indicate_buffer_boundaries) (bset_indicate_empty_lines, bset_invisibility_spec) (bset_left_fringe_width, bset_major_mode, bset_mark) (bset_minor_modes, bset_mode_line_format, bset_mode_name) (bset_name, bset_overwrite_mode, bset_pt_marker) (bset_right_fringe_width, bset_save_length) (bset_scroll_bar_width, bset_scroll_down_aggressively) (bset_scroll_up_aggressively, bset_selective_display) (bset_selective_display_ellipses, bset_vertical_scroll_bar_type) (bset_word_wrap, bset_zv_marker, set_buffer_overlays_before) (set_buffer_overlays_after): * category.c (bset_category_table): * charset.c (read_hex): * coding.c (produce_composition, produce_charset) (handle_composition_annotation, handle_charset_annotation) (char_encodable_p): * dispnew.c (swap_glyph_pointers, copy_row_except_pointers) (assign_row, set_frame_matrix_frame, make_current) (add_row_entry): * eval.c (set_specpdl_symbol, set_specpdl_old_value): * fns.c (maybe_resize_hash_table): * frame.c (fset_buffer_predicate, fset_minibuffer_window): * gmalloc.c (register_heapinfo): * image.c (lookup_image_type): * intervals.c (set_interval_object, set_interval_left) (set_interval_right, copy_interval_parent, rotate_right) (rotate_left, balance_possible_root_interval): * keyboard.c (kset_echo_string, kset_kbd_queue) (kset_keyboard_translate_table, kset_last_prefix_arg) (kset_last_repeatable_command, kset_local_function_key_map) (kset_overriding_terminal_local_map, kset_real_last_command) (kset_system_key_syms, clear_event, set_prop): * lread.c (digit_to_number): * marker.c (attach_marker, live_buffer, set_marker_internal): * nsterm.m (ns_compute_glyph_string_overhangs): * process.c (pset_buffer, pset_command) (pset_decode_coding_system, pset_decoding_buf) (pset_encode_coding_system, pset_encoding_buf, pset_filter) (pset_log, pset_mark, pset_name, pset_plist, pset_sentinel) (pset_status, pset_tty_name, pset_type, pset_write_queue): * syntax.c (bset_syntax_table, dec_bytepos): * terminal.c (tset_param_alist): * textprop.c (interval_has_some_properties) (interval_has_some_properties_list): * window.c (wset_combination_limit, wset_dedicated) (wset_display_table, wset_hchild, wset_left_fringe_width) (wset_left_margin_cols, wset_new_normal, wset_new_total) (wset_normal_cols, wset_normal_lines, wset_parent, wset_pointm) (wset_right_fringe_width, wset_right_margin_cols) (wset_scroll_bar_width, wset_start, wset_temslot, wset_vchild) (wset_vertical_scroll_bar_type, wset_window_parameters): * xdisp.c (wset_base_line_number, wset_base_line_pos) (wset_column_number_displayed, wset_region_showing) (window_box_edges, run_window_scroll_functions) (append_glyph_string_lists, prepend_glyph_string_lists) (append_glyph_string, set_glyph_string_background_width) (append_glyph, append_composite_glyph) (take_vertical_position_into_account): * xfaces.c (x_create_gc, x_free_gc, merge_face_vectors) (face_attr_equal_p, lface_equal_p, hash_string_case_insensitive) (lface_hash, lface_same_font_attributes_p, lookup_face): * xml.c (libxml2_loaded_p): * xterm.c (x_set_mode_line_face_gc, x_set_glyph_string_gc) (x_set_glyph_string_clipping, x_clear_glyph_string_rect): Now 'static', not 'static inline'. Fixes: debbugs:12541 --- src/coding.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 32d300b9923..d9606cf5710 100644 --- a/src/coding.c +++ b/src/coding.c @@ -6822,7 +6822,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table, [ -LENGTH ANNOTATION_MASK NCHARS NBYTES METHOD [ COMPONENTS... ] ] */ -static inline void +static void produce_composition (struct coding_system *coding, int *charbuf, ptrdiff_t pos) { int len; @@ -6866,7 +6866,7 @@ produce_composition (struct coding_system *coding, int *charbuf, ptrdiff_t pos) [ -LENGTH ANNOTATION_MASK NCHARS CHARSET-ID ] */ -static inline void +static void produce_charset (struct coding_system *coding, int *charbuf, ptrdiff_t pos) { ptrdiff_t from = pos - charbuf[2]; @@ -7101,7 +7101,7 @@ decode_coding (struct coding_system *coding) position of a composition after POS (if any) or to LIMIT, and return BUF. */ -static inline int * +static int * handle_composition_annotation (ptrdiff_t pos, ptrdiff_t limit, struct coding_system *coding, int *buf, ptrdiff_t *stop) @@ -7184,7 +7184,7 @@ handle_composition_annotation (ptrdiff_t pos, ptrdiff_t limit, If the property value is nil, set *STOP to the position where the property value is non-nil (limiting by LIMIT), and return BUF. */ -static inline int * +static int * handle_charset_annotation (ptrdiff_t pos, ptrdiff_t limit, struct coding_system *coding, int *buf, ptrdiff_t *stop) @@ -8429,7 +8429,7 @@ highest priority. */) } -static inline bool +static bool char_encodable_p (int c, Lisp_Object attrs) { Lisp_Object tail; -- cgit v1.2.1 From 0ba06a77fd4ccf92f1106b8ab7d8d64d6d812a1d Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Sat, 13 Oct 2012 21:58:52 +0900 Subject: coding.c (detect_coding): Set coding->id before calling this->detector. --- src/coding.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index d9606cf5710..412d7245223 100644 --- a/src/coding.c +++ b/src/coding.c @@ -6301,6 +6301,9 @@ detect_coding (struct coding_system *coding) { category = coding_priorities[i]; this = coding_categories + category; + /* Some of this->detector (e.g. detect_coding_sjis) + require this information. */ + coding->id = this->id; if (this->id < 0) { /* No coding system of this category is defined. */ -- cgit v1.2.1 From a0d7415fb62cf17e1465ee19cffb3ae6e20390b3 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Fri, 19 Oct 2012 21:59:42 +0900 Subject: font.c (Ffont_at): Fix previous change. --- 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 412d7245223..7628a9fbf2e 100644 --- a/src/coding.c +++ b/src/coding.c @@ -415,7 +415,7 @@ enum iso_code_class_type ISO_shift_out, /* ISO_CODE_SO (0x0E) */ ISO_shift_in, /* ISO_CODE_SI (0x0F) */ ISO_single_shift_2_7, /* ISO_CODE_SS2_7 (0x19) */ - ISO_escape, /* ISO_CODE_SO (0x1B) */ + ISO_escape, /* ISO_CODE_ESC (0x1B) */ ISO_control_1, /* Control codes in the range 0x80..0x9F, except for the following 3 codes. */ -- cgit v1.2.1 From ba11600816880f862a7a85899bfa3dc41c176273 Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Mon, 29 Oct 2012 09:24:29 -0800 Subject: 2012-10-29 Daniel Colascione cygw32.h, cygw32.c (Qutf_16le, from_unicode, to_unicode): In preparation for fixing bug#12739, move these functions from here... * coding.h, coding.c: ... to here, and compile them only when WINDOWSNT or HAVE_NTGUI. Moving these functions out of cygw32 proper lets us write cygw32-agnostic code for the HAVE_NTGUI case. --- src/coding.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 7628a9fbf2e..611f92ea152 100644 --- a/src/coding.c +++ b/src/coding.c @@ -343,6 +343,10 @@ Lisp_Object Qcoding_system_p, Qcoding_system_error; Lisp_Object Qemacs_mule, Qraw_text; Lisp_Object Qutf_8_emacs; +#if defined (WINDOWSNT) || defined (HAVE_NTGUI) +static Lisp_Object Qutf_16le; +#endif + /* Coding-systems are handed between Emacs Lisp programs and C internal routines by the following three variables. */ /* Coding system to be used to encode text for terminal display when @@ -7971,6 +7975,39 @@ preferred_coding_system (void) return CODING_ID_NAME (id); } +#if defined (WINDOWSNT) || defined (HAVE_NTGUI) + +Lisp_Object +from_unicode (Lisp_Object str) +{ + CHECK_STRING (str); + if (!STRING_MULTIBYTE (str) && + SBYTES (str) & 1) + { + str = Fsubstring (str, make_number (0), make_number (-1)); + } + + return code_convert_string_norecord (str, Qutf_16le, 0); +} + +wchar_t * +to_unicode (Lisp_Object str, Lisp_Object *buf) +{ + *buf = code_convert_string_norecord (str, Qutf_16le, 1); + /* We need to make a another copy (in addition to the one made by + code_convert_string_norecord) to ensure that the final string is + _doubly_ zero terminated --- that is, that the string is + terminated by two zero bytes and one utf-16le null character. + Because strings are already terminated with a single zero byte, + we just add one additional zero. */ + str = make_uninit_string (SBYTES (*buf) + 1); + memcpy (SDATA (str), SDATA (*buf), SBYTES (*buf)); + SDATA (str) [SBYTES (*buf)] = '\0'; + *buf = str; + return WCSDATA (*buf); +} +#endif /* WINDOWSNT || HAVE_NTGUI */ + #ifdef emacs /*** 8. Emacs Lisp library functions ***/ @@ -10284,6 +10321,11 @@ syms_of_coding (void) DEFSYM (Qutf_8, "utf-8"); DEFSYM (Qutf_8_emacs, "utf-8-emacs"); +#if defined (WINDOWSNT) || defined (HAVE_NTGUI) + /* No, not utf-16-le: that one has a BOM. */ + DEFSYM (Qutf_16le, "utf-16le"); +#endif + DEFSYM (Qutf_16, "utf-16"); DEFSYM (Qbig, "big"); DEFSYM (Qlittle, "little"); -- cgit v1.2.1 From 7f590b0c3b25602499432bf986e7b593fc158c0b Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Mon, 29 Oct 2012 17:56:38 -0800 Subject: Fix build break in non-Cygw32 Cygwin builds introduced in 2012-10-29T17:24:29Z!dancol@dancol.org. --- src/coding.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 611f92ea152..97268e0dcd8 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7975,7 +7975,7 @@ preferred_coding_system (void) return CODING_ID_NAME (id); } -#if defined (WINDOWSNT) || defined (HAVE_NTGUI) +#if defined (WINDOWSNT) || defined (CYGWIN) Lisp_Object from_unicode (Lisp_Object str) @@ -8006,7 +8006,8 @@ to_unicode (Lisp_Object str, Lisp_Object *buf) *buf = str; return WCSDATA (*buf); } -#endif /* WINDOWSNT || HAVE_NTGUI */ + +#endif /* WINDOWSNT || CYGWIN */ #ifdef emacs @@ -10321,7 +10322,7 @@ syms_of_coding (void) DEFSYM (Qutf_8, "utf-8"); DEFSYM (Qutf_8_emacs, "utf-8-emacs"); -#if defined (WINDOWSNT) || defined (HAVE_NTGUI) +#if defined (WINDOWSNT) || defined (CYGWIN) /* No, not utf-16-le: that one has a BOM. */ DEFSYM (Qutf_16le, "utf-16le"); #endif -- cgit v1.2.1 From 53372c278e7e79b97aed97b159a00bde45de3a80 Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Mon, 29 Oct 2012 19:10:52 -0800 Subject: Complete fix for build break --- 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 97268e0dcd8..56202e4861d 100644 --- a/src/coding.c +++ b/src/coding.c @@ -343,7 +343,7 @@ Lisp_Object Qcoding_system_p, Qcoding_system_error; Lisp_Object Qemacs_mule, Qraw_text; Lisp_Object Qutf_8_emacs; -#if defined (WINDOWSNT) || defined (HAVE_NTGUI) +#if defined (WINDOWSNT) || defined (CYGWIN) static Lisp_Object Qutf_16le; #endif -- cgit v1.2.1 From a2f07cd28277fbcef42541509e3710a9863cac3a Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Wed, 19 Dec 2012 19:52:48 +0400 Subject: * coding.c (Fdetect_coding_region): Do not check start and end with CHECK_NUMBER_COERCE_MARKER since validate_region does that itself. (code_convert_region): Likewise. --- src/coding.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 56202e4861d..e42461f52a0 100644 --- a/src/coding.c +++ b/src/coding.c @@ -8426,9 +8426,6 @@ highest priority. */) ptrdiff_t from, to; ptrdiff_t from_byte, to_byte; - CHECK_NUMBER_COERCE_MARKER (start); - CHECK_NUMBER_COERCE_MARKER (end); - validate_region (&start, &end); from = XINT (start), to = XINT (end); from_byte = CHAR_TO_BYTE (from); @@ -8872,8 +8869,6 @@ code_convert_region (Lisp_Object start, Lisp_Object end, ptrdiff_t from, from_byte, to, to_byte; Lisp_Object src_object; - CHECK_NUMBER_COERCE_MARKER (start); - CHECK_NUMBER_COERCE_MARKER (end); if (NILP (coding_system)) coding_system = Qno_conversion; else -- cgit v1.2.1 From 4b298d5a3e0d5fb75f66c48598e80122669cef8b Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Wed, 26 Dec 2012 13:40:45 +0400 Subject: * keyboard.c (record_asynch_buffer_change): Initialize an event only if it's really needed. * frame.h (enum output_method): Remove output_mac member since it's a leftover from the deleted code. * frame.c (Fframep): Adjust user here ... * terminal.c (Fterminal_live_p): ... and here. * coding.c (Qmac): Now here because it's only used to denote end-of-line encoding type. (syms_of_coding): DEFSYM it. * frame.h (Qmac): Remove duplicated declaration. --- src/coding.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index e42461f52a0..2c1139ec5fc 100644 --- a/src/coding.c +++ b/src/coding.c @@ -301,7 +301,7 @@ Lisp_Object Vcoding_system_hash_table; static Lisp_Object Qcoding_system, Qeol_type; static Lisp_Object Qcoding_aliases; -Lisp_Object Qunix, Qdos; +Lisp_Object Qunix, Qdos, Qmac; Lisp_Object Qbuffer_file_coding_system; static Lisp_Object Qpost_read_conversion, Qpre_write_conversion; static Lisp_Object Qdefault_char; @@ -10303,6 +10303,7 @@ syms_of_coding (void) DEFSYM (Qeol_type, "eol-type"); DEFSYM (Qunix, "unix"); DEFSYM (Qdos, "dos"); + DEFSYM (Qmac, "mac"); DEFSYM (Qbuffer_file_coding_system, "buffer-file-coding-system"); DEFSYM (Qpost_read_conversion, "post-read-conversion"); -- cgit v1.2.1 From 84cc1ab62539eed7869a88003a017330d79e8cac Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 30 Dec 2012 13:34:39 -0800 Subject: * coding.c (Qmac): Now static. --- src/coding.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 2c1139ec5fc..044583d26b6 100644 --- a/src/coding.c +++ b/src/coding.c @@ -301,7 +301,8 @@ Lisp_Object Vcoding_system_hash_table; static Lisp_Object Qcoding_system, Qeol_type; static Lisp_Object Qcoding_aliases; -Lisp_Object Qunix, Qdos, Qmac; +Lisp_Object Qunix, Qdos; +static Lisp_Object Qmac; Lisp_Object Qbuffer_file_coding_system; static Lisp_Object Qpost_read_conversion, Qpre_write_conversion; static Lisp_Object Qdefault_char; -- cgit v1.2.1 From ab422c4d6899b1442cb6954c1829c1fb656b006c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 1 Jan 2013 09:11:05 +0000 Subject: Update copyright notices for 2013. --- 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 56202e4861d..47d5e138e1c 100644 --- a/src/coding.c +++ b/src/coding.c @@ -1,5 +1,5 @@ /* Coding system handler (conversion, detection, etc). - Copyright (C) 2001-2012 Free Software Foundation, Inc. + Copyright (C) 2001-2013 Free Software Foundation, Inc. Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 National Institute of Advanced Industrial Science and Technology (AIST) -- cgit v1.2.1 From eefd727851555237c7bc205b7ad255c50ba3fff9 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Wed, 9 Jan 2013 17:50:22 +0400 Subject: * lisp.h (make_gap_1): New prototype. * buffer.h (GAP_BYTES_DFL, GAP_BYTES_MIN): New macros for the special gap size values. * editfns.c (Fbuffer_size): Rename from Fbufsize to fit the common naming convention. (syms_of_editfns): Adjust defsubr. Drop commented-out obsolete code. * insdel.c (make_gap_larger): Use GAP_BYTES_DFL. (make_gap_smaller): Use GAP_BYTES_MIN. Adjust comment. (make_gap_1): New function to adjust the gap of any buffer. * coding.c (coding_alloc_by_making_gap): Use it. * buffer.c (compact_buffer): Likewise. Use BUF_Z_BYTE, BUF_GAP_SIZE, GAP_BYTES_DFL and GAP_BYTES_MIN. Adjust comment. --- src/coding.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 5285a906823..a9bf9032a69 100644 --- a/src/coding.c +++ b/src/coding.c @@ -1049,14 +1049,7 @@ coding_alloc_by_making_gap (struct coding_system *coding, GPT -= gap_head_used, GPT_BYTE -= gap_head_used; } else - { - Lisp_Object this_buffer; - - this_buffer = Fcurrent_buffer (); - set_buffer_internal (XBUFFER (coding->dst_object)); - make_gap (bytes); - set_buffer_internal (XBUFFER (this_buffer)); - } + make_gap_1 (XBUFFER (coding->dst_object), bytes); } -- cgit v1.2.1 From ba14c607ba7fdadb494b57a9788997059ba510bf Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Sun, 20 Jan 2013 23:59:47 +0100 Subject: Fixes: debbugs:13505 * src/coding.c (detect_coding_iso_2022): Move back mis-reordered code at check_extra_latin label. --- src/coding.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 47d5e138e1c..20d5d92f046 100644 --- a/src/coding.c +++ b/src/coding.c @@ -3063,20 +3063,7 @@ detect_coding_iso_2022 (struct coding_system *coding, } if (single_shifting) break; - check_extra_latin: - if (! VECTORP (Vlatin_extra_code_table) - || NILP (AREF (Vlatin_extra_code_table, c))) - { - rejected = CATEGORY_MASK_ISO; - break; - } - if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1]) - & CODING_ISO_FLAG_LATIN_EXTRA) - found |= CATEGORY_MASK_ISO_8_1; - else - rejected |= CATEGORY_MASK_ISO_8_1; - rejected |= CATEGORY_MASK_ISO_8_2; - break; + goto check_extra_latin; default: if (c < 0) @@ -3127,6 +3114,20 @@ detect_coding_iso_2022 (struct coding_system *coding, } break; } + check_extra_latin: + if (! VECTORP (Vlatin_extra_code_table) + || NILP (AREF (Vlatin_extra_code_table, c))) + { + rejected = CATEGORY_MASK_ISO; + break; + } + if (CODING_ISO_FLAGS (&coding_categories[coding_category_iso_8_1]) + & CODING_ISO_FLAG_LATIN_EXTRA) + found |= CATEGORY_MASK_ISO_8_1; + else + rejected |= CATEGORY_MASK_ISO_8_1; + rejected |= CATEGORY_MASK_ISO_8_2; + break; } } detect_info->rejected |= CATEGORY_MASK_ISO; -- cgit v1.2.1 From 9a9d91d9c247adefa7137338d7609d81734f888d Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Thu, 7 Feb 2013 20:09:04 +0400 Subject: * coding.c (Fdefine_coding_system_internal): Use AREF where argument is known to be a vector. * fns.c (Flocale_info): Likewise for ASET. * xselect.c (selection_data_to_lisp_data): Likewise for ASET. * w32fns.c (w32_parse_hot_key): Likewise for ASIZE and AREF. --- 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 93da9db0d36..c7bfe25e0cc 100644 --- a/src/coding.c +++ b/src/coding.c @@ -9783,7 +9783,7 @@ usage: (define-coding-system-internal ...) */) CHECK_VECTOR (initial); for (i = 0; i < 4; i++) { - val = Faref (initial, make_number (i)); + val = AREF (initial, i); if (! NILP (val)) { struct charset *charset; -- cgit v1.2.1 From 25721f5bb5681c22f666a0b4e61d94687d92a671 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Fri, 8 Feb 2013 09:28:52 +0400 Subject: * lisp.h (make_uninit_vector): New function. * alloc.c (Fvector, Fmake_byte_code): * ccl.c (Fregister_ccl_program): * charset.c (Fdefine_charset_internal, define_charset_internal): * coding.c (make_subsidiaries, Fdefine_coding_system_internal): * composite.c (syms_of_composite): * font.c (Fquery_font, Ffont_info, syms_of_font): * fontset.c (FONT_DEF_NEW, Fset_fontset_font): * ftfont.c (ftfont_shape_by_flt): * indent.c (recompute_width_table): * nsselect.m (clean_local_selection_data): * syntax.c (init_syntax_once): * w32unsubscribe.c (uniscribe_shape): * window.c (Fcurrent_window_configuration): * xfaces.c (Fx_family_fonts): * xselect.c (selection_data_to_lisp_data): Use it. --- src/coding.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index c7bfe25e0cc..b881f162ab9 100644 --- a/src/coding.c +++ b/src/coding.c @@ -9483,7 +9483,7 @@ make_subsidiaries (Lisp_Object base) int i; memcpy (buf, SDATA (SYMBOL_NAME (base)), base_name_len); - subsidiaries = Fmake_vector (make_number (3), Qnil); + subsidiaries = make_uninit_vector (3); for (i = 0; i < 3; i++) { strcpy (buf + base_name_len, suffixes[i]); @@ -9988,7 +9988,8 @@ usage: (define-coding-system-internal ...) */) this_name = AREF (eol_type, i); this_aliases = Fcons (this_name, Qnil); this_eol_type = (i == 0 ? Qunix : i == 1 ? Qdos : Qmac); - this_spec = Fmake_vector (make_number (3), attrs); + this_spec = make_uninit_vector (3); + ASET (this_spec, 0, attrs); ASET (this_spec, 1, this_aliases); ASET (this_spec, 2, this_eol_type); Fputhash (this_name, this_spec, Vcoding_system_hash_table); @@ -10001,7 +10002,8 @@ usage: (define-coding-system-internal ...) */) } } - spec_vec = Fmake_vector (make_number (3), attrs); + spec_vec = make_uninit_vector (3); + ASET (spec_vec, 0, attrs); ASET (spec_vec, 1, aliases); ASET (spec_vec, 2, eol_type); -- cgit v1.2.1 From 65e7ca35a69003788134f8c961f561fe6f7a9720 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 12 Feb 2013 09:36:54 -0800 Subject: In doc, use standard American English style for e.g., etc., i.e. --- 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 20d5d92f046..346a8573b70 100644 --- a/src/coding.c +++ b/src/coding.c @@ -10720,7 +10720,7 @@ reading if you suppress escape sequence detection. The other way to read escape sequences in a file without decoding is to explicitly specify some coding system that doesn't use ISO-2022 -escape sequence (e.g `latin-1') on reading by \\[universal-coding-system-argument]. */); +escape sequence (e.g., `latin-1') on reading by \\[universal-coding-system-argument]. */); inhibit_iso_escape_detection = 0; DEFVAR_BOOL ("inhibit-null-byte-detection", -- cgit v1.2.1 From 1af1a51aada18d88fac7b2ba09231428c6a65d7c Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Wed, 6 Mar 2013 15:26:30 +0400 Subject: Coding system support cleanup and minor refactoring. * coding.h (enum coding_result_code): Remove CODING_RESULT_INCONSISTENT_EOL and CODING_RESULT_INSUFFICIENT_MEM. (toplevel): Remove unused CODING_MODE_INHIBIT_INCONSISTENT_EOL. (CODING_MODE_LAST_BLOCK, CODING_MODE_SELECTIVE_DISPLAY) (CODING_MODE_DIRECTION, CODING_MODE_FIXED_DESTINATION) (CODING_MODE_SAFE_ENCODING): Rearrange bit values. (decode_coding_region, encode_coding_region, decode_coding_string): Remove unused compatibility macros. * coding.c (Qinconsistent_eol, Qinsufficient_memory): Remove. (record_conversion_result): Adjust user. (syms_of_coding): Likewise. (ALLOC_CONVERSION_WORK_AREA): Use SAFE_ALLOCA. (decode_coding, encode_coding): Add USE_SAFE_ALLOCA and SAFE_FREE. (decode_coding_object): Simplify since xrealloc never returns NULL. Add eassert. --- src/coding.c | 45 ++++++++++++--------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 868fb7df0ea..32da72ab626 100644 --- a/src/coding.c +++ b/src/coding.c @@ -322,8 +322,7 @@ Lisp_Object Qcall_process, Qcall_process_region; Lisp_Object Qstart_process, Qopen_network_stream; static Lisp_Object Qtarget_idx; -static Lisp_Object Qinsufficient_source, Qinconsistent_eol, Qinvalid_source; -static Lisp_Object Qinterrupted, Qinsufficient_memory; +static Lisp_Object Qinsufficient_source, Qinvalid_source, Qinterrupted; /* If a symbol has this property, evaluate the value to define the symbol as a coding system. */ @@ -820,18 +819,12 @@ record_conversion_result (struct coding_system *coding, case CODING_RESULT_INSUFFICIENT_SRC: Vlast_code_conversion_error = Qinsufficient_source; break; - case CODING_RESULT_INCONSISTENT_EOL: - Vlast_code_conversion_error = Qinconsistent_eol; - break; case CODING_RESULT_INVALID_SRC: Vlast_code_conversion_error = Qinvalid_source; break; case CODING_RESULT_INTERRUPT: Vlast_code_conversion_error = Qinterrupted; break; - case CODING_RESULT_INSUFFICIENT_MEM: - Vlast_code_conversion_error = Qinsufficient_memory; - break; case CODING_RESULT_INSUFFICIENT_DST: /* Don't record this error in Vlast_code_conversion_error because it happens just temporarily and is resolved when the @@ -6884,22 +6877,8 @@ produce_charset (struct coding_system *coding, int *charbuf, ptrdiff_t pos) #define ALLOC_CONVERSION_WORK_AREA(coding) \ do { \ - int size = CHARBUF_SIZE; \ - \ - coding->charbuf = NULL; \ - while (size > 1024) \ - { \ - coding->charbuf = alloca (sizeof (int) * size); \ - if (coding->charbuf) \ - break; \ - size >>= 1; \ - } \ - if (! coding->charbuf) \ - { \ - record_conversion_result (coding, CODING_RESULT_INSUFFICIENT_MEM); \ - return; \ - } \ - coding->charbuf_size = size; \ + coding->charbuf = SAFE_ALLOCA (CHARBUF_SIZE * sizeof (int)); \ + coding->charbuf_size = CHARBUF_SIZE; \ } while (0) @@ -6968,6 +6947,8 @@ decode_coding (struct coding_system *coding) int carryover; int i; + USE_SAFE_ALLOCA; + if (BUFFERP (coding->src_object) && coding->src_pos > 0 && coding->src_pos < GPT @@ -7090,6 +7071,8 @@ decode_coding (struct coding_system *coding) bset_undo_list (current_buffer, undo_list); record_insert (coding->dst_pos, coding->produced_char); } + + SAFE_FREE (); } @@ -7373,6 +7356,8 @@ encode_coding (struct coding_system *coding) int max_lookup; struct ccl_spec cclspec; + USE_SAFE_ALLOCA; + attrs = CODING_ID_ATTRS (coding->id); if (coding->encoder == encode_coding_raw_text) translation_table = Qnil, max_lookup = 0; @@ -7407,6 +7392,8 @@ encode_coding (struct coding_system *coding) if (BUFFERP (coding->dst_object) && coding->produced_char > 0) insert_from_gap (coding->produced_char, coding->produced); + + SAFE_FREE (); } @@ -7695,14 +7682,8 @@ decode_coding_object (struct coding_system *coding, set_buffer_internal (XBUFFER (coding->dst_object)); if (dst_bytes < coding->produced) { + eassert (coding->produced > 0); destination = xrealloc (destination, coding->produced); - if (! destination) - { - record_conversion_result (coding, - CODING_RESULT_INSUFFICIENT_MEM); - unbind_to (count, Qnil); - return; - } if (BEGV < GPT && GPT < BEGV + coding->produced_char) move_gap_both (BEGV, BEGV_BYTE); memcpy (destination, BEGV_ADDR, coding->produced); @@ -10408,10 +10389,8 @@ syms_of_coding (void) intern_c_string ("coding-category-undecided")); DEFSYM (Qinsufficient_source, "insufficient-source"); - DEFSYM (Qinconsistent_eol, "inconsistent-eol"); DEFSYM (Qinvalid_source, "invalid-source"); DEFSYM (Qinterrupted, "interrupted"); - DEFSYM (Qinsufficient_memory, "insufficient-memory"); DEFSYM (Qcoding_system_define_form, "coding-system-define-form"); defsubr (&Scoding_system_p); -- cgit v1.2.1 From bc989a58e2412c152c2aef9d35ca103979edebd5 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 9 Mar 2013 20:09:33 +0200 Subject: coding.c (to_unicode): Fix a typo in a 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 32da72ab626..78e6cff7078 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7970,7 +7970,7 @@ wchar_t * to_unicode (Lisp_Object str, Lisp_Object *buf) { *buf = code_convert_string_norecord (str, Qutf_16le, 1); - /* We need to make a another copy (in addition to the one made by + /* We need to make another copy (in addition to the one made by code_convert_string_norecord) to ensure that the final string is _doubly_ zero terminated --- that is, that the string is terminated by two zero bytes and one utf-16le null character. -- cgit v1.2.1 From c230dd7d89730f565df77046d0666d2082e386ee Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Sun, 10 Mar 2013 23:36:35 +0900 Subject: On file insertion, skip decoding if all bytes are ASCII. --- src/coding.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 32da72ab626..f33b5e7c7d5 100644 --- a/src/coding.c +++ b/src/coding.c @@ -6349,7 +6349,12 @@ detect_coding (struct coding_system *coding) coding_systems = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom); detect_info.found = detect_info.rejected = 0; - coding->head_ascii = 0; + for (src = coding->source; src < src_end; src++) + { + if (*src & 0x80) + break; + } + coding->head_ascii = src - coding->source; if (CONSP (coding_systems) && detect_coding_utf_8 (coding, &detect_info)) { @@ -7487,8 +7492,6 @@ decode_coding_gap (struct coding_system *coding, ptrdiff_t count = SPECPDL_INDEX (); Lisp_Object attrs; - code_conversion_save (0, 0); - coding->src_object = Fcurrent_buffer (); coding->src_chars = chars; coding->src_bytes = bytes; @@ -7502,13 +7505,45 @@ decode_coding_gap (struct coding_system *coding, if (CODING_REQUIRE_DETECTION (coding)) detect_coding (coding); + attrs = CODING_ID_ATTRS (coding->id); +#ifndef CODING_DISABLE_ASCII_OPTIMIZATION + if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs)) + && NILP (CODING_ATTR_POST_READ (attrs)) + && NILP (get_translation_table (attrs, 0, NULL))) + { + /* We can skip the conversion if all source bytes are ASCII. */ + if (coding->head_ascii < 0) + { + /* We have not yet counted the number of ASCII bytes at the + head of the source. Do it now. */ + const unsigned char *src, *src_end; + + coding_set_source (coding); + src_end = coding->source + coding->src_bytes; + for (src = coding->source; src < src_end; src++) + { + if (*src & 0x80) + break; + } + coding->head_ascii = src - coding->source; + } + if (coding->src_bytes == coding->head_ascii) + { + /* No need of conversion. Use the data in the gap as is. */ + coding->produced_char = chars; + coding->produced = bytes; + adjust_after_replace (PT, PT_BYTE, Qnil, chars, bytes, 1); + return; + } + } +#endif /* not CODING_DISABLE_ASCII_OPTIMIZATION */ + code_conversion_save (0, 0); coding->mode |= CODING_MODE_LAST_BLOCK; current_buffer->text->inhibit_shrinking = 1; decode_coding (coding); current_buffer->text->inhibit_shrinking = 0; - attrs = CODING_ID_ATTRS (coding->id); if (! NILP (CODING_ATTR_POST_READ (attrs))) { ptrdiff_t prev_Z = Z, prev_Z_BYTE = Z_BYTE; -- cgit v1.2.1 From 7d051e215477753b813864caa23c1009c7692bda Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Mon, 11 Mar 2013 00:06:04 +0900 Subject: Fix previous change. --- src/coding.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 98af4ddcef7..d6560a92b70 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7509,7 +7509,9 @@ decode_coding_gap (struct coding_system *coding, #ifndef CODING_DISABLE_ASCII_OPTIMIZATION if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs)) && NILP (CODING_ATTR_POST_READ (attrs)) - && NILP (get_translation_table (attrs, 0, NULL))) + && NILP (get_translation_table (attrs, 0, NULL)) + && (inhibit_eol_conversion + || EQ (CODING_ID_EOL_TYPE (coding->id), Qunix))) { /* We can skip the conversion if all source bytes are ASCII. */ if (coding->head_ascii < 0) -- cgit v1.2.1 From 819e2da92a18d7af03ccd9cf0a2e5b940eb7b54f Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Sun, 10 Mar 2013 14:55:25 -0800 Subject: 2013-03-10 Daniel Colascione * w32term.h (GUISTR, GUI_ENCODE_FILE, GUI_ENCODE_SYSTEM, GUI_FN) (GUI_SDATA, guichar_t): Macros to abstract out differences between NTGUI_UNICODE and !NTGUI_UNICODE builds, some moved out of w32fns.c. * w32term.c (construct_drag_n_drop): Use the above macros to make drag-and-drop work for non-ASCII filenames in cygw32 builds. * w32fns.c (x_set_name, x_set_title): Use the above macros to properly display non-ASCII frame titles in cygw32 builds. * w32fns.c (Fw32_shell_execute): Use the above macros to properly call ShellExecute in cygw32 builds. * w32fn.c (Fx_file_dialog): Use the above macros to simplify the common file dialog code. * w32fns.c (Ffile_system_info): Remove from cygw32 builds, which can just use du like other systems. * coding.c (from_unicode_buffer): Declare. * coding.c (from_unicode_buffer): Implement. --- src/coding.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index d6560a92b70..c18632f301b 100644 --- a/src/coding.c +++ b/src/coding.c @@ -286,6 +286,10 @@ encode_coding_XXX (struct coding_system *coding) #include #include +#ifdef HAVE_WCHAR_H +#include +#endif /* HAVE_WCHAR_H */ + #include "lisp.h" #include "character.h" #include "buffer.h" @@ -8003,6 +8007,16 @@ from_unicode (Lisp_Object str) return code_convert_string_norecord (str, Qutf_16le, 0); } +Lisp_Object +from_unicode_buffer (const wchar_t* wstr) +{ + return from_unicode ( + make_unibyte_string ( + (char*) wstr, + /* we get one of the two final 0 bytes for free. */ + 1 + sizeof (wchar_t) * wcslen (wstr))); +} + wchar_t * to_unicode (Lisp_Object str, Lisp_Object *buf) { -- cgit v1.2.1 From 8a44e6d176989d8eef140314098c76a70248ba61 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Sat, 16 Mar 2013 01:03:54 +0900 Subject: Optimize ASCII file reading with EOL format detection and decoding. --- src/coding.c | 197 +++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 159 insertions(+), 38 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index c18632f301b..5047e1149bc 100644 --- a/src/coding.c +++ b/src/coding.c @@ -6071,6 +6071,93 @@ complement_process_encoding_system (Lisp_Object coding_system) #define EOL_SEEN_CR 2 #define EOL_SEEN_CRLF 4 + +static Lisp_Object adjust_coding_eol_type (struct coding_system *coding, int eol_seen); + + +/* Return 1 if all the source bytes are ASCII, and return 0 otherwize. + By side effects, set coding->head_ascii and coding->eol_seen. The + value of coding->eol_seen is "logical or" of EOL_SEEN_LF, + EOL_SEEN_CR, and EOL_SEEN_CRLF, but the value is reliable only when + all the source bytes are ASCII. */ + +static bool +detect_ascii (struct coding_system *coding) +{ + const unsigned char *src, *end; + Lisp_Object eol_type = CODING_ID_EOL_TYPE (coding->id); + int eol_seen; + + eol_seen = (VECTORP (eol_type) ? EOL_SEEN_NONE + : EQ (eol_type, Qunix) ? EOL_SEEN_LF + : EQ (eol_type, Qdos) ? EOL_SEEN_CRLF + : EOL_SEEN_CR); + coding_set_source (coding); + src = coding->source; + end = src + coding->src_bytes; + + if (inhibit_eol_conversion) + { + /* We don't have to check EOL format. */ + while (src < end && !( *src & 0x80)) src++; + eol_seen = EOL_SEEN_LF; + adjust_coding_eol_type (coding, eol_seen); + } + else if (eol_seen != EOL_SEEN_NONE) + { + /* We don't have to check EOL format either. */ + while (src < end && !(*src & 0x80)) src++; + } + else + { + end--; /* We look ahead one byte. */ + while (src < end) + { + int c = *src; + + if (c & 0x80) + break; + src++; + if (c < 0x20) + { + if (c == '\r') + { + if (*src == '\n') + { + eol_seen |= EOL_SEEN_CRLF; + src++; + } + else + eol_seen |= EOL_SEEN_CR; + } + else if (c == '\n') + eol_seen |= EOL_SEEN_LF; + } + } + if (src > end) + /* The last two bytes are CR LF, which means that we have + scanned all bytes. */ + end++; + else if (src == end) + { + end++; + if (! (*src & 0x80)) + { + if (*src == '\r') + eol_seen |= EOL_SEEN_CR; + else if (*src == '\n') + eol_seen |= EOL_SEEN_LF; + src++; + } + } + adjust_coding_eol_type (coding, eol_seen); + } + coding->head_ascii = src - coding->source; + coding->eol_seen = eol_seen; + return (src == end); +} + + /* Detect how end-of-line of a text of length SRC_BYTES pointed by SOURCE is encoded. If CATEGORY is one of coding_category_utf_16_XXXX, assume that CR and LF are encoded by @@ -6215,7 +6302,6 @@ detect_coding (struct coding_system *coding) coding_set_source (coding); src_end = coding->source + coding->src_bytes; - coding->head_ascii = 0; /* If we have not yet decided the text encoding type, detect it now. */ @@ -6225,6 +6311,8 @@ detect_coding (struct coding_system *coding) struct coding_detection_info detect_info; bool null_byte_found = 0, eight_bit_found = 0; + coding->head_ascii = 0; + coding->eol_seen = EOL_SEEN_NONE; detect_info.checked = detect_info.found = detect_info.rejected = 0; for (src = coding->source; src < src_end; src++) { @@ -6263,6 +6351,26 @@ detect_coding (struct coding_system *coding) if (eight_bit_found) break; } + else if (! disable_ascii_optimization + && ! inhibit_eol_conversion) + { + if (c == '\r') + { + if (src < src_end && src[1] == '\n') + { + coding->eol_seen |= EOL_SEEN_CRLF; + src++; + coding->head_ascii++; + } + else + coding->eol_seen |= EOL_SEEN_CR; + } + else if (c == '\n') + { + coding->eol_seen |= EOL_SEEN_LF; + } + } + if (! eight_bit_found) coding->head_ascii++; } @@ -6353,19 +6461,20 @@ detect_coding (struct coding_system *coding) coding_systems = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom); detect_info.found = detect_info.rejected = 0; - for (src = coding->source; src < src_end; src++) + if (detect_ascii (coding)) { - if (*src & 0x80) - break; + setup_coding_system (XCDR (coding_systems), coding); } - coding->head_ascii = src - coding->source; - if (CONSP (coding_systems) - && detect_coding_utf_8 (coding, &detect_info)) + else { - if (detect_info.found & CATEGORY_MASK_UTF_8_SIG) - setup_coding_system (XCAR (coding_systems), coding); - else - setup_coding_system (XCDR (coding_systems), coding); + if (CONSP (coding_systems) + && detect_coding_utf_8 (coding, &detect_info)) + { + if (detect_info.found & CATEGORY_MASK_UTF_8_SIG) + setup_coding_system (XCAR (coding_systems), coding); + else + setup_coding_system (XCDR (coding_systems), coding); + } } } else if (XINT (CODING_ATTR_CATEGORY (CODING_ID_ATTRS (coding->id))) @@ -6378,6 +6487,7 @@ detect_coding (struct coding_system *coding) = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom); detect_info.found = detect_info.rejected = 0; coding->head_ascii = 0; + coding->eol_seen = EOL_SEEN_NONE; if (CONSP (coding_systems) && detect_coding_utf_16 (coding, &detect_info)) { @@ -6815,7 +6925,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table, produced = dst - (coding->destination + coding->produced); if (BUFFERP (coding->dst_object) && produced_chars > 0) - insert_from_gap (produced_chars, produced); + insert_from_gap (produced_chars, produced, 0); coding->produced += produced; coding->produced_char += produced_chars; return carryover; @@ -7400,7 +7510,7 @@ encode_coding (struct coding_system *coding) } while (coding->consumed_char < coding->src_chars); if (BUFFERP (coding->dst_object) && coding->produced_char > 0) - insert_from_gap (coding->produced_char, coding->produced); + insert_from_gap (coding->produced_char, coding->produced, 0); SAFE_FREE (); } @@ -7510,39 +7620,45 @@ decode_coding_gap (struct coding_system *coding, if (CODING_REQUIRE_DETECTION (coding)) detect_coding (coding); attrs = CODING_ID_ATTRS (coding->id); -#ifndef CODING_DISABLE_ASCII_OPTIMIZATION - if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs)) - && NILP (CODING_ATTR_POST_READ (attrs)) - && NILP (get_translation_table (attrs, 0, NULL)) - && (inhibit_eol_conversion - || EQ (CODING_ID_EOL_TYPE (coding->id), Qunix))) + if (! disable_ascii_optimization) { - /* We can skip the conversion if all source bytes are ASCII. */ - if (coding->head_ascii < 0) + if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs)) + && NILP (CODING_ATTR_POST_READ (attrs)) + && NILP (get_translation_table (attrs, 0, NULL)) + && (coding->head_ascii >= 0 /* We've already called detect_coding */ + ? coding->head_ascii == bytes + : detect_ascii (coding))) { - /* We have not yet counted the number of ASCII bytes at the - head of the source. Do it now. */ - const unsigned char *src, *src_end; + if (coding->eol_seen == EOL_SEEN_CR) + { + unsigned char *src_end = GAP_END_ADDR; + unsigned char *src = src - coding->src_bytes; - coding_set_source (coding); - src_end = coding->source + coding->src_bytes; - for (src = coding->source; src < src_end; src++) + while (src < src_end) + { + if (*src++ == '\r') + src[-1] = '\n'; + } + } + else if (coding->eol_seen == EOL_SEEN_CRLF) { - if (*src & 0x80) - break; + unsigned char *src = GAP_END_ADDR; + unsigned char *src_beg = src - coding->src_bytes; + unsigned char *dst = src; + + while (src_beg < src) + { + *--dst = *--src; + if (*src == '\n') + src--; + } + bytes -= dst - src; } - coding->head_ascii = src - coding->source; - } - if (coding->src_bytes == coding->head_ascii) - { - /* No need of conversion. Use the data in the gap as is. */ - coding->produced_char = chars; - coding->produced = bytes; - adjust_after_replace (PT, PT_BYTE, Qnil, chars, bytes, 1); + coding->produced_char = coding->produced = bytes; + insert_from_gap (bytes, bytes, 1); return; } } -#endif /* not CODING_DISABLE_ASCII_OPTIMIZATION */ code_conversion_save (0, 0); coding->mode |= CODING_MODE_LAST_BLOCK; @@ -10758,6 +10874,11 @@ from GNU Find and GNU Grep. Emacs will then ignore the null bytes and decode text as usual. */); inhibit_null_byte_detection = 0; + DEFVAR_BOOL ("disable-ascii-optimization", disable_ascii_optimization, + doc: /* If non-nil, Emacs does not optimize code decoder for ASCII files. +Internal use only. Removed after the experimental optimizer gets stable. */); + disable_ascii_optimization = 0; + DEFVAR_LISP ("translation-table-for-input", Vtranslation_table_for_input, doc: /* Char table for translating self-inserting characters. This is applied to the result of input methods, not their input. -- cgit v1.2.1 From cded56c19b30e038537398b5213438c339428ed9 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 15 Mar 2013 13:03:31 -0700 Subject: * coding.c (decode_coding_gap): Fix typo caught by static checking. --- 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 5047e1149bc..6cfcec905a1 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7632,7 +7632,7 @@ decode_coding_gap (struct coding_system *coding, if (coding->eol_seen == EOL_SEEN_CR) { unsigned char *src_end = GAP_END_ADDR; - unsigned char *src = src - coding->src_bytes; + unsigned char *src = src_end - coding->src_bytes; while (src < src_end) { -- cgit v1.2.1 From bad98418bf75efc6dd8ac393157413bc6ef769b4 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 18 Mar 2013 21:41:53 -0700 Subject: Spelling fixes. --- 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 6cfcec905a1..8a09cd67859 100644 --- a/src/coding.c +++ b/src/coding.c @@ -6075,7 +6075,7 @@ complement_process_encoding_system (Lisp_Object coding_system) static Lisp_Object adjust_coding_eol_type (struct coding_system *coding, int eol_seen); -/* Return 1 if all the source bytes are ASCII, and return 0 otherwize. +/* Return true iff all the source bytes are ASCII. By side effects, set coding->head_ascii and coding->eol_seen. The value of coding->eol_seen is "logical or" of EOL_SEEN_LF, EOL_SEEN_CR, and EOL_SEEN_CRLF, but the value is reliable only when -- cgit v1.2.1 From c0a17406acd4b9db561ba99f8a02bf5461130e82 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Wed, 20 Mar 2013 16:58:20 +0900 Subject: coding.c (syms_of_coding): Initialize disable_ascii_optimization 1. --- 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 6cfcec905a1..a5b07019388 100644 --- a/src/coding.c +++ b/src/coding.c @@ -10877,7 +10877,7 @@ decode text as usual. */); DEFVAR_BOOL ("disable-ascii-optimization", disable_ascii_optimization, doc: /* If non-nil, Emacs does not optimize code decoder for ASCII files. Internal use only. Removed after the experimental optimizer gets stable. */); - disable_ascii_optimization = 0; + disable_ascii_optimization = 1; DEFVAR_LISP ("translation-table-for-input", Vtranslation_table_for_input, doc: /* Char table for translating self-inserting characters. -- cgit v1.2.1 From 8bc369d4a23a3a8040d77e3ce89a7f63b1ecff97 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Fri, 22 Mar 2013 00:18:44 +0900 Subject: Fix a bug introduced by 2013-03-15T16:06:12Z!handa@gnu.org. --- 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 cb81375a043..8a09cd67859 100644 --- a/src/coding.c +++ b/src/coding.c @@ -10877,7 +10877,7 @@ decode text as usual. */); DEFVAR_BOOL ("disable-ascii-optimization", disable_ascii_optimization, doc: /* If non-nil, Emacs does not optimize code decoder for ASCII files. Internal use only. Removed after the experimental optimizer gets stable. */); - disable_ascii_optimization = 1; + disable_ascii_optimization = 0; DEFVAR_LISP ("translation-table-for-input", Vtranslation_table_for_input, doc: /* Char table for translating self-inserting characters. -- cgit v1.2.1 From 251e91474c91e16b101502c2ed7c05fc13e4ecea Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Fri, 5 Apr 2013 23:08:56 +0900 Subject: Optimize the code for reading UTF-8 files. --- src/coding.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 163 insertions(+), 43 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 8a09cd67859..735af25502d 100644 --- a/src/coding.c +++ b/src/coding.c @@ -6072,17 +6072,18 @@ complement_process_encoding_system (Lisp_Object coding_system) #define EOL_SEEN_CRLF 4 -static Lisp_Object adjust_coding_eol_type (struct coding_system *coding, int eol_seen); +static Lisp_Object adjust_coding_eol_type (struct coding_system *coding, + int eol_seen); -/* Return true iff all the source bytes are ASCII. +/* Return the number of ASCII characters at the head of the source. By side effects, set coding->head_ascii and coding->eol_seen. The value of coding->eol_seen is "logical or" of EOL_SEEN_LF, EOL_SEEN_CR, and EOL_SEEN_CRLF, but the value is reliable only when all the source bytes are ASCII. */ -static bool -detect_ascii (struct coding_system *coding) +static int +check_ascii (struct coding_system *coding) { const unsigned char *src, *end; Lisp_Object eol_type = CODING_ID_EOL_TYPE (coding->id); @@ -6096,21 +6097,20 @@ detect_ascii (struct coding_system *coding) src = coding->source; end = src + coding->src_bytes; - if (inhibit_eol_conversion) + if (inhibit_eol_conversion + || eol_seen != EOL_SEEN_NONE) { /* We don't have to check EOL format. */ while (src < end && !( *src & 0x80)) src++; - eol_seen = EOL_SEEN_LF; - adjust_coding_eol_type (coding, eol_seen); - } - else if (eol_seen != EOL_SEEN_NONE) - { - /* We don't have to check EOL format either. */ - while (src < end && !(*src & 0x80)) src++; + if (inhibit_eol_conversion) + { + eol_seen = EOL_SEEN_LF; + adjust_coding_eol_type (coding, eol_seen); + } } else { - end--; /* We look ahead one byte. */ + end--; /* We look ahead one byte for "CR LF". */ while (src < end) { int c = *src; @@ -6118,6 +6118,69 @@ detect_ascii (struct coding_system *coding) if (c & 0x80) break; src++; + if (c == '\r') + { + if (*src == '\n') + { + eol_seen |= EOL_SEEN_CRLF; + src++; + } + else + eol_seen |= EOL_SEEN_CR; + } + else if (c == '\n') + eol_seen |= EOL_SEEN_LF; + } + if (src == end) + { + int c = *src; + + /* All bytes but the last one C are ASCII. */ + if (! (c & 0x80)) + { + if (c == '\r') + eol_seen |= EOL_SEEN_CR; + else if (c == '\n') + eol_seen |= EOL_SEEN_LF; + src++; + } + } + } + coding->head_ascii = src - coding->source; + coding->eol_seen = eol_seen; + return (coding->head_ascii); +} + + +/* Return the number of charcters at the source if all the bytes are + valid UTF-8 (of Unicode range). Otherwise, return -1. By side + effects, update coding->eol_seen. The value of coding->eol_seen is + "logical or" of EOL_SEEN_LF, EOL_SEEN_CR, and EOL_SEEN_CRLF, but + the value is reliable only when all the source bytes are valid + UTF-8. */ + +static int +check_utf_8 (struct coding_system *coding) +{ + const unsigned char *src, *end; + int eol_seen = coding->eol_seen; + int nchars = coding->head_ascii; + + if (coding->head_ascii < 0) + check_ascii (coding); + else + coding_set_source (coding); + src = coding->source + coding->head_ascii; + /* We look ahead one byte for CR LF. */ + end = coding->source + coding->src_bytes - 1; + + while (src < end) + { + int c = *src; + + if (UTF_8_1_OCTET_P (*src)) + { + src++; if (c < 0x20) { if (c == '\r') @@ -6126,6 +6189,7 @@ detect_ascii (struct coding_system *coding) { eol_seen |= EOL_SEEN_CRLF; src++; + nchars++; } else eol_seen |= EOL_SEEN_CR; @@ -6134,27 +6198,58 @@ detect_ascii (struct coding_system *coding) eol_seen |= EOL_SEEN_LF; } } - if (src > end) - /* The last two bytes are CR LF, which means that we have - scanned all bytes. */ - end++; - else if (src == end) + else if (UTF_8_2_OCTET_LEADING_P (c)) { - end++; - if (! (*src & 0x80)) - { - if (*src == '\r') - eol_seen |= EOL_SEEN_CR; - else if (*src == '\n') - eol_seen |= EOL_SEEN_LF; - src++; - } + if (c < 0xC2 /* overlong sequence */ + || src + 1 >= end + || ! UTF_8_EXTRA_OCTET_P (src[1])) + return -1; + src += 2; } - adjust_coding_eol_type (coding, eol_seen); + else if (UTF_8_3_OCTET_LEADING_P (c)) + { + if (src + 2 >= end + || ! (UTF_8_EXTRA_OCTET_P (src[1]) + && UTF_8_EXTRA_OCTET_P (src[2]))) + return -1; + c = (((c & 0xF) << 12) + | ((src[1] & 0x3F) << 6) | (src[2] & 0x3F)); + if (c < 0x800 /* overlong sequence */ + || (c >= 0xd800 && c < 0xe000)) /* surrogates (invalid) */ + return -1; + src += 3; + } + else if (UTF_8_4_OCTET_LEADING_P (c)) + { + if (src + 3 >= end + || ! (UTF_8_EXTRA_OCTET_P (src[1]) + && UTF_8_EXTRA_OCTET_P (src[2]) + && UTF_8_EXTRA_OCTET_P (src[3]))) + return -1; + c = (((c & 0x7) << 18) | ((src[1] & 0x3F) << 12) + | ((src[2] & 0x3F) << 6) | (src[3] & 0x3F)); + if (c < 0x10000 /* overlong sequence */ + || c >= 0x110000) /* non-Unicode character */ + return -1; + src += 4; + } + else + return -1; + nchars++; + } + + if (src == end) + { + if (! UTF_8_1_OCTET_P (*src)) + return -1; + nchars++; + if (*src == '\r') + eol_seen |= EOL_SEEN_CR; + else if (*src == '\n') + eol_seen |= EOL_SEEN_LF; } - coding->head_ascii = src - coding->source; coding->eol_seen = eol_seen; - return (src == end); + return nchars; } @@ -6269,6 +6364,9 @@ adjust_coding_eol_type (struct coding_system *coding, int eol_seen) Lisp_Object eol_type; eol_type = CODING_ID_EOL_TYPE (coding->id); + if (! VECTORP (eol_type)) + /* Already adjusted. */ + return eol_type; if (eol_seen & EOL_SEEN_LF) { coding->id = CODING_SYSTEM_ID (AREF (eol_type, 0)); @@ -6360,7 +6458,8 @@ detect_coding (struct coding_system *coding) { coding->eol_seen |= EOL_SEEN_CRLF; src++; - coding->head_ascii++; + if (! eight_bit_found) + coding->head_ascii++; } else coding->eol_seen |= EOL_SEEN_CR; @@ -6461,9 +6560,14 @@ detect_coding (struct coding_system *coding) coding_systems = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom); detect_info.found = detect_info.rejected = 0; - if (detect_ascii (coding)) + if (check_ascii (coding) == coding->src_bytes) { + int head_ascii = coding->head_ascii; + + if (coding->eol_seen != EOL_SEEN_NONE) + adjust_coding_eol_type (coding, coding->eol_seen); setup_coding_system (XCDR (coding_systems), coding); + coding->head_ascii = head_ascii; } else { @@ -7620,15 +7724,27 @@ decode_coding_gap (struct coding_system *coding, if (CODING_REQUIRE_DETECTION (coding)) detect_coding (coding); attrs = CODING_ID_ATTRS (coding->id); - if (! disable_ascii_optimization) - { - if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs)) - && NILP (CODING_ATTR_POST_READ (attrs)) - && NILP (get_translation_table (attrs, 0, NULL)) - && (coding->head_ascii >= 0 /* We've already called detect_coding */ - ? coding->head_ascii == bytes - : detect_ascii (coding))) + if (! disable_ascii_optimization + && ! coding->src_multibyte + && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)) + && NILP (CODING_ATTR_POST_READ (attrs)) + && NILP (get_translation_table (attrs, 0, NULL))) + { + chars = coding->head_ascii; + if (chars < 0) + chars = check_ascii (coding); + if (chars != bytes) + { + if (EQ (CODING_ATTR_TYPE (attrs), Qutf_8)) + chars = check_utf_8 (coding); + else + chars = -1; + } + if (chars >= 0) { + if (coding->eol_seen != EOL_SEEN_NONE) + adjust_coding_eol_type (coding, coding->eol_seen); + if (coding->eol_seen == EOL_SEEN_CR) { unsigned char *src_end = GAP_END_ADDR; @@ -7645,6 +7761,7 @@ decode_coding_gap (struct coding_system *coding, unsigned char *src = GAP_END_ADDR; unsigned char *src_beg = src - coding->src_bytes; unsigned char *dst = src; + ptrdiff_t diff; while (src_beg < src) { @@ -7652,10 +7769,13 @@ decode_coding_gap (struct coding_system *coding, if (*src == '\n') src--; } - bytes -= dst - src; + diff = dst - src; + bytes -= diff; + chars -= diff; } - coding->produced_char = coding->produced = bytes; - insert_from_gap (bytes, bytes, 1); + coding->produced = bytes; + coding->produced_char = chars; + insert_from_gap (chars, bytes, 1); return; } } -- cgit v1.2.1 From 8ead390103b65c93977dd4dee419f66316a79b96 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 6 Apr 2013 00:33:18 -0700 Subject: Spelling fix. --- 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 735af25502d..f9799035b3c 100644 --- a/src/coding.c +++ b/src/coding.c @@ -6152,7 +6152,7 @@ check_ascii (struct coding_system *coding) } -/* Return the number of charcters at the source if all the bytes are +/* Return the number of characters at the source if all the bytes are valid UTF-8 (of Unicode range). Otherwise, return -1. By side effects, update coding->eol_seen. The value of coding->eol_seen is "logical or" of EOL_SEEN_LF, EOL_SEEN_CR, and EOL_SEEN_CRLF, but -- cgit v1.2.1 From ec5098562a018551a4ec9652fa7658304b1bbe59 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Thu, 25 Apr 2013 00:09:49 +0900 Subject: coding.c (decode_coding_iso_2022): When an invalid escape sequence is encountered, reset the invocation and designation status to the safest one. --- src/coding.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index f9799035b3c..b9fb92c481b 100644 --- a/src/coding.c +++ b/src/coding.c @@ -3887,6 +3887,14 @@ decode_coding_iso_2022 (struct coding_system *coding) *charbuf++ = c < 0 ? -c : ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); char_offset++; coding->errors++; + /* Reset the invocation and designation status to the safest + one; i.e. designate ASCII to the graphic register 0, and + invoke that register to the graphic plane 0. This typically + helps the case that an designation sequence for ASCII "ESC ( + B" is somehow broken (e.g. broken by a newline). */ + CODING_ISO_INVOCATION (coding, 0) = 0; + CODING_ISO_DESIGNATION (coding, 0) = charset_ascii; + charset_id_0 = charset_ascii; continue; break_loop: -- cgit v1.2.1 From 9e63b4a53403840acf3d759d8ac16475c12562e2 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sun, 28 Apr 2013 21:21:01 +0300 Subject: Fix bug #14287 with decoding EOL by *-dos coding systems. src/coding.c (decode_coding_gap): Don't remove the character before a newline unless it's a CR character. --- 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 b9fb92c481b..f6664e179b7 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7774,7 +7774,7 @@ decode_coding_gap (struct coding_system *coding, while (src_beg < src) { *--dst = *--src; - if (*src == '\n') + if (*src == '\n' && src > src_beg && src[-1] == '\r') src--; } diff = dst - src; -- cgit v1.2.1 From e6d2f1553635a746396f2f4261dde31e03e0fdd1 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Wed, 22 May 2013 23:53:21 +0900 Subject: Fix the setting of buffer-file-coding-system on, for instance, C-x RET c unix RET _FILE_OF_DOS_EOL_TYPE_ RET. --- src/coding.c | 221 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 154 insertions(+), 67 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index f6664e179b7..42fd81b6322 100644 --- a/src/coding.c +++ b/src/coding.c @@ -1125,6 +1125,14 @@ alloc_destination (struct coding_system *coding, ptrdiff_t nbytes, *buf++ = id; \ } while (0) + +/* Bitmasks for coding->eol_seen. */ + +#define EOL_SEEN_NONE 0 +#define EOL_SEEN_LF 1 +#define EOL_SEEN_CR 2 +#define EOL_SEEN_CRLF 4 + /*** 2. Emacs' internal format (emacs-utf-8) ***/ @@ -1147,6 +1155,9 @@ alloc_destination (struct coding_system *coding, ptrdiff_t nbytes, #define UTF_8_BOM_2 0xBB #define UTF_8_BOM_3 0xBF +/* Unlike the other detect_coding_XXX, this function counts number of + characters and check EOL format. */ + static bool detect_coding_utf_8 (struct coding_system *coding, struct coding_detection_info *detect_info) @@ -1156,11 +1167,23 @@ detect_coding_utf_8 (struct coding_system *coding, bool multibytep = coding->src_multibyte; ptrdiff_t consumed_chars = 0; bool bom_found = 0; - bool found = 0; + int nchars = coding->head_ascii; + int eol_seen = coding->eol_seen; detect_info->checked |= CATEGORY_MASK_UTF_8; /* A coding system of this category is always ASCII compatible. */ - src += coding->head_ascii; + src += nchars; + + if (src == coding->source /* BOM should be at the head. */ + && src + 3 < src_end /* BOM is 3-byte long. */ + && src[0] == UTF_8_BOM_1 + && src[1] == UTF_8_BOM_2 + && src[2] == UTF_8_BOM_3) + { + bom_found = 1; + src += 3; + nchars++; + } while (1) { @@ -1169,13 +1192,29 @@ detect_coding_utf_8 (struct coding_system *coding, src_base = src; ONE_MORE_BYTE (c); if (c < 0 || UTF_8_1_OCTET_P (c)) - continue; + { + nchars++; + if (c == '\r') + { + if (src < src_end && *src == '\n') + { + eol_seen |= EOL_SEEN_CRLF; + src++; + nchars++; + } + else + eol_seen |= EOL_SEEN_CR; + } + else if (c == '\n') + eol_seen |= EOL_SEEN_LF; + continue; + } ONE_MORE_BYTE (c1); if (c1 < 0 || ! UTF_8_EXTRA_OCTET_P (c1)) break; if (UTF_8_2_OCTET_LEADING_P (c)) { - found = 1; + nchars++; continue; } ONE_MORE_BYTE (c2); @@ -1183,10 +1222,7 @@ detect_coding_utf_8 (struct coding_system *coding, break; if (UTF_8_3_OCTET_LEADING_P (c)) { - found = 1; - if (src_base == coding->source - && c == UTF_8_BOM_1 && c1 == UTF_8_BOM_2 && c2 == UTF_8_BOM_3) - bom_found = 1; + nchars++; continue; } ONE_MORE_BYTE (c3); @@ -1194,7 +1230,7 @@ detect_coding_utf_8 (struct coding_system *coding, break; if (UTF_8_4_OCTET_LEADING_P (c)) { - found = 1; + nchars++; continue; } ONE_MORE_BYTE (c4); @@ -1202,7 +1238,7 @@ detect_coding_utf_8 (struct coding_system *coding, break; if (UTF_8_5_OCTET_LEADING_P (c)) { - found = 1; + nchars++; continue; } break; @@ -1219,14 +1255,17 @@ detect_coding_utf_8 (struct coding_system *coding, if (bom_found) { /* The first character 0xFFFE doesn't necessarily mean a BOM. */ - detect_info->found |= CATEGORY_MASK_UTF_8_SIG | CATEGORY_MASK_UTF_8_NOSIG; + detect_info->found |= CATEGORY_MASK_UTF_8_AUTO | CATEGORY_MASK_UTF_8_SIG | CATEGORY_MASK_UTF_8_NOSIG; } else { detect_info->rejected |= CATEGORY_MASK_UTF_8_SIG; - if (found) - detect_info->found |= CATEGORY_MASK_UTF_8_NOSIG; + if (nchars < src_end - coding->source) + /* The found characters are less than source bytes, which + means that we found a valid non-ASCII characters. */ + detect_info->found |= CATEGORY_MASK_UTF_8_AUTO | CATEGORY_MASK_UTF_8_NOSIG; } + coding->detected_utf8_chars = nchars; return 1; } @@ -5622,7 +5661,6 @@ setup_coding_system (Lisp_Object coding_system, struct coding_system *coding) eol_type = inhibit_eol_conversion ? Qunix : CODING_ID_EOL_TYPE (coding->id); coding->mode = 0; - coding->head_ascii = -1; if (VECTORP (eol_type)) coding->common_flags = (CODING_REQUIRE_DECODING_MASK | CODING_REQUIRE_DETECTION_MASK); @@ -6074,46 +6112,35 @@ complement_process_encoding_system (Lisp_Object coding_system) */ -#define EOL_SEEN_NONE 0 -#define EOL_SEEN_LF 1 -#define EOL_SEEN_CR 2 -#define EOL_SEEN_CRLF 4 - - static Lisp_Object adjust_coding_eol_type (struct coding_system *coding, int eol_seen); /* Return the number of ASCII characters at the head of the source. - By side effects, set coding->head_ascii and coding->eol_seen. The - value of coding->eol_seen is "logical or" of EOL_SEEN_LF, - EOL_SEEN_CR, and EOL_SEEN_CRLF, but the value is reliable only when - all the source bytes are ASCII. */ + By side effects, set coding->head_ascii and update + coding->eol_seen. The value of coding->eol_seen is "logical or" of + EOL_SEEN_LF, EOL_SEEN_CR, and EOL_SEEN_CRLF, but the value is + reliable only when all the source bytes are ASCII. */ static int check_ascii (struct coding_system *coding) { const unsigned char *src, *end; Lisp_Object eol_type = CODING_ID_EOL_TYPE (coding->id); - int eol_seen; + int eol_seen = coding->eol_seen; - eol_seen = (VECTORP (eol_type) ? EOL_SEEN_NONE - : EQ (eol_type, Qunix) ? EOL_SEEN_LF - : EQ (eol_type, Qdos) ? EOL_SEEN_CRLF - : EOL_SEEN_CR); coding_set_source (coding); src = coding->source; end = src + coding->src_bytes; if (inhibit_eol_conversion - || eol_seen != EOL_SEEN_NONE) + || SYMBOLP (eol_type)) { /* We don't have to check EOL format. */ - while (src < end && !( *src & 0x80)) src++; - if (inhibit_eol_conversion) + while (src < end && !( *src & 0x80)) { - eol_seen = EOL_SEEN_LF; - adjust_coding_eol_type (coding, eol_seen); + if (*src++ == '\n') + eol_seen |= EOL_SEEN_LF; } } else @@ -6171,7 +6198,7 @@ static int check_utf_8 (struct coding_system *coding) { const unsigned char *src, *end; - int eol_seen = coding->eol_seen; + int eol_seen; int nchars = coding->head_ascii; if (coding->head_ascii < 0) @@ -6181,7 +6208,7 @@ check_utf_8 (struct coding_system *coding) src = coding->source + coding->head_ascii; /* We look ahead one byte for CR LF. */ end = coding->source + coding->src_bytes - 1; - + eol_seen = coding->eol_seen; while (src < end) { int c = *src; @@ -6402,6 +6429,8 @@ detect_coding (struct coding_system *coding) { const unsigned char *src, *src_end; unsigned int saved_mode = coding->mode; + Lisp_Object found = Qnil; + Lisp_Object eol_type = CODING_ID_EOL_TYPE (coding->id); coding->consumed = coding->consumed_char = 0; coding->produced = coding->produced_char = 0; @@ -6409,6 +6438,7 @@ detect_coding (struct coding_system *coding) src_end = coding->source + coding->src_bytes; + coding->eol_seen = EOL_SEEN_NONE; /* If we have not yet decided the text encoding type, detect it now. */ if (EQ (CODING_ATTR_TYPE (CODING_ID_ATTRS (coding->id)), Qundecided)) @@ -6418,7 +6448,6 @@ detect_coding (struct coding_system *coding) bool null_byte_found = 0, eight_bit_found = 0; coding->head_ascii = 0; - coding->eol_seen = EOL_SEEN_NONE; detect_info.checked = detect_info.found = detect_info.rejected = 0; for (src = coding->source; src < src_end; src++) { @@ -6529,32 +6558,58 @@ detect_coding (struct coding_system *coding) } else if ((*(this->detector)) (coding, &detect_info) && detect_info.found & (1 << category)) - { - if (category == coding_category_utf_16_auto) - { - if (detect_info.found & CATEGORY_MASK_UTF_16_LE) - category = coding_category_utf_16_le; - else - category = coding_category_utf_16_be; - } - break; - } + break; } } if (i < coding_category_raw_text) - setup_coding_system (CODING_ID_NAME (this->id), coding); + { + if (category == coding_category_utf_8_auto) + { + Lisp_Object coding_systems; + + coding_systems = AREF (CODING_ID_ATTRS (this->id), + coding_attr_utf_bom); + if (CONSP (coding_systems)) + { + if (detect_info.found & CATEGORY_MASK_UTF_8_SIG) + found = XCAR (coding_systems); + else + found = XCDR (coding_systems); + } + else + found = CODING_ID_NAME (this->id); + } + else if (category == coding_category_utf_16_auto) + { + Lisp_Object coding_systems; + + coding_systems = AREF (CODING_ID_ATTRS (this->id), + coding_attr_utf_bom); + if (CONSP (coding_systems)) + { + if (detect_info.found & CATEGORY_MASK_UTF_16_LE) + found = XCAR (coding_systems); + else if (detect_info.found & CATEGORY_MASK_UTF_16_BE) + found = XCDR (coding_systems); + } + else + found = CODING_ID_NAME (this->id); + } + else + found = CODING_ID_NAME (this->id); + } else if (null_byte_found) - setup_coding_system (Qno_conversion, coding); + found = Qno_conversion; else if ((detect_info.rejected & CATEGORY_MASK_ANY) == CATEGORY_MASK_ANY) - setup_coding_system (Qraw_text, coding); + found = Qraw_text; else if (detect_info.rejected) for (i = 0; i < coding_category_raw_text; i++) if (! (detect_info.rejected & (1 << coding_priorities[i]))) { this = coding_categories + coding_priorities[i]; - setup_coding_system (CODING_ID_NAME (this->id), coding); + found = CODING_ID_NAME (this->id); break; } } @@ -6570,12 +6625,8 @@ detect_coding (struct coding_system *coding) detect_info.found = detect_info.rejected = 0; if (check_ascii (coding) == coding->src_bytes) { - int head_ascii = coding->head_ascii; - - if (coding->eol_seen != EOL_SEEN_NONE) - adjust_coding_eol_type (coding, coding->eol_seen); - setup_coding_system (XCDR (coding_systems), coding); - coding->head_ascii = head_ascii; + if (CONSP (coding_systems)) + found = XCDR (coding_systems); } else { @@ -6583,9 +6634,9 @@ detect_coding (struct coding_system *coding) && detect_coding_utf_8 (coding, &detect_info)) { if (detect_info.found & CATEGORY_MASK_UTF_8_SIG) - setup_coding_system (XCAR (coding_systems), coding); + found = XCAR (coding_systems); else - setup_coding_system (XCDR (coding_systems), coding); + found = XCDR (coding_systems); } } } @@ -6599,16 +6650,28 @@ detect_coding (struct coding_system *coding) = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom); detect_info.found = detect_info.rejected = 0; coding->head_ascii = 0; - coding->eol_seen = EOL_SEEN_NONE; if (CONSP (coding_systems) && detect_coding_utf_16 (coding, &detect_info)) { if (detect_info.found & CATEGORY_MASK_UTF_16_LE) - setup_coding_system (XCAR (coding_systems), coding); + found = XCAR (coding_systems); else if (detect_info.found & CATEGORY_MASK_UTF_16_BE) - setup_coding_system (XCDR (coding_systems), coding); + found = XCDR (coding_systems); } } + + if (! NILP (found)) + { + int specified_eol = (VECTORP (eol_type) ? EOL_SEEN_NONE + : EQ (eol_type, Qdos) ? EOL_SEEN_CRLF + : EQ (eol_type, Qmac) ? EOL_SEEN_CR + : EOL_SEEN_LF); + + setup_coding_system (found, coding); + if (specified_eol != EOL_SEEN_NONE) + adjust_coding_eol_type (coding, specified_eol); + } + coding->mode = saved_mode; } @@ -7729,6 +7792,9 @@ decode_coding_gap (struct coding_system *coding, coding->dst_pos_byte = PT_BYTE; coding->dst_multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); + coding->head_ascii = -1; + coding->detected_utf8_chars = -1; + coding->eol_seen = EOL_SEEN_NONE; if (CODING_REQUIRE_DETECTION (coding)) detect_coding (coding); attrs = CODING_ID_ATTRS (coding->id); @@ -7743,17 +7809,38 @@ decode_coding_gap (struct coding_system *coding, chars = check_ascii (coding); if (chars != bytes) { + /* There exists a non-ASCII byte. */ if (EQ (CODING_ATTR_TYPE (attrs), Qutf_8)) - chars = check_utf_8 (coding); + { + if (coding->detected_utf8_chars >= 0) + chars = coding->detected_utf8_chars; + else + chars = check_utf_8 (coding); + if (CODING_UTF_8_BOM (coding) != utf_without_bom + && coding->head_ascii == 0 + && coding->source[0] == UTF_8_BOM_1 + && coding->source[1] == UTF_8_BOM_2 + && coding->source[2] == UTF_8_BOM_3) + { + chars--; + bytes -= 3; + coding->src_bytes -= 3; + } + } else chars = -1; } if (chars >= 0) { - if (coding->eol_seen != EOL_SEEN_NONE) - adjust_coding_eol_type (coding, coding->eol_seen); + Lisp_Object eol_type; - if (coding->eol_seen == EOL_SEEN_CR) + eol_type = CODING_ID_EOL_TYPE (coding->id); + if (VECTORP (eol_type)) + { + if (coding->eol_seen != EOL_SEEN_NONE) + eol_type = adjust_coding_eol_type (coding, coding->eol_seen); + } + if (EQ (eol_type, Qmac)) { unsigned char *src_end = GAP_END_ADDR; unsigned char *src = src_end - coding->src_bytes; @@ -7764,7 +7851,7 @@ decode_coding_gap (struct coding_system *coding, src[-1] = '\n'; } } - else if (coding->eol_seen == EOL_SEEN_CRLF) + else if (EQ (eol_type, Qdos)) { unsigned char *src = GAP_END_ADDR; unsigned char *src_beg = src - coding->src_bytes; -- cgit v1.2.1 From 84575e67fc390815f8f9fc8bea095e006f0890c4 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 16 Jun 2013 23:03:19 -0700 Subject: Use functions, not macros, for XINT etc. In lisp.h, prefer functions to function-like macros, and constants to object-like macros, when either will do. This: . simplifies use, as there's no more need to worry about arguments' side effects being evaluated multiple times. . makes the code easier to debug on some platforms. However, when using gcc -O0, keep using function-like macros for a few critical operations, for performance reasons. This sort of thing isn't needed with gcc -Og, but -Og is a GCC 4.8 feature and isn't widely-enough available yet. Also, move functions from lisp.h to individual modules when possible. From a suggestion by Andreas Schwab in . * alloc.c (XFLOAT_INIT, set_symbol_name): * buffer.c (CHECK_OVERLAY): * chartab.c (CHECK_CHAR_TABLE, set_char_table_ascii) (set_char_table_parent): * coding.c (CHECK_NATNUM_CAR, CHECK_NATNUM_CDR): * data.c (BOOLFWDP, INTFWDP, KBOARD_OBJFWDP, OBJFWDP, XBOOLFWD) (XKBOARD_OBJFWD, XINTFWD, XOBJFWD, CHECK_SUBR, set_blv_found) (blv_value, set_blv_value, set_blv_where, set_blv_defcell) (set_blv_valcell): * emacs.c (setlocale) [!HAVE_SETLOCALE]: * eval.c (specpdl_symbol, specpdl_old_value, specpdl_where) (specpdl_arg, specpdl_func, backtrace_function, backtrace_nargs) (backtrace_args, backtrace_debug_on_exit): * floatfns.c (CHECK_FLOAT): * fns.c (CHECK_HASH_TABLE, CHECK_LIST_END) (set_hash_key_and_value, set_hash_next, set_hash_next_slot) (set_hash_hash, set_hash_hash_slot, set_hash_index) (set_hash_index_slot): * keymap.c (CHECK_VECTOR_OR_CHAR_TABLE): * marker.c (CHECK_MARKER): * textprop.c (CHECK_STRING_OR_BUFFER): * window.c (CHECK_WINDOW_CONFIGURATION): Move here from lisp.h, and make these functions static rather than extern inline. * buffer.c (Qoverlayp): * data.c (Qsubrp): * fns.c (Qhash_table_p): * window.c (Qwindow_configuration_p): Now static. * lisp.h: Remove the abovementioned defns and decls. * configure.ac (WARN_CFLAGS): Remove -Wbad-function-cast, as it generates bogus warnings about reasonable casts of calls. * alloc.c (gdb_make_enums_visible) [USE_LSB_TAG]: Remove enum lsb_bits; no longer needed. (allocate_misc, free_misc): Don't use XMISCTYPE as an lvalue. * buffer.c (Qoverlap): * data.c (Qsubrp): * fns.c (Qhash_table_p): Now extern, so lisp.h can use these symbols. * dispextern.h: Include character.h, for MAX_CHAR etc. (GLYPH, GLYPH_CHAR, GLYPH_FACE, SET_GLYPH_CHAR, SET_GLYPH_FACE) (SET_GLYPH, GLYPH_CODE_CHAR, GLYPH_CODE_FACE) (SET_GLYPH_FROM_GLYPH_CODE, GLYPH_MODE_LINE_FACE, GLYPH_CHAR_VALID_P) (GLYPH_CODE_P): Move here from lisp.h. (GLYPH_CHAR, GLYPH_FACE, GLYPH_CODE_CHAR, GLYPH_CODE_FACE) (GLYPH_CHAR_VALID_P, GLYPH_CODE_P): Now functions, not macros. (GLYPH_MODE_LINE_FACE): Now enums, not macros. * eval.c (Fautoload): Cast XUNTAG output to intptr_t, since XUNTAG now returns void *. * lisp.h (lisp_h_XLI, lisp_h_XIL, lisp_h_CHECK_LIST_CONS) (lisp_h_CHECK_NUMBER CHECK_SYMBOL, lisp_h_CHECK_TYPE) (lisp_h_CONSP, lisp_h_EQ, lisp_h_FLOATP, lisp_h_INTEGERP) (lisp_h_MARKERP, lisp_h_MISCP, lisp_h_NILP) (lisp_h_SET_SYMBOL_VAL, lisp_h_SYMBOL_CONSTANT_P) (lisp_h_SYMBOL_VAL, lisp_h_SYMBOLP, lisp_h_VECTORLIKEP) (lisp_h_XCAR, lisp_h_XCDR, lisp_h_XCONS, lisp_h_XHASH) (lisp_h_XPNTR, lisp_h_XSYMBOL): New macros, renamed from their sans-lisp_h_ counterparts. (XLI, XIL, CHECK_LIST_CONS, CHECK_NUMBER CHECK_SYMBOL) (CHECK_TYPE, CONSP, EQ, FLOATP, INTEGERP, MARKERP) (MISCP, NILP, SET_SYMBOL_VAL, SYMBOL_CONSTANT_P, SYMBOL_VAL, SYMBOLP) (VECTORLIKEP, XCAR, XCDR, XCONS, XHASH, XPNTR, XSYMBOL): If compiling via GCC without optimization, define these as macros in addition to inline functions. To disable this, compile with -DINLINING=0. (LISP_MACRO_DEFUN, LISP_MACRO_DEFUN_VOID): New macros. (check_cons_list) [!GC_CHECK_CONS_LIST]: Likewise. (make_number, XFASTINT, XINT, XTYPE, XUNTAG): Likewise, but hand-optimize only in the USE_LSB_TAG case, as GNUish hosts do that. (INTMASK, VALMASK): Now macros, since static values cannot be accessed from extern inline functions. (VALMASK): Also a constant, for benefit of old GDB. (LISP_INT_TAG_P): Remove; no longer needed as the only caller is INTEGERP, which can fold it in. (XLI, XIL, XHASH, XTYPE,XINT, XFASTINT, XUINT) (make_number, XPNTR, XUNTAG, EQ, XCONS, XVECTOR, XSTRING, XSYMBOL) (XFLOAT, XPROCESS, XWINDOW, XTERMINAL, XSUBR, XBUFFER, XCHAR_TABLE) (XSUB_CHAR_TABLE, XBOOL_VECTOR, make_lisp_ptr, CHECK_TYPE) (CHECK_STRING_OR_BUFFER, XCAR, XCDR, XSETCAR, XSETCDR, CAR, CDR) (CAR_SAFE, CDR_SAFE, STRING_MULTIBYTE, SDATA, SSDATA, SREF, SSET) (SCHARS, STRING_BYTES, SBYTES, STRING_SET_CHARS, STRING_COPYIN, AREF) (ASIZE, ASET, CHAR_TABLE_REF_ASCII, CHAR_TABLE_REF) (CHAR_TABLE_SET, CHAR_TABLE_EXTRA_SLOTS, SYMBOL_VAL, SYMBOL_ALIAS) (SYMBOL_BLV, SYMBOL_FWD, SET_SYMBOL_VAL, SET_SYMBOL_ALIAS) (SET_SYMBOL_BLV, SET_SYMBOL_FWD, SYMBOL_NAME, SYMBOL_INTERNED_P) (SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P, SYMBOL_CONSTANT_P) (XHASH_TABLE, HASH_TABLE_P, CHECK_HASH_TABLE, HASH_KEY, HASH_VALUE) (HASH_NEXT, HASH_HASH, HASH_INDEX, HASH_TABLE_SIZE) (XMISC, XMISCANY, XMARKER, XOVERLAY, XSAVE_VALUE, XFWDTYPE) (XINTFWD, XBOOLFWD, XOBJFWD, XBUFFER_OBJFWD, XKBOARD_OBJFWD) (XFLOAT_DATA, XFLOAT_INIT, NILP, NUMBERP, NATNUMP) (RANGED_INTEGERP, CONSP, FLOATP, MISCP, STRINGP, SYMBOLP) (INTEGERP, VECTORLIKEP, VECTORP, OVERLAYP) (MARKERP, SAVE_VALUEP, AUTOLOADP, INTFWDP, BOOLFWDP, OBJFWDP) (BUFFER_OBJFWDP, KBOARD_OBJFWDP, PSEUDOVECTOR_TYPEP) (PSEUDOVECTORP, WINDOW_CONFIGURATIONP, PROCESSP, WINDOWP) (TERMINALP, SUBRP, COMPILEDP, BUFFERP, CHAR_TABLE_P) (SUB_CHAR_TABLE_P, BOOL_VECTOR_P, FRAMEP, IMAGEP, ARRAYP) (CHECK_LIST, CHECK_LIST_CONS, CHECK_LIST_END, CHECK_STRING) (CHECK_STRING_CAR, CHECK_CONS, CHECK_SYMBOL, CHECK_CHAR_TABLE) (CHECK_VECTOR, CHECK_VECTOR_OR_STRING, CHECK_ARRAY) (CHECK_VECTOR_OR_CHAR_TABLE, CHECK_BUFFER, CHECK_WINDOW) (CHECK_WINDOW_CONFIGURATION, CHECK_PROCESS, CHECK_SUBR) (CHECK_NUMBER, CHECK_NATNUM, CHECK_MARKER, XFLOATINT) (CHECK_FLOAT, CHECK_NUMBER_OR_FLOAT, CHECK_OVERLAY) (CHECK_NUMBER_CAR, CHECK_NUMBER_CDR, CHECK_NATNUM_CAR) (CHECK_NATNUM_CDR, FUNCTIONP, SPECPDL_INDEX, LOADHIST_ATTACH) Now functions. (check_cons_list) [!GC_CHECK_CONS_LIST]: New empty function. (LISP_MAKE_RVALUE, TYPEMASK): Remove; no longer needed. (VALMASK): Define in one place rather than in two, merging the USE_LSB_TAG parts; this is simpler. (aref_addr, gc_aset, MOST_POSITIVE_FIXNUM, MOST_NEGATIVE_FIXNUM) (max, min, struct Lisp_String, UNSIGNED_CMP, ASCII_CHAR_P): Move up, to avoid use before definition. Also include "globals.h" earlier, for the same reason. (make_natnum): New function. (XUNTAG): Now returns void *, not intptr_t, as this means fewer casts. (union Lisp_Fwd, BOOLFWDP, BOOL_VECTOR_P, BUFFER_OBJFWDP, BUFFERP) (CHAR_TABLE_P, CHAR_TABLE_REF_ASCII, CONSP, FLOATP, INTEGERP, INTFWDP) (KBOARD_OBJFWDP, MARKERP, MISCP, NILP, OBJFWDP, OVERLAYP, PROCESSP) (PSEUDOVECTORP, SAVE_VALUEP, STRINGP, SUB_CHAR_TABLE_P, SUBRP, SYMBOLP) (VECTORLIKEP, WINDOWP, Qoverlayp, char_table_ref, char_table_set) (char_table_translate, Qarrayp, Qbufferp, Qbuffer_or_string_p) (Qchar_table_p, Qconsp, Qfloatp, Qintegerp, Qlambda, Qlistp, Qmarkerp) (Qnil, Qnumberp, Qsubrp, Qstringp, Qsymbolp, Qvectorp) (Qvector_or_char_table_p, Qwholenump, Ffboundp, wrong_type_argument) (initialized, Qhash_table_p, extract_float, Qprocessp, Qwindowp) (Qwindow_configuration_p, Qimage): New forward declarations. (XSETFASTINT): Simplify by rewriting in terms of make_natnum. (STRING_COPYIN): Remove; unused. (XCAR_AS_LVALUE, XCDR_AS_LVALUE): Remove these macros, replacing with ... (xcar_addr, xcdr_addr): New functions. All uses changed. (IEEE_FLOATING_POINT): Now a constant, not a macro. (GLYPH, GLYPH_CHAR, GLYPH_FACE, SET_GLYPH_CHAR, SET_GLYPH_FACE) (SET_GLYPH, GLYPH_CODE_CHAR, GLYPH_CODE_FACE) (SET_GLYPH_FROM_GLYPH_CODE, GLYPH_MODE_LINE_FACE, GLYPH_CHAR_VALID_P) (GLYPH_CODE_P): Move to dispextern.h, to avoid define-before-use. (TYPE_RANGED_INTEGERP): Simplify. (Qsubrp, Qhash_table_p, Qoverlayp): New extern decls. (setlocale, fixup_locale, synchronize_system_messages_locale) (synchronize_system_time_locale) [!HAVE_SETLOCALE]: Now empty functions, not macros. (functionp): Return bool, not int. * window.c (Qwindow_configuration_p): Now extern, so window.h can use it. * window.h (Qwindowp): Move decl back to lisp.h. --- src/coding.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 42fd81b6322..497c26d4856 100644 --- a/src/coding.c +++ b/src/coding.c @@ -655,6 +655,22 @@ static struct coding_system coding_categories[coding_category_max]; (charset_list) = CODING_ATTR_CHARSET_LIST (attrs); \ } while (0) +static void +CHECK_NATNUM_CAR (Lisp_Object x) +{ + Lisp_Object tmp = XCAR (x); + CHECK_NATNUM (tmp); + XSETCAR (x, tmp); +} + +static void +CHECK_NATNUM_CDR (Lisp_Object x) +{ + Lisp_Object tmp = XCDR (x); + CHECK_NATNUM (tmp); + XSETCDR (x, tmp); +} + /* Safely get one byte from the source text pointed by SRC which ends at SRC_END, and set C to that byte. If there are not enough bytes -- cgit v1.2.1 From c3a7b3f45f9baffd3e7b4dbc4381fd67356adb44 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Sat, 29 Jun 2013 00:00:17 +0900 Subject: coding.c (setup_coding_system): Handle CODING->spec.undecided. (detect_coding): Likewise. (detect_coding_system): Likewise. (Fdefine_coding_system_internal): New coding system properties :inhibit-null-byte-detection, :inhibit-iso-escape-detection, and :prefer-utf-8. (syms_of_coding): Adjusted for coding_arg_undecided_max. --- src/coding.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 10 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 497c26d4856..c4aaefa8182 100644 --- a/src/coding.c +++ b/src/coding.c @@ -5705,6 +5705,20 @@ setup_coding_system (Lisp_Object coding_system, struct coding_system *coding) coding->decoder = decode_coding_raw_text; coding->encoder = encode_coding_raw_text; coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; + coding->spec.undecided.inhibit_nbd + = (NILP (AREF (attrs, coding_attr_undecided_inhibit_null_byte_detection)) + ? -1 + : EQ (AREF (attrs, coding_attr_undecided_inhibit_null_byte_detection), Qt) + ? 1 + : 0); + coding->spec.undecided.inhibit_ied + = (NILP (AREF (attrs, coding_attr_undecided_inhibit_iso_escape_detection)) + ? -1 + : EQ (AREF (attrs, coding_attr_undecided_inhibit_iso_escape_detection), Qt) + ? 1 + : 0); + coding->spec.undecided.prefer_utf_8 + = ! NILP (AREF (attrs, coding_attr_undecided_prefer_utf_8)); } else if (EQ (coding_type, Qiso_2022)) { @@ -6462,6 +6476,16 @@ detect_coding (struct coding_system *coding) int c, i; struct coding_detection_info detect_info; bool null_byte_found = 0, eight_bit_found = 0; + int inhibit_nbd /* null byte detection */ + = (coding->spec.undecided.inhibit_nbd > 0 + | (coding->spec.undecided.inhibit_nbd == 0 + & inhibit_null_byte_detection)); + int inhibit_ied /* iso escape detection */ + = (coding->spec.undecided.inhibit_ied > 0 + | (coding->spec.undecided.inhibit_ied == 0 + & inhibit_iso_escape_detection)); + int prefer_utf_8 + = coding->spec.undecided.prefer_utf_8; coding->head_ascii = 0; detect_info.checked = detect_info.found = detect_info.rejected = 0; @@ -6477,7 +6501,7 @@ detect_coding (struct coding_system *coding) else if (c < 0x20) { if ((c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) - && ! inhibit_iso_escape_detection + && ! inhibit_ied && ! detect_info.checked) { if (detect_coding_iso_2022 (coding, &detect_info)) @@ -6496,7 +6520,7 @@ detect_coding (struct coding_system *coding) break; } } - else if (! c && !inhibit_null_byte_detection) + else if (! c && !inhibit_nbd) { null_byte_found = 1; if (eight_bit_found) @@ -6553,6 +6577,12 @@ detect_coding (struct coding_system *coding) detect_info.checked |= ~CATEGORY_MASK_UTF_16; detect_info.rejected |= ~CATEGORY_MASK_UTF_16; } + else if (prefer_utf_8 + && detect_coding_utf_8 (coding, &detect_info)) + { + detect_info.checked |= ~CATEGORY_MASK_UTF_8; + detect_info.rejected |= ~CATEGORY_MASK_UTF_8; + } for (i = 0; i < coding_category_raw_text; i++) { category = coding_priorities[i]; @@ -8514,6 +8544,17 @@ detect_coding_system (const unsigned char *src, enum coding_category category IF_LINT (= 0); struct coding_system *this IF_LINT (= NULL); int c, i; + int inhibit_nbd /* null byte detection */ + = (coding.spec.undecided.inhibit_nbd > 0 + | (coding.spec.undecided.inhibit_nbd == 0 + & inhibit_null_byte_detection)); + int inhibit_ied /* iso escape detection */ + = (coding.spec.undecided.inhibit_ied > 0 + | (coding.spec.undecided.inhibit_ied == 0 + & inhibit_iso_escape_detection)); + int prefer_utf_8 + = coding.spec.undecided.prefer_utf_8; + /* Skip all ASCII bytes except for a few ISO2022 controls. */ for (; src < src_end; src++) @@ -8528,7 +8569,7 @@ detect_coding_system (const unsigned char *src, else if (c < 0x20) { if ((c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO) - && ! inhibit_iso_escape_detection + && ! inhibit_ied && ! detect_info.checked) { if (detect_coding_iso_2022 (&coding, &detect_info)) @@ -8547,7 +8588,7 @@ detect_coding_system (const unsigned char *src, break; } } - else if (! c && !inhibit_null_byte_detection) + else if (! c && !inhibit_nbd) { null_byte_found = 1; if (eight_bit_found) @@ -8580,6 +8621,12 @@ detect_coding_system (const unsigned char *src, detect_info.checked |= ~CATEGORY_MASK_UTF_16; detect_info.rejected |= ~CATEGORY_MASK_UTF_16; } + else if (prefer_utf_8 + && detect_coding_utf_8 (&coding, &detect_info)) + { + detect_info.checked |= ~CATEGORY_MASK_UTF_8; + detect_info.rejected |= ~CATEGORY_MASK_UTF_8; + } for (i = 0; i < coding_category_raw_text; i++) { category = coding_priorities[i]; @@ -8918,8 +8965,7 @@ DEFUN ("find-coding-systems-region-internal", Lisp_Object attrs; attrs = AREF (CODING_SYSTEM_SPEC (XCAR (tail)), 0); - if (EQ (XCAR (tail), CODING_ATTR_BASE_NAME (attrs)) - && ! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) + if (EQ (XCAR (tail), CODING_ATTR_BASE_NAME (attrs))) { ASET (attrs, coding_attr_trans_tbl, get_translation_table (attrs, 1, NULL)); @@ -10333,7 +10379,17 @@ usage: (define-coding-system-internal ...) */) : coding_category_utf_8_sig); } else if (EQ (coding_type, Qundecided)) - category = coding_category_undecided; + { + if (nargs < coding_arg_undecided_max) + goto short_args; + ASET (attrs, coding_attr_undecided_inhibit_null_byte_detection, + args[coding_arg_undecided_inhibit_null_byte_detection]); + ASET (attrs, coding_attr_undecided_inhibit_iso_escape_detection, + args[coding_arg_undecided_inhibit_iso_escape_detection]); + ASET (attrs, coding_attr_undecided_prefer_utf_8, + args[coding_arg_undecided_prefer_utf_8]); + category = coding_category_undecided; + } else error ("Invalid coding system type: %s", SDATA (SYMBOL_NAME (coding_type))); @@ -11121,11 +11177,11 @@ internal character representation. */); Vtranslation_table_for_input = Qnil; { - Lisp_Object args[coding_arg_max]; + Lisp_Object args[coding_arg_undecided_max]; Lisp_Object plist[16]; int i; - for (i = 0; i < coding_arg_max; i++) + for (i = 0; i < coding_arg_undecided_max; i++) args[i] = Qnil; plist[0] = intern_c_string (":name"); @@ -11162,7 +11218,7 @@ character."); 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); + Fdefine_coding_system_internal (coding_arg_undecided_max, args); } setup_coding_system (Qno_conversion, &safe_terminal_coding); -- cgit v1.2.1 From 9c90cc06dd36f217422973ea41663a1f2105296f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 29 Jun 2013 08:52:20 -0700 Subject: Fix minor problems found by static checking. * coding.c (encode_inhibit_flag, inhibit_flag): New functions. Redo the latter's body to sidestep GCC parenthesization warnings. (setup_coding_system, detect_coding, detect_coding_system): Use them. * coding.c (detect_coding, detect_coding_system): * coding.h (struct undecided_spec): Use bool for boolean. * image.c (QCmax_width, QCmax_height): Now static. * xdisp.c (Fmove_point_visually): Remove unused local. --- src/coding.c | 62 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index c4aaefa8182..1ab59294b98 100644 --- a/src/coding.c +++ b/src/coding.c @@ -649,6 +649,23 @@ static struct coding_system coding_categories[coding_category_max]; #define max(a, b) ((a) > (b) ? (a) : (b)) #endif +/* Encode a flag that can be nil, something else, or t as -1, 0, 1. */ + +static int +encode_inhibit_flag (Lisp_Object flag) +{ + return NILP (flag) ? -1 : EQ (flag, Qt); +} + +/* True if the value of ENCODED_FLAG says a flag should be treated as set. + 1 means yes, -1 means no, 0 means ask the user variable VAR. */ + +static bool +inhibit_flag (int encoded_flag, bool var) +{ + return 0 < encoded_flag + var; +} + #define CODING_GET_INFO(coding, attrs, charset_list) \ do { \ (attrs) = CODING_ID_ATTRS ((coding)->id); \ @@ -5706,17 +5723,11 @@ setup_coding_system (Lisp_Object coding_system, struct coding_system *coding) coding->encoder = encode_coding_raw_text; coding->common_flags |= CODING_REQUIRE_DETECTION_MASK; coding->spec.undecided.inhibit_nbd - = (NILP (AREF (attrs, coding_attr_undecided_inhibit_null_byte_detection)) - ? -1 - : EQ (AREF (attrs, coding_attr_undecided_inhibit_null_byte_detection), Qt) - ? 1 - : 0); + = (encode_inhibit_flag + (AREF (attrs, coding_attr_undecided_inhibit_null_byte_detection))); coding->spec.undecided.inhibit_ied - = (NILP (AREF (attrs, coding_attr_undecided_inhibit_iso_escape_detection)) - ? -1 - : EQ (AREF (attrs, coding_attr_undecided_inhibit_iso_escape_detection), Qt) - ? 1 - : 0); + = (encode_inhibit_flag + (AREF (attrs, coding_attr_undecided_inhibit_iso_escape_detection))); coding->spec.undecided.prefer_utf_8 = ! NILP (AREF (attrs, coding_attr_undecided_prefer_utf_8)); } @@ -6476,16 +6487,11 @@ detect_coding (struct coding_system *coding) int c, i; struct coding_detection_info detect_info; bool null_byte_found = 0, eight_bit_found = 0; - int inhibit_nbd /* null byte detection */ - = (coding->spec.undecided.inhibit_nbd > 0 - | (coding->spec.undecided.inhibit_nbd == 0 - & inhibit_null_byte_detection)); - int inhibit_ied /* iso escape detection */ - = (coding->spec.undecided.inhibit_ied > 0 - | (coding->spec.undecided.inhibit_ied == 0 - & inhibit_iso_escape_detection)); - int prefer_utf_8 - = coding->spec.undecided.prefer_utf_8; + bool inhibit_nbd = inhibit_flag (coding->spec.undecided.inhibit_nbd, + inhibit_null_byte_detection); + bool inhibit_ied = inhibit_flag (coding->spec.undecided.inhibit_ied, + inhibit_iso_escape_detection); + bool prefer_utf_8 = coding->spec.undecided.prefer_utf_8; coding->head_ascii = 0; detect_info.checked = detect_info.found = detect_info.rejected = 0; @@ -8544,17 +8550,11 @@ detect_coding_system (const unsigned char *src, enum coding_category category IF_LINT (= 0); struct coding_system *this IF_LINT (= NULL); int c, i; - int inhibit_nbd /* null byte detection */ - = (coding.spec.undecided.inhibit_nbd > 0 - | (coding.spec.undecided.inhibit_nbd == 0 - & inhibit_null_byte_detection)); - int inhibit_ied /* iso escape detection */ - = (coding.spec.undecided.inhibit_ied > 0 - | (coding.spec.undecided.inhibit_ied == 0 - & inhibit_iso_escape_detection)); - int prefer_utf_8 - = coding.spec.undecided.prefer_utf_8; - + bool inhibit_nbd = inhibit_flag (coding.spec.undecided.inhibit_nbd, + inhibit_null_byte_detection); + bool inhibit_ied = inhibit_flag (coding.spec.undecided.inhibit_ied, + inhibit_iso_escape_detection); + bool prefer_utf_8 = coding.spec.undecided.prefer_utf_8; /* Skip all ASCII bytes except for a few ISO2022 controls. */ for (; src < src_end; src++) -- cgit v1.2.1 From f9a74c4cc26f349abaaa073d4f56a09405a6f8c3 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 13 Jul 2013 13:29:15 +0300 Subject: Fix bug #14822 with decoding when inhibit-null-byte-detection is non-nil. src/coding.c (syms_of_coding): Set up inhibit-null-byte-detection and inhibit-iso-escape-detection attributes of 'undecided'. --- src/coding.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 1ab59294b98..a1494ad38aa 100644 --- a/src/coding.c +++ b/src/coding.c @@ -11218,6 +11218,8 @@ character."); 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); + args[coding_arg_undecided_inhibit_null_byte_detection] = make_number (0); + args[coding_arg_undecided_inhibit_iso_escape_detection] = make_number (0); Fdefine_coding_system_internal (coding_arg_undecided_max, args); } -- cgit v1.2.1 From 6c6f1994bf684f510d600bd18023fa01b4b06500 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 15 Jul 2013 23:39:49 -0700 Subject: Prefer list1 (X) to Fcons (X, Qnil) when building lists. This makes the code easier to read and the executable a bit smaller. Do not replace all calls to Fcons that happen to create lists, just calls that are intended to create lists. For example, when creating an alist that maps FOO to nil, use list1 (Fcons (FOO, Qnil)) rather than list1 (list1 (FOO)) or Fcons (Fcons (FOO, Qnil), Qnil). Similarly for list2 through list5. * buffer.c (Fget_buffer_create, Fmake_indirect_buffer): * bytecode.c (exec_byte_code): * callint.c (quotify_arg, Fcall_interactively): * callproc.c (Fcall_process, create_temp_file): * charset.c (load_charset_map_from_file) (Fdefine_charset_internal, init_charset): * coding.c (get_translation_table, detect_coding_system) (Fcheck_coding_systems_region) (Fset_terminal_coding_system_internal) (Fdefine_coding_system_internal, Fdefine_coding_system_alias): * composite.c (update_compositions, Ffind_composition_internal): * dired.c (directory_files_internal, file_name_completion) (Fsystem_users): * dispnew.c (Fopen_termscript, bitch_at_user, init_display): * doc.c (Fsnarf_documentation): * editfns.c (Fmessage_box): * emacs.c (main): * eval.c (do_debug_on_call, signal_error, maybe_call_debugger) (Feval, eval_sub, Ffuncall, apply_lambda): * fileio.c (make_temp_name, Fcopy_file, Faccess_file) (Fset_file_selinux_context, Fset_file_acl, Fset_file_modes) (Fset_file_times, Finsert_file_contents) (Fchoose_write_coding_system, Fwrite_region): * fns.c (Flax_plist_put, Fyes_or_no_p, syms_of_fns): * font.c (font_registry_charsets, font_parse_fcname) (font_prepare_cache, font_update_drivers, Flist_fonts): * fontset.c (Fset_fontset_font, Ffontset_info, syms_of_fontset): * frame.c (make_frame, Fmake_terminal_frame) (x_set_frame_parameters, x_report_frame_params) (x_default_parameter, Fx_parse_geometry): * ftfont.c (syms_of_ftfont): * image.c (gif_load): * keyboard.c (command_loop_1): * keymap.c (Fmake_keymap, Fmake_sparse_keymap, access_keymap_1) (Fcopy_keymap, append_key, Fcurrent_active_maps) (Fminor_mode_key_binding, accessible_keymaps_1) (Faccessible_keymaps, Fwhere_is_internal): * lread.c (read_emacs_mule_char): * menu.c (find_and_return_menu_selection): * minibuf.c (get_minibuffer): * nsfns.m (Fns_perform_service): * nsfont.m (ns_script_to_charset): * nsmenu.m (ns_popup_dialog): * nsselect.m (ns_get_local_selection, ns_string_from_pasteboard) (Fx_own_selection_internal): * nsterm.m (append2): * print.c (Fredirect_debugging_output) (print_prune_string_charset): * process.c (Fdelete_process, Fprocess_contact) (Fformat_network_address, set_socket_option) (read_and_dispose_of_process_output, write_queue_push) (send_process, exec_sentinel): * sound.c (Fplay_sound_internal): * textprop.c (validate_plist, add_properties) (Fput_text_property, Fadd_face_text_property) (copy_text_properties, text_property_list, syms_of_textprop): * unexaix.c (report_error): * unexcoff.c (report_error): * unexsol.c (unexec): * xdisp.c (redisplay_tool_bar, store_mode_line_string) (Fformat_mode_line, syms_of_xdisp): * xfaces.c (set_font_frame_param) (Finternal_lisp_face_attribute_values) (Finternal_merge_in_global_face, syms_of_xfaces): * xfns.c (x_default_scroll_bar_color_parameter) (x_default_font_parameter, x_create_tip_frame): * xfont.c (xfont_supported_scripts): * xmenu.c (Fx_popup_dialog, xmenu_show, xdialog_show) (menu_help_callback, xmenu_show): * xml.c (make_dom): * xterm.c (set_wm_state): Prefer list1 (FOO) to Fcons (FOO, Qnil) when creating a list, and similarly for list2 through list5. --- src/coding.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index a1494ad38aa..8dcc4013c1d 100644 --- a/src/coding.c +++ b/src/coding.c @@ -6864,11 +6864,9 @@ get_translation_table (Lisp_Object attrs, bool encodep, int *max_lookup) if (CHAR_TABLE_P (standard)) { if (CONSP (translation_table)) - translation_table = nconc2 (translation_table, - Fcons (standard, Qnil)); + translation_table = nconc2 (translation_table, list1 (standard)); else - translation_table = Fcons (translation_table, - Fcons (standard, Qnil)); + translation_table = list2 (translation_table, standard); } } @@ -8667,20 +8665,20 @@ detect_coding_system (const unsigned char *src, { detect_info.found = CATEGORY_MASK_RAW_TEXT; id = CODING_SYSTEM_ID (Qno_conversion); - val = Fcons (make_number (id), Qnil); + val = list1 (make_number (id)); } else if (! detect_info.rejected && ! detect_info.found) { detect_info.found = CATEGORY_MASK_ANY; id = coding_categories[coding_category_undecided].id; - val = Fcons (make_number (id), Qnil); + val = list1 (make_number (id)); } else if (highest) { if (detect_info.found) { detect_info.found = 1 << category; - val = Fcons (make_number (this->id), Qnil); + val = list1 (make_number (this->id)); } else for (i = 0; i < coding_category_raw_text; i++) @@ -8688,7 +8686,7 @@ detect_coding_system (const unsigned char *src, { detect_info.found = 1 << coding_priorities[i]; id = coding_categories[coding_priorities[i]].id; - val = Fcons (make_number (id), Qnil); + val = list1 (make_number (id)); break; } } @@ -8705,7 +8703,7 @@ detect_coding_system (const unsigned char *src, found |= 1 << category; id = coding_categories[category].id; if (id >= 0) - val = Fcons (make_number (id), val); + val = list1 (make_number (id)); } } for (i = coding_category_raw_text - 1; i >= 0; i--) @@ -8730,7 +8728,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 = Fcons (make_number (this->id), Qnil); + val = list1 (make_number (this->id)); } } else if (base_category == coding_category_utf_16_auto) @@ -8747,13 +8745,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 = Fcons (make_number (this->id), Qnil); + val = list1 (make_number (this->id)); } } else { detect_info.found = 1 << XINT (CODING_ATTR_CATEGORY (attrs)); - val = Fcons (make_number (coding.id), Qnil); + val = list1 (make_number (coding.id)); } /* Then, detect eol-format if necessary. */ @@ -9224,7 +9222,7 @@ is nil. */) attrs = AREF (CODING_SYSTEM_SPEC (elt), 0); ASET (attrs, coding_attr_trans_tbl, get_translation_table (attrs, 1, NULL)); - list = Fcons (Fcons (elt, Fcons (attrs, Qnil)), list); + list = Fcons (list2 (elt, attrs), list); } if (STRINGP (start)) @@ -9635,7 +9633,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) - : Fcons (make_number (charset_ascii), Qnil))); + : list1 (make_number (charset_ascii)))); return Qnil; } @@ -10080,9 +10078,9 @@ usage: (define-coding-system-internal ...) */) { dim2 = CHARSET_DIMENSION (CHARSET_FROM_ID (XFASTINT (tmp))); if (dim < dim2) - tmp = Fcons (XCAR (tail), Fcons (tmp, Qnil)); + tmp = list2 (XCAR (tail), tmp); else - tmp = Fcons (tmp, Fcons (XCAR (tail), Qnil)); + tmp = list2 (tmp, XCAR (tail)); } else { @@ -10093,7 +10091,7 @@ usage: (define-coding-system-internal ...) */) break; } if (NILP (tmp2)) - tmp = nconc2 (tmp, Fcons (XCAR (tail), Qnil)); + tmp = nconc2 (tmp, list1 (XCAR (tail))); else { XSETCDR (tmp2, Fcons (XCAR (tmp2), XCDR (tmp2))); @@ -10411,7 +10409,7 @@ usage: (define-coding-system-internal ...) */) && ! EQ (eol_type, Qmac)) error ("Invalid eol-type"); - aliases = Fcons (name, Qnil); + aliases = list1 (name); if (NILP (eol_type)) { @@ -10421,7 +10419,7 @@ usage: (define-coding-system-internal ...) */) Lisp_Object this_spec, this_name, this_aliases, this_eol_type; this_name = AREF (eol_type, i); - this_aliases = Fcons (this_name, Qnil); + this_aliases = list1 (this_name); this_eol_type = (i == 0 ? Qunix : i == 1 ? Qdos : Qmac); this_spec = make_uninit_vector (3); ASET (this_spec, 0, attrs); @@ -10536,7 +10534,7 @@ DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias, list. */ while (!NILP (XCDR (aliases))) aliases = XCDR (aliases); - XSETCDR (aliases, Fcons (alias, Qnil)); + XSETCDR (aliases, list1 (alias)); eol_type = AREF (spec, 2); if (VECTORP (eol_type)) -- cgit v1.2.1 From 27e498e6e5fea8ac64c90ac13678b537b7b12302 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 16 Jul 2013 14:35:45 -0700 Subject: New unwind-protect flavors to better type-check C callbacks. This also lessens the need to write wrappers for callbacks, and the need for make_save_pointer. * alloca.c (free_save_value): * atimer.c (run_all_atimers): Now extern. * alloc.c (safe_alloca_unwind): * atimer.c (unwind_stop_other_atimers): * keyboard.c (cancel_hourglass_unwind) [HAVE_WINDOW_SYSTEM]: * menu.c (cleanup_popup_menu) [HAVE_NS]: * minibuf.c (choose_minibuf_frame_1): * process.c (make_serial_process_unwind): * xdisp.h (pop_message_unwind): * xselect.c (queue_selection_requests_unwind): Remove no-longer-needed wrapper. All uses replaced by the wrappee. * alloca.c (record_xmalloc): Prefer record_unwind_protect_ptr to record_unwind_protect with make_save_pointer. * alloca.c (Fgarbage_collect): Prefer record_unwind_protect_void to passing a dummy. * buffer.c (restore_buffer): * window.c (restore_window_configuration): * xfns.c, w32fns.c (do_unwind_create_frame) New wrapper. All record-unwind uses of wrappee changed. * buffer.c (set_buffer_if_live): * callproc.c (call_process_cleanup, delete_temp_file): * coding.c (code_conversion_restore): * dired.c (directory_files_internal_w32_unwind) [WINDOWSNT]: * editfns.c (save_excursion_restore) (subst_char_in_region_unwind, subst_char_in_region_unwind_1) (save_restriction_restore): * eval.c (restore_stack_limits, un_autoload): * fns.c (require_unwind): * keyboard.c (recursive_edit_unwind, tracking_off): * lread.c (record_load_unwind, load_warn_old_style_backquotes): * macros.c (pop_kbd_macro, restore_menu_items): * nsfns.m (unwind_create_frame): * print.c (print_unwind): * process.c (start_process_unwind): * search.c (unwind_set_match_data): * window.c (select_window_norecord, select_frame_norecord): * xdisp.c (unwind_with_echo_area_buffer, unwind_format_mode_line) (fast_set_selected_frame): * xfns.c, w32fns.c (unwind_create_tip_frame): Return void, not a dummy Lisp_Object. All uses changed. * buffer.h (set_buffer_if_live): Move decl here from lisp.h. * callproc.c (call_process_kill): * fileio.c (restore_point_unwind, decide_coding_unwind) (build_annotations_unwind): * insdel.c (Fcombine_after_change_execute_1): * keyboard.c (read_char_help_form_unwind): * menu.c (unuse_menu_items): * minibuf.c (run_exit_minibuf_hook, read_minibuf_unwind): * sound.c (sound_cleanup): * xdisp.c (unwind_redisplay): * xfns.c (clean_up_dialog): * xselect.c (x_selection_request_lisp_error, x_catch_errors_unwind): Accept no args and return void, instead of accepting and returning a dummy Lisp_Object. All uses changed. * cygw32.c (fchdir_unwind): * fileio.c (close_file_unwind): * keyboard.c (restore_kboard_configuration): * lread.c (readevalllop_1): * process.c (wait_reading_process_output_unwind): Accept int and return void, rather than accepting an Emacs integer and returning a dummy object. In some cases this fixes an unlikely bug when the corresponding int is outside Emacs integer range. All uses changed. * dired.c (directory_files_internal_unwind): * fileio.c (do_auto_save_unwind): * gtkutil.c (pop_down_dialog): * insdel.c (reset_var_on_error): * lread.c (load_unwind): * xfns.c (clean_up_file_dialog): * xmenu.c, nsmenu.m (pop_down_menu): * xmenu.c (cleanup_widget_value_tree): * xselect.c (wait_for_property_change_unwind): Accept pointer and return void, rather than accepting an Emacs save value encapsulating the pointer and returning a dummy object. All uses changed. * editfns.c (Fformat): Update the saved pointer directly via set_unwind_protect_ptr rather than indirectly via make_save_pointer. * eval.c (specpdl_func): Remove. All uses replaced by definiens. (unwind_body): New function. (record_unwind_protect): First arg is now a function returning void, not a dummy Lisp_Object. (record_unwind_protect_ptr, record_unwind_protect_int) (record_unwind_protect_void): New functions. (unbind_to): Support SPECPDL_UNWIND_PTR etc. * fileio.c (struct auto_save_unwind): New type. (do_auto_save_unwind): Use it. (do_auto_save_unwind_1): Remove; subsumed by new do_auto_save_unwind. * insdel.c (struct rvoe_arg): New type. (reset_var_on_error): Use it. * lisp.h (SPECPDL_UNWIND_PTR, SPECPDL_UNWIND_INT, SPECPDL_UNWIND_VOID): New constants. (specbinding_func): Remove; there are now several such functions. (union specbinding): New members unwind_ptr, unwind_int, unwind_void. (set_unwind_protect_ptr): New function. * xselect.c: Remove unnecessary forward decls, to simplify maintenance. --- src/coding.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 8dcc4013c1d..e779197bbde 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7791,7 +7791,7 @@ make_conversion_work_buffer (bool multibyte) } -static Lisp_Object +static void code_conversion_restore (Lisp_Object arg) { Lisp_Object current, workbuf; @@ -7809,7 +7809,6 @@ code_conversion_restore (Lisp_Object arg) } set_buffer_internal (XBUFFER (current)); UNGCPRO; - return Qnil; } Lisp_Object -- cgit v1.2.1 From a1aeeffedd3b05a33bdd73737651debbda00cf5f Mon Sep 17 00:00:00 2001 From: Richard M. Stallman Date: Fri, 19 Jul 2013 12:15:51 -0400 Subject: (decode_coding_utf_8): Add simple loop for fast processing of ASCII characters. --- src/coding.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index e779197bbde..385a22a188d 100644 --- a/src/coding.c +++ b/src/coding.c @@ -1363,6 +1363,45 @@ decode_coding_utf_8 (struct coding_system *coding) break; } + /* In the simple case, rapidly handle ordinary characters */ + if (multibytep && ! eol_dos + && charbuf < charbuf_end - 6 && src < src_end - 6) + { + while (charbuf < charbuf_end - 6 && src < src_end - 6) + { + c1 = *src; + if (c1 & 0x80) + break; + src++; + consumed_chars++; + *charbuf++ = c1; + + c1 = *src; + if (c1 & 0x80) + break; + src++; + consumed_chars++; + *charbuf++ = c1; + + c1 = *src; + if (c1 & 0x80) + break; + src++; + consumed_chars++; + *charbuf++ = c1; + + c1 = *src; + if (c1 & 0x80) + break; + src++; + consumed_chars++; + *charbuf++ = c1; + } + /* If we handled at least one character, restart the main loop. */ + if (src != src_base) + continue; + } + if (byte_after_cr >= 0) c1 = byte_after_cr, byte_after_cr = -1; else -- cgit v1.2.1 From 99107004b1126160d8dc69df59af03dfb62d2f54 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Sat, 20 Jul 2013 13:19:05 +0900 Subject: * coding.c (CODING_ISO_FLAG_LEVEL_4): New macro. (decode_coding_iso_2022): Check the single-shift area. (Bug#8522) --- src/coding.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index e779197bbde..ad2042672b2 100644 --- a/src/coding.c +++ b/src/coding.c @@ -493,6 +493,8 @@ enum iso_code_class_type #define CODING_ISO_FLAG_USE_OLDJIS 0x10000 +#define CODING_ISO_FLAG_LEVEL_4 0x20000 + #define CODING_ISO_FLAG_FULL_SUPPORT 0x100000 /* A character to be produced on output if encoding of the original @@ -3733,7 +3735,9 @@ decode_coding_iso_2022 (struct coding_system *coding) else charset = CHARSET_FROM_ID (charset_id_2); ONE_MORE_BYTE (c1); - if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) + if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0) + || ((CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LEVEL_4) + ? c1 >= 0x80 : c1 < 0x80)) goto invalid_code; break; @@ -3747,7 +3751,9 @@ decode_coding_iso_2022 (struct coding_system *coding) else charset = CHARSET_FROM_ID (charset_id_3); ONE_MORE_BYTE (c1); - if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0)) + if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0) + || ((CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LEVEL_4) + ? c1 >= 0x80 : c1 < 0x80)) goto invalid_code; break; -- cgit v1.2.1 From 0efe47a860bba25617132f02e2220056bfa098b0 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Sat, 20 Jul 2013 20:45:50 +0900 Subject: coding.c (decode_coding_iso_2022): Fix previous change. --- src/coding.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index ad2042672b2..3acbd090e13 100644 --- a/src/coding.c +++ b/src/coding.c @@ -3736,8 +3736,9 @@ decode_coding_iso_2022 (struct coding_system *coding) charset = CHARSET_FROM_ID (charset_id_2); ONE_MORE_BYTE (c1); if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0) - || ((CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LEVEL_4) - ? c1 >= 0x80 : c1 < 0x80)) + || (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) + && ((CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LEVEL_4) + ? c1 >= 0x80 : c1 < 0x80))) goto invalid_code; break; @@ -3752,8 +3753,9 @@ decode_coding_iso_2022 (struct coding_system *coding) charset = CHARSET_FROM_ID (charset_id_3); ONE_MORE_BYTE (c1); if (c1 < 0x20 || (c1 >= 0x80 && c1 < 0xA0) - || ((CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LEVEL_4) - ? c1 >= 0x80 : c1 < 0x80)) + || (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_SEVEN_BITS) + && ((CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_LEVEL_4) + ? c1 >= 0x80 : c1 < 0x80))) goto invalid_code; break; -- cgit v1.2.1 From 75c59fb3ec3188d4c7c20675b7beaa07cb0c1891 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Sat, 3 Aug 2013 22:16:43 +0400 Subject: Do not use global Lisp_Object in composition macros. * composite.h (composition_temp): Remove declaration. (COMPOSITION_METHOD, COMPOSITION_VALID_P): Replace with... (composition_method, composition_valid_p): ...inline functions. * composite.c (composition_temp): Remove. (run_composition_function, update_compositions) (composition_compute_stop_pos, composition_adjust_point) (Ffind_composition_internal): * coding.c (handle_composition_annotation): * xdisp.c (handle_composition_prop, check_point_in_composition): Related users changed. --- 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 0cdd8f9cd9e..5b637627763 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7497,7 +7497,7 @@ handle_composition_annotation (ptrdiff_t pos, ptrdiff_t limit, /* We found a composition. Store the corresponding annotation data in BUF. */ int *head = buf; - enum composition_method method = COMPOSITION_METHOD (prop); + enum composition_method method = composition_method (prop); int nchars = COMPOSITION_LENGTH (prop); ADD_COMPOSITION_DATA (buf, nchars, 0, method); -- cgit v1.2.1 From c76826d98c8f890d8877c9ed5e7738d3268a70af Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Mon, 26 Aug 2013 09:20:59 +0400 Subject: * syntax.c (init_syntax_once): Adjust comment and do an early initialization of Qchar_table_extra_slots just once... * casetab.c (init_casetab_once): * category.c (init_category_once): * character.c (syms_of_character): * coding.c (syms_of_coding): * xdisp.c (syms_of_xdisp): ...and omit it here. --- src/coding.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 5b637627763..c10fb375672 100644 --- a/src/coding.c +++ b/src/coding.c @@ -10814,11 +10814,6 @@ syms_of_coding (void) Fput (Qcoding_system_error, Qerror_message, build_pure_c_string ("Invalid coding system")); - /* Intern this now in case it isn't already done. - Setting this variable twice is harmless. - But don't staticpro it here--that is done in alloc.c. */ - Qchar_table_extra_slots = intern_c_string ("char-table-extra-slots"); - DEFSYM (Qtranslation_table, "translation-table"); Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (2)); DEFSYM (Qtranslation_table_id, "translation-table-id"); -- cgit v1.2.1