/* Random utility Lisp functions.
Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997,
1998, 1999, 2000, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+ 2005, 2006, 2007, 2008, 2009, 2010
+ Free Software Foundation, Inc.
This file is part of GNU Emacs.
extern Lisp_Object Qinput_method_function;
-static int internal_equal P_ ((Lisp_Object , Lisp_Object, int, int));
+static int internal_equal (Lisp_Object , Lisp_Object, int, int);
-extern long get_random ();
-extern void seed_random P_ ((long));
+extern long get_random (void);
+extern void seed_random (long);
#ifndef HAVE_UNISTD_H
extern long time ();
if (SCHARS (s1) != SCHARS (s2)
|| SBYTES (s1) != SBYTES (s2)
- || bcmp (SDATA (s1), SDATA (s2), SBYTES (s1)))
+ || memcmp (SDATA (s1), SDATA (s2), SBYTES (s1)))
return Qnil;
return Qt;
}
/* "gcc -O3" enables automatic function inlining, which optimizes out
the arguments for the invocations of this function, whereas it
expects these values on the stack. */
-static Lisp_Object concat P_ ((int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_special)) __attribute__((noinline));
+static Lisp_Object concat (int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_special) __attribute__((noinline));
#else /* !__GNUC__ */
-static Lisp_Object concat P_ ((int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_special));
+static Lisp_Object concat (int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_special);
#endif
/* ARGSUSED */
Lisp_Object
-concat2 (s1, s2)
- Lisp_Object s1, s2;
+concat2 (Lisp_Object s1, Lisp_Object s2)
{
Lisp_Object args[2];
args[0] = s1;
/* ARGSUSED */
Lisp_Object
-concat3 (s1, s2, s3)
- Lisp_Object s1, s2, s3;
+concat3 (Lisp_Object s1, Lisp_Object s2, Lisp_Object s3)
{
Lisp_Object args[3];
args[0] = s1;
/ BOOL_VECTOR_BITS_PER_CHAR);
val = Fmake_bool_vector (Flength (arg), Qnil);
- bcopy (XBOOL_VECTOR (arg)->data, XBOOL_VECTOR (val)->data,
- size_in_chars);
+ memcpy (XBOOL_VECTOR (val)->data, XBOOL_VECTOR (arg)->data,
+ size_in_chars);
return val;
}
};
static Lisp_Object
-concat (nargs, args, target_type, last_special)
- int nargs;
- Lisp_Object *args;
- enum Lisp_Type target_type;
- int last_special;
+concat (int nargs, Lisp_Object *args, enum Lisp_Type target_type, int last_special)
{
Lisp_Object val;
register Lisp_Object tail;
So, we record strings that have text properties to be copied
here, and copy the text properties after the concatination. */
struct textprop_rec *textprops = NULL;
- /* Number of elments in textprops. */
+ /* Number of elements in textprops. */
int num_textprops = 0;
USE_SAFE_ALLOCA;
{
int thislen_byte = SBYTES (this);
- bcopy (SDATA (this), SDATA (val) + toindex_byte,
- SBYTES (this));
+ memcpy (SDATA (val) + toindex_byte, SDATA (this), SBYTES (this));
if (! NULL_INTERVAL_P (STRING_INTERVALS (this)))
{
textprops[num_textprops].argnum = argnum;
static EMACS_INT string_char_byte_cache_bytepos;
void
-clear_string_char_byte_cache ()
+clear_string_char_byte_cache (void)
{
string_char_byte_cache_string = Qnil;
}
/* Return the byte index corresponding to CHAR_INDEX in STRING. */
EMACS_INT
-string_char_to_byte (string, char_index)
- Lisp_Object string;
- EMACS_INT char_index;
+string_char_to_byte (Lisp_Object string, EMACS_INT char_index)
{
EMACS_INT i_byte;
EMACS_INT best_below, best_below_byte;
/* Return the character index corresponding to BYTE_INDEX in STRING. */
EMACS_INT
-string_byte_to_char (string, byte_index)
- Lisp_Object string;
- EMACS_INT byte_index;
+string_byte_to_char (Lisp_Object string, EMACS_INT byte_index)
{
EMACS_INT i, i_byte;
EMACS_INT best_below, best_below_byte;
/* Convert STRING to a multibyte string. */
Lisp_Object
-string_make_multibyte (string)
- Lisp_Object string;
+string_make_multibyte (Lisp_Object string)
{
unsigned char *buf;
EMACS_INT nbytes;
converted to eight-bit characters. */
Lisp_Object
-string_to_multibyte (string)
- Lisp_Object string;
+string_to_multibyte (Lisp_Object string)
{
unsigned char *buf;
EMACS_INT nbytes;
return make_multibyte_string (SDATA (string), nbytes, nbytes);
SAFE_ALLOCA (buf, unsigned char *, nbytes);
- bcopy (SDATA (string), buf, SBYTES (string));
+ memcpy (buf, SDATA (string), SBYTES (string));
str_to_multibyte (buf, nbytes, SBYTES (string));
ret = make_multibyte_string (buf, SCHARS (string), nbytes);
/* Convert STRING to a single-byte string. */
Lisp_Object
-string_make_unibyte (string)
- Lisp_Object string;
+string_make_unibyte (Lisp_Object string)
{
int nchars;
unsigned char *buf;
int bytes = SBYTES (string);
unsigned char *str = (unsigned char *) xmalloc (bytes);
- bcopy (SDATA (string), str, bytes);
+ memcpy (str, SDATA (string), bytes);
bytes = str_as_unibyte (str, bytes);
string = make_unibyte_string (str, bytes);
xfree (str);
SBYTES (string),
&nchars, &nbytes);
new_string = make_uninit_multibyte_string (nchars, nbytes);
- bcopy (SDATA (string), SDATA (new_string),
- SBYTES (string));
+ memcpy (SDATA (new_string), SDATA (string), SBYTES (string));
if (nbytes != SBYTES (string))
str_as_multibyte (SDATA (new_string), nbytes,
SBYTES (string), NULL);
both in characters and in bytes. */
Lisp_Object
-substring_both (string, from, from_byte, to, to_byte)
- Lisp_Object string;
- int from, from_byte, to, to_byte;
+substring_both (Lisp_Object string, int from, int from_byte, int to, int to_byte)
{
Lisp_Object res;
int size;
Use only on lists known never to be circular. */
Lisp_Object
-assq_no_quit (key, list)
- Lisp_Object key, list;
+assq_no_quit (Lisp_Object key, Lisp_Object list)
{
while (CONSP (list)
&& (!CONSP (XCAR (list))
Use only on lists known never to be circular. */
Lisp_Object
-assoc_no_quit (key, list)
- Lisp_Object key, list;
+assoc_no_quit (Lisp_Object key, Lisp_Object list)
{
while (CONSP (list)
&& (!CONSP (XCAR (list))
return new;
}
\f
-Lisp_Object merge ();
+Lisp_Object merge (Lisp_Object org_l1, Lisp_Object org_l2, Lisp_Object pred);
DEFUN ("sort", Fsort, Ssort, 2, 2, 0,
doc: /* Sort LIST, stably, comparing elements using PREDICATE.
}
Lisp_Object
-merge (org_l1, org_l2, pred)
- Lisp_Object org_l1, org_l2;
- Lisp_Object pred;
+merge (Lisp_Object org_l1, Lisp_Object org_l2, Lisp_Object pred)
{
Lisp_Object value;
register Lisp_Object tail;
PROPS, if non-nil, means compare string text properties too. */
static int
-internal_equal (o1, o2, depth, props)
- register Lisp_Object o1, o2;
- int depth, props;
+internal_equal (register Lisp_Object o1, register Lisp_Object o2, int depth, int props)
{
if (depth > 200)
error ("Stack overflow in equal");
if (XBOOL_VECTOR (o1)->size != XBOOL_VECTOR (o2)->size)
return 0;
- if (bcmp (XBOOL_VECTOR (o1)->data, XBOOL_VECTOR (o2)->data,
- size_in_chars))
+ if (memcmp (XBOOL_VECTOR (o1)->data, XBOOL_VECTOR (o2)->data,
+ size_in_chars))
return 0;
return 1;
}
return 0;
if (SBYTES (o1) != SBYTES (o2))
return 0;
- if (bcmp (SDATA (o1), SDATA (o2),
- SBYTES (o1)))
+ if (memcmp (SDATA (o1), SDATA (o2), SBYTES (o1)))
return 0;
if (props && !compare_string_intervals (o1, o2))
return 0;
return 0;
}
\f
-extern Lisp_Object Fmake_char_internal ();
DEFUN ("fillarray", Ffillarray, Sfillarray, 2, 2, 0,
doc: /* Store each element of ARRAY with ITEM.
if (size != size_byte)
while (p1 < endp)
{
- int this_len = MULTIBYTE_FORM_LENGTH (p1, endp - p1);
+ int this_len = BYTES_BY_CHAR_HEAD (*p1);
if (len != this_len)
error ("Attempt to change byte length of a string");
p1 += this_len;
int len;
CHECK_STRING (string);
len = SBYTES (string);
- bzero (SDATA (string), len);
+ memset (SDATA (string), 0, len);
STRING_SET_CHARS (string, len);
STRING_SET_UNIBYTE (string);
return Qnil;
\f
/* ARGSUSED */
Lisp_Object
-nconc2 (s1, s2)
- Lisp_Object s1, s2;
+nconc2 (Lisp_Object s1, Lisp_Object s2)
{
Lisp_Object args[2];
args[0] = s1;
LENI is the length of VALS, which should also be the length of SEQ. */
static void
-mapcar1 (leni, vals, fn, seq)
- int leni;
- Lisp_Object *vals;
- Lisp_Object fn, seq;
+mapcar1 (int leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq)
{
register Lisp_Object tail;
Lisp_Object dummy;
Anything that calls this function must protect from GC! */
Lisp_Object
-do_yes_or_no_p (prompt)
- Lisp_Object prompt;
+do_yes_or_no_p (Lisp_Object prompt)
{
return call1 (intern ("yes-or-no-p"), prompt);
}
Lisp_Object require_nesting_list;
Lisp_Object
-require_unwind (old_value)
- Lisp_Object old_value;
+require_unwind (Lisp_Object old_value)
{
return require_nesting_list = old_value;
}
base64 characters. */
-static int base64_encode_1 P_ ((const char *, char *, int, int, int));
-static int base64_decode_1 P_ ((const char *, char *, int, int, int *));
+static int base64_encode_1 (const char *, char *, int, int, int);
+static int base64_decode_1 (const char *, char *, int, int, int *);
DEFUN ("base64-encode-region", Fbase64_encode_region, Sbase64_encode_region,
2, 3, "r",
}
static int
-base64_encode_1 (from, to, length, line_break, multibyte)
- const char *from;
- char *to;
- int length;
- int line_break;
- int multibyte;
+base64_encode_1 (const char *from, char *to, int length, int line_break, int multibyte)
{
int counter = 0, i = 0;
char *e = to;
characters in *NCHARS_RETURN. */
static int
-base64_decode_1 (from, to, length, multibyte, nchars_return)
- const char *from;
- char *to;
- int length;
- int multibyte;
- int *nchars_return;
+base64_decode_1 (const char *from, char *to, int length, int multibyte, int *nchars_return)
{
int i = 0;
char *e = to;
/* Function prototypes. */
-static struct Lisp_Hash_Table *check_hash_table P_ ((Lisp_Object));
-static int get_key_arg P_ ((Lisp_Object, int, Lisp_Object *, char *));
-static void maybe_resize_hash_table P_ ((struct Lisp_Hash_Table *));
-static int cmpfn_eql P_ ((struct Lisp_Hash_Table *, Lisp_Object, unsigned,
- Lisp_Object, unsigned));
-static int cmpfn_equal P_ ((struct Lisp_Hash_Table *, Lisp_Object, unsigned,
- Lisp_Object, unsigned));
-static int cmpfn_user_defined P_ ((struct Lisp_Hash_Table *, Lisp_Object,
- unsigned, Lisp_Object, unsigned));
-static unsigned hashfn_eq P_ ((struct Lisp_Hash_Table *, Lisp_Object));
-static unsigned hashfn_eql P_ ((struct Lisp_Hash_Table *, Lisp_Object));
-static unsigned hashfn_equal P_ ((struct Lisp_Hash_Table *, Lisp_Object));
-static unsigned hashfn_user_defined P_ ((struct Lisp_Hash_Table *,
- Lisp_Object));
-static unsigned sxhash_string P_ ((unsigned char *, int));
-static unsigned sxhash_list P_ ((Lisp_Object, int));
-static unsigned sxhash_vector P_ ((Lisp_Object, int));
-static unsigned sxhash_bool_vector P_ ((Lisp_Object));
-static int sweep_weak_table P_ ((struct Lisp_Hash_Table *, int));
+static struct Lisp_Hash_Table *check_hash_table (Lisp_Object);
+static int get_key_arg (Lisp_Object, int, Lisp_Object *, char *);
+static void maybe_resize_hash_table (struct Lisp_Hash_Table *);
+static int cmpfn_eql (struct Lisp_Hash_Table *, Lisp_Object, unsigned,
+ Lisp_Object, unsigned);
+static int cmpfn_equal (struct Lisp_Hash_Table *, Lisp_Object, unsigned,
+ Lisp_Object, unsigned);
+static int cmpfn_user_defined (struct Lisp_Hash_Table *, Lisp_Object,
+ unsigned, Lisp_Object, unsigned);
+static unsigned hashfn_eq (struct Lisp_Hash_Table *, Lisp_Object);
+static unsigned hashfn_eql (struct Lisp_Hash_Table *, Lisp_Object);
+static unsigned hashfn_equal (struct Lisp_Hash_Table *, Lisp_Object);
+static unsigned hashfn_user_defined (struct Lisp_Hash_Table *,
+ Lisp_Object);
+static unsigned sxhash_string (unsigned char *, int);
+static unsigned sxhash_list (Lisp_Object, int);
+static unsigned sxhash_vector (Lisp_Object, int);
+static unsigned sxhash_bool_vector (Lisp_Object);
+static int sweep_weak_table (struct Lisp_Hash_Table *, int);
\f
Lisp_Hash_Table. Otherwise, signal an error. */
static struct Lisp_Hash_Table *
-check_hash_table (obj)
- Lisp_Object obj;
+check_hash_table (Lisp_Object obj)
{
CHECK_HASH_TABLE (obj);
return XHASH_TABLE (obj);
number. */
int
-next_almost_prime (n)
- int n;
+next_almost_prime (int n)
{
if (n % 2 == 0)
n += 1;
a DEFUN parameter list. */
static int
-get_key_arg (key, nargs, args, used)
- Lisp_Object key;
- int nargs;
- Lisp_Object *args;
- char *used;
+get_key_arg (Lisp_Object key, int nargs, Lisp_Object *args, char *used)
{
int i;
vector that are not copied from VEC are set to INIT. */
Lisp_Object
-larger_vector (vec, new_size, init)
- Lisp_Object vec;
- int new_size;
- Lisp_Object init;
+larger_vector (Lisp_Object vec, int new_size, Lisp_Object init)
{
struct Lisp_Vector *v;
int i, old_size;
xassert (new_size >= old_size);
v = allocate_vector (new_size);
- bcopy (XVECTOR (vec)->contents, v->contents,
- old_size * sizeof *v->contents);
+ memcpy (v->contents, XVECTOR (vec)->contents, old_size * sizeof *v->contents);
for (i = old_size; i < new_size; ++i)
v->contents[i] = init;
XSETVECTOR (vec, v);
KEY2 are the same. */
static int
-cmpfn_eql (h, key1, hash1, key2, hash2)
- struct Lisp_Hash_Table *h;
- Lisp_Object key1, key2;
- unsigned hash1, hash2;
+cmpfn_eql (struct Lisp_Hash_Table *h, Lisp_Object key1, unsigned int hash1, Lisp_Object key2, unsigned int hash2)
{
return (FLOATP (key1)
&& FLOATP (key2)
KEY2 are the same. */
static int
-cmpfn_equal (h, key1, hash1, key2, hash2)
- struct Lisp_Hash_Table *h;
- Lisp_Object key1, key2;
- unsigned hash1, hash2;
+cmpfn_equal (struct Lisp_Hash_Table *h, Lisp_Object key1, unsigned int hash1, Lisp_Object key2, unsigned int hash2)
{
return hash1 == hash2 && !NILP (Fequal (key1, key2));
}
if KEY1 and KEY2 are the same. */
static int
-cmpfn_user_defined (h, key1, hash1, key2, hash2)
- struct Lisp_Hash_Table *h;
- Lisp_Object key1, key2;
- unsigned hash1, hash2;
+cmpfn_user_defined (struct Lisp_Hash_Table *h, Lisp_Object key1, unsigned int hash1, Lisp_Object key2, unsigned int hash2)
{
if (hash1 == hash2)
{
in a Lisp integer. */
static unsigned
-hashfn_eq (h, key)
- struct Lisp_Hash_Table *h;
- Lisp_Object key;
+hashfn_eq (struct Lisp_Hash_Table *h, Lisp_Object key)
{
unsigned hash = XUINT (key) ^ XTYPE (key);
xassert ((hash & ~INTMASK) == 0);
in a Lisp integer. */
static unsigned
-hashfn_eql (h, key)
- struct Lisp_Hash_Table *h;
- Lisp_Object key;
+hashfn_eql (struct Lisp_Hash_Table *h, Lisp_Object key)
{
unsigned hash;
if (FLOATP (key))
in a Lisp integer. */
static unsigned
-hashfn_equal (h, key)
- struct Lisp_Hash_Table *h;
- Lisp_Object key;
+hashfn_equal (struct Lisp_Hash_Table *h, Lisp_Object key)
{
unsigned hash = sxhash (key, 0);
xassert ((hash & ~INTMASK) == 0);
guaranteed to fit in a Lisp integer. */
static unsigned
-hashfn_user_defined (h, key)
- struct Lisp_Hash_Table *h;
- Lisp_Object key;
+hashfn_user_defined (struct Lisp_Hash_Table *h, Lisp_Object key)
{
Lisp_Object args[2], hash;
only the table itself is. */
Lisp_Object
-copy_hash_table (h1)
- struct Lisp_Hash_Table *h1;
+copy_hash_table (struct Lisp_Hash_Table *h1)
{
Lisp_Object table;
struct Lisp_Hash_Table *h2;
h2 = allocate_hash_table ();
next = h2->vec_next;
- bcopy (h1, h2, sizeof *h2);
+ memcpy (h2, h1, sizeof *h2);
h2->vec_next = next;
h2->key_and_value = Fcopy_sequence (h1->key_and_value);
h2->hash = Fcopy_sequence (h1->hash);
because it's already too large, throw an error. */
static INLINE void
-maybe_resize_hash_table (h)
- struct Lisp_Hash_Table *h;
+maybe_resize_hash_table (struct Lisp_Hash_Table *h)
{
if (NILP (h->next_free))
{
matching KEY, or -1 if not found. */
int
-hash_lookup (h, key, hash)
- struct Lisp_Hash_Table *h;
- Lisp_Object key;
- unsigned *hash;
+hash_lookup (struct Lisp_Hash_Table *h, Lisp_Object key, unsigned int *hash)
{
unsigned hash_code;
int start_of_bucket;
Value is the index of the entry in H matching KEY. */
int
-hash_put (h, key, value, hash)
- struct Lisp_Hash_Table *h;
- Lisp_Object key, value;
- unsigned hash;
+hash_put (struct Lisp_Hash_Table *h, Lisp_Object key, Lisp_Object value, unsigned int hash)
{
int start_of_bucket, i;
/* Remove the entry matching KEY from hash table H, if there is one. */
static void
-hash_remove_from_table (h, key)
- struct Lisp_Hash_Table *h;
- Lisp_Object key;
+hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key)
{
unsigned hash_code;
int start_of_bucket;
/* Clear hash table H. */
void
-hash_clear (h)
- struct Lisp_Hash_Table *h;
+hash_clear (struct Lisp_Hash_Table *h)
{
if (h->count > 0)
{
************************************************************************/
void
-init_weak_hash_tables ()
+init_weak_hash_tables (void)
{
weak_hash_tables = NULL;
}
non-zero if anything was marked. */
static int
-sweep_weak_table (h, remove_entries_p)
- struct Lisp_Hash_Table *h;
- int remove_entries_p;
+sweep_weak_table (struct Lisp_Hash_Table *h, int remove_entries_p)
{
int bucket, n, marked;
from Vweak_hash_tables. Called from gc_sweep. */
void
-sweep_weak_hash_tables ()
+sweep_weak_hash_tables (void)
{
struct Lisp_Hash_Table *h, *used, *next;
int marked;
code returned is guaranteed to fit in a Lisp integer. */
static unsigned
-sxhash_string (ptr, len)
- unsigned char *ptr;
- int len;
+sxhash_string (unsigned char *ptr, int len)
{
unsigned char *p = ptr;
unsigned char *end = p + len;
list. We don't recurse deeper than SXHASH_MAX_DEPTH in it. */
static unsigned
-sxhash_list (list, depth)
- Lisp_Object list;
- int depth;
+sxhash_list (Lisp_Object list, int depth)
{
unsigned hash = 0;
int i;
the Lisp structure. */
static unsigned
-sxhash_vector (vec, depth)
- Lisp_Object vec;
- int depth;
+sxhash_vector (Lisp_Object vec, int depth)
{
unsigned hash = ASIZE (vec);
int i, n;
/* Return a hash for bool-vector VECTOR. */
static unsigned
-sxhash_bool_vector (vec)
- Lisp_Object vec;
+sxhash_bool_vector (Lisp_Object vec)
{
unsigned hash = XBOOL_VECTOR (vec)->size;
int i, n;
structure. Value is an unsigned integer clipped to INTMASK. */
unsigned
-sxhash (obj, depth)
- Lisp_Object obj;
- int depth;
+sxhash (Lisp_Object obj, int depth)
{
unsigned hash;
/* The vector `used' is used to keep track of arguments that
have been consumed. */
used = (char *) alloca (nargs * sizeof *used);
- bzero (used, nargs * sizeof *used);
+ memset (used, 0, nargs * sizeof *used);
/* See if there's a `:test TEST' among the arguments. */
i = get_key_arg (QCtest, nargs, args, used);
\f
void
-syms_of_fns ()
+syms_of_fns (void)
{
/* Hash table stuff. */
Qhash_table_p = intern_c_string ("hash-table-p");
void
-init_fns ()
+init_fns (void)
{
}