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

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:83:   {   #if PRECOMPILE_API_VERSION > 5   #ifdef PIKE_DEBUG    PIKEVAR int b.num_malloc;    PIKEVAR int b.num_move;   #endif   #endif       CVAR Buffer b;    -  EXTRA -  { -  PIKE_MAP_VARIABLE("__output", OFFSETOF(Buffer_struct, b.output), -  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;    }       PMOD_EXPORT Buffer *io_buffer_from_object(struct object *o) {    return get_storage(o, Buffer_program);    }
pike.git/src/modules/_Stdio/buffer.cmod:185:    break;    case PIKE_T_MIXED: {    Buffer *parent = io->source.parent;    io_unlock(parent);    free_object(parent->this);    break;    }    case PIKE_T_OBJECT:    free_object(io->source.obj);    break; +  case PIKE_T_FUNCTION: +  free_object(io->source.output); +  break;    }    io->sourcetype = 0;    }       PMOD_EXPORT void io_ensure_malloced( Buffer *io, size_t headroom )    {    if( UNLIKELY(!io->allocated) )    {    /* convert to malloced buffer from a shared one. */    unsigned char *old = io_read_pointer(io);
pike.git/src/modules/_Stdio/buffer.cmod:481:    return l;    }    return -1;    }       PMOD_EXPORT void io_actually_trigger_output( Buffer *io )    ATTRIBUTE((noclone,noinline));       PMOD_EXPORT void io_actually_trigger_output( Buffer *io )    { -  if (UNLIKELY(!io->output.u.object->prog)) { -  /* Destructed object. */ -  free_svalue(&io->output); -  SET_SVAL(io->output, PIKE_T_INT, NUMBER_NUMBER, integer, 0); -  return; -  } -  -  if ( io->output.u.object ) { -  move_svalue(Pike_sp++, &io->output); -  SET_SVAL(io->output, PIKE_T_INT, NUMBER_NUMBER, integer, 0); +  push_object(io->source.output); +  io->sourcetype = 0;    apply_svalue(Pike_sp-1, 0);    pop_n_elems(2);    } -  } +        static int io_range_error( Buffer *io, ptrdiff_t howmuch )    ATTRIBUTE((noclone,noinline));       static int io_range_error( Buffer *io, ptrdiff_t howmuch )    {    int res;    struct svalue *osp = Pike_sp;       push_int64( howmuch );
pike.git/src/modules/_Stdio/buffer.cmod:1033:    *! This is used internally by @[Stdio.File] and @[SSL.File] to    *! handle nonblocking buffered mode, and is not necessarily    *! intended to be used directly by anything but implementations    *! of File or Stream like programs. Do not use this yourself    *! on buffers with Files or Streams in buffer modes.    */    PIKEFUN void __set_on_write( zero|function f )    {    Buffer *io = THIS;    -  if (f) -  assign_svalue(&io->output, f); -  else { -  if (io->output.u.object) { -  free_svalue(&io->output); -  io->output.u.object = 0; // free_svalue() puts in -1 +  switch (io->sourcetype) { +  default: +  Pike_error("Impossible to add callback on a dependent buffer."); +  /* FALLTHROUGH */ +  case PIKE_T_FUNCTION: +  free_object(io->source.output); +  break; +  case 0:; +  /* FALLTHROUGH */    } -  SET_SVAL(io->output, PIKE_T_INT, NUMBER_NUMBER, integer, 0); +  +  if (f && TYPEOF(*f) == PIKE_T_OBJECT) { +  add_ref(io->source.output = f->u.object); +  io->sourcetype = PIKE_T_FUNCTION; +  } else +  io->sourcetype = 0;    } -  } +        /*! @decl int(-1..) output_to( Stdio.Stream|function(string(8bit):int) fun, @    *! int(0..)|void nbytes )    *!    *! Write data from the buffer to the indicated file.    *!    *! @param fun    *! Write function. Either one of:    *! @mixed    *! @type Stdio.Stream
pike.git/src/modules/_Stdio/buffer.cmod:2987:    }    }       /*! @endclass RewindKey    */       static struct object* io_create_rewind_key( Buffer *io, int auto_mode )    {    struct object *o = fast_clone_object( Buffer_RewindKey_program );    struct Buffer_RewindKey_struct *s = (void*)o->storage; -  add_ref(io->this); -  s->obj = io->this; +  add_ref(s->obj = io->this);    s->rewind_to = io->offset;    s->io = io;    s->auto_mode = auto_mode;    io->locked_move++;    return o;    }      }   /*! @endclass Buffer    */