aboutsummaryrefslogtreecommitdiffstats
path: root/src/casefiddle.c
diff options
context:
space:
mode:
authorBill Wohler2012-11-24 19:43:02 -0800
committerBill Wohler2012-11-24 19:43:02 -0800
commit5244bc019bf7376caff3bb198ff674e0ad9fb0e6 (patch)
tree02ee1615e904771f692ec2957c79a08ae029a13d /src/casefiddle.c
parent9f7e719509474e92f85955e22e57ffeebd4e96f3 (diff)
parentc07a6ded1df2f4156badc9add2953579622c3722 (diff)
downloademacs-5244bc019bf7376caff3bb198ff674e0ad9fb0e6.tar.gz
emacs-5244bc019bf7376caff3bb198ff674e0ad9fb0e6.zip
Merge from trunk.
Diffstat (limited to 'src/casefiddle.c')
-rw-r--r--src/casefiddle.c66
1 files changed, 30 insertions, 36 deletions
diff --git a/src/casefiddle.c b/src/casefiddle.c
index 77222c9e0a3..e3654627576 100644
--- a/src/casefiddle.c
+++ b/src/casefiddle.c
@@ -1,6 +1,6 @@
1/* GNU Emacs case conversion functions. 1/* GNU Emacs case conversion functions.
2 2
3Copyright (C) 1985, 1994, 1997-1999, 2001-2011 Free Software Foundation, Inc. 3Copyright (C) 1985, 1994, 1997-1999, 2001-2012 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
6 6
@@ -19,10 +19,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19 19
20 20
21#include <config.h> 21#include <config.h>
22#include <setjmp.h> 22
23#include "lisp.h" 23#include "lisp.h"
24#include "buffer.h"
25#include "character.h" 24#include "character.h"
25#include "buffer.h"
26#include "commands.h" 26#include "commands.h"
27#include "syntax.h" 27#include "syntax.h"
28#include "composite.h" 28#include "composite.h"
@@ -35,8 +35,8 @@ Lisp_Object Qidentity;
35static Lisp_Object 35static Lisp_Object
36casify_object (enum case_action flag, Lisp_Object obj) 36casify_object (enum case_action flag, Lisp_Object obj)
37{ 37{
38 register int c, c1; 38 int c, c1;
39 register int inword = flag == CASE_DOWN; 39 bool inword = flag == CASE_DOWN;
40 40
41 /* If the case table is flagged as modified, rescan it. */ 41 /* If the case table is flagged as modified, rescan it. */
42 if (NILP (XCHAR_TABLE (BVAR (current_buffer, downcase_table))->extras[1])) 42 if (NILP (XCHAR_TABLE (BVAR (current_buffer, downcase_table))->extras[1]))
@@ -47,7 +47,8 @@ casify_object (enum case_action flag, Lisp_Object obj)
47 int flagbits = (CHAR_ALT | CHAR_SUPER | CHAR_HYPER 47 int flagbits = (CHAR_ALT | CHAR_SUPER | CHAR_HYPER
48 | CHAR_SHIFT | CHAR_CTL | CHAR_META); 48 | CHAR_SHIFT | CHAR_CTL | CHAR_META);
49 int flags = XINT (obj) & flagbits; 49 int flags = XINT (obj) & flagbits;
50 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); 50 bool multibyte = ! NILP (BVAR (current_buffer,
51 enable_multibyte_characters));
51 52
52 /* If the character has higher bits set 53 /* If the character has higher bits set
53 above the flags, return it unchanged. 54 above the flags, return it unchanged.
@@ -82,8 +83,8 @@ casify_object (enum case_action flag, Lisp_Object obj)
82 wrong_type_argument (Qchar_or_string_p, obj); 83 wrong_type_argument (Qchar_or_string_p, obj);
83 else if (!STRING_MULTIBYTE (obj)) 84 else if (!STRING_MULTIBYTE (obj))
84 { 85 {
85 EMACS_INT i; 86 ptrdiff_t i;
86 EMACS_INT size = SCHARS (obj); 87 ptrdiff_t size = SCHARS (obj);
87 88
88 obj = Fcopy_sequence (obj); 89 obj = Fcopy_sequence (obj);
89 for (i = 0; i < size; i++) 90 for (i = 0; i < size; i++)
@@ -111,26 +112,19 @@ casify_object (enum case_action flag, Lisp_Object obj)
111 } 112 }
112 else 113 else
113 { 114 {
114 EMACS_INT i, i_byte, size = SCHARS (obj); 115 ptrdiff_t i, i_byte, size = SCHARS (obj);
115 int len; 116 int len;
116 USE_SAFE_ALLOCA; 117 USE_SAFE_ALLOCA;
117 unsigned char *dst, *o; 118 ptrdiff_t o_size = (size < STRING_BYTES_BOUND / MAX_MULTIBYTE_LENGTH
118 /* Over-allocate by 12%: this is a minor overhead, but should be 119 ? size * MAX_MULTIBYTE_LENGTH
119 sufficient in 99.999% of the cases to avoid a reallocation. */ 120 : STRING_BYTES_BOUND);
120 EMACS_INT o_size = SBYTES (obj) + SBYTES (obj) / 8 + MAX_MULTIBYTE_LENGTH; 121 unsigned char *dst = SAFE_ALLOCA (o_size);
121 SAFE_ALLOCA (dst, void *, o_size); 122 unsigned char *o = dst;
122 o = dst;
123 123
124 for (i = i_byte = 0; i < size; i++, i_byte += len) 124 for (i = i_byte = 0; i < size; i++, i_byte += len)
125 { 125 {
126 if ((o - dst) + MAX_MULTIBYTE_LENGTH > o_size) 126 if (o_size - (o - dst) < MAX_MULTIBYTE_LENGTH)
127 { /* Not enough space for the next char: grow the destination. */ 127 string_overflow ();
128 unsigned char *old_dst = dst;
129 o_size += o_size; /* Probably overkill, but extremely rare. */
130 SAFE_ALLOCA (dst, void *, o_size);
131 memcpy (dst, old_dst, o - old_dst);
132 o = dst + (o - old_dst);
133 }
134 c = STRING_CHAR_AND_LENGTH (SDATA (obj) + i_byte, len); 128 c = STRING_CHAR_AND_LENGTH (SDATA (obj) + i_byte, len);
135 if (inword && flag != CASE_CAPITALIZE_UP) 129 if (inword && flag != CASE_CAPITALIZE_UP)
136 c = downcase (c); 130 c = downcase (c);
@@ -196,17 +190,17 @@ The argument object is not altered--the value is a copy. */)
196static void 190static void
197casify_region (enum case_action flag, Lisp_Object b, Lisp_Object e) 191casify_region (enum case_action flag, Lisp_Object b, Lisp_Object e)
198{ 192{
199 register int c; 193 int c;
200 register int inword = flag == CASE_DOWN; 194 bool inword = flag == CASE_DOWN;
201 register int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 195 bool multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
202 EMACS_INT start, end; 196 ptrdiff_t start, end;
203 EMACS_INT start_byte; 197 ptrdiff_t start_byte;
204 198
205 /* Position of first and last changes. */ 199 /* Position of first and last changes. */
206 EMACS_INT first = -1, last IF_LINT (= 0); 200 ptrdiff_t first = -1, last IF_LINT (= 0);
207 201
208 EMACS_INT opoint = PT; 202 ptrdiff_t opoint = PT;
209 EMACS_INT opoint_byte = PT_BYTE; 203 ptrdiff_t opoint_byte = PT_BYTE;
210 204
211 if (EQ (b, e)) 205 if (EQ (b, e))
212 /* Not modifying because nothing marked */ 206 /* Not modifying because nothing marked */
@@ -351,10 +345,10 @@ character positions to operate on. */)
351} 345}
352 346
353static Lisp_Object 347static Lisp_Object
354operate_on_word (Lisp_Object arg, EMACS_INT *newpoint) 348operate_on_word (Lisp_Object arg, ptrdiff_t *newpoint)
355{ 349{
356 Lisp_Object val; 350 Lisp_Object val;
357 EMACS_INT farend; 351 ptrdiff_t farend;
358 EMACS_INT iarg; 352 EMACS_INT iarg;
359 353
360 CHECK_NUMBER (arg); 354 CHECK_NUMBER (arg);
@@ -376,7 +370,7 @@ See also `capitalize-word'. */)
376 (Lisp_Object arg) 370 (Lisp_Object arg)
377{ 371{
378 Lisp_Object beg, end; 372 Lisp_Object beg, end;
379 EMACS_INT newpoint; 373 ptrdiff_t newpoint;
380 XSETFASTINT (beg, PT); 374 XSETFASTINT (beg, PT);
381 end = operate_on_word (arg, &newpoint); 375 end = operate_on_word (arg, &newpoint);
382 casify_region (CASE_UP, beg, end); 376 casify_region (CASE_UP, beg, end);
@@ -390,7 +384,7 @@ With negative argument, convert previous words but do not move. */)
390 (Lisp_Object arg) 384 (Lisp_Object arg)
391{ 385{
392 Lisp_Object beg, end; 386 Lisp_Object beg, end;
393 EMACS_INT newpoint; 387 ptrdiff_t newpoint;
394 XSETFASTINT (beg, PT); 388 XSETFASTINT (beg, PT);
395 end = operate_on_word (arg, &newpoint); 389 end = operate_on_word (arg, &newpoint);
396 casify_region (CASE_DOWN, beg, end); 390 casify_region (CASE_DOWN, beg, end);
@@ -406,7 +400,7 @@ With negative argument, capitalize previous words but do not move. */)
406 (Lisp_Object arg) 400 (Lisp_Object arg)
407{ 401{
408 Lisp_Object beg, end; 402 Lisp_Object beg, end;
409 EMACS_INT newpoint; 403 ptrdiff_t newpoint;
410 XSETFASTINT (beg, PT); 404 XSETFASTINT (beg, PT);
411 end = operate_on_word (arg, &newpoint); 405 end = operate_on_word (arg, &newpoint);
412 casify_region (CASE_CAPITALIZE, beg, end); 406 casify_region (CASE_CAPITALIZE, beg, end);