From 233f3db624556da41f0edb0c0a03dc4288eeea98 Mon Sep 17 00:00:00 2001 From: "Kim F. Storm" Date: Tue, 26 Oct 2004 22:38:50 +0000 Subject: [PATCH 1/2] Fix SAFE_FREE calls. Replace SAFE_FREE_LISP calls. --- src/ChangeLog | 11 +++++++++++ src/casefiddle.c | 2 +- src/charset.c | 2 +- src/data.c | 4 ++-- src/fns.c | 24 ++++++++++++------------ src/xdisp.c | 2 +- 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 150bc439979..fbef104296f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2004-10-27 Kim F. Storm + + * editfns.c (Fformat): Allocate discarded table with SAFE_ALLOCA. + Only allocate info and discarded tables once. + + * lisp.h (USE_SAFE_ALLOCA): Add and init sa_must_free integer. + (SAFE_ALLOCA, SAFE_ALLOCA_LISP): Increment it when malloc is used. + (SAFE_FREE): Test it to determine if we need to unwind to free. + Remove size arg. All users changed. + (SAFE_FREE_LISP) Remove. All users changed to use SAFE_FREE. + 2004-10-26 Jan Dj,Ad(Brv * gtkutil.c: Put empty line between comment and function body. diff --git a/src/casefiddle.c b/src/casefiddle.c index 25a5a3d12b8..51fc6444f49 100644 --- a/src/casefiddle.c +++ b/src/casefiddle.c @@ -137,7 +137,7 @@ casify_object (flag, obj) } obj = make_multibyte_string (buf, SCHARS (obj), j_byte); - SAFE_FREE (bufsize); + SAFE_FREE (); } return obj; } diff --git a/src/charset.c b/src/charset.c index 8eeddd51c92..c03107a9c46 100644 --- a/src/charset.c +++ b/src/charset.c @@ -1673,7 +1673,7 @@ usage: (string &rest CHARACTERS) */) } ret = make_string_from_bytes (buf, n, p - buf); - SAFE_FREE (bufsize); + SAFE_FREE (); return ret; } diff --git a/src/data.c b/src/data.c index 33b37376a49..92487f82ddb 100644 --- a/src/data.c +++ b/src/data.c @@ -2165,7 +2165,7 @@ bool-vector. IDX starts at 0. */) p1 = SDATA (array) + idxval_byte; bcopy (str + idxval_byte + prev_bytes, p1 + new_bytes, nbytes - (idxval_byte + prev_bytes)); - SAFE_FREE (nbytes); + SAFE_FREE (); clear_string_char_byte_cache (); } while (new_bytes--) @@ -2206,7 +2206,7 @@ bool-vector. IDX starts at 0. */) *p1++ = *p0++; bcopy (str + idxval_byte + prev_bytes, p1, nbytes - (idxval_byte + prev_bytes)); - SAFE_FREE (nbytes); + SAFE_FREE (); clear_string_char_byte_cache (); } } diff --git a/src/fns.c b/src/fns.c index 814babae7d8..b366cab196a 100644 --- a/src/fns.c +++ b/src/fns.c @@ -1012,7 +1012,7 @@ string_make_multibyte (string) 0, 1); ret = make_multibyte_string (buf, SCHARS (string), nbytes); - SAFE_FREE (nbytes); + SAFE_FREE (); return ret; } @@ -1046,7 +1046,7 @@ string_to_multibyte (string) str_to_multibyte (buf, nbytes, SBYTES (string)); ret = make_multibyte_string (buf, SCHARS (string), nbytes); - SAFE_FREE (nbytes); + SAFE_FREE (); return ret; } @@ -1073,7 +1073,7 @@ string_make_unibyte (string) 1, 0); ret = make_unibyte_string (buf, nchars); - SAFE_FREE (nchars); + SAFE_FREE (); return ret; } @@ -3030,7 +3030,7 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string. */) args[i] = separator; ret = Fconcat (nargs, args); - SAFE_FREE_LISP (nargs); + SAFE_FREE (); return ret; } @@ -3056,7 +3056,7 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string. */) mapcar1 (leni, args, function, sequence); ret = Flist (leni, args); - SAFE_FREE_LISP (leni); + SAFE_FREE (); return ret; } @@ -3763,7 +3763,7 @@ into shorter lines. */) if (encoded_length < 0) { /* The encoding wasn't possible. */ - SAFE_FREE (allength); + SAFE_FREE (); error ("Multibyte character in data for base64 encoding"); } @@ -3771,7 +3771,7 @@ into shorter lines. */) and delete the old. (Insert first in order to preserve markers.) */ SET_PT_BOTH (XFASTINT (beg), ibeg); insert (encoded, encoded_length); - SAFE_FREE (allength); + SAFE_FREE (); del_range_byte (ibeg + encoded_length, iend + encoded_length, 1); /* If point was outside of the region, restore it exactly; else just @@ -3820,12 +3820,12 @@ into shorter lines. */) if (encoded_length < 0) { /* The encoding wasn't possible. */ - SAFE_FREE (allength); + SAFE_FREE (); error ("Multibyte character in data for base64 encoding"); } encoded_string = make_unibyte_string (encoded, encoded_length); - SAFE_FREE (allength); + SAFE_FREE (); return encoded_string; } @@ -3962,7 +3962,7 @@ If the region can't be decoded, signal an error and don't modify the buffer. */ if (decoded_length < 0) { /* The decoding wasn't possible. */ - SAFE_FREE (allength); + SAFE_FREE (); error ("Invalid base64 data"); } @@ -3970,7 +3970,7 @@ If the region can't be decoded, signal an error and don't modify the buffer. */ and delete the old. (Insert first in order to preserve markers.) */ TEMP_SET_PT_BOTH (XFASTINT (beg), ibeg); insert_1_both (decoded, inserted_chars, decoded_length, 0, 1, 0); - SAFE_FREE (allength); + SAFE_FREE (); /* Delete the original text. */ del_range_both (PT, PT_BYTE, XFASTINT (end) + inserted_chars, @@ -4014,7 +4014,7 @@ DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string, else decoded_string = Qnil; - SAFE_FREE (length); + SAFE_FREE (); if (!STRINGP (decoded_string)) error ("Invalid base64 data"); diff --git a/src/xdisp.c b/src/xdisp.c index 306e26702f5..afae7fd22af 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -6365,7 +6365,7 @@ add_to_log (format, arg1, arg2) bcopy (SDATA (msg), buffer, len); message_dolog (buffer, len - 1, 1, 0); - SAFE_FREE (len); + SAFE_FREE (); UNGCPRO; } From fce59e4038c02d88aca0ba6ef06db7ceb991d279 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Wed, 27 Oct 2004 06:01:59 +0000 Subject: [PATCH 2/2] (utf-translate-cjk-unicode-range-string): New variable. (utf-translate-cjk-set-unicode-range): New function. (utf-translate-cjk-unicode-range): Make it customizable. (utf-8-post-read-conversion): Use utf-translate-cjk-unicode-range-string. --- lisp/international/utf-8.el | 103 +++++++++++++++++++++++++++++------- 1 file changed, 85 insertions(+), 18 deletions(-) diff --git a/lisp/international/utf-8.el b/lisp/international/utf-8.el index 5a7acee0f0e..02d7733e2dd 100644 --- a/lisp/international/utf-8.el +++ b/lisp/international/utf-8.el @@ -197,10 +197,81 @@ Setting this variable outside customize has no effect." korean-ksc5601) "List of charsets supported by `utf-translate-cjk-mode'.") -(defconst utf-translate-cjk-unicode-range - '((#x2e80 . #xd7a3) - (#xff00 . #xffef)) - "List of Unicode code ranges supported by `utf-translate-cjk-mode'.") +(defvar utf-translate-cjk-lang-env nil + "Language environment in which tables for `utf-translate-cjk-mode' is loaded. +The value nil means that the tables are not yet loaded.") + +(defvar utf-translate-cjk-unicode-range) + +;; String generated from utf-translate-cjk-unicode-range. It is +;; suitable for an argument to skip-chars-forward. +(defvar utf-translate-cjk-unicode-range-string nil) + +(defun utf-translate-cjk-set-unicode-range (range) + (setq utf-translate-cjk-unicode-range range) + (setq utf-translate-cjk-unicode-range-string + (let ((decode-char-no-trans + #'(lambda (x) + (cond ((< x #x100) (make-char 'latin-iso8859-1 x)) + ((< x #x2500) + (setq x (- x #x100)) + (make-char 'mule-unicode-0100-24ff + (+ (/ x 96) 32) (+ (% x 96) 32))) + ((< x #x3400) + (setq x (- x #x2500)) + (make-char 'mule-unicode-2500-33ff + (+ (/ x 96) 32) (+ (% x 96) 32))) + (t + (setq x (- x #xe000)) + (make-char 'mule-unicode-e000-ffff + (+ (/ x 96) 32) (+ (% x 96) 32)))))) + ranges from to) + (dolist (elt range) + (setq from (max #xA0 (car elt)) to (min #xffff (cdr elt))) + (if (and (>= to #x3400) (< to #xE000)) + (setq to #x33FF)) + (cond ((< from #x100) + (if (>= to #xE000) + (setq ranges (cons (cons #xE000 to) ranges) + to #x33FF)) + (if (>= to #x2500) + (setq ranges (cons (cons #x2500 to) ranges) + to #x24FF)) + (if (>= to #x100) + (setq ranges (cons (cons #x100 to) ranges) + to #xFF))) + ((< from #x2500) + (if (>= to #xE000) + (setq ranges (cons (cons #xE000 to) ranges) + to #x33FF)) + (if (>= to #x2500) + (setq ranges (cons (cons #x2500 to) ranges) + to #x24FF))) + ((< from #x3400) + (if (>= to #xE000) + (setq ranges (cons (cons #xE000 to) ranges) + to #x33FF)))) + (if (<= from to) + (setq ranges (cons (cons from to) ranges)))) + (mapconcat #'(lambda (x) + (format "%c-%c" + (funcall decode-char-no-trans (car x)) + (funcall decode-char-no-trans (cdr x)))) + ranges ""))) + ;; This forces loading tables for utf-translate-cjk-mode. + (setq utf-translate-cjk-lang-env nil)) + +(defcustom utf-translate-cjk-unicode-range '((#x2e80 . #xd7a3) + (#xff00 . #xffef)) + "List of Unicode code ranges supported by `utf-translate-cjk-mode'. +Setting this variable directly does not take effect; +use either \\[customize] or the function +`utf-translate-cjk-set-unicode-range'." + :version "21.4" + :type '(repeat (cons integer integer)) + :set (lambda (symbol value) + (utf-translate-cjk-set-unicode-range value)) + :group 'mule) ;; Return non-nil if CODE-POINT is in `utf-translate-cjk-unicode-range'. (defsubst utf-translate-cjk-substitutable-p (code-point) @@ -213,10 +284,6 @@ Setting this variable outside customize has no effect." (setq elt nil))) elt)) -(defvar utf-translate-cjk-lang-env nil - "Language environment in which tables for `utf-translate-cjk-mode' is loaded. -The value nil means that the tables are not yet loaded.") - (defun utf-translate-cjk-load-tables () "Load tables for `utf-translate-cjk-mode'." ;; Fixme: Allow the use of the CJK charsets to be @@ -874,17 +941,17 @@ Also compose particular scripts if `utf-8-compose-scripts' is non-nil." hash-table ch) (set-buffer-multibyte t) (when utf-translate-cjk-mode - (if (not utf-translate-cjk-lang-env) - ;; Check these characters: - ;; "U+2e80-U+33ff", "U+ff00-U+ffef" - ;; We may have to translate them to CJK charsets. - (let ((range2 "$,29@(B-$,2G$,3r`(B-$,3u/(B")) - (skip-chars-forward (concat range range2)) - (unless (eobp) - (utf-translate-cjk-load-tables) - (setq range (concat range range2))) + (unless utf-translate-cjk-lang-env + ;; Check these characters in utf-translate-cjk-range. + ;; We may have to translate them to CJK charsets. + (skip-chars-forward + (concat range utf-translate-cjk-unicode-range-string)) + (unless (eobp) + (utf-translate-cjk-load-tables) + (setq range + (concat range utf-translate-cjk-unicode-range-string)))) (setq hash-table (get 'utf-subst-table-for-decode - 'translation-hash-table))))) + 'translation-hash-table))) (while (and (skip-chars-forward range) (not (eobp))) (setq ch (following-char))