Branch: Tag:

2018-11-04

2018-11-04 10:50:40 by Tobias S. Josefowitz <tobij@tobij.de>

Stdio.File()->read(): advance buffer if possible

This commit also removed Stdio.Buffer()->advance() because it
is a bad API. It allows one to 'validate' uninitialized memory
inside of Stdio.Buffer objects.

Instead, we now try to advance the write offset in Buffer objects
in Stdio.File()->read(), instead. This is done using a new internal
API which can be extended to advance other buffer types in the future.

2315:    io_trim(io);    }    -  /*! @decl void advance( int(0..) n ) -  *! -  *! Discard the first @[n] bytes from the buffer -  *! -  *! Throws an error if not enough space has been allocated. -  */ -  PIKEFUN void advance( int n ) -  { -  Buffer *io = THIS; -  Pike_sp--; -  if (!n) return; -  if (n < 0) -  SIMPLE_BAD_ARG_ERROR("advance()", 1, "int(0..1)"); -  if (n > io->allocated - io->len) -  Pike_error("Not enough buffer space.\n"); -  io->len += n; -  } -  +     /*! @decl void allocate( int(0..) n )    *!    *! Make sure that at least @[n] bytes of space are available in this buffer.
2343:    Pike_sp--;    if (!n) return;    if (n < 0) -  SIMPLE_BAD_ARG_ERROR("advance()", 1, "int(0..1)"); +  SIMPLE_BAD_ARG_ERROR("allocate()", 1, "int(0..1)");    io_add_space(io, n, 0);    }