aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
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/alloc.c
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/alloc.c')
-rw-r--r--src/alloc.c45
1 files changed, 45 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.