aboutsummaryrefslogtreecommitdiffstats
path: root/src/fns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fns.c')
-rw-r--r--src/fns.c65
1 files changed, 33 insertions, 32 deletions
diff --git a/src/fns.c b/src/fns.c
index 7c2222e9805..82ce933b25d 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -1,6 +1,6 @@
1/* Random utility Lisp functions. 1/* Random utility Lisp functions.
2 Copyright (C) 1985-1987, 1993-1995, 1997-2012 2
3 Free Software Foundation, Inc. 3Copyright (C) 1985-1987, 1993-1995, 1997-2013 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
6 6
@@ -66,7 +66,10 @@ and `most-positive-fixnum', inclusive, are equally likely.
66 66
67With positive integer LIMIT, return random number in interval [0,LIMIT). 67With positive integer LIMIT, return random number in interval [0,LIMIT).
68With argument t, set the random number seed from the current time and pid. 68With argument t, set the random number seed from the current time and pid.
69Other values of LIMIT are ignored. */) 69With a string argument, set the seed based on the string's contents.
70Other values of LIMIT are ignored.
71
72See Info node `(elisp)Random Numbers' for more details. */)
70 (Lisp_Object limit) 73 (Lisp_Object limit)
71{ 74{
72 EMACS_INT val; 75 EMACS_INT val;
@@ -86,7 +89,7 @@ Other values of LIMIT are ignored. */)
86 before it's time to do a QUIT. This must be a power of 2. */ 89 before it's time to do a QUIT. This must be a power of 2. */
87enum { QUIT_COUNT_HEURISTIC = 1 << 16 }; 90enum { QUIT_COUNT_HEURISTIC = 1 << 16 };
88 91
89/* Random data-structure functions */ 92/* Random data-structure functions. */
90 93
91DEFUN ("length", Flength, Slength, 1, 1, 0, 94DEFUN ("length", Flength, Slength, 1, 1, 0,
92 doc: /* Return the length of vector, list or string SEQUENCE. 95 doc: /* Return the length of vector, list or string SEQUENCE.
@@ -211,12 +214,18 @@ Symbols are also allowed; their print names are used instead. */)
211 214
212DEFUN ("compare-strings", Fcompare_strings, Scompare_strings, 6, 7, 0, 215DEFUN ("compare-strings", Fcompare_strings, Scompare_strings, 6, 7, 0,
213 doc: /* Compare the contents of two strings, converting to multibyte if needed. 216 doc: /* Compare the contents of two strings, converting to multibyte if needed.
214In string STR1, skip the first START1 characters and stop at END1. 217The arguments START1, END1, START2, and END2, if non-nil, are
215In string STR2, skip the first START2 characters and stop at END2. 218positions specifying which parts of STR1 or STR2 to compare. In
216END1 and END2 default to the full lengths of the respective strings. 219string STR1, compare the part between START1 (inclusive) and END1
217 220\(exclusive). If START1 is nil, it defaults to 0, the beginning of
218Case is significant in this comparison if IGNORE-CASE is nil. 221the string; if END1 is nil, it defaults to the length of the string.
219Unibyte strings are converted to multibyte for comparison. 222Likewise, in string STR2, compare the part between START2 and END2.
223
224The strings are compared by the numeric values of their characters.
225For instance, STR1 is "less than" STR2 if its first differing
226character has a smaller numeric value. If IGNORE-CASE is non-nil,
227characters are converted to lower-case before comparing them. Unibyte
228strings are converted to multibyte for comparison.
220 229
221The value is t if the strings (or specified portions) match. 230The value is t if the strings (or specified portions) match.
222If string STR1 is less, the value is a negative number N; 231If string STR1 is less, the value is a negative number N;
@@ -2476,7 +2485,7 @@ is nil, and `use-dialog-box' is non-nil. */)
2476 2485
2477 Fding (Qnil); 2486 Fding (Qnil);
2478 Fdiscard_input (); 2487 Fdiscard_input ();
2479 message ("Please answer yes or no."); 2488 message1 ("Please answer yes or no.");
2480 Fsleep_for (make_number (2), Qnil); 2489 Fsleep_for (make_number (2), Qnil);
2481 } 2490 }
2482} 2491}
@@ -2736,7 +2745,7 @@ ARGS are passed as extra arguments to the function.
2736usage: (widget-apply WIDGET PROPERTY &rest ARGS) */) 2745usage: (widget-apply WIDGET PROPERTY &rest ARGS) */)
2737 (ptrdiff_t nargs, Lisp_Object *args) 2746 (ptrdiff_t nargs, Lisp_Object *args)
2738{ 2747{
2739 /* This function can GC. */ 2748 /* This function can GC. */
2740 Lisp_Object newargs[3]; 2749 Lisp_Object newargs[3];
2741 struct gcpro gcpro1, gcpro2; 2750 struct gcpro gcpro1, gcpro2;
2742 Lisp_Object result; 2751 Lisp_Object result;
@@ -2798,9 +2807,8 @@ The data read from the system are decoded using `locale-coding-system'. */)
2798 val = build_unibyte_string (str); 2807 val = build_unibyte_string (str);
2799 /* Fixme: Is this coding system necessarily right, even if 2808 /* Fixme: Is this coding system necessarily right, even if
2800 it is consistent with CODESET? If not, what to do? */ 2809 it is consistent with CODESET? If not, what to do? */
2801 Faset (v, make_number (i), 2810 ASET (v, i, code_convert_string_norecord (val, Vlocale_coding_system,
2802 code_convert_string_norecord (val, Vlocale_coding_system, 2811 0));
2803 0));
2804 } 2812 }
2805 UNGCPRO; 2813 UNGCPRO;
2806 return v; 2814 return v;
@@ -2820,8 +2828,8 @@ The data read from the system are decoded using `locale-coding-system'. */)
2820 { 2828 {
2821 str = nl_langinfo (months[i]); 2829 str = nl_langinfo (months[i]);
2822 val = build_unibyte_string (str); 2830 val = build_unibyte_string (str);
2823 Faset (v, make_number (i), 2831 ASET (v, i, code_convert_string_norecord (val, Vlocale_coding_system,
2824 code_convert_string_norecord (val, Vlocale_coding_system, 0)); 2832 0));
2825 } 2833 }
2826 UNGCPRO; 2834 UNGCPRO;
2827 return v; 2835 return v;
@@ -2831,10 +2839,7 @@ The data read from the system are decoded using `locale-coding-system'. */)
2831 but is in the locale files. This could be used by ps-print. */ 2839 but is in the locale files. This could be used by ps-print. */
2832#ifdef PAPER_WIDTH 2840#ifdef PAPER_WIDTH
2833 else if (EQ (item, Qpaper)) 2841 else if (EQ (item, Qpaper))
2834 { 2842 return list2i (nl_langinfo (PAPER_WIDTH), nl_langinfo (PAPER_HEIGHT));
2835 return list2 (make_number (nl_langinfo (PAPER_WIDTH)),
2836 make_number (nl_langinfo (PAPER_HEIGHT)));
2837 }
2838#endif /* PAPER_WIDTH */ 2843#endif /* PAPER_WIDTH */
2839#endif /* HAVE_LANGINFO_CODESET*/ 2844#endif /* HAVE_LANGINFO_CODESET*/
2840 return Qnil; 2845 return Qnil;
@@ -3404,7 +3409,7 @@ larger_vector (Lisp_Object vec, ptrdiff_t incr_min, ptrdiff_t nitems_max)
3404 ptrdiff_t n_max = (0 <= nitems_max && nitems_max < C_language_max 3409 ptrdiff_t n_max = (0 <= nitems_max && nitems_max < C_language_max
3405 ? nitems_max : C_language_max); 3410 ? nitems_max : C_language_max);
3406 eassert (VECTORP (vec)); 3411 eassert (VECTORP (vec));
3407 eassert (0 < incr_min && -1 <= nitems_max); 3412 eassert (incr_min > 0 && nitems_max >= -1);
3408 old_size = ASIZE (vec); 3413 old_size = ASIZE (vec);
3409 incr_max = n_max - old_size; 3414 incr_max = n_max - old_size;
3410 incr = max (incr_min, min (old_size >> 1, incr_max)); 3415 incr = max (incr_min, min (old_size >> 1, incr_max));
@@ -3569,9 +3574,9 @@ make_hash_table (struct hash_table_test test,
3569 eassert (SYMBOLP (test.name)); 3574 eassert (SYMBOLP (test.name));
3570 eassert (INTEGERP (size) && XINT (size) >= 0); 3575 eassert (INTEGERP (size) && XINT (size) >= 0);
3571 eassert ((INTEGERP (rehash_size) && XINT (rehash_size) > 0) 3576 eassert ((INTEGERP (rehash_size) && XINT (rehash_size) > 0)
3572 || (FLOATP (rehash_size) && 1 < XFLOAT_DATA (rehash_size))); 3577 || (FLOATP (rehash_size) && XFLOAT_DATA (rehash_size) > 1));
3573 eassert (FLOATP (rehash_threshold) 3578 eassert (FLOATP (rehash_threshold)
3574 && 0 < XFLOAT_DATA (rehash_threshold) 3579 && XFLOAT_DATA (rehash_threshold) > 0
3575 && XFLOAT_DATA (rehash_threshold) <= 1.0); 3580 && XFLOAT_DATA (rehash_threshold) <= 1.0);
3576 3581
3577 if (XFASTINT (size) == 0) 3582 if (XFASTINT (size) == 0)
@@ -4037,10 +4042,6 @@ sweep_weak_hash_tables (void)
4037 4042
4038#define SXHASH_MAX_LEN 7 4043#define SXHASH_MAX_LEN 7
4039 4044
4040/* Hash X, returning a value that fits into a Lisp integer. */
4041#define SXHASH_REDUCE(X) \
4042 ((((X) ^ (X) >> (BITS_PER_EMACS_INT - FIXNUM_BITS))) & INTMASK)
4043
4044/* Return a hash for string PTR which has length LEN. The hash value 4045/* Return a hash for string PTR which has length LEN. The hash value
4045 can be any EMACS_UINT value. */ 4046 can be any EMACS_UINT value. */
4046 4047
@@ -4073,7 +4074,7 @@ sxhash_string (char const *ptr, ptrdiff_t len)
4073 4074
4074/* Return a hash for the floating point value VAL. */ 4075/* Return a hash for the floating point value VAL. */
4075 4076
4076static EMACS_INT 4077static EMACS_UINT
4077sxhash_float (double val) 4078sxhash_float (double val)
4078{ 4079{
4079 EMACS_UINT hash = 0; 4080 EMACS_UINT hash = 0;
@@ -4311,15 +4312,15 @@ usage: (make-hash-table &rest KEYWORD-ARGS) */)
4311 /* Look for `:rehash-size SIZE'. */ 4312 /* Look for `:rehash-size SIZE'. */
4312 i = get_key_arg (QCrehash_size, nargs, args, used); 4313 i = get_key_arg (QCrehash_size, nargs, args, used);
4313 rehash_size = i ? args[i] : make_float (DEFAULT_REHASH_SIZE); 4314 rehash_size = i ? args[i] : make_float (DEFAULT_REHASH_SIZE);
4314 if (! ((INTEGERP (rehash_size) && 0 < XINT (rehash_size)) 4315 if (! ((INTEGERP (rehash_size) && XINT (rehash_size) > 0)
4315 || (FLOATP (rehash_size) && 1 < XFLOAT_DATA (rehash_size)))) 4316 || (FLOATP (rehash_size) && XFLOAT_DATA (rehash_size) > 1)))
4316 signal_error ("Invalid hash table rehash size", rehash_size); 4317 signal_error ("Invalid hash table rehash size", rehash_size);
4317 4318
4318 /* Look for `:rehash-threshold THRESHOLD'. */ 4319 /* Look for `:rehash-threshold THRESHOLD'. */
4319 i = get_key_arg (QCrehash_threshold, nargs, args, used); 4320 i = get_key_arg (QCrehash_threshold, nargs, args, used);
4320 rehash_threshold = i ? args[i] : make_float (DEFAULT_REHASH_THRESHOLD); 4321 rehash_threshold = i ? args[i] : make_float (DEFAULT_REHASH_THRESHOLD);
4321 if (! (FLOATP (rehash_threshold) 4322 if (! (FLOATP (rehash_threshold)
4322 && 0 < XFLOAT_DATA (rehash_threshold) 4323 && XFLOAT_DATA (rehash_threshold) > 0
4323 && XFLOAT_DATA (rehash_threshold) <= 1)) 4324 && XFLOAT_DATA (rehash_threshold) <= 1))
4324 signal_error ("Invalid hash table rehash threshold", rehash_threshold); 4325 signal_error ("Invalid hash table rehash threshold", rehash_threshold);
4325 4326