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

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:83:    tMix, PIKE_T_MIXED, ID_PRIVATE|ID_HIDDEN|ID_PROTECTED);    }       static void io_set_error_mode( Buffer *io, struct program *m )    {    if( m ) add_ref(m);    if( io->error_mode ) free_program( io->error_mode );    io->error_mode = m;    }    -  static size_t io_len( Buffer *io ) -  { -  return io->len-io->offset; +  PMOD_EXPORT Buffer *io_buffer_from_object(struct object *o) { +  return get_storage(o, Buffer_program);    }    -  +     static void io_unlock( Buffer *io )    {    io->locked--;    }       static void io_lock( Buffer *io )    {    io->locked++;    }   
pike.git/src/modules/_Stdio/buffer.cmod:113:    Pike_error("Can not modify the buffer right now, "    " there are active subbuffers.\n");    }       static void io_ensure_unlocked(Buffer *io)    {    if( io->locked )    io_was_locked( );    }    -  static void io_trim( Buffer *io ) +  PMOD_EXPORT void io_trim( Buffer *io )    ATTRIBUTE((noinline));    -  static INT_TYPE io_consume( Buffer *io, int num ) -  { -  io->offset += num; -  if( UNLIKELY(io->allocated > (io_len(io) * io->max_waste)) ) -  io_trim(io); -  return io_len(io); -  } -  -  static unsigned char *io_read_pointer(Buffer *io) -  { -  return io->buffer + io->offset; -  } -  +     static int io_is_whitespace( Buffer *io, size_t pos )    {    if( pos > io_len( io ) )    return -1;    switch( io->buffer[io->offset+pos] )    {    SPACECASE8    return 1;    }    return 0;    }    -  static void io_trim( Buffer *io ) +  PMOD_EXPORT void io_trim( Buffer *io )    {    if( io->malloced && (io->offset > 64 || io->len > 64) && !io->locked)    {    if( io->offset > 64 && (!io->locked_move && (io->offset > io_len(io))))    {    memmove( io->buffer, io_read_pointer(io), io_len(io) );    io->len -= io->offset;    io->num_move++;    io->offset = 0;    }
pike.git/src/modules/_Stdio/buffer.cmod:177:    io_unlock( get_storage(io->sub,Buffer_program ) );    free_object( io->sub );    }    if( io->source ) free_object( io->source );    if( io->str ) free_string( io->str );    io->source = 0;    io->sub = 0;    io->str = 0;    }    -  static void io_ensure_malloced( Buffer *io, size_t bytes ) +  PMOD_EXPORT void io_ensure_malloced( Buffer *io, size_t bytes )    {    if( UNLIKELY(!io->malloced) )    {    /* convert to malloced buffer from a shared one. */    unsigned char *old = io->buffer;       bytes += io->len;       if (bytes < io->len || bytes + 100 < bytes)    Pike_error(msg_out_of_mem_2, bytes + 100);
pike.git/src/modules/_Stdio/buffer.cmod:200:       io->buffer = xalloc( bytes );    io->malloced = 1;    io->allocated = bytes;    io->num_malloc++;    memcpy( io->buffer, old, io->len );    io_unlink_external_storage(io);    }    }    -  static unsigned char *io_add_space_do_something( Buffer *io, size_t bytes, int force ) +  PMOD_EXPORT unsigned char *io_add_space_do_something( Buffer *io, size_t bytes, int force )    ATTRIBUTE((noclone,noinline)); -  static unsigned char *io_add_space_do_something( Buffer *io, size_t bytes, int force ) +  PMOD_EXPORT unsigned char *io_add_space_do_something( Buffer *io, size_t bytes, int force )    {    if( bytes && io->len+bytes < io->len )    Pike_error("Too large buffer, can not have more than %lu bytes",    (size_t)-1);          io_ensure_unlocked(io);    io_ensure_malloced(io, bytes);       /*
pike.git/src/modules/_Stdio/buffer.cmod:259:    if( io->allocated + growth < io->allocated )    Pike_error("Overflow in buffer size calculations\n");    }    io->buffer = xrealloc( io->buffer, io->allocated + growth );    io->num_malloc++;    io->allocated += growth;    }    return io->buffer+io->len;    }    -  static unsigned char *io_add_space( Buffer *io, size_t bytes, int force ) -  { -  if( io->len == io->offset ) -  io->offset = io->len = 0; -  if( !force && io->malloced && !io->locked && io->len+bytes < io->allocated && -  (!bytes || io->len+bytes > io->len)) -  return io->buffer+io->len; -  return io_add_space_do_something( io, bytes, force ); -  } -  +     /*! @decl protected bool range_error( int howmuch )    *!    *! This function is called when an attempt is made to read out of bounds.    *!    *! The default implementation simply returns @expr{0@} (zero).    *!    *! Override this function to change the behavior.    *!    *! @param howmuch    *! The argument @[howmuch] indicates how much data is needed: