pike.git / src / modules / Pipe / pipe.c

version» Context lines:

pike.git/src/modules/Pipe/pipe.c:205:   void close_and_free_everything(struct object *o,struct pipe *);   static INLINE void output_finish(struct object *obj);   static INLINE void output_try_write_some(struct object *obj);      /********** internal ********************************************************/      /* Push a callback to this object given the internal function number.    */   static void push_callback(ptrdiff_t no)   { -  add_ref(Pike_sp->u.object=THISOBJ); -  Pike_sp->subtype = DO_NOT_WARN(no + Pike_fp->context->identifier_level); -  Pike_sp->type = T_FUNCTION; +  SET_SVAL(*Pike_sp, T_FUNCTION, +  DO_NOT_WARN(no + Pike_fp->context->identifier_level), +  object, THISOBJ); +  add_ref(THISOBJ);    Pike_sp++;   }      /* Allocate a new struct input, link it last in the linked list */   static INLINE struct input *new_input(void)   {    struct input *i;    ninputs++;    i=ALLOC_STRUCT(input);    i->type=I_NONE;
pike.git/src/modules/Pipe/pipe.c:275:    break;       case I_NONE: break;    }    free((char *)i);   }      /* do the done_callback, then close and free everything */   static INLINE void pipe_done(void)   { -  if (THIS->done_callback.type!=T_INT) +  if (TYPEOF(THIS->done_callback) != T_INT)    {    assign_svalue_no_free(sp++,&THIS->id);    apply_svalue(&(THIS->done_callback),1);    pop_stack();       if(!THISOBJ->prog) /* We will not free anything in this case. */    return;    /* Pike_error("Pipe done callback destructed pipe.\n"); */    }    close_and_free_everything(THISOBJ,THIS);
pike.git/src/modules/Pipe/pipe.c:404:    struct pipe *this = THIS;    struct input * i = this->firstinput;       if (!i || i->type != I_BLOCKING_OBJ) {    Pike_fatal("PIPE: read_some_data(): Bad input type!\n");    return -1;    }    push_int(8192);    push_int(1); /* We don't care if we don't get all 8192 bytes. */    apply(i->u.obj, "read", 2); -  if ((sp[-1].type == T_STRING) && (sp[-1].u.string->len > 0)) { +  if ((TYPEOF(sp[-1]) == T_STRING) && (sp[-1].u.string->len > 0)) {    append_buffer(sp[-1].u.string);    pop_stack();    THIS->sleeping = 1;    return(1); /* Success */    }       /* FIXME: Should we check the return value here? */    pop_stack();    /* EOF */    return(0); /* EOF */
pike.git/src/modules/Pipe/pipe.c:688:    out->mode=O_SLEEP;    }    return;    }    len=s->len;    push_string(s);    apply_low(out->obj,out->write_offset,1);    out->mode=O_RUN;       ret=-1; -  if(sp[-1].type == T_INT) ret=sp[-1].u.integer; +  if(TYPEOF(sp[-1]) == T_INT) ret=sp[-1].u.integer;    pop_stack();       if (ret==-1) /* error, byebye */    {    output_finish(obj);    return;    }    out->pos+=ret;    THIS->sent+=ret;   
pike.git/src/modules/Pipe/pipe.c:716:   /*! @decl void input(object obj)    *!    *! Add an input file to this pipe.    */   static void pipe_input(INT32 args)   {    struct input *i;    int fd=-1; /* Per, one less warning to worry about... */    struct object *obj;    -  if (args<1 || sp[-args].type != T_OBJECT) +  if (args<1 || TYPEOF(sp[-args]) != T_OBJECT)    Pike_error("Bad/missing argument 1 to pipe->input().\n");       obj=sp[-args].u.object;    if(!obj || !obj->prog)    Pike_error("pipe->input() on destructed object.\n");       push_int(0);    apply(sp[-args-1].u.object,"set_id", 1);    pop_stack();   
pike.git/src/modules/Pipe/pipe.c:738: Inside #if defined(HAVE_MMAP) && defined(HAVE_MUNMAP)
     #if defined(HAVE_MMAP) && defined(HAVE_MUNMAP)       /* We do not handle mmaps if we have a buffer */    if(THIS->fd == -1)    {    char *m;    struct stat s;       apply(obj, "query_fd", 0); -  if(sp[-1].type == T_INT) fd=sp[-1].u.integer; +  if(TYPEOF(sp[-1]) == T_INT) fd=sp[-1].u.integer;    pop_stack();       if (fd != -1 && fstat(fd,&s)==0)    {    off_t filep=fd_lseek(fd, 0L, SEEK_CUR); /* keep the file pointer */    size_t len = s.st_size - filep;    if(S_ISREG(s.st_mode) /* regular file */    && ((m=(char *)mmap(0, len, PROT_READ,    MAP_FILE|MAP_SHARED,fd,filep))+1))    {
pike.git/src/modules/Pipe/pipe.c:829:   }      /*! @decl void write(string bytes)    *!    *! Add an input string to this pipe.    */   static void pipe_write(INT32 args)   {    struct input *i;    -  if (args<1 || sp[-args].type!=T_STRING) +  if (args<1 || TYPEOF(sp[-args]) != T_STRING)    Pike_error("illegal argument to pipe->write()\n");       if (!THIS->firstinput)    {    append_buffer(sp[-args].u.string);    pop_n_elems(args);    push_int(0);    return;    }   
pike.git/src/modules/Pipe/pipe.c:862:    */   static void pipe_output(INT32 args)   {    struct object *obj;    struct output *o;    int fd;    struct stat s;    struct buffer *b;       if (args<1 || -  sp[-args].type != T_OBJECT || +  TYPEOF(sp[-args]) != T_OBJECT ||    !sp[-args].u.object ||    !sp[-args].u.object->prog)    Pike_error("Bad/missing argument 1 to pipe->output().\n");       if (args==2 && -  sp[1-args].type != T_INT) +  TYPEOF(sp[1-args]) != T_INT)    Pike_error("Bad argument 2 to pipe->output().\n");       if (THIS->fd==-1) /* no buffer */    {    /* test if usable as buffer */    apply(sp[-args].u.object,"query_fd",0);    -  if ((sp[-1].type==T_INT) +  if ((TYPEOF(sp[-1]) == T_INT)    && (fd=sp[-1].u.integer)>=0    && (fstat(fd,&s)==0)    && S_ISREG(s.st_mode)    && (THIS->fd=fd_dup(fd))!=-1 )    {    /* keep the file pointer of the duped fd */    THIS->pos=fd_lseek(fd, 0L, SEEK_CUR);       THIS->living_outputs++;   
pike.git/src/modules/Pipe/pipe.c:986:    *! void|mixed id)    *!    *! Set the callback function to be called when all the outputs    *! have been sent.    */   static void pipe_set_done_callback(INT32 args)   {    if (args==0)    {    free_svalue(&THIS->done_callback); -  THIS->done_callback.type=T_INT; +  SET_SVAL_TYPE(THIS->done_callback, T_INT);    return;    } -  if (args<1 || (sp[-args].type!=T_FUNCTION && sp[-args].type!=T_ARRAY)) +  if (args<1 || (TYPEOF(sp[-args]) != T_FUNCTION && +  TYPEOF(sp[-args]) != T_ARRAY))    Pike_error("Illegal argument to set_done_callback()\n");       if (args>1)    {    free_svalue(&THIS->id);    assign_svalue_no_free(&(THIS->id),sp-args+1);    }       free_svalue(&THIS->done_callback);    assign_svalue_no_free(&(THIS->done_callback),sp-args);
pike.git/src/modules/Pipe/pipe.c:1014:    *! void|mixed id)    *!    *! Set the callback function to be called when one of the outputs has    *! been closed from the other side.    */   static void pipe_set_output_closed_callback(INT32 args)   {    if (args==0)    {    free_svalue(&THIS->output_closed_callback); -  THIS->output_closed_callback.type=T_INT; +  SET_SVAL_TYPE(THIS->output_closed_callback, T_INT);    return;    } -  if (args<1 || (sp[-args].type!=T_FUNCTION && sp[-args].type!=T_ARRAY)) +  if (args<1 || (TYPEOF(sp[-args]) != T_FUNCTION && +  TYPEOF(sp[-args]) != T_ARRAY))    Pike_error("Illegal argument to set_output_closed_callback()\n");       if (args>1)    {    free_svalue(&THIS->id);    assign_svalue_no_free(&(THIS->id),sp-args+1);    }    free_svalue(&THIS->output_closed_callback);    assign_svalue_no_free(&(THIS->output_closed_callback),sp-args);    pop_n_elems(args-1);
pike.git/src/modules/Pipe/pipe.c:1066:   static void f_bytes_sent(INT32 args)   {    pop_n_elems(args);    push_int(THIS->sent);   }      /********** callbacks *******************************************************/      static void pipe_write_output_callback(INT32 args)   { -  if (args<1 || sp[-args].type!=T_OBJECT) +  if (args<1 || TYPEOF(sp[-args]) != T_OBJECT)    Pike_error("Illegal argument to pipe->write_output_callback\n");       if(!sp[-args].u.object->prog) return;       if(sp[-args].u.object->prog != output_program)    Pike_error("Illegal argument to pipe->write_output_callback\n");       debug_malloc_touch(sp[-args].u.object);    output_try_write_some(sp[-args].u.object);    pop_n_elems(args-1);   }      static void pipe_close_output_callback(INT32 args)   {    struct output *o; -  if (args<1 || sp[-args].type!=T_OBJECT) +  if (args<1 || TYPEOF(sp[-args]) != T_OBJECT)       if(!sp[-args].u.object->prog) return;       if(sp[-args].u.object->prog != output_program)    Pike_error("Illegal argument to pipe->close_output_callback\n");       o=(struct output *)(sp[-args].u.object->storage);    -  if (THIS->output_closed_callback.type!=T_INT) +  if (TYPEOF(THIS->output_closed_callback) != T_INT)    {    assign_svalue_no_free(sp++,&THIS->id);    push_object(o->obj);    apply_svalue(&(THIS->output_closed_callback),2);    pop_stack();    }       output_finish(sp[-args].u.object);    pop_n_elems(args-1);   }      static void pipe_read_input_callback(INT32 args)   {    struct input *i;    struct pike_string *s;    -  if (args<2 || sp[1-args].type!=T_STRING) +  if (args<2 || TYPEOF(sp[1-args]) != T_STRING)    Pike_error("Illegal argument to pipe->read_input_callback\n");       i=THIS->firstinput;       if (!i)    Pike_error("Pipe read callback without any inputs left.\n");       s=sp[1-args].u.string;       if(append_buffer(s))
pike.git/src/modules/Pipe/pipe.c:1236:       p->living_outputs=0;       if (thisobj)    free_object(thisobj);       free_svalue(& p->done_callback);    free_svalue(& p->output_closed_callback);    free_svalue(& p->id);    -  p->done_callback.type=T_INT; -  p->output_closed_callback.type=T_INT; -  p->id.type=T_INT; +  SET_SVAL_TYPE(p->done_callback, T_INT); +  SET_SVAL_TYPE(p->output_closed_callback, T_INT); +  SET_SVAL_TYPE(p->id, T_INT);       /* p->done=0; */   }      static void init_pipe_struct(struct object *o)   {    debug_malloc_touch(o);       THIS->firstbuffer=THIS->lastbuffer=NULL;    THIS->firstinput=THIS->lastinput=NULL;    THIS->firstoutput=NULL;    THIS->bytes_in_buffer=0;    THIS->pos=0;    THIS->sleeping=0;    THIS->done=0;    THIS->fd=-1; -  THIS->done_callback.type=T_INT; -  THIS->output_closed_callback.type=T_INT; -  THIS->id.type=T_INT; +  SET_SVAL_TYPE(THIS->done_callback, T_INT); +  SET_SVAL_TYPE(THIS->output_closed_callback, T_INT); +  SET_SVAL_TYPE(THIS->id, T_INT);    THIS->id.u.integer=0;    THIS->living_outputs=0;    THIS->sent=0;   }      static void exit_pipe_struct(struct object *o)   {    close_and_free_everything(NULL,THIS);   }