Branch: Tag:

2017-12-02

2017-12-02 12:52:43 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Stdio.Buffer: Support bignums in add_int{8,16,32}().

add_int8() and add_int16() now support getting called
with a bignum.

add_int32() with a bignum now ignores any bits outside
the 32-bit range.

1268:    ref_push_object(Pike_fp->current_object);    }    +  /*! @decl Buffer add_int8( Gmp.mpz ) +  *! Adds a single byte to the buffer. +  */ +  PIKEFUN Buffer add_int8( object mpz ) +  { +  INT64 i = 0; +  Buffer *io = THIS; +  unsigned char *p = io_add_space(io,1,0); +  if (!low_int64_from_bignum(&i, mpz)) { +  SIMPLE_ARG_TYPE_ERROR("add_int8", 1, "int|Gmp.mpz"); +  } +  *p = i; +  io->len++; +  ref_push_object(Pike_fp->current_object); +  } +     /*! @decl Buffer add_int16( int(16bit) )    *!    *! Add a 16-bit network byte order value to the buffer
1283:    ref_push_object(Pike_fp->current_object);    }    +  /*! @decl Buffer add_int16( Gmp.mpz ) +  *! +  *! Add a 16-bit network byte order value to the buffer +  */ +  PIKEFUN Buffer add_int16( object mpz ) +  { +  INT64 i = 0; +  Buffer *io = THIS; +  unsigned char *p = io_add_space(io,2,0); +  if (!low_int64_from_bignum(&i, mpz)) { +  SIMPLE_ARG_TYPE_ERROR("add_int16", 1, "int|Gmp.mpz"); +  } +  p[0] = i>>8; +  p[1] = i; +  io->len += 2; +  ref_push_object(Pike_fp->current_object); +  } +     /*! @decl Buffer add_int32( int i )    *! Adds a 32 bit network byte order value to the buffer    */
1307:    INT64 i = 0;    Buffer *io = THIS;    unsigned char *p = io_add_space(io,4,0); -  if (!int64_from_bignum(&i, mpz)) { +  if (!low_int64_from_bignum(&i, mpz)) {    SIMPLE_ARG_TYPE_ERROR("add_int32", 1, "int|Gmp.mpz");    }    p[0] = i>>24;