diff options
| author | Eli Zaretskii | 2013-03-28 20:13:59 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2013-03-28 20:13:59 +0200 |
| commit | d76bf86f438d4f5f9fe493ab76f02ffc78f3ae2e (patch) | |
| tree | 04fa8bc7bd2058a316a7ee30f8741d25bfd0b060 /src/fns.c | |
| parent | 2ef26ceb192c7683754cf0b4aa3087f501254332 (diff) | |
| parent | e74aeda863cd6896e06e92586f87b45d63d67d15 (diff) | |
| download | emacs-d76bf86f438d4f5f9fe493ab76f02ffc78f3ae2e.tar.gz emacs-d76bf86f438d4f5f9fe493ab76f02ffc78f3ae2e.zip | |
Merge from trunk and resolve conflicts.
Diffstat (limited to 'src/fns.c')
| -rw-r--r-- | src/fns.c | 65 |
1 files changed, 33 insertions, 32 deletions
| @@ -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. | 3 | Copyright (C) 1985-1987, 1993-1995, 1997-2013 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This file is part of GNU Emacs. | 5 | This file is part of GNU Emacs. |
| 6 | 6 | ||
| @@ -66,7 +66,10 @@ and `most-positive-fixnum', inclusive, are equally likely. | |||
| 66 | 66 | ||
| 67 | With positive integer LIMIT, return random number in interval [0,LIMIT). | 67 | With positive integer LIMIT, return random number in interval [0,LIMIT). |
| 68 | With argument t, set the random number seed from the current time and pid. | 68 | With argument t, set the random number seed from the current time and pid. |
| 69 | Other values of LIMIT are ignored. */) | 69 | With a string argument, set the seed based on the string's contents. |
| 70 | Other values of LIMIT are ignored. | ||
| 71 | |||
| 72 | See 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. */ |
| 87 | enum { QUIT_COUNT_HEURISTIC = 1 << 16 }; | 90 | enum { QUIT_COUNT_HEURISTIC = 1 << 16 }; |
| 88 | 91 | ||
| 89 | /* Random data-structure functions */ | 92 | /* Random data-structure functions. */ |
| 90 | 93 | ||
| 91 | DEFUN ("length", Flength, Slength, 1, 1, 0, | 94 | DEFUN ("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 | ||
| 212 | DEFUN ("compare-strings", Fcompare_strings, Scompare_strings, 6, 7, 0, | 215 | DEFUN ("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. |
| 214 | In string STR1, skip the first START1 characters and stop at END1. | 217 | The arguments START1, END1, START2, and END2, if non-nil, are |
| 215 | In string STR2, skip the first START2 characters and stop at END2. | 218 | positions specifying which parts of STR1 or STR2 to compare. In |
| 216 | END1 and END2 default to the full lengths of the respective strings. | 219 | string STR1, compare the part between START1 (inclusive) and END1 |
| 217 | 220 | \(exclusive). If START1 is nil, it defaults to 0, the beginning of | |
| 218 | Case is significant in this comparison if IGNORE-CASE is nil. | 221 | the string; if END1 is nil, it defaults to the length of the string. |
| 219 | Unibyte strings are converted to multibyte for comparison. | 222 | Likewise, in string STR2, compare the part between START2 and END2. |
| 223 | |||
| 224 | The strings are compared by the numeric values of their characters. | ||
| 225 | For instance, STR1 is "less than" STR2 if its first differing | ||
| 226 | character has a smaller numeric value. If IGNORE-CASE is non-nil, | ||
| 227 | characters are converted to lower-case before comparing them. Unibyte | ||
| 228 | strings are converted to multibyte for comparison. | ||
| 220 | 229 | ||
| 221 | The value is t if the strings (or specified portions) match. | 230 | The value is t if the strings (or specified portions) match. |
| 222 | If string STR1 is less, the value is a negative number N; | 231 | If 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. | |||
| 2736 | usage: (widget-apply WIDGET PROPERTY &rest ARGS) */) | 2745 | usage: (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 | ||
| 4076 | static EMACS_INT | 4077 | static EMACS_UINT |
| 4077 | sxhash_float (double val) | 4078 | sxhash_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 | ||