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

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:949:    /*! @decl int __fd_set_output( object|function(string:int) write_callback )    *!    *! This tells the buffer to trigger the write callback for the    *! specified filedescriptor when data is added to the buffer.    *!    *! This is used internally by Stdio.File to handle nonblocking    *! buffered mode, and is not really intended to be used directly.    *!    *! If @[write_callback] is @expr{0@} (zero) the state is cleared.    */ -  PIKEFUN void __fd_set_output( int(0..0)|object|function f ) +  PIKEFUN void __fd_set_output( zero|object|function f )    {    Buffer *io = THIS;    if( TYPEOF(*f) == PIKE_T_OBJECT ) {    struct program *p = f->u.object->prog;    if (p) {    struct inherit *inh = p->inherits + SUBTYPEOF(*f);    int write_fun_num;    p = inh->prog;    if ((write_fun_num = find_identifier("write", p)) == -1) {    Pike_error("Function \"write\" not available in object.\n");
pike.git/src/modules/_Stdio/buffer.cmod:1180:    *! @code    *! private typedef @[System.Memory]|@[Stdio.Buffer]|@[String.Buffer] BufferObject;    *! private typedef BufferObject|string(8bit)|int(8bit)|array(AddArgument) AddArgument;    *! @endcode    *!    *! Add the items in data to the end of the buffer.    *!    *! The supported argument types are:    *!    *! @mixed -  *! @type string(0..255) +  *! @type string(8bit)    *! An eight bit string. -  *! @type int(0..255) +  *! @type int(8bit)    *! A single byte    *! @type System.Memory    *! A chunk of memory. The whole memory area is added.    *! @type Stdio.Buffer    *! A chunk of memory. The whole memory area is added.    *! @type String.Buffer    *! A chunk of memory. The whole memory area is added.    *! @type array(AddArgument)    *! Add all elements in the array individually. Each element may be    *! any one of the types listed here.
pike.git/src/modules/_Stdio/buffer.cmod:1212:    int i;    Buffer *io = THIS;       for(i=0; i<args; i++ )    io_append_svalue( io, argp+i );       pop_stack();    ref_push_object(io->this);    }    -  /*! @decl Buffer add_int8( int(0..255) ) +  /*! @decl Buffer add_int8( int(8bit) )    *! Adds a single byte to the buffer.    */    PIKEFUN Buffer add_int8( int i )    {    Buffer *io = THIS;    *io_add_space(io,1,0)=i;    io->len++;    Pike_sp--;    ref_push_object(Pike_fp->current_object);    }    -  /*! @decl Buffer add_int16( int(0..65535) ) +  /*! @decl Buffer add_int16( int(16bit) )    *!    *! Add a 16-bit network byte order value to the buffer    */    PIKEFUN Buffer add_int16( int i )    {    Buffer *io = THIS;    unsigned char *p = io_add_space(io,2,0);    p[0] = i>>8;    p[1] = i;    io->len += 2;
pike.git/src/modules/_Stdio/buffer.cmod:1253:    Buffer *io = THIS;    unsigned char *p = io_add_space(io,4,0);    p[0] = i>>24;    p[1] = i>>16;    p[2] = i>>8;    p[3] = i;    io->len += 4;    ref_push_object(Pike_fp->current_object);    }    -  /*! @decl Buffer add_hstring( string(0..255) data, int size_size ) +  /*! @decl Buffer add_hstring( string(8bit) data, int size_size )    *! @decl Buffer add_hstring( Stdio.Buffer data, int size_size )    *! @decl Buffer add_hstring( System.Memory data, int size_size )    *! @decl Buffer add_hstring( String.Buffer data, int size_size ) -  *! @decl Buffer add_hstring( int(0..255) data, int size_size ) +  *! @decl Buffer add_hstring( int(8bit) data, int size_size )    *! @decl Buffer add_hstring( array data, int size_size ) -  *! @decl Buffer add_hstring( int|string(0..255)|Stdio.Buffer|System.Memory|array data, int size_size, int offset ) +  *! @decl Buffer add_hstring( int|string(8bit)|Stdio.Buffer|System.Memory|array data, int size_size, int offset )    *!    *! Adds length of data followed by @[data] to the buffer.    *!    *! This is identical to    *! @tt{sprintf("%"+size_size+"H",(string)Stdio.Buffer(data))@} but    *! significantly faster.    *!    *! @[size_size] is the number of bytes used to represent the length of the data.    *! It must be less than Int.NATIVE_MAX.    *!    *! @[offset] is added to the length of the data prior to writing out    *! the length. Typical usage involves adding @[size_size] to account    *! for the room used by the size.    *!    *! The supported @[data] argument types are    *!    *! @mixed -  *! @type int(0..255) +  *! @type int(8bit)    *! An eight bit character. -  *! @type string(0..255) +  *! @type string(8bit)    *! An eight bit string.    *! @type System.Memory    *! A chunk of memory. The whole memory area is added.    *! @type Stdio.Buffer    *! A chunk of memory. The whole memory area is added.    *! @type String.Buffer    *! A chunk of memory. The whole memory area is added.    *! @type array    *! Add all elements in the array individually. Each element may be    *! any one of the types listed here.
pike.git/src/modules/_Stdio/buffer.cmod:1383:    {    convert_stack_top_to_bignum();    width = (mpz_sizeinbase( (void*)i->u.object->storage, 2)+7)/8;    io_add_int( THIS, width, len_width );    io_add_bignum( THIS, i->u.object, width );    pop_stack(); /* o. */    }    ref_push_object(Pike_fp->current_object);    }    -  /*! @decl Buffer add_ints( array(int) integers, int(0..255) len ) +  /*! @decl Buffer add_ints( array(int) integers, int(8bit) len )    *!    *! Add the integers in the specified array, @[len] bytes per int.    *! Equivalent to calling @[add_int] for each integer, but faster,    *! and if an error occurs the buffer will contain no new    *! data. Either all or none of the integers will be added.    *!    *! Errors can occur if one of the elements in @[integers] is not    *! actually an integer, if sizeof(integers)*len is bigger than can    *! be represented in a size_t, or if the buffer cannot grow due to    *! an out of memory condition.
pike.git/src/modules/_Stdio/buffer.cmod:1464:    io_trigger_output( io );    Pike_sp--;    pop_stack();    ref_push_object(io->this);    }       /*! @decl protected int `[](int off)    *!    *! Return the character at the specified offset.    */ -  PIKEFUN int(0..255) `[]( int off ) +  PIKEFUN int(8bit) `[]( int off )    flags ID_PROTECTED;    {    Buffer *io = THIS;    if( off < 0 )    off = io_len(io)-off;       if( io_avail( io, off ) )    Pike_sp[-1].u.integer = io_read_pointer(io)[off];    else    Pike_sp[-1].u.integer = -1;    }       /*! @decl protected int `[]=(int off, int char)    *!    *! Set the character at the specified offset to @[char].    */ -  PIKEFUN int(0..255) `[]=( int off, int val ) +  PIKEFUN int(8bit) `[]=( int off, int val )    flags ID_PROTECTED;    {    Buffer *io = THIS;       io_ensure_malloced( io, 0 );       if( off < 0 ) off = io_len(io)-off;    again:    if( io_avail( io, off ) )    {
pike.git/src/modules/_Stdio/buffer.cmod:1521:    push_int64(io_len(THIS));    }       /*! @decl string cast(string type)    *!    *! Convert the buffer to a string.    *!    *!@note    *! This only works for buffers whose length is less than 0x7fffffff.    */ -  PIKEFUN string(0..255) cast(string to) +  PIKEFUN string(8bit) cast(string to)    flags ID_PROTECTED;    {    if( to != literal_string_string )    {    push_undefined();    return;    }    if( io_len(THIS) > 0x7fffffff )    Pike_error("This buffer is too large to convert to a string.\n");    push_string(make_shared_binary_string((void*)io_read_pointer(THIS),
pike.git/src/modules/_Stdio/buffer.cmod:1609:    *! Makes this buffer read only until the returned object is released.    *!    *! @note    *! This currently simply returns a 0-length subbuffer.    */    PIKEFUN Buffer lock()    {    push_object( io_read_buffer( THIS, 0, 0 ) );    }    -  PIKEFUN string(0..255) _sprintf(int o, mapping UNUSED) +  PIKEFUN string(8bit) _sprintf(int o, mapping UNUSED)    flags ID_PROTECTED;    {    size_t bytes;    pop_n_elems(args-1);    Pike_sp--;    switch( o )    {    case 'O':    {    push_static_text("%O(%d bytes, read=[..%d] data=[%d..%d] free=[%d..%d] %s%s)");
pike.git/src/modules/_Stdio/buffer.cmod:1676:    *! indicated number of bytes as a string.    *!    *! @[offset] is substracted from the specified length prior to reading the    *! string. Typical usage involves substracting @[n] to account    *! for the room used by the size.    *!    *! If there is not enough data available return 0.    *!    *! Note that pike string can not be longer than 0x7fffffff bytes (~2Gb).    */ -  PIKEFUN string(0..255) read_hstring( int bytes, void|int offset ) +  PIKEFUN string(8bit) read_hstring( int bytes, void|int offset )    {    INT64 len;    Buffer *io = THIS;    struct pike_string *s;    ONERROR e;       io_rewind_on_error( io, &e );    len = io_read_number( io, bytes );       if (offset)
pike.git/src/modules/_Stdio/buffer.cmod:1721:    *! Reads a \0 terminated C-string and returns the    *! string excluding the terminating \0.    *!    *! If there is not enough data available return UNDEFINED.    *!    *! Note that pike string can not be longer than 0x7fffffff bytes (~2Gb).    *!    *! @param sentinel    *! A different character can be used as end sentinel of the string.    */ -  PIKEFUN string(0..255) read_cstring(void|int sentinel) +  PIKEFUN string(8bit) read_cstring(void|int sentinel)    {    INT64 len;    Buffer *io = THIS;    struct pike_string *s;    ONERROR e;    int end = 0;    if( sentinel )    end = sentinel->u.integer;       io_rewind_on_error( io, &e );
pike.git/src/modules/_Stdio/buffer.cmod:1982:    *! This function is very similar to @[sscanf], but the    *! result is the sum of the matches. Most useful to match    *! a single value.    *!    *! @example    *! @code    *! // get the next whitespace separated word from the buffer.    *! buffer->match("%*[ \t\r\n]%[^ \t\r\n]");    *! @endcode    */ -  PIKEFUN string(0..255)|int|float|array match( string format ) +  PIKEFUN string(8bit)|int|float|array match( string format )    {    INT32 i;    ptrdiff_t num_used;    struct svalue *start = Pike_sp;    retry:    i = low_sscanf_pcharp(    MKPCHARP(io_read_pointer(THIS), 0), io_len(THIS),    MKPCHARP(format->str,format->size_shift), format->len,    &num_used);   
pike.git/src/modules/_Stdio/buffer.cmod:2119:       /*! @decl string(8bit) read( int n )    *!    *! Read @[bytes] bytes of data from the buffer.    *!    *! If there is not enough data available this returns 0.    *!    *! @seealso    *! @[try_read()]    */ -  PIKEFUN string(0..255) read( int bytes ) +  PIKEFUN string(8bit) read( int bytes )    {    struct pike_string *s;    Pike_sp--;    s = io_read_string(THIS, bytes );    if( s )    push_string( s );    else    push_undefined();    }   
pike.git/src/modules/_Stdio/buffer.cmod:2142:    *! Read all data from the buffer.    *!    *! If there is not enough data available this returns 0.    *!    *! This is basically equivalent to (string)buffer, but it also    *! removes the data from the buffer.    *!    *! @seealso    *! @[try_read()]    */ -  PIKEFUN string(0..255) read() +  PIKEFUN string(8bit) read()    {    push_string( io_read_string(THIS, io_len(THIS)) );    }       /*! @decl string(8bit) try_read(int len)    *!    *! Attempt to read some data from the buffer.    *!    *! @param len    *! Read at most @[len] bytes from the buffer.    *!    *! @returns    *! If the buffer contains less than @[len] bytes    *! of data, the entire buffer contents are returned.    *! Otherwise the first @[len] bytes are returned.    *!    *! @seealso    *! @[read()]    */ -  PIKEFUN string(0..255) try_read( int bytes ) +  PIKEFUN string(8bit) try_read( int bytes )    {    Buffer *this = THIS;    struct pike_string *s;    Pike_sp--;    /* Hm. signed/unsigned comparisons abound. */    if( bytes > 0 && (size_t)bytes > io_len(this) )    bytes = io_len(this);    push_string( io_read_string(this, bytes ) );    }   
pike.git/src/modules/_Stdio/buffer.cmod:2349:    *! @decl void _decode(string x)    *!    *! Encode and decode Stdio.Buffer objects.    *! Only the buffer data is kept, no other state is saved.    */    PIKEFUN string _encode()    {    push_string(io_read_string(THIS, io_len(THIS)));    }    -  PIKEFUN void _decode(string(0..255) x) +  PIKEFUN void _decode(string(8bit) x)    {    Buffer *this = THIS;    if( this->buffer )    Pike_error("Can not initialize twice.\n");    if( x->size_shift )    Pike_error("Can not handle non-8bit data.\n");    this->buffer = (unsigned char*)x->str;    this->len = x->len;    this->malloced = 0;    this->str = x;