aboutsummaryrefslogtreecommitdiffstats
path: root/src/fns.c
diff options
context:
space:
mode:
authorStefan Monnier2012-03-25 16:37:21 -0400
committerStefan Monnier2012-03-25 16:37:21 -0400
commit699c782b7668c44d0fa4446331b0590a6d5dac82 (patch)
tree5dcce364741d0761920a3d274b0fc8aba4103d45 /src/fns.c
parent98fb480ee31bf74cf554044f60f21df16566dd7f (diff)
parente99a9b8bdccadded1f6fae88ee7a2a93dfd4eacf (diff)
downloademacs-pending.tar.gz
emacs-pending.zip
Merge from trunkpending
Diffstat (limited to 'src/fns.c')
-rw-r--r--src/fns.c69
1 files changed, 41 insertions, 28 deletions
diff --git a/src/fns.c b/src/fns.c
index 0ca731ed331..1edfe966098 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -1,5 +1,5 @@
1/* Random utility Lisp functions. 1/* Random utility Lisp functions.
2 Copyright (C) 1985-1987, 1993-1995, 1997-2011 2 Copyright (C) 1985-1987, 1993-1995, 1997-2012
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
@@ -602,7 +602,7 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
602 602
603 prev = Qnil; 603 prev = Qnil;
604 if (STRINGP (val)) 604 if (STRINGP (val))
605 SAFE_ALLOCA (textprops, struct textprop_rec *, sizeof (struct textprop_rec) * nargs); 605 SAFE_NALLOCA (textprops, 1, nargs);
606 606
607 for (argnum = 0; argnum < nargs; argnum++) 607 for (argnum = 0; argnum < nargs; argnum++)
608 { 608 {
@@ -3252,9 +3252,9 @@ DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string,
3252 return decoded_string; 3252 return decoded_string;
3253} 3253}
3254 3254
3255/* Base64-decode the data at FROM of LENGHT bytes into TO. If 3255/* Base64-decode the data at FROM of LENGTH bytes into TO. If
3256 MULTIBYTE is nonzero, the decoded result should be in multibyte 3256 MULTIBYTE is nonzero, the decoded result should be in multibyte
3257 form. If NCHARS_RETRUN is not NULL, store the number of produced 3257 form. If NCHARS_RETURN is not NULL, store the number of produced
3258 characters in *NCHARS_RETURN. */ 3258 characters in *NCHARS_RETURN. */
3259 3259
3260static EMACS_INT 3260static EMACS_INT
@@ -3395,11 +3395,13 @@ check_hash_table (Lisp_Object obj)
3395 3395
3396 3396
3397/* Value is the next integer I >= N, N >= 0 which is "almost" a prime 3397/* Value is the next integer I >= N, N >= 0 which is "almost" a prime
3398 number. */ 3398 number. A number is "almost" a prime number if it is not divisible
3399 by any integer in the range 2 .. (NEXT_ALMOST_PRIME_LIMIT - 1). */
3399 3400
3400EMACS_INT 3401EMACS_INT
3401next_almost_prime (EMACS_INT n) 3402next_almost_prime (EMACS_INT n)
3402{ 3403{
3404 verify (NEXT_ALMOST_PRIME_LIMIT == 11);
3403 for (n |= 1; ; n += 2) 3405 for (n |= 1; ; n += 2)
3404 if (n % 3 != 0 && n % 5 != 0 && n % 7 != 0) 3406 if (n % 3 != 0 && n % 5 != 0 && n % 7 != 0)
3405 return n; 3407 return n;
@@ -3787,11 +3789,11 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h)
3787 the hash code of KEY. Value is the index of the entry in H 3789 the hash code of KEY. Value is the index of the entry in H
3788 matching KEY, or -1 if not found. */ 3790 matching KEY, or -1 if not found. */
3789 3791
3790EMACS_INT 3792ptrdiff_t
3791hash_lookup (struct Lisp_Hash_Table *h, Lisp_Object key, EMACS_UINT *hash) 3793hash_lookup (struct Lisp_Hash_Table *h, Lisp_Object key, EMACS_UINT *hash)
3792{ 3794{
3793 EMACS_UINT hash_code; 3795 EMACS_UINT hash_code;
3794 EMACS_INT start_of_bucket; 3796 ptrdiff_t start_of_bucket;
3795 Lisp_Object idx; 3797 Lisp_Object idx;
3796 3798
3797 hash_code = h->hashfn (h, key); 3799 hash_code = h->hashfn (h, key);
@@ -3821,11 +3823,11 @@ hash_lookup (struct Lisp_Hash_Table *h, Lisp_Object key, EMACS_UINT *hash)
3821 HASH is a previously computed hash code of KEY. 3823 HASH is a previously computed hash code of KEY.
3822 Value is the index of the entry in H matching KEY. */ 3824 Value is the index of the entry in H matching KEY. */
3823 3825
3824EMACS_INT 3826ptrdiff_t
3825hash_put (struct Lisp_Hash_Table *h, Lisp_Object key, Lisp_Object value, 3827hash_put (struct Lisp_Hash_Table *h, Lisp_Object key, Lisp_Object value,
3826 EMACS_UINT hash) 3828 EMACS_UINT hash)
3827{ 3829{
3828 EMACS_INT start_of_bucket, i; 3830 ptrdiff_t start_of_bucket, i;
3829 3831
3830 xassert ((hash & ~INTMASK) == 0); 3832 xassert ((hash & ~INTMASK) == 0);
3831 3833
@@ -4098,25 +4100,33 @@ sweep_weak_hash_tables (void)
4098#define SXHASH_REDUCE(X) \ 4100#define SXHASH_REDUCE(X) \
4099 ((((X) ^ (X) >> (BITS_PER_EMACS_INT - FIXNUM_BITS))) & INTMASK) 4101 ((((X) ^ (X) >> (BITS_PER_EMACS_INT - FIXNUM_BITS))) & INTMASK)
4100 4102
4101/* Return a hash for string PTR which has length LEN. The hash 4103/* Return a hash for string PTR which has length LEN. The hash value
4102 code returned is guaranteed to fit in a Lisp integer. */ 4104 can be any EMACS_UINT value. */
4103 4105
4104static EMACS_UINT 4106EMACS_UINT
4105sxhash_string (unsigned char *ptr, EMACS_INT len) 4107hash_string (char const *ptr, ptrdiff_t len)
4106{ 4108{
4107 unsigned char *p = ptr; 4109 char const *p = ptr;
4108 unsigned char *end = p + len; 4110 char const *end = p + len;
4109 unsigned char c; 4111 unsigned char c;
4110 EMACS_UINT hash = 0; 4112 EMACS_UINT hash = 0;
4111 4113
4112 while (p != end) 4114 while (p != end)
4113 { 4115 {
4114 c = *p++; 4116 c = *p++;
4115 if (c >= 0140)
4116 c -= 40;
4117 hash = SXHASH_COMBINE (hash, c); 4117 hash = SXHASH_COMBINE (hash, c);
4118 } 4118 }
4119 4119
4120 return hash;
4121}
4122
4123/* Return a hash for string PTR which has length LEN. The hash
4124 code returned is guaranteed to fit in a Lisp integer. */
4125
4126static EMACS_UINT
4127sxhash_string (char const *ptr, ptrdiff_t len)
4128{
4129 EMACS_UINT hash = hash_string (ptr, len);
4120 return SXHASH_REDUCE (hash); 4130 return SXHASH_REDUCE (hash);
4121} 4131}
4122 4132
@@ -4231,7 +4241,7 @@ sxhash (Lisp_Object obj, int depth)
4231 /* Fall through. */ 4241 /* Fall through. */
4232 4242
4233 case Lisp_String: 4243 case Lisp_String:
4234 hash = sxhash_string (SDATA (obj), SCHARS (obj)); 4244 hash = sxhash_string (SSDATA (obj), SBYTES (obj));
4235 break; 4245 break;
4236 4246
4237 /* This can be everything from a vector to an overlay. */ 4247 /* This can be everything from a vector to an overlay. */
@@ -4474,7 +4484,7 @@ If KEY is not found, return DFLT which defaults to nil. */)
4474 (Lisp_Object key, Lisp_Object table, Lisp_Object dflt) 4484 (Lisp_Object key, Lisp_Object table, Lisp_Object dflt)
4475{ 4485{
4476 struct Lisp_Hash_Table *h = check_hash_table (table); 4486 struct Lisp_Hash_Table *h = check_hash_table (table);
4477 EMACS_INT i = hash_lookup (h, key, NULL); 4487 ptrdiff_t i = hash_lookup (h, key, NULL);
4478 return i >= 0 ? HASH_VALUE (h, i) : dflt; 4488 return i >= 0 ? HASH_VALUE (h, i) : dflt;
4479} 4489}
4480 4490
@@ -4486,7 +4496,7 @@ VALUE. In any case, return VALUE. */)
4486 (Lisp_Object key, Lisp_Object value, Lisp_Object table) 4496 (Lisp_Object key, Lisp_Object value, Lisp_Object table)
4487{ 4497{
4488 struct Lisp_Hash_Table *h = check_hash_table (table); 4498 struct Lisp_Hash_Table *h = check_hash_table (table);
4489 EMACS_INT i; 4499 ptrdiff_t i;
4490 EMACS_UINT hash; 4500 EMACS_UINT hash;
4491 4501
4492 i = hash_lookup (h, key, &hash); 4502 i = hash_lookup (h, key, &hash);
@@ -4694,13 +4704,13 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_
4694 force_raw_text = 1; 4704 force_raw_text = 1;
4695 } 4705 }
4696 4706
4697 if (NILP (coding_system) && !NILP (Fbuffer_file_name(object))) 4707 if (NILP (coding_system) && !NILP (Fbuffer_file_name (object)))
4698 { 4708 {
4699 /* Check file-coding-system-alist. */ 4709 /* Check file-coding-system-alist. */
4700 Lisp_Object args[4], val; 4710 Lisp_Object args[4], val;
4701 4711
4702 args[0] = Qwrite_region; args[1] = start; args[2] = end; 4712 args[0] = Qwrite_region; args[1] = start; args[2] = end;
4703 args[3] = Fbuffer_file_name(object); 4713 args[3] = Fbuffer_file_name (object);
4704 val = Ffind_operation_coding_system (4, args); 4714 val = Ffind_operation_coding_system (4, args);
4705 if (CONSP (val) && !NILP (XCDR (val))) 4715 if (CONSP (val) && !NILP (XCDR (val)))
4706 coding_system = XCDR (val); 4716 coding_system = XCDR (val);
@@ -4837,12 +4847,15 @@ guesswork fails. Normally, an error is signaled in such case. */)
4837} 4847}
4838 4848
4839DEFUN ("secure-hash", Fsecure_hash, Ssecure_hash, 2, 5, 0, 4849DEFUN ("secure-hash", Fsecure_hash, Ssecure_hash, 2, 5, 0,
4840 doc: /* Return the secure hash of an OBJECT. 4850 doc: /* Return the secure hash of OBJECT, a buffer or string.
4841ALGORITHM is a symbol: md5, sha1, sha224, sha256, sha384 or sha512. 4851ALGORITHM is a symbol specifying the hash to use:
4842OBJECT is either a string or a buffer. 4852md5, sha1, sha224, sha256, sha384 or sha512.
4843Optional arguments START and END are character positions specifying 4853
4844which portion of OBJECT for computing the hash. If BINARY is non-nil, 4854The two optional arguments START and END are positions specifying for
4845return a string in binary form. */) 4855which part of OBJECT to compute the hash. If nil or omitted, uses the
4856whole OBJECT.
4857
4858If BINARY is non-nil, returns a string in binary form. */)
4846 (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object binary) 4859 (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object binary)
4847{ 4860{
4848 return secure_hash (algorithm, object, start, end, Qnil, Qnil, binary); 4861 return secure_hash (algorithm, object, start, end, Qnil, Qnil, binary);