Exemplo n.º 1
0
static void _new_remove_length(void **state)
{
    arr_t * arr = arr_new(5);
    assert_int_equal(arr_length(arr), 5);
    arr_remove(&arr);
    assert_null(arr);
    arr = arr_new(5000000);
    assert_null(arr);
}
Exemplo n.º 2
0
static void new_void_arr_minus(void**state)
{
    arr_t * arr = arr_new(5);
    arr_add(arr, 3, -2);
    arr_add(arr, 1, -1);
    assert_int_equal(arr_minus(arr), 1);
    arr_remove(&arr);
}
Exemplo n.º 3
0
static void new_void_arr_find(void**state)
{
    arr_t * arr = arr_new(5);
    int mas[5] = {1 , 3 , 3 ,3 ,5};
    for(int i = 0 ; i<5 ; i++)
    arr_add(arr, i, mas[i]);
    assert_int_equal(arr_find(arr) , 3);
    arr_remove(&arr);
}
Exemplo n.º 4
0
static void new_void__arr_add(void **state)
{
    arr_t * arr = arr_new(5);
    assert_int_equal(arr_add(arr, 3, 10), 0);
    assert_int_equal(arr_add(arr, 6, 10), 1);
    int elem = 0;
    assert_int_equal(arr_get(arr, 3, &elem), 1);
    assert_int_equal(elem, 10);
    assert_int_equal(arr_get(arr, 37, &elem), 0);
    arr_remove(&arr);
}
Exemplo n.º 5
0
template<typename ...T> int *arr_new(T ...v) {
  return new int[]{v...};
}

#else

New<int> *clone_new(New<int> *n) {
  return n->clone();
}

int *use_arr_new = arr_new(1, 2, 3);
Exemplo n.º 6
0
/**
Allocate dvar_vector with indexmin = ncl and indexmax = nch.
*/
void dvar_vector::allocate(int ncl, int nch)
{
  if (ncl > nch)
  {
    allocate();
  }
  else
  {
    index_min=ncl;
    index_max=nch;
#ifndef OPT_LIB
    assert(nch >= ncl);
#endif
    unsigned int itemp = (unsigned int)(nch - ncl + 1);
/*
    if (itemp<=0)
    {
         cerr << "Error in dvar_vector constructor max index must be"
                 " >= minindex\n"
            << "minindex = " << ncl << " maxindex = " << nch <<endl;
         ad_exit(1);
    }
*/
    if ((va = arr_new(itemp)) == 0)
    {
      cerr << " Error trying to allocate memory for dvar_vector\n";
      ad_exit(1);
    }
    else
    {
      if ( (shape=new vector_shapex(ncl,nch,va)) == NULL)
      {
        cerr << "Error trying to allocate memory for dvar_vector\n";
        ad_exit(1);
      }
      link_ptr=* (arr_link **) va;
      va -= indexmin();
      // if ( ((int)va) %8) cerr << "Array is not QWORD alligned" << endl;
#ifdef DIAG
      myheapcheck("Leaving dvar_vector::allocate(ncl,nch)");
#endif
    }
  }
}
Exemplo n.º 7
0
Arquivo: data.c Projeto: Miraculix/dgd
/*
 * NAME:	data->list_callouts()
 * DESCRIPTION:	list all call_outs in an object
 */
array *d_list_callouts(dataspace *host, dataspace *data)
{
    uindex n, count, size;
    dcallout *co;
    value *v, *v2, *elts;
    array *list, *a;
    uindex max_args;
    xfloat flt;

    if (data->ncallouts == 0) {
	return arr_new(host, 0L);
    }
    if (data->callouts == (dcallout *) NULL) {
	d_get_callouts(data);
    }

    /* get the number of callouts in this object */
    count = data->ncallouts;
    for (n = data->fcallouts; n != 0; n = data->callouts[n - 1].co_next) {
	--count;
    }
    if (count > conf_array_size()) {
	return (array *) NULL;
    }

    list = arr_new(host, (long) count);
    elts = list->elts;
    max_args = conf_array_size() - 3;

    for (co = data->callouts; count > 0; co++) {
	if (co->val[0].type == T_STRING) {
	    size = co->nargs;
	    if (size > max_args) {
		/* unlikely, but possible */
		size = max_args;
	    }
	    a = arr_new(host, size + 3L);
	    v = a->elts;

	    /* handle */
	    PUT_INTVAL(v, co - data->callouts + 1);
	    v++;
	    /* function */
	    PUT_STRVAL(v, co->val[0].u.string);
	    v++;
	    /* time */
	    if (co->mtime == 0xffff) {
		PUT_INTVAL(v, co->time);
	    } else {
		flt.low = co->time;
		flt.high = co->mtime;
		PUT_FLTVAL(v, flt);
	    }
	    v++;

	    /* copy arguments */
	    switch (size) {
	    case 3:
		*v++ = co->val[3];
	    case 2:
		*v++ = co->val[2];
	    case 1:
		*v++ = co->val[1];
	    case 0:
		break;

	    default:
		n = size - 2;
		for (v2 = d_get_elts(co->val[3].u.array) + n; n > 0; --n) {
		    *v++ = *--v2;
		}
		*v++ = co->val[2];
		*v++ = co->val[1];
		break;
	    }
	    while (size > 0) {
		i_ref_value(--v);
		--size;
	    }
	    d_ref_imports(a);

	    /* put in list */
	    PUT_ARRVAL(elts, a);
	    elts++;
	    --count;
	}
    }
    co_list(list);

    return list;
}
Exemplo n.º 8
0
Arquivo: data.c Projeto: Miraculix/dgd
/*
 * NAME:	data->new_call_out()
 * DESCRIPTION:	add a new callout
 */
uindex d_new_call_out(dataspace *data, string *func, Int delay, 
	unsigned int mdelay, frame *f, int nargs)
{
    Uint ct, t;
    unsigned short m;
    uindex *q;
    value v[4];
    uindex handle;

    ct = co_check(ncallout, delay, mdelay, &t, &m, &q);
    if (ct == 0 && q == (uindex *) NULL) {
	/* callouts are disabled */
	return 0;
    }

    PUT_STRVAL(&v[0], func);
    switch (nargs) {
    case 3:
	v[3] = f->sp[2];
    case 2:
	v[2] = f->sp[1];
    case 1:
	v[1] = f->sp[0];
    case 0:
	break;

    default:
	v[1] = f->sp[0];
	v[2] = f->sp[1];
	PUT_ARRVAL(&v[3], arr_new(data, nargs - 2L));
	memcpy(v[3].u.array->elts, f->sp + 2, (nargs - 2) * sizeof(value));
	d_ref_imports(v[3].u.array);
	break;
    }
    f->sp += nargs;
    handle = d_alloc_call_out(data, 0, ct, m, nargs, v);

    if (data->plane->level == 0) {
	/*
	 * add normal callout
	 */
	co_new(data->oindex, handle, t, m, q);
    } else {
	dataplane *plane;
	copatch **c, *cop;
	dcallout *co;
	copatch **cc;

	/*
	 * add callout patch
	 */
	plane = data->plane;
	if (plane->coptab == (coptable *) NULL) {
	    cop_init(plane);
	}
	co = &data->callouts[handle - 1];
	cc = c = &plane->coptab->cop[handle % COPATCHHTABSZ];
	for (;;) {
	    cop = *c;
	    if (cop == (copatch *) NULL || cop->plane != plane) {
		/* add new */
		cop_new(plane, cc, COP_ADD, handle, co, t, m, q);
		break;
	    }

	    if (cop->handle == handle) {
		/* replace removed */
		cop_replace(cop, co, t, m, q);
		break;
	    }

	    c = &cop->next;
	}

	ncallout++;
    }

    return handle;
}