[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master e7193902b2: Better `take` and `ntake` bignum argument handling
From: |
Mattias Engdegård |
Subject: |
master e7193902b2: Better `take` and `ntake` bignum argument handling |
Date: |
Thu, 1 Sep 2022 04:12:03 -0400 (EDT) |
branch: master
commit e7193902b23deb842f55c1cd9100b807e199f4bd
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
Better `take` and `ntake` bignum argument handling
* src/fns.c (Ftake, Fntake): Treat positive bignum arguments
as most-positive-fixnum which results in better error checking
of improper lists.
---
src/fns.c | 34 ++++++++++++++++++++--------------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/src/fns.c b/src/fns.c
index 07102256fe..2f4808be3d 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -1563,18 +1563,21 @@ If N is zero or negative, return nil.
If N is greater or equal to the length of LIST, return LIST (or a copy). */)
(Lisp_Object n, Lisp_Object list)
{
- if (BIGNUMP (n))
+ EMACS_INT m;
+ if (FIXNUMP (n))
+ {
+ m = XFIXNUM (n);
+ if (m <= 0)
+ return Qnil;
+ }
+ else if (BIGNUMP (n))
{
if (mpz_sgn (*xbignum_val (n)) < 0)
return Qnil;
- CHECK_LIST (list);
- return list;
+ m = MOST_POSITIVE_FIXNUM;
}
- if (!FIXNUMP (n))
+ else
wrong_type_argument (Qintegerp, n);
- EMACS_INT m = XFIXNUM (n);
- if (m <= 0)
- return Qnil;
CHECK_LIST (list);
if (NILP (list))
return Qnil;
@@ -1602,18 +1605,21 @@ If N is greater or equal to the length of LIST, return
LIST unmodified.
Otherwise, return LIST after truncating it. */)
(Lisp_Object n, Lisp_Object list)
{
- if (BIGNUMP (n))
+ EMACS_INT m;
+ if (FIXNUMP (n))
+ {
+ m = XFIXNUM (n);
+ if (m <= 0)
+ return Qnil;
+ }
+ else if (BIGNUMP (n))
{
if (mpz_sgn (*xbignum_val (n)) < 0)
return Qnil;
- CHECK_LIST (list);
- return list;
+ m = MOST_POSITIVE_FIXNUM;
}
- if (!FIXNUMP (n))
+ else
wrong_type_argument (Qintegerp, n);
- EMACS_INT m = XFIXNUM (n);
- if (m <= 0)
- return Qnil;
CHECK_LIST (list);
Lisp_Object tail = list;
--m;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master e7193902b2: Better `take` and `ntake` bignum argument handling,
Mattias Engdegård <=