pike.git / src / modules / _Stdio / buffer.cmod

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:621:    static INT64 io_read_number( Buffer *io, size_t len, int endian )    {    INT64 res;    if( !io_avail(io, len) )    return -1;    /* ensure only leading 0:s */    for (; UNLIKELY(len > SIZEOF_INT_TYPE); len--)    if( UNLIKELY(io_read_byte_uc(io)) )    Pike_error("Integer (%dbit) overflow.\n", SIZEOF_INT_TYPE*8);    +  /* NB: endian == 0 for little endian, +  * 1 for big endian. +  */    if( endian )    res = io_read_number_uc( io, len );    else    res = io_read_le_number_uc( io, len );       if ( UNLIKELY(res < 0) )    Pike_error("Signed (%dbit) overflow.\n", SIZEOF_INT_TYPE*8);    return res;    }       static struct object *io_read_bignum( Buffer *io, size_t len, int endian )    {    struct object *o;    MP_INT *i;    unsigned char *p;       if( !io_avail(io,len) ) return NULL;    o = fast_clone_object(bignum_program);    i = (void*)o->storage; -  mpz_import( i, len, 1, endian, 0, 0, io_read_pointer(io) ); +  /* NB: endian == -1 for little endian, +  * 0 for native, +  * 1 for big endian. +  */ +  mpz_import( i, len, endian, 1, endian, 0, io_read_pointer(io) );    io_consume(io,len);    return o;    }       static void io_add_bignum( Buffer *io, struct object *o, int width )    ATTRIBUTE((noclone,noinline));       static void io_add_bignum( Buffer *io, struct object *o, int width )    {    MP_INT *i = (void*)o->storage;
pike.git/src/modules/_Stdio/buffer.cmod:2438:    *! @seealso    *! @[read_le_int]    */    PIKEFUN int(0..) read_int( int len )    {    Buffer *io = THIS;    struct object *o;       Pike_sp--;    -  if( len < SIZEOF_INT_TYPE-1 ) /* will for sure fit. */ +  if( len < SIZEOF_INT_TYPE ) /* will for sure fit. */    {    push_int( io_read_number( io, len, 1 ) );    return;    }       if( (o = io_read_bignum(io, len, 1)) )    {    push_object(o);    reduce_stack_top_bignum();    return;    }    push_int(-1);    }    -  /*! @decl int read_int( int n ) +  /*! @decl int read_le_int( int n )    *!    *! Read a big endian byte order unsigned number of size n*8 bits,    *! then return it.    *!    *! Will return -1 if there is not enough buffer space available    *! unless error mode is set to throw errors.    *!    *! @seealso    *! @[read_int]    */    PIKEFUN int(0..) read_le_int( int len )    {    Buffer *io = THIS;    struct object *o;       Pike_sp--;    -  if( len < SIZEOF_INT_TYPE-1 ) /* will for sure fit. */ +  if( len < SIZEOF_INT_TYPE ) /* will for sure fit. */    {    push_int( io_read_number( io, len, 0 ) );    return;    }    -  if( (o = io_read_bignum(io, len, 0)) ) +  if( (o = io_read_bignum(io, len, -1)) )    {    push_object(o);    reduce_stack_top_bignum();    return;    }    push_int(-1);    }       /*! @decl int read_hint( int n )    *!