summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ChangeLog9
-rw-r--r--src/fns.c14
-rw-r--r--src/fringe.c8
-rw-r--r--src/keymap.c8
-rw-r--r--src/lisp.h9
-rw-r--r--src/macros.c26
6 files changed, 32 insertions, 42 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 877898443ec..9fb23b2d825 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
+2014-07-14 Dmitry Antipov <dmantipov@yandex.ru>
+
+ * lisp.h (CHECK_VECTOR_OR_STRING): Return number of elements
+ or characters in string, respectively. Add comment.
+ * fringe.c (Fdefine_fringe_bitmap):
+ * fns.c (Fsubstring, substring_both): Use it.
+ * keymap.c (Fdefine_key, Flookup_key):
+ * macros.c (Fstart_kbd_macro): Likewise. Avoid call to Flength.
+
2014-07-13 Paul Eggert <eggert@cs.ucla.edu>
Improve behavior of 'bzr up; cd src; make -k'.
diff --git a/src/fns.c b/src/fns.c
index 887a856f224..79967116a11 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -1151,13 +1151,7 @@ With one argument, just copy STRING (with properties, if any). */)
Lisp_Object res;
ptrdiff_t size, ifrom, ito;
- if (STRINGP (string))
- size = SCHARS (string);
- else if (VECTORP (string))
- size = ASIZE (string);
- else
- wrong_type_argument (Qarrayp, string);
-
+ size = CHECK_VECTOR_OR_STRING (string);
validate_subarray (string, from, to, size, &ifrom, &ito);
if (STRINGP (string))
@@ -1212,11 +1206,7 @@ substring_both (Lisp_Object string, ptrdiff_t from, ptrdiff_t from_byte,
ptrdiff_t to, ptrdiff_t to_byte)
{
Lisp_Object res;
- ptrdiff_t size;
-
- CHECK_VECTOR_OR_STRING (string);
-
- size = STRINGP (string) ? SCHARS (string) : ASIZE (string);
+ ptrdiff_t size = CHECK_VECTOR_OR_STRING (string);
if (!(0 <= from && from <= to && to <= size))
args_out_of_range_3 (string, make_number (from), make_number (to));
diff --git a/src/fringe.c b/src/fringe.c
index d00aee0e0b6..54f880dc624 100644
--- a/src/fringe.c
+++ b/src/fringe.c
@@ -1571,13 +1571,7 @@ If BITMAP already exists, the existing definition is replaced. */)
int fill1 = 0, fill2 = 0;
CHECK_SYMBOL (bitmap);
-
- if (STRINGP (bits))
- h = SCHARS (bits);
- else if (VECTORP (bits))
- h = ASIZE (bits);
- else
- wrong_type_argument (Qsequencep, bits);
+ h = CHECK_VECTOR_OR_STRING (bits);
if (NILP (height))
fb.height = h;
diff --git a/src/keymap.c b/src/keymap.c
index 76119606643..f4dd644aebd 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -1092,9 +1092,7 @@ binding KEY to DEF is added at the front of KEYMAP. */)
GCPRO3 (keymap, key, def);
keymap = get_keymap (keymap, 1, 1);
- CHECK_VECTOR_OR_STRING (key);
-
- length = XFASTINT (Flength (key));
+ length = CHECK_VECTOR_OR_STRING (key);
if (length == 0)
RETURN_UNGCPRO (Qnil);
@@ -1248,9 +1246,7 @@ recognize the default bindings, just as `read-key-sequence' does. */)
GCPRO2 (keymap, key);
keymap = get_keymap (keymap, 1, 1);
- CHECK_VECTOR_OR_STRING (key);
-
- length = XFASTINT (Flength (key));
+ length = CHECK_VECTOR_OR_STRING (key);
if (length == 0)
RETURN_UNGCPRO (keymap);
diff --git a/src/lisp.h b/src/lisp.h
index 1c5bb14aafe..85110677693 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2555,10 +2555,15 @@ CHECK_BOOL_VECTOR (Lisp_Object x)
{
CHECK_TYPE (BOOL_VECTOR_P (x), Qbool_vector_p, x);
}
-INLINE void
+/* This is a bit special because we always need size afterwards. */
+INLINE ptrdiff_t
CHECK_VECTOR_OR_STRING (Lisp_Object x)
{
- CHECK_TYPE (VECTORP (x) || STRINGP (x), Qarrayp, x);
+ if (VECTORP (x))
+ return ASIZE (x);
+ if (STRINGP (x))
+ return SCHARS (x);
+ wrong_type_argument (Qarrayp, x);
}
INLINE void
CHECK_ARRAY (Lisp_Object x, Lisp_Object predicate)
diff --git a/src/macros.c b/src/macros.c
index acba125edc5..c73986abd34 100644
--- a/src/macros.c
+++ b/src/macros.c
@@ -80,28 +80,24 @@ macro before appending to it. */)
}
else
{
- ptrdiff_t i;
- EMACS_INT len;
+ const ptrdiff_t incr = 30;
+ ptrdiff_t i, len;
bool cvt;
/* Check the type of last-kbd-macro in case Lisp code changed it. */
- CHECK_VECTOR_OR_STRING (KVAR (current_kboard, Vlast_kbd_macro));
+ len = CHECK_VECTOR_OR_STRING (KVAR (current_kboard, Vlast_kbd_macro));
- len = XINT (Flength (KVAR (current_kboard, Vlast_kbd_macro)));
+ if (INT_ADD_OVERFLOW (len, incr))
+ memory_full (SIZE_MAX);
/* Copy last-kbd-macro into the buffer, in case the Lisp code
has put another macro there. */
- if (current_kboard->kbd_macro_bufsize < len + 30)
- {
- if (PTRDIFF_MAX < MOST_POSITIVE_FIXNUM + 30
- && PTRDIFF_MAX < len + 30)
- memory_full (SIZE_MAX);
- current_kboard->kbd_macro_buffer =
- xpalloc (current_kboard->kbd_macro_buffer,
- &current_kboard->kbd_macro_bufsize,
- len + 30 - current_kboard->kbd_macro_bufsize, -1,
- sizeof *current_kboard->kbd_macro_buffer);
- }
+ if (current_kboard->kbd_macro_bufsize < len + incr)
+ current_kboard->kbd_macro_buffer =
+ xpalloc (current_kboard->kbd_macro_buffer,
+ &current_kboard->kbd_macro_bufsize,
+ len + incr - current_kboard->kbd_macro_bufsize, -1,
+ sizeof *current_kboard->kbd_macro_buffer);
/* Must convert meta modifier when copying string to vector. */
cvt = STRINGP (KVAR (current_kboard, Vlast_kbd_macro));