diff options
| author | Dmitry Antipov | 2013-03-06 15:26:30 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2013-03-06 15:26:30 +0400 |
| commit | 1af1a51aada18d88fac7b2ba09231428c6a65d7c (patch) | |
| tree | 0de56c02accf7de21dff3d26da734374ab2c9b6f /src | |
| parent | 34fd7a48dde735b199d618c06ea87a5e8f193406 (diff) | |
| download | emacs-1af1a51aada18d88fac7b2ba09231428c6a65d7c.tar.gz emacs-1af1a51aada18d88fac7b2ba09231428c6a65d7c.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 19 | ||||
| -rw-r--r-- | src/coding.c | 45 | ||||
| -rw-r--r-- | src/coding.h | 34 |
3 files changed, 37 insertions, 61 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index bbf2aae960a..00d78a83336 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,22 @@ | |||
| 1 | 2013-03-06 Dmitry Antipov <dmantipov@yandex.ru> | ||
| 2 | |||
| 3 | Coding system support cleanup and minor refactoring. | ||
| 4 | * coding.h (enum coding_result_code): Remove | ||
| 5 | CODING_RESULT_INCONSISTENT_EOL and CODING_RESULT_INSUFFICIENT_MEM. | ||
| 6 | (toplevel): Remove unused CODING_MODE_INHIBIT_INCONSISTENT_EOL. | ||
| 7 | (CODING_MODE_LAST_BLOCK, CODING_MODE_SELECTIVE_DISPLAY) | ||
| 8 | (CODING_MODE_DIRECTION, CODING_MODE_FIXED_DESTINATION) | ||
| 9 | (CODING_MODE_SAFE_ENCODING): Rearrange bit values. | ||
| 10 | (decode_coding_region, encode_coding_region, decode_coding_string): | ||
| 11 | Remove unused compatibility macros. | ||
| 12 | * coding.c (Qinconsistent_eol, Qinsufficient_memory): Remove. | ||
| 13 | (record_conversion_result): Adjust user. | ||
| 14 | (syms_of_coding): Likewise. | ||
| 15 | (ALLOC_CONVERSION_WORK_AREA): Use SAFE_ALLOCA. | ||
| 16 | (decode_coding, encode_coding): Add USE_SAFE_ALLOCA and SAFE_FREE. | ||
| 17 | (decode_coding_object): Simplify since xrealloc never returns NULL. | ||
| 18 | Add eassert. | ||
| 19 | |||
| 1 | 2013-03-06 Paul Eggert <eggert@cs.ucla.edu> | 20 | 2013-03-06 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 21 | ||
| 3 | Fix a build failure on OpenBSD 4.x and MirBSD (Bug#13881). | 22 | Fix a build failure on OpenBSD 4.x and MirBSD (Bug#13881). |
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; | |||
| 322 | Lisp_Object Qstart_process, Qopen_network_stream; | 322 | Lisp_Object Qstart_process, Qopen_network_stream; |
| 323 | static Lisp_Object Qtarget_idx; | 323 | static Lisp_Object Qtarget_idx; |
| 324 | 324 | ||
| 325 | static Lisp_Object Qinsufficient_source, Qinconsistent_eol, Qinvalid_source; | 325 | static Lisp_Object Qinsufficient_source, Qinvalid_source, Qinterrupted; |
| 326 | static Lisp_Object Qinterrupted, Qinsufficient_memory; | ||
| 327 | 326 | ||
| 328 | /* If a symbol has this property, evaluate the value to define the | 327 | /* If a symbol has this property, evaluate the value to define the |
| 329 | symbol as a coding system. */ | 328 | symbol as a coding system. */ |
| @@ -820,18 +819,12 @@ record_conversion_result (struct coding_system *coding, | |||
| 820 | case CODING_RESULT_INSUFFICIENT_SRC: | 819 | case CODING_RESULT_INSUFFICIENT_SRC: |
| 821 | Vlast_code_conversion_error = Qinsufficient_source; | 820 | Vlast_code_conversion_error = Qinsufficient_source; |
| 822 | break; | 821 | break; |
| 823 | case CODING_RESULT_INCONSISTENT_EOL: | ||
| 824 | Vlast_code_conversion_error = Qinconsistent_eol; | ||
| 825 | break; | ||
| 826 | case CODING_RESULT_INVALID_SRC: | 822 | case CODING_RESULT_INVALID_SRC: |
| 827 | Vlast_code_conversion_error = Qinvalid_source; | 823 | Vlast_code_conversion_error = Qinvalid_source; |
| 828 | break; | 824 | break; |
| 829 | case CODING_RESULT_INTERRUPT: | 825 | case CODING_RESULT_INTERRUPT: |
| 830 | Vlast_code_conversion_error = Qinterrupted; | 826 | Vlast_code_conversion_error = Qinterrupted; |
| 831 | break; | 827 | break; |
| 832 | case CODING_RESULT_INSUFFICIENT_MEM: | ||
| 833 | Vlast_code_conversion_error = Qinsufficient_memory; | ||
| 834 | break; | ||
| 835 | case CODING_RESULT_INSUFFICIENT_DST: | 828 | case CODING_RESULT_INSUFFICIENT_DST: |
| 836 | /* Don't record this error in Vlast_code_conversion_error | 829 | /* Don't record this error in Vlast_code_conversion_error |
| 837 | because it happens just temporarily and is resolved when the | 830 | 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) | |||
| 6884 | 6877 | ||
| 6885 | #define ALLOC_CONVERSION_WORK_AREA(coding) \ | 6878 | #define ALLOC_CONVERSION_WORK_AREA(coding) \ |
| 6886 | do { \ | 6879 | do { \ |
| 6887 | int size = CHARBUF_SIZE; \ | 6880 | coding->charbuf = SAFE_ALLOCA (CHARBUF_SIZE * sizeof (int)); \ |
| 6888 | \ | 6881 | coding->charbuf_size = CHARBUF_SIZE; \ |
| 6889 | coding->charbuf = NULL; \ | ||
| 6890 | while (size > 1024) \ | ||
| 6891 | { \ | ||
| 6892 | coding->charbuf = alloca (sizeof (int) * size); \ | ||
| 6893 | if (coding->charbuf) \ | ||
| 6894 | break; \ | ||
| 6895 | size >>= 1; \ | ||
| 6896 | } \ | ||
| 6897 | if (! coding->charbuf) \ | ||
| 6898 | { \ | ||
| 6899 | record_conversion_result (coding, CODING_RESULT_INSUFFICIENT_MEM); \ | ||
| 6900 | return; \ | ||
| 6901 | } \ | ||
| 6902 | coding->charbuf_size = size; \ | ||
| 6903 | } while (0) | 6882 | } while (0) |
| 6904 | 6883 | ||
| 6905 | 6884 | ||
| @@ -6968,6 +6947,8 @@ decode_coding (struct coding_system *coding) | |||
| 6968 | int carryover; | 6947 | int carryover; |
| 6969 | int i; | 6948 | int i; |
| 6970 | 6949 | ||
| 6950 | USE_SAFE_ALLOCA; | ||
| 6951 | |||
| 6971 | if (BUFFERP (coding->src_object) | 6952 | if (BUFFERP (coding->src_object) |
| 6972 | && coding->src_pos > 0 | 6953 | && coding->src_pos > 0 |
| 6973 | && coding->src_pos < GPT | 6954 | && coding->src_pos < GPT |
| @@ -7090,6 +7071,8 @@ decode_coding (struct coding_system *coding) | |||
| 7090 | bset_undo_list (current_buffer, undo_list); | 7071 | bset_undo_list (current_buffer, undo_list); |
| 7091 | record_insert (coding->dst_pos, coding->produced_char); | 7072 | record_insert (coding->dst_pos, coding->produced_char); |
| 7092 | } | 7073 | } |
| 7074 | |||
| 7075 | SAFE_FREE (); | ||
| 7093 | } | 7076 | } |
| 7094 | 7077 | ||
| 7095 | 7078 | ||
| @@ -7373,6 +7356,8 @@ encode_coding (struct coding_system *coding) | |||
| 7373 | int max_lookup; | 7356 | int max_lookup; |
| 7374 | struct ccl_spec cclspec; | 7357 | struct ccl_spec cclspec; |
| 7375 | 7358 | ||
| 7359 | USE_SAFE_ALLOCA; | ||
| 7360 | |||
| 7376 | attrs = CODING_ID_ATTRS (coding->id); | 7361 | attrs = CODING_ID_ATTRS (coding->id); |
| 7377 | if (coding->encoder == encode_coding_raw_text) | 7362 | if (coding->encoder == encode_coding_raw_text) |
| 7378 | translation_table = Qnil, max_lookup = 0; | 7363 | translation_table = Qnil, max_lookup = 0; |
| @@ -7407,6 +7392,8 @@ encode_coding (struct coding_system *coding) | |||
| 7407 | 7392 | ||
| 7408 | if (BUFFERP (coding->dst_object) && coding->produced_char > 0) | 7393 | if (BUFFERP (coding->dst_object) && coding->produced_char > 0) |
| 7409 | insert_from_gap (coding->produced_char, coding->produced); | 7394 | insert_from_gap (coding->produced_char, coding->produced); |
| 7395 | |||
| 7396 | SAFE_FREE (); | ||
| 7410 | } | 7397 | } |
| 7411 | 7398 | ||
| 7412 | 7399 | ||
| @@ -7695,14 +7682,8 @@ decode_coding_object (struct coding_system *coding, | |||
| 7695 | set_buffer_internal (XBUFFER (coding->dst_object)); | 7682 | set_buffer_internal (XBUFFER (coding->dst_object)); |
| 7696 | if (dst_bytes < coding->produced) | 7683 | if (dst_bytes < coding->produced) |
| 7697 | { | 7684 | { |
| 7685 | eassert (coding->produced > 0); | ||
| 7698 | destination = xrealloc (destination, coding->produced); | 7686 | destination = xrealloc (destination, coding->produced); |
| 7699 | if (! destination) | ||
| 7700 | { | ||
| 7701 | record_conversion_result (coding, | ||
| 7702 | CODING_RESULT_INSUFFICIENT_MEM); | ||
| 7703 | unbind_to (count, Qnil); | ||
| 7704 | return; | ||
| 7705 | } | ||
| 7706 | if (BEGV < GPT && GPT < BEGV + coding->produced_char) | 7687 | if (BEGV < GPT && GPT < BEGV + coding->produced_char) |
| 7707 | move_gap_both (BEGV, BEGV_BYTE); | 7688 | move_gap_both (BEGV, BEGV_BYTE); |
| 7708 | memcpy (destination, BEGV_ADDR, coding->produced); | 7689 | memcpy (destination, BEGV_ADDR, coding->produced); |
| @@ -10408,10 +10389,8 @@ syms_of_coding (void) | |||
| 10408 | intern_c_string ("coding-category-undecided")); | 10389 | intern_c_string ("coding-category-undecided")); |
| 10409 | 10390 | ||
| 10410 | DEFSYM (Qinsufficient_source, "insufficient-source"); | 10391 | DEFSYM (Qinsufficient_source, "insufficient-source"); |
| 10411 | DEFSYM (Qinconsistent_eol, "inconsistent-eol"); | ||
| 10412 | DEFSYM (Qinvalid_source, "invalid-source"); | 10392 | DEFSYM (Qinvalid_source, "invalid-source"); |
| 10413 | DEFSYM (Qinterrupted, "interrupted"); | 10393 | DEFSYM (Qinterrupted, "interrupted"); |
| 10414 | DEFSYM (Qinsufficient_memory, "insufficient-memory"); | ||
| 10415 | DEFSYM (Qcoding_system_define_form, "coding-system-define-form"); | 10394 | DEFSYM (Qcoding_system_define_form, "coding-system-define-form"); |
| 10416 | 10395 | ||
| 10417 | defsubr (&Scoding_system_p); | 10396 | defsubr (&Scoding_system_p); |
diff --git a/src/coding.h b/src/coding.h index eb95fa13ddb..28a7d776b63 100644 --- a/src/coding.h +++ b/src/coding.h | |||
| @@ -272,37 +272,31 @@ enum coding_result_code | |||
| 272 | CODING_RESULT_SUCCESS, | 272 | CODING_RESULT_SUCCESS, |
| 273 | CODING_RESULT_INSUFFICIENT_SRC, | 273 | CODING_RESULT_INSUFFICIENT_SRC, |
| 274 | CODING_RESULT_INSUFFICIENT_DST, | 274 | CODING_RESULT_INSUFFICIENT_DST, |
| 275 | CODING_RESULT_INCONSISTENT_EOL, | ||
| 276 | CODING_RESULT_INVALID_SRC, | 275 | CODING_RESULT_INVALID_SRC, |
| 277 | CODING_RESULT_INTERRUPT, | 276 | CODING_RESULT_INTERRUPT |
| 278 | CODING_RESULT_INSUFFICIENT_MEM | ||
| 279 | }; | 277 | }; |
| 280 | 278 | ||
| 281 | 279 | ||
| 282 | /* Macros used for the member `mode' of the struct coding_system. */ | 280 | /* Macros used for the member `mode' of the struct coding_system. */ |
| 283 | 281 | ||
| 284 | /* If set, recover the original CR or LF of the already decoded text | ||
| 285 | when the decoding routine encounters an inconsistent eol format. */ | ||
| 286 | #define CODING_MODE_INHIBIT_INCONSISTENT_EOL 0x01 | ||
| 287 | |||
| 288 | /* If set, the decoding/encoding routines treat the current data as | 282 | /* If set, the decoding/encoding routines treat the current data as |
| 289 | the last block of the whole text to be converted, and do the | 283 | the last block of the whole text to be converted, and do the |
| 290 | appropriate finishing job. */ | 284 | appropriate finishing job. */ |
| 291 | #define CODING_MODE_LAST_BLOCK 0x02 | 285 | #define CODING_MODE_LAST_BLOCK 0x01 |
| 292 | 286 | ||
| 293 | /* If set, it means that the current source text is in a buffer which | 287 | /* If set, it means that the current source text is in a buffer which |
| 294 | enables selective display. */ | 288 | enables selective display. */ |
| 295 | #define CODING_MODE_SELECTIVE_DISPLAY 0x04 | 289 | #define CODING_MODE_SELECTIVE_DISPLAY 0x02 |
| 296 | 290 | ||
| 297 | /* This flag is used by the decoding/encoding routines on the fly. If | 291 | /* This flag is used by the decoding/encoding routines on the fly. If |
| 298 | set, it means that right-to-left text is being processed. */ | 292 | set, it means that right-to-left text is being processed. */ |
| 299 | #define CODING_MODE_DIRECTION 0x08 | 293 | #define CODING_MODE_DIRECTION 0x04 |
| 300 | 294 | ||
| 301 | #define CODING_MODE_FIXED_DESTINATION 0x10 | 295 | #define CODING_MODE_FIXED_DESTINATION 0x08 |
| 302 | 296 | ||
| 303 | /* If set, it means that the encoding routines produces some safe | 297 | /* If set, it means that the encoding routines produces some safe |
| 304 | ASCII characters (usually '?') for unsupported characters. */ | 298 | ASCII characters (usually '?') for unsupported characters. */ |
| 305 | #define CODING_MODE_SAFE_ENCODING 0x20 | 299 | #define CODING_MODE_SAFE_ENCODING 0x10 |
| 306 | 300 | ||
| 307 | /* For handling composition sequence. */ | 301 | /* For handling composition sequence. */ |
| 308 | #include "composite.h" | 302 | #include "composite.h" |
| @@ -725,22 +719,6 @@ extern Lisp_Object from_unicode (Lisp_Object str); | |||
| 725 | 719 | ||
| 726 | /* Macros for backward compatibility. */ | 720 | /* Macros for backward compatibility. */ |
| 727 | 721 | ||
| 728 | #define decode_coding_region(coding, from, to) \ | ||
| 729 | decode_coding_object (coding, Fcurrent_buffer (), \ | ||
| 730 | from, CHAR_TO_BYTE (from), \ | ||
| 731 | to, CHAR_TO_BYTE (to), Fcurrent_buffer ()) | ||
| 732 | |||
| 733 | |||
| 734 | #define encode_coding_region(coding, from, to) \ | ||
| 735 | encode_coding_object (coding, Fcurrent_buffer (), \ | ||
| 736 | from, CHAR_TO_BYTE (from), \ | ||
| 737 | to, CHAR_TO_BYTE (to), Fcurrent_buffer ()) | ||
| 738 | |||
| 739 | |||
| 740 | #define decode_coding_string(coding, string, nocopy) \ | ||
| 741 | decode_coding_object (coding, string, 0, 0, SCHARS (string), \ | ||
| 742 | SBYTES (string), Qt) | ||
| 743 | |||
| 744 | #define encode_coding_string(coding, string, nocopy) \ | 722 | #define encode_coding_string(coding, string, nocopy) \ |
| 745 | (STRING_MULTIBYTE(string) ? \ | 723 | (STRING_MULTIBYTE(string) ? \ |
| 746 | (encode_coding_object (coding, string, 0, 0, SCHARS (string), \ | 724 | (encode_coding_object (coding, string, 0, 0, SCHARS (string), \ |