Пример #1
0
void
sip_calls_rotate()
{
    sip_call_t *call = vector_first(calls.list);

    // Remove from callids hash
    htable_remove(calls.callids, call->callid);
    // Remove first call from active and call lists
    vector_remove(calls.active, call);
    vector_remove(calls.list, call);

}
Пример #2
0
void Document::on_selection_event(ISelectable* s) {
	Module* m = dynamic_cast<Module*>(s);
	if(m) {
		if(s->bSelected) selected_modules.push_back(m);
		else vector_remove(selected_modules, m);
	}
	Link* l = dynamic_cast<Link*>(s);
	if(l) {
		if(s->bSelected) selected_links.push_back(l);
		else vector_remove(selected_links, l);
	}
}
Пример #3
0
rcl_status cl_release_kernel(struct client_state* state, kernel_t kernel)
{
	struct kernel_state* kernel_state;
	cl_int retval;
	uint32_t i;

	if (!vector_valid_idx(&state->kernels, kernel)) {
		log_print(log_error, "Kernel %" PRIu32 " not found", kernel);
		return RCL_INVALID_KERNEL;
	}

	kernel_state = *vector_element(&state->kernels, kernel,
		struct kernel_state*);
	retval = clReleaseKernel(kernel_state->id);
	if (retval)
		return opencl_error(retval);

	vector_remove(&state->kernels, kernel);

	for (i = 0; i < kernel_state->argument_count; i++) {
		if (!kernel_state->arguments[i].is_set
			|| kernel_state->arguments[i].is_buffer) {
			continue;
		}

		free(kernel_state->arguments[i].argument.value.value);
	}

	free(kernel_state->arguments);
	free(kernel_state->name);
	free(kernel_state);
	return RCL_OK;
}
Пример #4
0
void comms_load_player_choices()
{

	while (vector_get_size(&comms_player_choices) > 0)
	{
		Comms_PlayerChoice *pc = (Comms_PlayerChoice *)vector_get(&comms_player_choices, 0);
		vector_remove(&comms_player_choices, 0);
		free(pc);
	}

	vector_init(&comms_player_choices, COMMS_PLAYER_CHOICE_COUNT);
	vector_fill(&comms_player_choices, NULL);


	Comms_PlayerChoice *pc;

	pc = malloc(sizeof(Comms_PlayerChoice));
	pc->text0 = "attack";
	pc->choice0 = COMMS_NPC_DEFEND;
	pc->text1 = "trade";
	pc->choice1 = COMMS_NPC_TRADE;
	pc->text2 = "talk";
	pc->choice2 = COMMS_NPC_INFO;
	pc->text3 = "disengage";
	pc->choice3 = COMMS_NPC_FAREWELL;
	vector_set(&comms_player_choices, COMMS_PLAYER_CHOICE_MAIN, pc);

	pc = malloc(sizeof(Comms_PlayerChoice));
	pc->text0 = "aggree";
	pc->choice0 = COMMS_NPC_TRADE_ACCEPT_BUY; //TODO: This doesn't account for buy/sell separation
	pc->text1 = "decline";
	pc->choice1 = COMMS_NPC_TRADE_DECLINE;
	pc->text2 = NULL;
	pc->choice2 = -1;
	pc->text3 = NULL;
	pc->choice3 = -1;
	vector_set(&comms_player_choices, COMMS_PLAYER_CHOICE_TRADE_INVITE, pc);

	pc = malloc(sizeof(Comms_PlayerChoice));
	pc->text0 = "buy";
	pc->choice0 = COMMS_NPC_TRADE_ACCEPT_BUY;
	pc->text1 = "sell";
	pc->choice1 = COMMS_NPC_TRADE_ACCEPT_SELL;
	pc->text2 = "back";
	pc->choice2 = COMMS_PLAYER_CHOICE_MAIN;
	pc->text3 = NULL;
	pc->choice3 = -1;
	vector_set(&comms_player_choices, COMMS_PLAYER_CHOICE_TRADE, pc);

	pc = malloc(sizeof(Comms_PlayerChoice));
	pc->text0 = "attack";
	pc->choice0 = COMMS_NPC_ATTACK_ACCEPT;
	pc->text1 = "flee";
	pc->choice1 = COMMS_NPC_ATTACK_FLEE;
	pc->text2 = "plead";
	pc->choice2 = COMMS_NPC_ATTACK_PLEAD;
	pc->text3 = NULL;
	pc->choice3 = -1;
	vector_set(&comms_player_choices, COMMS_PLAYER_CHOICE_DEFEND, pc);
}
Пример #5
0
void hashmap_remove(hashmap_p m, char* key){
	int n = strlen(key);
	size_t h = hash_func(key) % m->num_buckets;
	item_t *itm = m->buckets[h];
	item_t *last = NULL;
	int keyind;
	while(itm!=NULL){
		if(strcmp(key, itm->key)==0)
			break;
		last = itm;
		itm = itm->next;
	}
	
	if(itm != NULL){
		if(last==NULL)
			m->buckets[h] = NULL;
		else last->next = itm->next;
		
		free(itm->key);
		m->destructor(itm->val);
		free(itm);
		
		keyind = vector_index(m->keys, key, n);
		vector_remove(m->keys, keyind);
		m->size--;
	}
}
Пример #6
0
void
vector_clear(vector_t *vector)
{
    // Remove all items in the vector
    while (vector_first(vector))
        vector_remove(vector, vector_first(vector));
}
Пример #7
0
void test_vector_remove_empty_array() {
    array* arr = vector_create();

    ASSERT(vector_remove(arr, 0) == false);
    ASSERT(arr->size == 0);
    vector_free(arr);
}
Пример #8
0
void
sip_calls_rotate()
{
    sip_call_t *call;
    vector_iter_t it = vector_iterator(calls.list);
    while ((call = vector_iterator_next(&it))) {
        if (!call->locked) {
            // Remove from callids hash
            htable_remove(calls.callids, call->callid);
            // Remove first call from active and call lists
            vector_remove(calls.active, call);
            vector_remove(calls.list, call);
            return;
        }
    }
}
Пример #9
0
void* vector_dequeue(vector_p vec)
{
	void * data = vector_get(vec, 0);
	if(data) {
		vector_remove(vec, 0);
	}
	return data;
}
Пример #10
0
/*** hard close ***************************************************************/
void pptp_call_destroy(PPTP_CONN *conn, PPTP_CALL *call)
{
    assert(conn && conn->call); assert(call);
    assert(vector_contains(conn->call, call->call_id));
    /* notify */
    if (call->callback != NULL) call->callback(conn, call, CALL_CLOSE_DONE);
    /* deallocate */
    vector_remove(conn->call, call->call_id);
    free(call);
}
Пример #11
0
extern bool table_clear(TABLE **t){
	if(!*t)
		return false;

	if((*t)->fields)
		do{
			free((*t)->fields->data);
		}while(vector_remove(&(*t)->fields,0));

	if((*t)->value)
		do{
			free((*t)->value->data);
		}while(vector_remove(&(*t)->value,0));

	free(*t);

	*t = NULL;
	return true;
}
Пример #12
0
char *test_remove_out_of_range()
{
  vector_p vector = vector_create(sizeof(int));

  vector_remove(vector, 100);

  mu_assert(vector->length == 0, "should be empty");

  vector_free(vector);
  return NULL;
}
Пример #13
0
void test_vector_remove() {
    array *arr = vector_create();
    vector_append(arr, 5);
    vector_append(arr, 4);
    vector_append(arr, 3);
    vector_insert(arr, 100, 2);
    vector_remove(arr, 2);
    ASSERT(arr->array[2] == 3);

    vector_free(arr);
}
Пример #14
0
void Document::remove_module(Module* m, bool bDeleteConnectedLinks) {
	for(uint i=0; i<m->in_links.size(); i++) {
		if(bDeleteConnectedLinks) {delete m->in_links[i]; i--;}
		else m->in_links[i]->detach(true);
	}
	for(uint i=0; i<m->out_links.size(); i++) {
		if(bDeleteConnectedLinks) {delete m->out_links[i]; i--;}
		else m->out_links[i]->detach(true);
	}
	vector_remove(modules, m);
}
Пример #15
0
int main(int argc, char** argv) {
    if (argc < 2) {
        helper();
        return PARAM_E;
    }

    int i;
    Vector *v = vector_create(2);

    if (v == NULL) {
        return MEMORY_E;
    }

    for (i = 1; i < argc; i++) {
        switch (argv[i][0]) {
            case 'f':
                printe(v, vector_find(v, atoi(argv[++i])));
            break;

            case 'c':
                printf("%d\n", vector_count(v, atoi(argv[++i])));
            break;

            case 'e':
                printe(v, atoi(argv[++i]));
            break;

            case 'p':
                if (!strcmp(argv[i], "print")) {
                    printv(v);
                }
            break;

            case 's':
                vector_sort(v, atoi(argv[++i]));
            break;

            case '-':
                vector_remove(v, -atoi(argv[i]));
            break;

            default:
                vector_insert(v, atoi(argv[i]), atoi(argv[i+1]));
                i++;
            break;
        }
    }

    vector_destroy(v);

    return SUCCESS;
}
Пример #16
0
RecordedExpectation *find_expectation(const char *function) {
    int i;
    for (i = 0; i < vector_size(expectation_queue); i++) {
        RecordedExpectation *expectation = (RecordedExpectation *)vector_get(expectation_queue, i);
        if (strcmp(expectation->function, function) == 0) {
            if (! expectation->should_keep) {
                return vector_remove(expectation_queue, i);
            }
            return expectation;
        }
    }
    return NULL;
}
Пример #17
0
RecordedResult *find_result(const char *function) {
    int i;
    for (i = 0; i < vector_size(result_queue); i++) {
        RecordedResult *result = (RecordedResult *)vector_get(result_queue, i);
        if (strcmp(result->function, function) == 0) {
            if (! result->should_keep) {
                return vector_remove(result_queue, i);
            }
            return result;
        }
    }
    return NULL;
}
Пример #18
0
/* Call callback */
void call_callback(PPTP_CONN *conn, PPTP_CALL *call, enum call_state state) {
  struct local_callinfo *lci;
  struct local_conninfo *conninfo;
  u_int16_t call_id[2];

  switch(state) {
  case CALL_OPEN_DONE:
    /* okey dokey.  This means that the call_id and peer_call_id are now
     * valid, so lets send them on to our friends who requested this call.
     */
	pptp_debug("About to get the call closure stuff");
    lci = pptp_call_closure_get(conn, call); assert(lci != NULL);
    pptp_call_get_ids(conn, call, &call_id[0], &call_id[1]);
	pptp_debug("writing out the call_ids");
	if (lci)
    write(lci->unix_sock, (char *) &call_id, sizeof(call_id));
    /* Our duty to the fatherland is now complete. */
    break;
  case CALL_OPEN_FAIL:
  case CALL_CLOSE_RQST:
  case CALL_CLOSE_DONE:
    /* don't need to do anything here, except make sure tables are sync'ed */
    conninfo = pptp_conn_closure_get(conn);
    lci = pptp_call_closure_get(conn, call); 
    // assert(lci != NULL && conninfo != NULL);
    if (lci && conninfo &&
		vector_contains(conninfo->call_list, lci->unix_sock)) {
      vector_remove(conninfo->call_list, lci->unix_sock);
	  if (lci->unix_sock >= 0)
        FD_CLR(lci->unix_sock, conninfo->call_set);
//	  syslog(LOG_NOTICE, "Closing connection");
      kill(lci->pid[0], SIGTERM);
    }
	if (lci) {
	  pptp_debug("close %d", lci->unix_sock);
      close(lci->unix_sock);
	  lci->unix_sock = -1;
#if 0
	  memset(lci, 0, sizeof(*lci));
	  free(lci);
	  pptp_call_closure_put(conn, call, NULL); 
#endif
	}
    break;
  default:
    logmsg("Unhandled call callback state [%d].", (int) state);
    break;
  }
}
Пример #19
0
int
main(int argc, char **argv)
{
	int *a, *b, *c, *d, *e, *f, *g;
	a = (int *)malloc(sizeof(int));
	b = (int *)malloc(sizeof(int));
	c = (int *)malloc(sizeof(int));
	d = (int *)malloc(sizeof(int));
	e = (int *)malloc(sizeof(int));
	f = (int *)malloc(sizeof(int));
	g = (int *)malloc(sizeof(int));
	*a = 6;
	*b = 1;
	*c = 99;
	*d = -17;
	*e = 22;
	*f = 9;
	*g = 6;

	struct Vector *iv = create_vector(2, free);
	vector_push_back(iv, a);
	vector_push_back(iv, b);
	vector_push_back(iv, c);
	vector_push_back(iv, d);
	vector_push_front(iv, e);
	vector_push_front(iv, f);
	vector_insert(iv, g, 5);

	vector_foreach(iv, print);
	printf("\nCount: %d, Capacity: %d--------------\n", vector_count(iv), vector_capacity(iv));

	printf("%d\n", *f);
	vector_remove(iv, f, compare, TRUE);
	vector_foreach(iv, print);
	printf("\nCount: %d, Capacity: %d--------------\n", vector_count(iv), vector_capacity(iv));

	vector_sort(iv, compare);
	vector_foreach(iv, print);
	printf("\nCount: %d, Capacity: %d--------------\n", vector_count(iv), vector_capacity(iv));

	printf("\nBsearch: %d, Lower: %d, Upper: %d\n", vector_bsearch(iv, a, compare), 
			vector_lower(iv, a, compare), vector_upper(iv, a, compare));

	vector_shuffle(iv);
	vector_foreach(iv, print);
	printf("\nCount: %d, Capacity: %d--------------\n", vector_count(iv), vector_capacity(iv));

	destroy_vector(iv, TRUE);
}
Пример #20
0
char *test_remove()
{
  vector_p vector = vector_create(sizeof(int));

  vector_add(vector, test_data(0));
  vector_add(vector, test_data(1));
  vector_add(vector, test_data(2));

  vector_remove(vector, 1);

  mu_assert(vector->length == 2, "should have a length of 2");
  mu_assert(*(int*)vector_get(vector, 1) == 2, "should have removed item");

  vector_free(vector);
  return NULL;
}
Пример #21
0
void hashtbl_remove(hashtbl_t *h, hash_elem_t *e) {
  if (!h || !e) return;
  /* CHECK: might be better to search hashing e->key */
  for (size_t i = 0; i < h->bktnum; ++i) {
    vector_t *b = h->buckets[i];
    if (!b) continue;
    for (size_t j = 0; j < vector_size(b); ++j) {
      if (e == vector_get(b, j)) {
        b = h->buckets[i] = vector_remove(b, j);
        h->size--;
        hashtbl_rehash(h);
        return;
      }
    }
  }
}
Пример #22
0
void test_vector()
{
   size_t arr[10], arr2[10];
   size_t i, j;
   vector vec;

   j = 200;

   vector_init(&vec, &malloc, &free);

   for (i = 0; i < 10; ++i)
   {
      arr[i] = i;

      vector_push_back(&vec, &arr[i]);

   }

   for (i = 0; i < 10; ++i)
   {
      arr2[i] = i + 10;

      vector_push_back(&vec, &arr2[i]);

   }

   vector_insert(&vec, &j, vec.size);
   vector_remove(&vec, 0);

   printf("-----\nVector testing\n-----\nSize: %d\nMax size: %d\nContents: ", vector_size(&vec), vector_max_size(&vec));

   for (i = 0; i < 20; ++i) printf("%d ", *(size_t*)vector_pop_back(&vec));

   vector_push_back(&vec, &j);

   printf("\nFront: %d\nBack: %d\n", *(size_t*)vector_front(&vec), *(size_t*)vector_back(&vec));

   vector_clear(&vec);

   printf("Vector cleared\nSize: %d\n", vec.size);

   vector_free(&vec);

   printf("\n");

}
Пример #23
0
bool vector_remove_item(Vector *vector, vector_comparitor comparitor, void *item)
{
    if(NULL == vector || NULL == comparitor || NULL == item)
    {
        errno = EINVAL;
        return false;
    }

    for(size_t i = 0; i < vector->length; i++)
    {
        if(comparitor(vector->items[i], item))
        {
            return NULL != vector_remove(vector, i);
        }
    }
    return false;
}
Пример #24
0
/**
 Usuwa słowo z poddrzewa node'a
 @param[in,out] node Węzeł
 @param[in] word Słowo
 @return NULL jeżeli node został usunięty, node w p. p.
 */
static trie_node * node_delete(trie_node *node, const wchar_t *word)
{
	assert(node != NULL);
	if(word[0] == L'\0')
	{
		node->end_of_word = false;
		return node_try_to_delete(node);
	}
	int index = node_son_index(node, word[0]);
	trie_node *son = NTH_SON(node, index);
	assert(son != NULL);
	son = NTH_SON(node, index) = node_delete(son, word + 1);
	if(son == NULL)
	{
		vector_remove(node->sons, index);
		return node_try_to_delete(node);
	}
	return node;
}
Пример #25
0
char *test_remove_and_resize()
{
  vector_p vector = vector_create(sizeof(int));

  for(int i = 0 ; i < 80 ; ++i)
  {
    vector_add(vector, test_data(i));
  }

  for(int i = 0 ; i < 60 ; ++i)
  {
    vector_remove(vector, 0);
  }

  mu_assert(vector->capacity == 20, "should have reduced capacity");

  vector_free(vector);
  return NULL;
}
Пример #26
0
int main(int argc, char **argv) {
    char *file_to_eval = NULL;
    int replize = argc < 1;
    for(int i = 1; i < argc; i++) {
        if(!strcmp("-f", argv[i]))
            file_to_eval = argv[++i];
        else if(!strcmp("--verbose", argv[i]))
            VERBOSE = true;
        else if(!strcmp("-i", argv[i]))
            replize = true;
    }

    init_alloc_system();
    init_symboltable();
    register_builtin_functions();

    new_var(new_symbol("nil"), (LispObject*)nil);
    new_var(new_symbol("t"), (LispObject*)new_symbol("t"));

    nexception_points++;
    if(setjmp(exception_points[nexception_points - 1]) == 0) {
        eval_file("prelude.l");
        if(file_to_eval)
            eval_file(file_to_eval);
        else
            repl();
    } else {
        fprintf(stderr, "%s", error_string);
        printf("Stack trace:\n");
        for(int i = 0; i < call_stack->size; i++) {
            printf("  ");
            obj_print(vector_getitem(call_stack, i));
            printf("\n");
        }
        while(scopes->size > 1)
            pop_scope();
        while(call_stack->size > 1)
            vector_remove(call_stack, -1);
        if(replize)
            repl();
    }
}
Пример #27
0
size_t hashtbl_delete(hashtbl_t *h, const char *key) {
  if (!h) return 0;
  if (!h->hash) {
    fprintf(stderr, "hashtbl insert error: no hash function\n");
    return 0;
  }
  size_t bnum = h->hash(key) % h->bktnum;
  vector_t *b = h->buckets[bnum];
  if (!b) return 0;
  size_t delcount = 0;
  ssize_t idx = vector_find(b, key);
  while (idx >= 0) {
    b = h->buckets[bnum] = vector_remove(b, idx);
    delcount++;
    idx = vector_find(b, key);
  }
  h->size -= delcount;
  if (delcount > 0)
    hashtbl_rehash(h);
  return delcount;
}
Пример #28
0
void remove1(CL_FORM *base)
{
	GEN_HEAPVAR(ARG(4), ARG(9));
	if(CL_TRUEP(ARG(3)))
	{
	}
	else
	{
		if(CL_TRUEP(INDIRECT(ARG(4))))
		{
			GEN_CLOSURE(array, ARG(9), 4, Z44_lambda, -1);
			COPY(ARG(4), &array[3]);
			LOAD_CLOSURE(array, ARG(9));
			COPY(ARG(9), ARG(3));
		}
		else
		{
			GEN_STATIC_GLOBAL_FUNARG(extern_closure, Feql, 2);
			LOAD_GLOBFUN(&extern_closure, ARG(3));
		}
	}
	if(CL_LISTP(ARG(1)))
	{
		COPY(ARG(5), ARG(4));
		COPY(ARG(6), ARG(5));
		COPY(ARG(7), ARG(6));
		COPY(ARG(8), ARG(7));
		list_remove(ARG(0));
	}
	else
	{
		COPY(ARG(5), ARG(4));
		COPY(ARG(6), ARG(5));
		COPY(ARG(7), ARG(6));
		COPY(ARG(8), ARG(7));
		vector_remove(ARG(0));
	}
}
Пример #29
0
rcl_status cl_release_buffer(struct client_state* state, buffer_t buffer)
{
	struct buffer_state* buffer_state;
	cl_int retval;

	buffer--;
	if (!vector_valid_idx(&state->buffers, buffer)) {
		log_print(log_error, "Buffer %" PRIu32 " not found", buffer);
		return RCL_INVALID_BUFFER;
	}

	buffer_state = *vector_element(&state->buffers, buffer,
		struct buffer_state*);
	retval = clReleaseMemObject(buffer_state->id);
	if (retval)
		return opencl_error(retval);

	vector_remove(&state->buffers, buffer);

	free(buffer_state->original);
	free(buffer_state);
	return RCL_OK;
}
Пример #30
0
rcl_status cl_release_program(struct client_state* state, program_t program)
{
	struct program_state* program_state;
	cl_int retval;

	if (!vector_valid_idx(&state->programs, program)) {
		log_print(log_error, "Prgram %" PRIu32 " not found", program);
		return RCL_INVALID_PROGRAM;
	}

	program_state = *vector_element(&state->programs, program,
		struct program_state*);
	retval = clReleaseProgram(program_state->id);
	if (retval)
		return opencl_error(retval);

	vector_remove(&state->programs, program);

	free(program_state->source);
	free(program_state->flags);
	free(program_state);
	return RCL_OK;
}