Esempio n. 1
0
void expr_let::dealloc(buffer<expr_cell*> & todelete) {
    dec_ref(m_body,  todelete);
    dec_ref(m_value, todelete);
    dec_ref(m_type,  todelete);
    this->~expr_let();
    get_let_allocator().recycle(this);
}
Esempio n. 2
0
void exec_while(env_t* env, ast_t* ast) {
  ast_t* cond = eval_expression(env, ast->data.while_statement.condition);
  if(cond->type != at_bool) {
    error_expected(NULL,get_ast_type_name(at_bool),get_ast_type_name(cond->type));
  } else {
    while(cond->data.b) {
      exec_statements(env, ast->data.while_statement.statements);
      dec_ref(cond);
      cond = eval_expression(env, ast->data.while_statement.condition);
    }
    dec_ref(cond);
  }
}
Esempio n. 3
0
void exec_dowhile(env_t* env, ast_t* ast) {
  /* same as exec_while() but with a call of exec_statements() before. */
  exec_statements(env, ast->data.while_statement.statements);
  ast_t* cond = eval_expression(env, ast->data.while_statement.condition);
  if(cond->type != at_bool) {
    error_expected(NULL,get_ast_type_name(at_bool),get_ast_type_name(cond->type));
  } else {
    while(cond->data.b) {
      exec_statements(env, ast->data.while_statement.statements);
      dec_ref(cond);
      cond = eval_expression(env, ast->data.while_statement.condition);
    }
    dec_ref(cond);
  }
}
Esempio n. 4
0
  void FiberStack::orphan(STATE, FiberData* user) {
    if(user == user_) {
      user_ = 0;
    }

    dec_ref();
  }
Esempio n. 5
0
void RequestHandler::return_connection_and_finish() {
  return_connection();
  if (io_worker_ != NULL) {
    io_worker_->request_finished(this);
  }
  dec_ref();
}
Esempio n. 6
0
static int
info_close(int fd, fdinfo_t* info)
{
    int rval = -1;

    switch( info->type )
    {
        case BOUND:
        case TRACKED:
        case EPOLL:
            if( info->type == BOUND && revive_mode == TRUE )
            {
                /* We don't close bound sockets in revive mode.
                 * This allows the program to exit "cleanly" and
                 * we will preserve the socket for the next run. */
                rval = 0;
                break;
            }
            dec_ref(info);
            fd_delete(fd);
            rval = libc.close(fd);
            break;

        case SAVED:
        case DUMMY:
            /* Woah, their program is most likely either messed up,
             * or it's going through and closing all descriptors
             * prior to an exec. We're just going to ignore this. */
            break;
    }

    return rval;
}
Esempio n. 7
0
AmBasicSipDialog::~AmBasicSipDialog()
{
  termUasTrans();
  termUacTrans();
  if (logger) dec_ref(logger);
  dump();
}
Esempio n. 8
0
		void lua_ref_base::reset()
		{
			dec_ref();
			m_L = nullptr;
			m_regidx = -1;
			m_pRef = nullptr;
		}
void func_decl_dependencies::erase(func_decl * f) {
    func_decl_set * s = 0;
    if (m_deps.find(f, s)) {
        m_manager.dec_ref(f);
        dec_ref(m_manager, *s);
        m_deps.erase(f);
        dealloc(s);
    }
}
Esempio n. 10
0
void release_my_map_info_list(map_info_t* milist) {
    if (milist) {
        pthread_mutex_lock(&g_my_map_info_list_mutex);

        my_map_info_data_t* data = (my_map_info_data_t*)milist->data;
        dec_ref(milist, data);

        pthread_mutex_unlock(&g_my_map_info_list_mutex);
    }
}
Esempio n. 11
0
sip_trans::~sip_trans() 
{
    reset_all_timers();
    delete msg;
    delete targets;
    delete [] retr_buf;
    if(retr_socket){
	dec_ref(retr_socket);
    }
    if((type == TT_UAC) && to_tag.s){
	delete [] to_tag.s;
    }
    if(dialog_id.s) {
	delete [] dialog_id.s;
    }
    if(logger) {
	dec_ref(logger);
    }
}
Esempio n. 12
0
void flush_my_map_info_list() {
    pthread_mutex_lock(&g_my_map_info_list_mutex);

    if (g_my_map_info_list != NULL) {
        my_map_info_data_t* data = (my_map_info_data_t*) g_my_map_info_list->data;
        dec_ref(g_my_map_info_list, data);
        g_my_map_info_list = NULL;
    }

    pthread_mutex_unlock(&g_my_map_info_list_mutex);
}
void func_decl_dependencies::reset() {
    dependency_graph::iterator it  = m_deps.begin();
    dependency_graph::iterator end = m_deps.end();
    for (; it != end; ++it) {
        func_decl * f  = (*it).m_key;
        func_decl_set * s    = (*it).m_value;
        m_manager.dec_ref(f);
        dec_ref(m_manager, *s);
        dealloc(s);
    }
    m_deps.reset();
}
Esempio n. 14
0
		lua_ref_base& lua_ref_base::operator=(const lua_ref_base& rht)
		{
			if (this != &rht)
			{
				dec_ref();
				m_L = rht.m_L;
				m_regidx = rht.m_regidx;
				m_pRef = rht.m_pRef;
				inc_ref();
			}
			return *this;
		}
Esempio n. 15
0
void AmBasicSipDialog::setMsgLogger(msg_logger* logger)
{
  if(this->logger) {
    dec_ref(this->logger);
  }

  if(logger){
    inc_ref(logger);
  }

  this->logger = logger;
}
Esempio n. 16
0
ImmT c_rt_lib0exec(ImmT ___nl__func, ImmT *___ref___arrI){
	if(!IS_HASH(___nl__func) && !IS_ARRHASH(___nl__func))
		nl_die_internal("function struct must by a hash", NAME(___nl__func));
	NlFunction *func = (NlFunction*)c_rt_lib0hash_get_value_dec(___nl__func, c_rt_lib0string_new("name"));
	if(!IS_FUNC(func))
		nl_die_internal("can call only function: %s", NAME(func));
	if(!IS_ARR(*___ref___arrI))
		nl_die_internal("expected array: %s", NAME(*___ref___arrI));
	NlArray *arr = priv_arr_to_change(___ref___arrI);
	ImmT (*f)(int n, ImmT *arg) = func->f;
	dec_ref((ImmT*)func);
	return (*f)(arr->size, arr->arr);
}
Esempio n. 17
0
int exec_if(env_t* env, ast_t* ast) {
  int result = 0; /* not null when condition was true,
                     null when condition was false */
  ast_t* cond = eval_expression(env, ast->data.if_statement.condition);
  if(cond->type != at_bool) {
    error_expected(NULL,get_ast_type_name(at_bool),get_ast_type_name(cond->type));
  } else {
    if(cond->data.b) {
      exec_statements(env, ast->data.if_statement.statements);
      result = 1;
    }
    dec_ref(cond);
  }
  return result;
}
Esempio n. 18
0
static mblk_t *v4l2_dequeue_ready_buffer(V4l2State *s, int poll_timeout_ms){
	struct v4l2_buffer buf;
	mblk_t *ret=NULL;
	struct pollfd fds;
	
	memset(&buf,0,sizeof(buf));
	buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	buf.memory = V4L2_MEMORY_MMAP;
	
	memset(&fds,0,sizeof(fds));
	fds.events=POLLIN;
	fds.fd=s->fd;
	/*check with poll if there is something to read */
	if (poll(&fds,1,poll_timeout_ms)==1 && fds.revents==POLLIN){
		if (v4l2_ioctl(s->fd, VIDIOC_DQBUF, &buf)<0) {
			switch (errno) {
			case EAGAIN:
			case EIO:
				/* Could ignore EIO, see spec. */
				break;
			default:
				ms_warning("VIDIOC_DQBUF failed: %s",strerror(errno));
			}
		}else{
			s->queued--;
			ms_debug("v4l2: de-queue buf %i",buf.index);
			/*decrement ref count of dequeued buffer */
			ret=s->frames[buf.index];
			dec_ref(ret);
			if (buf.index >= s->frame_max){
				ms_error("buf.index>=s->max_frames !");
				return NULL;
			}
			if (buf.bytesused<=30){
				ms_warning("Ignoring empty buffer...");
				return NULL;
			}
			/*normally buf.bytesused should contain the right buffer size; however we have found a buggy
			driver that puts a random value inside */
			if (s->picture_size!=0)
				ret->b_cont->b_wptr=ret->b_cont->b_rptr+s->picture_size;
			else ret->b_cont->b_wptr=ret->b_cont->b_rptr+buf.bytesused;
		}
	}
	return ret;
}
Esempio n. 19
0
    void clause::deallocate(ast_manager & m) {

        justification_stat j_stat;
        get_justification_stat(get_justification(), j_stat);

        ptr_buffer<clause>::iterator it  = j_stat.m_parent_clauses.begin();
        ptr_buffer<clause>::iterator end = j_stat.m_parent_clauses.end();
        for (; it != end; ++it) {
            clause * parent = *it;
            parent->del_child(this);
        }

        dec_ref(get_justification(), m);
        
        unsigned num_lits = get_num_literals();
        for (unsigned i = 0; i < num_lits; i++)
            m.dec_ref(get_literal(i).atom());

        unsigned capacity = get_num_literals_capacity();
        this->~clause();
        m.get_allocator().deallocate(sizeof(clause) +  capacity * sizeof(literal), this);
    }
Esempio n. 20
0
map_info_t* acquire_my_map_info_list() {
    pthread_mutex_lock(&g_my_map_info_list_mutex);

    int64_t time = now();
    if (g_my_map_info_list) {
        my_map_info_data_t* data = (my_map_info_data_t*)g_my_map_info_list->data;
        int64_t age = time - data->timestamp;
        if (age >= MAX_CACHE_AGE) {
            ALOGV("Invalidated my_map_info_list %p, age=%lld.", g_my_map_info_list, age);
            dec_ref(g_my_map_info_list, data);
            g_my_map_info_list = NULL;
        } else {
            ALOGV("Reusing my_map_info_list %p, age=%lld.", g_my_map_info_list, age);
        }
    }

    if (!g_my_map_info_list) {
        my_map_info_data_t* data = (my_map_info_data_t*)malloc(sizeof(my_map_info_data_t));
        g_my_map_info_list = load_map_info_list(getpid());
        if (g_my_map_info_list) {
            ALOGV("Loaded my_map_info_list %p.", g_my_map_info_list);
            g_my_map_info_list->data = data;
            data->refs = 1;
            data->timestamp = time;
        } else {
            free(data);
        }
    }

    map_info_t* milist = g_my_map_info_list;
    if (milist) {
        my_map_info_data_t* data = (my_map_info_data_t*)g_my_map_info_list->data;
        data->refs += 1;
    }

    pthread_mutex_unlock(&g_my_map_info_list_mutex);
    return milist;
}
Esempio n. 21
0
void
impl_init(void)
{
    const char* mode_env = getenv("HUPTIME_MODE");
    const char* multi_env = getenv("HUPTIME_MULTI");
    const char* revive_env = getenv("HUPTIME_REVIVE");
    const char* debug_env = getenv("HUPTIME_DEBUG");
    const char* pipe_env = getenv("HUPTIME_PIPE");
    const char* wait_env = getenv("HUPTIME_WAIT");

    if( debug_env != NULL && strlen(debug_env) > 0 )
    {
        debug_enabled = !strcasecmp(debug_env, "true") ? TRUE: FALSE;
    }

    DEBUG("Initializing...");

    /* Initialize our lock. */
    impl_init_lock();

    /* Save this pid as our master pid.
     * This is done to handle processes that use
     * process pools. We remember the master pid and
     * will do the full fork()/exec() only when we are
     * the master. Otherwise, we will simply shutdown
     * gracefully, and all the master to restart. */
    master_pid = getpid();

    /* Grab our exit strategy. */
    if( mode_env != NULL && strlen(mode_env) > 0 )
    {
        if( !strcasecmp(mode_env, "fork") )
        {
            exit_strategy = FORK;
            DEBUG("Exit strategy is fork.");
        }
        else if( !strcasecmp(mode_env, "exec") )
        {
            exit_strategy = EXEC;
            DEBUG("Exit strategy is exec.");
        }
        else
        {
            fprintf(stderr, "Unknown exit strategy.");
            libc.exit(1);
        }
    }

    /* Check if we have something to unlink. */
    to_unlink = getenv("HUPTIME_UNLINK");
    if( to_unlink != NULL && strlen(to_unlink) > 0 )
    {
        DEBUG("Unlink is '%s'.", to_unlink);
    }

    /* Clear up any outstanding child processes.
     * Because we may have exited before the process
     * could do appropriate waitpid()'s, we try to
     * clean up children here. Note that we may have
     * some zombies that hang around during the life
     * of the program, but at every restart they will
     * be cleaned up (so at least they won't grow
     * without bound). */
    int status = 0;
    while( waitpid((pid_t)-1, &status, WNOHANG) > 0 );

    /* Check if we're in multi mode. */
    if( multi_env != NULL && strlen(multi_env) > 0 )
    {
        multi_mode = !strcasecmp(multi_env, "true") ? TRUE: FALSE;
    }
#ifndef SO_REUSEPORT
    if( multi_mode == TRUE )
    {
        fprintf(stderr, "WARNING: Multi mode not supported.\n");
        fprintf(stderr, "(Requires at least Linux 3.9 and recent headers).\n");
    } 
#endif

    /* Check if we're in revive mode. */
    if( revive_env != NULL && strlen(revive_env) > 0 )
    {
        revive_mode = !strcasecmp(revive_env, "true") ? TRUE : FALSE;
    }

    /* Check if we are in wait mode. */
    if( wait_env != NULL && strlen(wait_env) > 0 )
    {
        wait_mode = !strcasecmp(wait_env, "true") ? TRUE : FALSE;
    }

    /* Check if we're a respawn. */
    if( pipe_env != NULL && strlen(pipe_env) > 0 )
    {
        int fd = -1;
        fdinfo_t *info = NULL;
        int pipefd = strtol(pipe_env, NULL, 10);

        DEBUG("Loading all file descriptors.");

        /* Decode all passed information. */
        while( !info_decode(pipefd, &fd, &info) )
        {
            fd_save(fd, info);
            DEBUG("Decoded fd %d (type %d).", fd, info->type);
            info = NULL;
        }
        if( info != NULL )
        {
            dec_ref(info);
        }

        /* Finished with the pipe. */
        libc.close(pipefd);
        unsetenv("HUPTIME_PIPE");
        DEBUG("Finished decoding.");

        /* Close all non-encoded descriptors. */
        for( fd = 0; fd < fd_max(); fd += 1 )
        {
            info = fd_lookup(fd);
            if( info == NULL )
            {
                DEBUG("Closing fd %d.", fd);
                libc.close(fd);
            }
        }

        /* Restore all given file descriptors. */
        for( fd = 0; fd < fd_limit(); fd += 1 )
        {
            info = fd_lookup(fd);
            if( info != NULL && info->type == SAVED )
            {
                fdinfo_t *orig_info = fd_lookup(info->saved.fd);
                if( orig_info != NULL )
                {
                    /* Uh-oh, conflict. Move the original (best effort). */
                    do_dup(info->saved.fd);
                    do_close(info->saved.fd);
                }

                /* Return the offset (ignore failure). */
                if( info->saved.offset != (off_t)-1 )
                {
                    lseek(fd, info->saved.offset, SEEK_SET);
                }

                /* Move the SAVED fd back. */
                libc.dup2(fd, info->saved.fd);
                DEBUG("Restored fd %d.", info->saved.fd);
            }
        }
    }
    else
    {
        DEBUG("Saving all initial file descriptors.");

        /* Save all of our initial files. These are used
         * for re-execing the process. These are persisted
         * effectively forever, and on restarts we close
         * everything that is not a BOUND socket or a SAVED
         * file descriptor. */
        for( int fd = 0; fd < fd_max(); fd += 1 )
        {
            fdinfo_t *info = fd_lookup(fd);
            if( info != NULL )
            {
                /* Encoded earlier. */
                continue;
            }

            /* Make a new SAVED FD. */
            int newfd = libc.dup(fd);
            if( newfd >= 0 )
            {
                fdinfo_t *saved_info = alloc_info(SAVED);

                if( saved_info != NULL )
                {
                    saved_info->saved.fd = fd;
                    saved_info->saved.offset = lseek(fd, 0, SEEK_CUR);
                    fd_save(newfd, saved_info);
                    DEBUG("Saved fd %d (offset %lld).",
                        fd, (long long int)saved_info->saved.offset);
                }
            }
        }
    }

    /* Save the environment.
     *
     * NOTE: We reserve extra space in the environment
     * for our special start-up parameters, which will be added
     * in impl_exec() below. (The encoded BOUND/SAVED sockets).
     *
     * We also filter out the special variables above that were
     * used to pass in information about sockets that were bound. */
    free(environ_copy);
    environ_copy = (char**)read_nul_sep("/proc/self/environ");
    DEBUG("Saved environment.");

    /* Save the arguments. */
    free(args_copy);
    args_copy = (char**)read_nul_sep("/proc/self/cmdline");
    DEBUG("Saved args.");
    for( int i = 0; args_copy[i] != NULL; i += 1 )
    {
        DEBUG(" arg%d=%s", i, args_copy[i]);
    }

    /* Save the cwd & exe. */
    free(cwd_copy);
    cwd_copy = (char*)read_link("/proc/self/cwd");
    DEBUG("Saved cwd.");
    free(exe_copy);
    exe_copy = (char*)read_link("/proc/self/exe");
    DEBUG("Saved exe.");

    /* Install our signal handlers. */
    impl_install_sighandlers();

    /* Initialize our thread. */
    impl_init_thread();

    /* Unblock our signals.
     * Note that we have specifically masked the
     * signals prior to the exec() below, to cover
     * the race between program start and having
     * installed the appropriate handlers. */
    sigset_t set;
    sigemptyset(&set);
    sigaddset(&set, SIGHUP);
    sigprocmask(SIG_UNBLOCK, &set, NULL);

    /* Done. */
    DEBUG("Initialization complete.");
}
Esempio n. 22
0
void expr_macro::dealloc(buffer<expr_cell*> & todelete) {
    for (unsigned i = 0; i < m_num_args; i++) dec_ref(m_args[i], todelete);
    delete(this);
}
Esempio n. 23
0
 ~Callable() { if (type == OBJECT) dec_ref(obj); }
Esempio n. 24
0
void expr_binding::dealloc(buffer<expr_cell*> & todelete) {
    dec_ref(m_body, todelete);
    dec_ref(m_binder.m_type, todelete);
    this->~expr_binding();
    get_binding_allocator().recycle(this);
}
Esempio n. 25
0
void expr_app::dealloc(buffer<expr_cell*> & todelete) {
    dec_ref(m_fn, todelete);
    dec_ref(m_arg, todelete);
    this->~expr_app();
    get_app_allocator().recycle(this);
}
Esempio n. 26
0
void expr_local::dealloc(buffer<expr_cell*> & todelete) {
    dec_ref(m_type, todelete);
    this->~expr_local();
    get_local_allocator().recycle(this);
}
Esempio n. 27
0
ast_t* eval_call(env_t* env, ast_t* ast) {
  ast_t* func = NULL;
  ast_t* result = NULL;
  char* fn = NULL;  /* function name */
  switch(ast->data.call.call_type) {
    case ct_anonymous:
      fn = "<anonymous>";
      func = ast->data.call.function.function;
      break;
    case ct_named:
      fn = ast->data.call.function.id;
      func = get_ast_by_id(env, fn);
      if(func == NULL) {
        error_id(NULL, fn);
      };
      break;
  }
  switch(func->type) {
    case at_function:{
      size_t i;
      if(ast->data.call.callargs->data.callargs.count != func->data.function.params->data.params.count) {
        error_paramcount(NULL, fn, func->data.function.params->data.params.count, ast->data.call.callargs->data.callargs.count);
      }
      env_t* inner = create_env();
      inner->parent =  env;
      for(i = 0; i < func->data.function.params->data.params.count; i++) {
        set_ast_to_id(
            inner,
            func->data.function.params->data.params.params[i],
            eval_expression(env,ast->data.call.callargs->data.callargs.callargs[i])
        );
      }
      /* execute the function */
      exec_statements(inner, func->data.function.statements);
      /* get the result */
      inner->parent = NULL; /* must be NULL, get_ast_by_id() also searches the parent environment */
      result = get_ast_by_id(inner, "@");
      free_env(inner);
      break;
    }
    case at_builtin:
      if(ast->data.call.callargs->data.callargs.count != func->data.builtin.paramcount) {
        error_paramcount(NULL, fn, func->data.function.params->data.params.count, ast->data.call.callargs->data.callargs.count);
      }
      switch(func->data.builtin.paramcount) {
        case 0:
          result = func->data.builtin.function.builtin_0();
          break;
        case 1: {
          ast_t* p = eval_expression(env,ast->data.call.callargs->data.callargs.callargs[0]);
          result = func->data.builtin.function.builtin_1(p);
          dec_ref(p);
          break;
        }
        case 2: {
          ast_t* p1 = eval_expression(env,ast->data.call.callargs->data.callargs.callargs[0]);
          ast_t* p2 = eval_expression(env,ast->data.call.callargs->data.callargs.callargs[1]);
          result = func->data.builtin.function.builtin_2(p1,p2);
          dec_ref(p1);
          dec_ref(p2);
          break;
        }
        case 3: {
          ast_t* p1 = eval_expression(env, ast->data.call.callargs->data.callargs.callargs[0]);
          ast_t* p2 = eval_expression(env, ast->data.call.callargs->data.callargs.callargs[1]);
          ast_t* p3 = eval_expression(env, ast->data.call.callargs->data.callargs.callargs[2]);
          result = func->data.builtin.function.builtin_3(p1,p2,p3);
          dec_ref(p1);
          dec_ref(p2);
          dec_ref(p3);
          break;
        }
        default:
          printf("\n\n*** HINT TO DEVELOPER ***\nimplement builtincall in vm.c\n\n");
          exit(1);
          /* if you create a builtin function with more parameters then you have to add a case here */
          break;
      }
      break;
    default:
      error_expected(NULL, get_ast_type_name(at_function), get_ast_type_name(func->type));
      break;
  }
  return result;
}
Esempio n. 28
0
		lua_ref_base::~lua_ref_base()
		{
			//if find it, than unref, else maybe lua is closed
			dec_ref();
		}
Esempio n. 29
0
static void dec_ref(mblk_t *m){
	m->b_datap->db_ref--;
	if (m->b_cont)
		dec_ref(m->b_cont);
}
Esempio n. 30
0
ast_t* eval_expression(env_t* env, ast_t* ast) {
  switch(ast->type) {
    /* valid */
    case at_call: return eval_call(env,ast);
    case at_identifier: return get_ast_by_id(env, ast->data.id);
    case at_expression: {
      ast_t* result = NULL;
      ast_t* left = eval_expression(env, ast->data.expression.left);
      ast_t* right = eval_expression(env, ast->data.expression.right);
      inc_ref(left);
      inc_ref(right);
      switch(ast->data.expression.op) {
        case op_add: result = eval_add(env, left, right); break;
        case op_mul: result = eval_mul(env, left, right); break;
        case op_div: result = eval_div(env, left, right); break;
        case op_sub: result = eval_sub(env, left, right); break;
        case op_mod: result = eval_mod(env, left, right); break;
        case op_and: result = eval_and(env, left, right); break;
        case op_or: result = eval_or(env, left, right); break;
        case op_gt: result = eval_gt(env, left, right); break;
        case op_ge: result = eval_ge(env, left, right); break;
        case op_lt: result = eval_lt(env, left, right); break;
        case op_le: result = eval_le(env, left, right); break;
        case op_eq: result = eval_eq(env, left, right); break;
        case op_neq: result = eval_neq(env, left, right); break;
        case op_cat: result = eval_cat(env, left, right); break;
        case op_deref: {
          ast_t* index = eval_expression(env, right);
          if (index->type != at_integer) {
            // TODO: error -> index must be an integer!
          } else {
            switch(left->type) {
              case at_list: result = left->data.list.elements[index->data.i];
            }
          }
        }
      }
      result->ref_count = 0;
      dec_ref(left);
      dec_ref(right);
      return result;
    }
    /* no need to evaluate */
    case at_integer:
    case at_bool:
    case at_double:
    case at_string:
    case at_function:
    case at_statements:
    case at_list:
      return ast;

    /* invalid */
    case at_assignment:
    case at_callargs:
    case at_conditional:
    case at_dowhile:
    case at_elif:
    case at_if:
    case at_params:
    case at_while:
    case at_builtin:
      error_expected(NULL,"expression",get_ast_type_name(ast->type));
  }
  return NULL; /* this should never happen */
}