Commit 201b6857 authored by Dmitry Antipov's avatar Dmitry Antipov
Browse files

* 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.
parent a705278d
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> 2014-07-13 Paul Eggert <eggert@cs.ucla.edu>
Improve behavior of 'bzr up; cd src; make -k'. Improve behavior of 'bzr up; cd src; make -k'.
......
...@@ -1151,13 +1151,7 @@ With one argument, just copy STRING (with properties, if any). */) ...@@ -1151,13 +1151,7 @@ With one argument, just copy STRING (with properties, if any). */)
Lisp_Object res; Lisp_Object res;
ptrdiff_t size, ifrom, ito; ptrdiff_t size, ifrom, ito;
if (STRINGP (string)) size = CHECK_VECTOR_OR_STRING (string);
size = SCHARS (string);
else if (VECTORP (string))
size = ASIZE (string);
else
wrong_type_argument (Qarrayp, string);
validate_subarray (string, from, to, size, &ifrom, &ito); validate_subarray (string, from, to, size, &ifrom, &ito);
if (STRINGP (string)) if (STRINGP (string))
...@@ -1212,11 +1206,7 @@ substring_both (Lisp_Object string, ptrdiff_t from, ptrdiff_t from_byte, ...@@ -1212,11 +1206,7 @@ substring_both (Lisp_Object string, ptrdiff_t from, ptrdiff_t from_byte,
ptrdiff_t to, ptrdiff_t to_byte) ptrdiff_t to, ptrdiff_t to_byte)
{ {
Lisp_Object res; Lisp_Object res;
ptrdiff_t size; ptrdiff_t size = CHECK_VECTOR_OR_STRING (string);
CHECK_VECTOR_OR_STRING (string);
size = STRINGP (string) ? SCHARS (string) : ASIZE (string);
if (!(0 <= from && from <= to && to <= size)) if (!(0 <= from && from <= to && to <= size))
args_out_of_range_3 (string, make_number (from), make_number (to)); args_out_of_range_3 (string, make_number (from), make_number (to));
......
...@@ -1571,13 +1571,7 @@ If BITMAP already exists, the existing definition is replaced. */) ...@@ -1571,13 +1571,7 @@ If BITMAP already exists, the existing definition is replaced. */)
int fill1 = 0, fill2 = 0; int fill1 = 0, fill2 = 0;
CHECK_SYMBOL (bitmap); CHECK_SYMBOL (bitmap);
h = CHECK_VECTOR_OR_STRING (bits);
if (STRINGP (bits))
h = SCHARS (bits);
else if (VECTORP (bits))
h = ASIZE (bits);
else
wrong_type_argument (Qsequencep, bits);
if (NILP (height)) if (NILP (height))
fb.height = h; fb.height = h;
......
...@@ -1092,9 +1092,7 @@ binding KEY to DEF is added at the front of KEYMAP. */) ...@@ -1092,9 +1092,7 @@ binding KEY to DEF is added at the front of KEYMAP. */)
GCPRO3 (keymap, key, def); GCPRO3 (keymap, key, def);
keymap = get_keymap (keymap, 1, 1); keymap = get_keymap (keymap, 1, 1);
CHECK_VECTOR_OR_STRING (key); length = CHECK_VECTOR_OR_STRING (key);
length = XFASTINT (Flength (key));
if (length == 0) if (length == 0)
RETURN_UNGCPRO (Qnil); RETURN_UNGCPRO (Qnil);
...@@ -1248,9 +1246,7 @@ recognize the default bindings, just as `read-key-sequence' does. */) ...@@ -1248,9 +1246,7 @@ recognize the default bindings, just as `read-key-sequence' does. */)
GCPRO2 (keymap, key); GCPRO2 (keymap, key);
keymap = get_keymap (keymap, 1, 1); keymap = get_keymap (keymap, 1, 1);
CHECK_VECTOR_OR_STRING (key); length = CHECK_VECTOR_OR_STRING (key);
length = XFASTINT (Flength (key));
if (length == 0) if (length == 0)
RETURN_UNGCPRO (keymap); RETURN_UNGCPRO (keymap);
......
...@@ -2555,10 +2555,15 @@ CHECK_BOOL_VECTOR (Lisp_Object x) ...@@ -2555,10 +2555,15 @@ CHECK_BOOL_VECTOR (Lisp_Object x)
{ {
CHECK_TYPE (BOOL_VECTOR_P (x), Qbool_vector_p, 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_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 INLINE void
CHECK_ARRAY (Lisp_Object x, Lisp_Object predicate) CHECK_ARRAY (Lisp_Object x, Lisp_Object predicate)
......
...@@ -80,28 +80,24 @@ macro before appending to it. */) ...@@ -80,28 +80,24 @@ macro before appending to it. */)
} }
else else
{ {
ptrdiff_t i; const ptrdiff_t incr = 30;
EMACS_INT len; ptrdiff_t i, len;
bool cvt; bool cvt;
/* Check the type of last-kbd-macro in case Lisp code changed it. */ /* 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 /* Copy last-kbd-macro into the buffer, in case the Lisp code
has put another macro there. */ has put another macro there. */
if (current_kboard->kbd_macro_bufsize < len + 30) if (current_kboard->kbd_macro_bufsize < len + incr)
{
if (PTRDIFF_MAX < MOST_POSITIVE_FIXNUM + 30
&& PTRDIFF_MAX < len + 30)
memory_full (SIZE_MAX);
current_kboard->kbd_macro_buffer = current_kboard->kbd_macro_buffer =
xpalloc (current_kboard->kbd_macro_buffer, xpalloc (current_kboard->kbd_macro_buffer,
&current_kboard->kbd_macro_bufsize, &current_kboard->kbd_macro_bufsize,
len + 30 - current_kboard->kbd_macro_bufsize, -1, len + incr - current_kboard->kbd_macro_bufsize, -1,
sizeof *current_kboard->kbd_macro_buffer); sizeof *current_kboard->kbd_macro_buffer);
}
/* Must convert meta modifier when copying string to vector. */ /* Must convert meta modifier when copying string to vector. */
cvt = STRINGP (KVAR (current_kboard, Vlast_kbd_macro)); cvt = STRINGP (KVAR (current_kboard, Vlast_kbd_macro));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment