aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTom Tromey2018-07-07 14:53:23 -0600
committerTom Tromey2018-07-12 22:12:27 -0600
commitb2f3f4ee29ba8510d3cad8025d9ce2c2014b1b7f (patch)
treea277ed9d40d0ae529f3d20b1379b3e34c40e7a37 /src
parenta0f2adbfc9cb1b69415f551a5e529f7e1162b9c7 (diff)
downloademacs-b2f3f4ee29ba8510d3cad8025d9ce2c2014b1b7f.tar.gz
emacs-b2f3f4ee29ba8510d3cad8025d9ce2c2014b1b7f.zip
Provide new functions to create bignums
* src/alloc.c (make_bignum_str, make_number): New functions. * src/lisp.h (make_bignum_str, make_number): Declare.
Diffstat (limited to 'src')
-rw-r--r--src/alloc.c45
-rw-r--r--src/lisp.h3
2 files changed, 48 insertions, 0 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 8ebf3e05d69..b775948fd96 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3780,6 +3780,51 @@ build_marker (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t bytepos)
3780} 3780}
3781 3781
3782 3782
3783
3784Lisp_Object
3785make_bignum_str (const char *num, int base)
3786{
3787 Lisp_Object obj;
3788 struct Lisp_Bignum *b;
3789 int check;
3790
3791 obj = allocate_misc (Lisp_Misc_Bignum);
3792 b = XBIGNUM (obj);
3793 mpz_init (b->value);
3794 check = mpz_set_str (b->value, num, base);
3795 eassert (check == 0);
3796 return obj;
3797}
3798
3799/* Given an mpz_t, make a number. This may return a bignum or a
3800 fixnum depending on VALUE. */
3801
3802Lisp_Object
3803make_number (mpz_t value)
3804{
3805 Lisp_Object obj;
3806 struct Lisp_Bignum *b;
3807
3808 if (mpz_fits_slong_p (value))
3809 {
3810 long l = mpz_get_si (value);
3811 if (!FIXNUM_OVERFLOW_P (l))
3812 {
3813 XSETINT (obj, l);
3814 return obj;
3815 }
3816 }
3817
3818 obj = allocate_misc (Lisp_Misc_Bignum);
3819 b = XBIGNUM (obj);
3820 /* We could mpz_init + mpz_swap here, to avoid a copy, but the
3821 resulting API seemed possibly confusing. */
3822 mpz_init_set (b->value, value);
3823
3824 return obj;
3825}
3826
3827
3783/* Return a newly created vector or string with specified arguments as 3828/* Return a newly created vector or string with specified arguments as
3784 elements. If all the arguments are characters that can fit 3829 elements. If all the arguments are characters that can fit
3785 in a string of events, make a string; otherwise, make a vector. 3830 in a string of events, make a string; otherwise, make a vector.
diff --git a/src/lisp.h b/src/lisp.h
index 37e43b0c5a1..6a3db24949a 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3643,6 +3643,9 @@ extern Lisp_Object list5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
3643enum constype {CONSTYPE_HEAP, CONSTYPE_PURE}; 3643enum constype {CONSTYPE_HEAP, CONSTYPE_PURE};
3644extern Lisp_Object listn (enum constype, ptrdiff_t, Lisp_Object, ...); 3644extern Lisp_Object listn (enum constype, ptrdiff_t, Lisp_Object, ...);
3645 3645
3646extern Lisp_Object make_bignum_str (const char *num, int base);
3647extern Lisp_Object make_number (mpz_t value);
3648
3646/* Build a frequently used 2/3/4-integer lists. */ 3649/* Build a frequently used 2/3/4-integer lists. */
3647 3650
3648INLINE Lisp_Object 3651INLINE Lisp_Object