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/coding.c | |
| 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/coding.c')
| -rw-r--r-- | src/coding.c | 45 |
1 files changed, 12 insertions, 33 deletions
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); |