{
if (cons_block_index == CONS_BLOCK_SIZE)
{
+ /* Maximum number of conses that should be active at any
+ given time, so that list lengths fit into a ptrdiff_t and
+ into a fixnum. */
+ ptrdiff_t max_conses = min (PTRDIFF_MAX, MOST_POSITIVE_FIXNUM);
+
+ /* This check is typically optimized away, as a runtime
+ check is needed only on weird platforms where a count of
+ distinct conses might not fit. */
+ if (max_conses < INTPTR_MAX / sizeof (struct Lisp_Cons)
+ && (max_conses - CONS_BLOCK_SIZE
+ < total_free_conses + total_conses))
+ memory_full (sizeof (struct cons_block));
+
struct cons_block *new
= lisp_align_malloc (sizeof *new, MEM_TYPE_CONS);
memset (new->gcmarkbits, 0, sizeof new->gcmarkbits);
FOR_EACH_TAIL (list)
i++;
CHECK_LIST_END (list, list);
- if (i <= min (PTRDIFF_MAX, MOST_POSITIVE_FIXNUM))
- return i;
- overflow_error ();
+ return i;
}
doc: /* Return the length of a list, but avoid error or infinite loop.
This function never gets an error. If LIST is not really a list,
it returns 0. If LIST is circular, it returns an integer that is at
-least the number of distinct elements.
-Value is a fixnum, if it's small enough, otherwise a bignum. */)
+least the number of distinct elements. */)
(Lisp_Object list)
{
intptr_t len = 0;
FOR_EACH_TAIL_SAFE (list)
len++;
- return INT_TO_INTEGER (len);
+ return make_fixnum (len);
}
DEFUN ("proper-list-p", Fproper_list_p, Sproper_list_p, 1, 1, 0,
}
if (!NILP (last_tail))
return Qnil;
- if (MOST_POSITIVE_FIXNUM < len)
- overflow_error ();
return make_fixnum (len);
}