Example #1
0
/*
 * Add a given buffer to the end of a list
 * Careful buffer is passed by reference,
 * and must be free with list_free()
 */
void list_add_str(list * l, char *value)
{
    list_node *ln;

    assert(l);
    assert(value);
    assert(l->size < UINT_MAX);

    ln = list_node_init();

    ln->value = buffer_init();
    buffer_add_str(ln->value, value);

    if (!l->first) {
        ln->prev = NULL;
        l->first = ln;
    } else {
        ln->prev = l->last;
        l->last->next = ln;
    }

    l->last = ln;
    l->last->next = NULL;
    l->size++;
}
Example #2
0
/* Update the Pending Register.  This will trigger an interrupt if a bit is
 * set.
 */
static void stm32_exti_change_EXTI_PR_bit(Stm32Exti *s, unsigned pos,
                                            unsigned new_bit_value)
{
    unsigned old_bit_value;

    assert((new_bit_value == 0) || (new_bit_value == 1));
    assert(pos < EXTI_LINE_COUNT);

    old_bit_value = GET_BIT_VALUE(s->EXTI_PR, pos);

    /* Only continue if the PR bit is actually changing value. */
    if(new_bit_value != old_bit_value) {
        /* If the bit is being reset, the corresponding Software Interrupt Event
         * Register bit is automatically reset.
         */
        if(!new_bit_value) {
            RESET_BIT(s->EXTI_SWIER, pos);
        }

        /* Update the IRQ for this EXTI line.  Some lines share the same
         * NVIC IRQ.
         */
        if(pos <= 4) {
            /* EXTI0 - EXTI4 each have their own NVIC IRQ */
            qemu_set_irq(s->irq[pos], new_bit_value);
        } else if(pos <= 9) {
            /* EXTI5 - EXTI9 share an NVIC IRQ */
            qemu_set_irq(s->irq[5], new_bit_value);
        } else if(pos <= 15) {
            /* EXTI10 - EXTI15 share an NVIC IRQ */
            qemu_set_irq(s->irq[6], new_bit_value);
        } else if(pos == 16) {
            /* PVD IRQ */
            qemu_set_irq(s->irq[7], new_bit_value);
        } else if(pos == 17) {
            /* RTCAlarm IRQ */
            qemu_set_irq(s->irq[8], new_bit_value);
        } else if(pos == 18) {
            /* OTG_FS_WKUP IRQ */
            qemu_set_irq(s->irq[9], new_bit_value);
        } else if(pos == 19) {
            /* ETH_WKUP IRQ */
            qemu_set_irq(s->irq[10], new_bit_value);
        } else if(pos == 20) {
            /* OTG_HS_WKUP IRQ */
            qemu_set_irq(s->irq[11], new_bit_value);
        } else if(pos == 21) {
            /* TAMP_STAMP IRQ */
            qemu_set_irq(s->irq[12], new_bit_value);
        } else if(pos == 22) {
            /* RTC_WKUP IRQ */
            qemu_set_irq(s->irq[13], new_bit_value);
        } else {
            assert(false);
        }

        /* Update the register. */
        CHANGE_BIT(s->EXTI_PR, pos, new_bit_value);
    }
}
Example #3
0
static int vhost_dev_set_log(struct vhost_dev *dev, bool enable_log)
{
    int r, t, i;
    r = vhost_dev_set_features(dev, enable_log);
    if (r < 0) {
        goto err_features;
    }
    for (i = 0; i < dev->nvqs; ++i) {
        r = vhost_virtqueue_set_addr(dev, dev->vqs + i, i,
                                     enable_log);
        if (r < 0) {
            goto err_vq;
        }
    }
    return 0;
err_vq:
    for (; i >= 0; --i) {
        t = vhost_virtqueue_set_addr(dev, dev->vqs + i, i,
                                     dev->log_enabled);
        assert(t >= 0);
    }
    t = vhost_dev_set_features(dev, dev->log_enabled);
    assert(t >= 0);
err_features:
    return r;
}
void generate_random_bytes(size_t n, void *result) {
#if !defined(NDEBUG)
  assert(curstate == 1);
  curstate = 2;
#endif
  if (n == 0) {
#if !defined(NDEBUG)
    assert(curstate == 2);
    curstate = 1;
#endif
    return;
  }
  for (;;) {
    hash_permutation(&state);
    if (n <= HASH_DATA_AREA) {
      memcpy(result, &state, n);
#if !defined(NDEBUG)
      assert(curstate == 2);
      curstate = 1;
#endif
      return;
    } else {
      memcpy(result, &state, HASH_DATA_AREA);
      result = padd(result, HASH_DATA_AREA);
      n -= HASH_DATA_AREA;
    }
  }
}
Example #5
0
void AddToPopulation(GainType Cost)
{
    int i, *P;
    Node *N;

    if (!Population) {
        assert(Population =
               (int **) malloc(MaxPopulationSize * sizeof(int *)));
        for (i = 0; i < MaxPopulationSize; i++)
            assert(Population[i] =
                   (int *) malloc((1 + Dimension) * sizeof(int)));
        assert(Fitness =
               (GainType *) malloc(MaxPopulationSize * sizeof(GainType)));
    }
    for (i = PopulationSize; i >= 1 && Cost < Fitness[i - 1]; i--) {
        Fitness[i] = Fitness[i - 1];
        P = Population[i];
        Population[i] = Population[i - 1];
        Population[i - 1] = P;
    }
    Fitness[i] = Cost;
    P = Population[i];
    N = FirstNode;
    i = 1;
    do
        P[i++] = N->Id;
    while ((N = N->Suc) != FirstNode);
    P[0] = P[Dimension];
    PopulationSize++;
}
Example #6
0
void smooth_amp(struct AEXP *aexp, MODEL *model) {
    int    m, i;
    int    nbins;
    int    b;
    float  f;
    float  av[MAX_BINS];
    int    nav[MAX_BINS];

    nbins = sizeof(bins)/sizeof(float);

    /* clear all bins */

    for(i=0; i<MAX_BINS; i++) {
	av[i] = 0.0;
	nav[i] = 0;
    }

    /* add amps into each bin */

    for(m=1; m<=model->L; m++) {
	f = m*model->Wo*FS/TWO_PI;
	if (f > bins[0]) {

	    /* find bin  */

	    for(i=0; i<nbins; i++)
		if ((f > bins[i]) && (f <= bins[i+1]))
		    b = i;
	    assert(b < MAX_BINS);

	    av[b] += model->A[m]*model->A[m];
	    nav[b]++;
	}

    }

    /* use averages to est amps */

    for(m=1; m<=model->L; m++) {
	f = m*model->Wo*FS/TWO_PI;
	if (f > bins[0]) {

	    /* find bin */

	    for(i=0; i<nbins; i++)
		if ((f > bins[i]) && (f <= bins[i+1]))
		    b = i;
	    assert(b < MAX_BINS);

	    /* add predicted phase error to this bin */

	    printf("L %d m %d f %4.f b %d\n", model->L, m, f, b);

	    printf(" %d: %4.3f -> ", m, 20*log10(model->A[m]));
	    model->A[m] = sqrt(av[b]/nav[b]);
	    printf("%4.3f\n", 20*log10(model->A[m]));
	}
    }
    printf("\n");
}
Example #7
0
UINT32 stream_read(imgtool_stream *stream, void *buf, UINT32 sz)
{
    UINT32 result = 0;

    switch(stream->imgtype)
    {
    case IMG_FILE:
        assert(sz == (UINT32) sz);
        core_fseek(stream->u.file, stream->position, SEEK_SET);
        result = core_fread(stream->u.file, buf, (UINT32) sz);
        break;

    case IMG_MEM:
        /* do we have to limit sz? */
        if (sz > (stream->filesize - stream->position))
            sz = (UINT32) (stream->filesize - stream->position);

        memcpy(buf, stream->u.buffer + stream->position, sz);
        result = sz;
        break;

    default:
        assert(0);
        break;
    }
    stream->position += result;
    return result;
}
Example #8
0
static void test_group(CuTest * tc)
{
    unit *u;
    region *r;
    faction *f;
    group *g;

    test_cleanup();
    test_create_world();
    r = findregion(0, 0);
    f = test_create_faction(0);
    assert(r && f);
    u = test_create_unit(f, r);
    assert(u);
    CuAssertTrue(tc, join_group(u, "hodor"));
    CuAssertPtrNotNull(tc, (g = get_group(u)));
    CuAssertStrEquals(tc, "hodor", g->name);
    CuAssertIntEquals(tc, 1, g->members);
    set_group(u, 0);
    CuAssertIntEquals(tc, 0, g->members);
    CuAssertPtrEquals(tc, 0, get_group(u));
    set_group(u, g);
    CuAssertIntEquals(tc, 1, g->members);
    CuAssertPtrEquals(tc, g, get_group(u));
    test_cleanup();
}
Example #9
0
SC_FUNC int state_addlist(int *list,int count,int fsa)
{
  statepool *ptr;
  int last;

  assert(list!=NULL);
  assert(count>0);
  ptr=state_findlist(list,count,fsa,&last);
  if (ptr==NULL) {
    if ((ptr=(statepool*)malloc(sizeof(statepool)))==NULL)
      error(103);       /* insufficient memory */
    if ((ptr->states=(int*)malloc(count*sizeof(int)))==NULL) {
      free(ptr);
      error(103);       /* insufficient memory */
    } /* if */
    memcpy(ptr->states,list,count*sizeof(int));
    ptr->numstates=count;
    ptr->fsa=fsa;
    ptr->listid=last+1;
    ptr->next=statepool_tab.next;
    statepool_tab.next=ptr;
  } /* if */
  assert(ptr!=NULL);
  return ptr->listid;
}
Example #10
0
char* wikimedia_titles_get(Wikimedia_Titles* wt, int index) {
  /* simple getter */
  assert(wt != NULL);
  assert(index >= 0);
  assert(index < wt->title_count);
  return wt->titles[index];
}
Example #11
0
int ty_firmware_load(const char *filename, const char *format_name, ty_firmware **rfw)
{
    assert(filename);
    assert(rfw);

    const ty_firmware_format *format = NULL;

    if (format_name) {
        for (unsigned int i = 0; i < ty_firmware_formats_count; i++) {
            if (strcasecmp(ty_firmware_formats[i].name, format_name) == 0) {
                format = &ty_firmware_formats[i];
                break;
            }
        }
        if (!format)
            return ty_error(TY_ERROR_UNSUPPORTED, "Firmware file format '%s' unknown", format_name);
    } else {
        const char *ext = strrchr(filename, '.');
        if (!ext)
            return ty_error(TY_ERROR_UNSUPPORTED, "Firmware '%s' has no file extension", filename);

        for (unsigned int i = 0; i < ty_firmware_formats_count; i++) {
            if (strcmp(ty_firmware_formats[i].ext, ext) == 0) {
                format = &ty_firmware_formats[i];
                break;
            }
        }
        if (!format)
            return ty_error(TY_ERROR_UNSUPPORTED, "Firmware '%s' uses unrecognized file format",
                            filename);
    }

    return (*format->load)(filename, rfw);
}
Example #12
0
/*
 * Routine to communicate eigenvalues such that every process has
 * all computed eigenvalues (iu-il+1) in W; this routine is designed 
 * to be called right after 'pmrrr'.
 */
int PMR_comm_eigvals(MPI_Comm comm, int *nz, int *myfirstp, double *W)
{
  MPI_Comm comm_dup;
  MPI_Comm_dup(comm, &comm_dup);
  int nproc;
  MPI_Comm_size(comm_dup, &nproc);

  int *rcount = (int*)malloc(nproc*sizeof(int)); assert(rcount!=NULL);
  int *rdispl = (int*)malloc(nproc*sizeof(int)); assert(rdispl!=NULL);
  double *work = (double*)malloc((*nz+1)*sizeof(double)); assert(work!=NULL);

  if (*nz > 0)
    memcpy(work, W, (*nz)*sizeof(double) );

  MPI_Allgather(nz, 1, MPI_INT, rcount, 1, MPI_INT, comm_dup);

  MPI_Allgather(myfirstp, 1, MPI_INT, rdispl, 1, MPI_INT, comm_dup);
  
  MPI_Allgatherv
  (work, *nz, MPI_DOUBLE, W, rcount, rdispl, MPI_DOUBLE, comm_dup);

  MPI_Comm_free(&comm_dup);
  free(rcount);
  free(rdispl);
  free(work);

  return 0;
}
Example #13
0
/*
 * Add a given buffer by copy to the end of a list
 * Careful buffer is passed by reference,
 * and must be free with list_free()
 */
void list_add_by_copy(list * l, buffer * value)
{
    list_node *ln;
    buffer *tmp;

    assert(l);
    assert(value);
    assert(l->size < UINT_MAX);

    ln = list_node_init();
    tmp = buffer_init();

    buffer_copy(tmp, value);
    ln->value = tmp;

    if (!l->first) {
        ln->prev = NULL;
        l->first = ln;
    } else {
        ln->prev = l->last;
        l->last->next = ln;
    }

    l->last = ln;
    l->last->next = NULL;
    l->size++;
}
Example #14
0
/*
 * Add a given list to the end of a list
 * Careful list is passed by reference,
 * and must be free with list_free()
 */
void list_add_list(list * l, list * l_to_add)
{
    list_node *ln, *ln_parse;

    assert(l);
    assert(l_to_add);

    for (ln_parse = l_to_add->first ; ln_parse ; ln_parse = ln_parse->next) {
        if (!in_list(l, ln_parse->value)) {
            ln = list_node_init();

            ln->value = buffer_init();
            buffer_copy(ln->value, ln_parse->value);

            if (!l->first) {
                ln->prev = NULL;
                l->first = ln;
            } else {
                ln->prev = l->last;
                l->last->next = ln;
            }

            l->last = ln;
            l->last->next = NULL;
            l->size++;
        }
    }
}
Example #15
0
static void print_sparse_pred_error(struct AEXP *aexp, MODEL *model, float mag_thresh)
{
    int    m, index;
    float  mag, error;
    float  sparse_pe[MAX_AMP];

    mag = 0.0;
    for(m=1; m<=model->L; m++)
	mag += model->A[m]*model->A[m];
    mag = 10*log10(mag/model->L);

    if (mag > mag_thresh) {
	for(m=0; m<MAX_AMP; m++) {
	    sparse_pe[m] = 0.0;
	}

	for(m=1; m<=model->L; m++) {
	    assert(model->A[m] > 0.0);
	    error = PRED_COEFF*20.0*log10(aexp->A_prev[m]) - 20.0*log10(model->A[m]);
	    //error = 20.0*log10(model->A[m]) - mag;

	    index = MAX_AMP*m*model->Wo/PI;
	    assert(index < MAX_AMP);
	    sparse_pe[index] = error;
	}

	/* dump sparse amp vector */

	for(m=0; m<MAX_AMP; m++)
	    printf("%f ", sparse_pe[m]);
	printf("\n");
    }
}
Example #16
0
/* This function searches whether one of the states in the list of statepool id's
 * of a symbol exists in any other statepool id's of the same function; it also
 * verifies that all definitions of the symbol are in the same automaton.
 */
SC_FUNC void state_conflict(symbol *root)
{
  statepool *psrc,*ptgt;
  statelist *srcptr,*tgtptr;
  symbol *sym;

  assert(root!=NULL);
  for (sym=root->next; sym!=NULL; sym=sym->next) {
    if (sym->parent!=NULL || sym->ident!=iFUNCTN)
      continue;                 /* hierarchical data type or no function */
    if (sym->states==NULL)
      continue;                 /* this function has no states */
    for (srcptr=sym->states->next; srcptr!=NULL; srcptr=srcptr->next) {
      if (srcptr->id==-1)
        continue;               /* state list id -1 is a special case */
      psrc=state_getlist_ptr(srcptr->id);
      assert(psrc!=NULL);
      for (tgtptr=srcptr->next; tgtptr!=NULL; tgtptr=tgtptr->next) {
        if (tgtptr->id==-1)
          continue;             /* state list id -1 is a special case */
        ptgt=state_getlist_ptr(tgtptr->id);
        assert(ptgt!=NULL);
        if (psrc->fsa!=ptgt->fsa && strcmp(sym->name,uENTRYFUNC)!=0)
          error(83,sym->name);  /* this function is part of another machine */
        if (checkconflict(psrc,ptgt))
          error(84,sym->name);  /* state conflict */
      } /* for (tgtptr) */
    } /* for (srcptr) */
  } /* for (sym) */
}
Example #17
0
static void print_sparse_amp_error(struct AEXP *aexp, MODEL *model, float edB_thresh)
{
    int    m, index;
    float  edB, enormdB, error, dWo;
    float  sparse_pe[MAX_AMP];

    edB = frame_energy(model, &enormdB);
    //printf("%f\n", enormdB);
    dWo = fabs((aexp->model_uq[2].Wo - aexp->model_uq[1].Wo)/aexp->model_uq[2].Wo);

    if ((edB > edB_thresh) && (dWo < 0.1)) {
	for(m=0; m<MAX_AMP; m++) {
	    sparse_pe[m] = 0.0;
	}

	for(m=1; m<=model->L; m++) {
	    assert(model->A[m] > 0.0);
	    error = 20.0*log10(model->A[m]) - enormdB;

	    index = MAX_AMP*m*model->Wo/PI;
	    assert(index < MAX_AMP);
	    sparse_pe[index] = error;
	}

	/* dump sparse amp vector */

	for(m=0; m<MAX_AMP; m++)
	    printf("%f ", sparse_pe[m]);
	printf("\n");
    }
}
Example #18
0
void EmergeManager::initMapgens() {
	if (mapgen.size())
		return;

	// Resolve names of nodes for things that were registered
	// (at this point, the registration period is over)
	biomedef->resolveNodeNames(ndef);

	for (size_t i = 0; i != ores.size(); i++)
		ores[i]->resolveNodeNames(ndef);

	for (size_t i = 0; i != decorations.size(); i++)
		decorations[i]->resolveNodeNames(ndef);

	if (!params.sparams) {
		params.sparams = createMapgenParams(params.mg_name);
		if (!params.sparams) {
			params.mg_name = DEFAULT_MAPGEN;
			params.sparams = createMapgenParams(params.mg_name);
			assert(params.sparams);
		}
		params.sparams->readParams(g_settings);
	}

	// Create the mapgens
	for (size_t i = 0; i != emergethread.size(); i++) {
		Mapgen *mg = createMapgen(params.mg_name, i, &params);
		assert(mg);
		mapgen.push_back(mg);
	}
}
Example #19
0
void stream_close(imgtool_stream *s)
{
    assert(s != NULL);

    switch(s->imgtype)
    {
    case IMG_FILE:
        if (s->u.file != NULL)
        {
            core_fclose(s->u.file);
            s->u.file = NULL;
        }
        break;

    case IMG_MEM:
        if (s->u.buffer != NULL)
        {
            free(s->u.buffer);
            s->u.buffer = NULL;
        }
        break;

    default:
        assert(0);
        break;
    }
    free((void *) s);
}
Ledger::pointer LedgerHistory::getLedgerBySeq (std::uint32_t index)
{
    {
        LedgersByHash::ScopedLockType sl (m_ledgers_by_hash.peekMutex ());
        std::map <std::uint32_t, uint256>::iterator it (mLedgersByIndex.find (index));

        if (it != mLedgersByIndex.end ())
        {
            uint256 hash = it->second;
            sl.unlock ();
            return getLedgerByHash (hash);
        }
    }

    Ledger::pointer ret (Ledger::loadByIndex (index));

    if (!ret)
        return ret;

    assert (ret->getLedgerSeq () == index);

    {
        // Add this ledger to the local tracking by index
        LedgersByHash::ScopedLockType sl (m_ledgers_by_hash.peekMutex ());

        assert (ret->isImmutable ());
        m_ledgers_by_hash.canonicalize (ret->getHash (), ret);
        mLedgersByIndex[ret->getLedgerSeq ()] = ret->getHash ();
        return (ret->getLedgerSeq () == index) ? ret : Ledger::pointer ();
    }
}
Example #21
0
fileblob *
textToFileblob(text *t, fileblob *fb, int destroy)
{
    assert(fb != NULL);
    assert(t != NULL);

    if(fb == NULL) {
        cli_dbgmsg("textToFileBlob, destroy = %d\n", destroy);
        fb = fileblobCreate();

        if(fb == NULL)
            return NULL;
    } else {
        cli_dbgmsg("textToFileBlob to %s, destroy = %d\n",
                   fileblobGetFilename(fb), destroy);

        fb->ctx = NULL;	/* no need to scan */
    }

    fb = textIterate(t, addToFileblob, fb, destroy);
    if(destroy && t->t_next) {
        textDestroy(t->t_next);
        t->t_next = NULL;
    }
    return fb;
}
Example #22
0
dbms_error_t
dbms_disconnect(
		dbms * me
)
{
	int             retval;

	assert(me);
	assert(me->sockfd >= 0);

	dbms_comms(me, TOKEN_CLOSE, &retval, NULL, NULL, NULL, NULL);
#ifdef TPS
	if (getenv("GATEWAY_INTERFACE") == NULL)
		fprintf(stderr, "Performance: %ld # %.2f mSec/trans = %.1f\n",
			ttps, ttime / ttps / 1000.0,
			1000000.0 * ttps / ttime
			);
#endif
	shutdown(me->sockfd, 2);
	close(me->sockfd);
	(*(me->free)) (me->name);
	(*(me->free)) (me->host);
	(*(me->free)) (me);
	if (logfile) fclose(logfile);

	return 0;
}
void KeyGenerator::slotStartKeyGeneration() {
  QString params = "<GnupgKeyParms format=\"internal\">\n";
  for ( int i = 0 ; i < numKeyParams ; ++i )
    if ( mLineEdits[i] && !mLineEdits[i]->text().trimmed().isEmpty() )
      params += keyParams[i] + ( ": " + mLineEdits[i]->text().trimmed() ) + '\n';
  params += "</GnupgKeyParms>\n";

  const Kleo::CryptoBackend::Protocol * proto = 0;
  if(protocol)
  {
     proto = !strcmp( protocol, "openpgp" ) ? Kleo::CryptoBackendFactory::instance()->openpgp() : Kleo::CryptoBackendFactory::instance()->smime() ;
  }
  if ( !proto )
    proto = Kleo::CryptoBackendFactory::instance()->smime();
  assert( proto );

  kDebug(5150) <<"Using protocol" << proto->name();

  Kleo::KeyGenerationJob * job = proto->keyGenerationJob();
  assert( job );

  connect( job, SIGNAL(result(GpgME::KeyGenerationResult,QByteArray)),
	   SLOT(slotResult(GpgME::KeyGenerationResult,QByteArray)) );

  const GpgME::Error err = job->start( params );
  if ( err )
    showError( err );
#ifndef LIBKLEO_NO_PROGRESSDIALOG
  else
    (void)new Kleo::ProgressDialog( job, "Generating key", this );
#endif
}
Example #24
0
void test_setsockopt_tcp_send_buffer()
{
    int rc;
    void *ctx = zmq_ctx_new();
    void *socket = zmq_socket(ctx, ZMQ_PUSH);

    int val = 0;
    size_t placeholder = sizeof(val);

    rc = zmq_getsockopt(socket, ZMQ_TCP_SEND_BUFFER, &val, &placeholder);
    assert(rc == 0);
    assert(val == 8192);

    rc = zmq_setsockopt(socket, ZMQ_TCP_SEND_BUFFER, &val, sizeof(val));
    assert(rc == 0);
    assert(val == 8192);

    rc = zmq_getsockopt(socket, ZMQ_TCP_SEND_BUFFER, &val, &placeholder);
    assert(rc == 0);
    assert(val == 8192);

    val = 16384;

    rc = zmq_setsockopt(socket, ZMQ_TCP_SEND_BUFFER, &val, sizeof(val));
    assert(rc == 0);
    assert(val == 16384);

    rc = zmq_getsockopt(socket, ZMQ_TCP_SEND_BUFFER, &val, &placeholder);
    assert(rc == 0);
    assert(val == 16384);

    zmq_close(socket);
    zmq_ctx_term(ctx);
}
Example #25
0
FRandom::FRandom (const char *name)
{
	NameCRC = CalcCRC32 ((const BYTE *)name, (unsigned int)strlen (name));
#ifndef NDEBUG
	initialized = false;
	Name = name;
	// A CRC of 0 is reserved for nameless RNGs that don't get stored
	// in savegames. The chance is very low that you would get a CRC of 0,
	// but it's still possible.
	assert (NameCRC != 0);
#endif

	// Insert the RNG in the list, sorted by CRC
	FRandom **prev = &RNGList, *probe = RNGList;

	while (probe != NULL && probe->NameCRC < NameCRC)
	{
		prev = &probe->Next;
		probe = probe->Next;
	}

#ifndef NDEBUG
	if (probe != NULL)
	{
		// Because RNGs are identified by their CRCs in save games,
		// no two RNGs can have names that hash to the same CRC.
		// Obviously, this means every RNG must have a unique name.
		assert (probe->NameCRC != NameCRC);
	}
#endif

	Next = probe;
	*prev = this;
}
Example #26
0
c_type
c_declaratorType(
    c_declarator declaration,
    c_type type)
{
    c_literal l;
    c_metaObject scope;
    c_collectionType o;

    if (declaration->sizes != NULL) {
        scope = c_metaObject(c__getBase(type));
        l = c_iterTakeFirst(declaration->sizes);
        while (l != NULL) {
            o = (c_collectionType)c_metaDefine(scope,M_COLLECTION);
            o->kind = OSPL_C_ARRAY;
            if (l->value.kind == V_LONGLONG) {
                assert (l->value.is.LongLong >= 0);
                o->maxSize = (c_ulong) l->value.is.LongLong;
            } else {
                assert (l->value.is.Long >= 0);
                o->maxSize = (c_ulong) l->value.is.Long;
            }
            o->subType = type;
            c_metaFinalize(c_metaObject(o));
            type = (c_type)o;
            c_free(l);
            l = c_iterTakeFirst(declaration->sizes);
        }
    }
    return type;
}
int main () {
  int i, v, count, qcount, prev;
  int s = nondet_int();
  __CPROVER_assume((s > 0) && (s <=SIZE));
  for (i = 0; i < s; i++) {
    v = nondet_int();
    ref[i] = v;
    a[i] = v;
  }
  sort(a, s);
  v = nondet_int();
  count = 0;
  qcount = 0;
  prev = a[0];
  for (i = 0; i < s; i++) {
    if (ref[i] == v) {
      count++;
    }
    if (a[i] == v) {
      qcount++;
    }
    assert (a[i] >= prev);
 /* MUTANT (del_stmt) */ /*     prev = a[i]; */ 
  }
  assert (count == qcount);
}
Example #28
0
void CChunkSequenceNode::DeleteLastChild()
{
	assert (!m_Children.empty());
	assert(m_Children.back()->m_RefCount > 1);
	m_Children.back()->m_RefCount--;
	m_Children.erase(m_Children.end() - 1);
}
Example #29
0
static void vhost_virtqueue_cleanup(struct vhost_dev *dev,
                                    struct VirtIODevice *vdev,
                                    struct vhost_virtqueue *vq,
                                    unsigned idx)
{
    struct vhost_vring_state state = {
        .index = idx,
    };
    int r;
    r = vdev->binding->set_host_notifier(vdev->binding_opaque, idx, false);
    if (r < 0) {
        fprintf(stderr, "vhost VQ %d host cleanup failed: %d\n", idx, r);
        fflush(stderr);
    }
    assert (r >= 0);
    r = ioctl(dev->control, VHOST_GET_VRING_BASE, &state);
    if (r < 0) {
        fprintf(stderr, "vhost VQ %d ring restore failed: %d\n", idx, r);
        fflush(stderr);
    }
    virtio_queue_set_last_avail_idx(vdev, idx, state.num);
    assert (r >= 0);
    cpu_physical_memory_unmap(vq->ring, virtio_queue_get_ring_size(vdev, idx),
                              0, virtio_queue_get_ring_size(vdev, idx));
    cpu_physical_memory_unmap(vq->used, virtio_queue_get_used_size(vdev, idx),
                              1, virtio_queue_get_used_size(vdev, idx));
    cpu_physical_memory_unmap(vq->avail, virtio_queue_get_avail_size(vdev, idx),
                              0, virtio_queue_get_avail_size(vdev, idx));
    cpu_physical_memory_unmap(vq->desc, virtio_queue_get_desc_size(vdev, idx),
                              0, virtio_queue_get_desc_size(vdev, idx));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   M a g i c k Q u e r y M u l t i l i n e F o n t M e t r i c s             %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  MagickQueryMultilineFontMetrics() returns a 13 element array representing the
%  following font metrics:
%
%    Element Description
%    -------------------------------------------------
%          0 character width
%          1 character height
%          2 ascender
%          3 descender
%          4 text width
%          5 text height
%          6 maximum horizontal advance
%          7 bounding box: x1
%          8 bounding box: y1
%          9 bounding box: x2
%         10 bounding box: y2
%         11 origin: x
%         12 origin: y
%
%  This method is like MagickQueryFontMetrics() but it returns the maximum text
%  width and height for multiple lines of text.
%
%  The format of the MagickQueryFontMetrics method is:
%
%      double *MagickQueryMultilineFontMetrics(MagickWand *wand,
%        const DrawingWand *drawing_wand,const char *text)
%
%  A description of each parameter follows:
%
%    o wand: the Magick wand.
%
%    o drawing_wand: the drawing wand.
%
%    o text: the text.
%
*/
WandExport double *MagickQueryMultilineFontMetrics(MagickWand *wand,
  const DrawingWand *drawing_wand,const char *text)
{
  double
    *font_metrics;

  DrawInfo
    *draw_info;

  MagickBooleanType
    status;

  TypeMetric
    metrics;

  assert(wand != (MagickWand *) NULL);
  assert(wand->signature == WandSignature);
  if (wand->debug != MagickFalse)
    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
  assert(drawing_wand != (const DrawingWand *) NULL);
  if (wand->images == (Image *) NULL)
    {
      (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
        "ContainsNoImages","`%s'",wand->name);
      return((double *) NULL);
    }
  font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
  if (font_metrics == (double *) NULL)
    return((double *) NULL);
  draw_info=PeekDrawingWand(drawing_wand);
  if (draw_info == (DrawInfo *) NULL)
    {
      font_metrics=(double *) RelinquishMagickMemory(font_metrics);
      return((double *) NULL);
    }
  (void) CloneString(&draw_info->text,text);
  (void) ResetMagickMemory(&metrics,0,sizeof(metrics));
  status=GetMultilineTypeMetrics(wand->images,draw_info,&metrics,
    wand->exception);
  draw_info=DestroyDrawInfo(draw_info);
  if (status == MagickFalse)
    {
      font_metrics=(double *) RelinquishMagickMemory(font_metrics);
      return((double *) NULL);
    }
  font_metrics[0]=metrics.pixels_per_em.x;
  font_metrics[1]=metrics.pixels_per_em.y;
  font_metrics[2]=metrics.ascent;
  font_metrics[3]=metrics.descent;
  font_metrics[4]=metrics.width;
  font_metrics[5]=metrics.height;
  font_metrics[6]=metrics.max_advance;
  font_metrics[7]=metrics.bounds.x1;
  font_metrics[8]=metrics.bounds.y1;
  font_metrics[9]=metrics.bounds.x2;
  font_metrics[10]=metrics.bounds.y2;
  font_metrics[11]=metrics.origin.x;
  font_metrics[12]=metrics.origin.y;
  return(font_metrics);
}