Example #1
0
/*///////////////////////////////////////////////////////////////*/
KScalar     stats_mean_fitness_outcross_progeny_n (KConfig_n KN)
/*
** Compute mean fitness of outcross progeny
*/
{
    const char* thisfunction = "stats_mean_fitness_outcross_progeny_n";
    KScalar wmean;
    IF_DEBUG(DEBUG_TRACE1) fprintf(stderr, "%s\n", thisfunction);
    if (KN->O == 0.0) {
        IF_DEBUG(DEBUG_TRACE1) fprintf(stderr, "%s: O==0.0, outcross wmean=0.0\n", 
                                      thisfunction);
        wmean = 0.0;
    } else {
        //void* a = alloc_KArray_n();
        //void* vm = alloc_KVector_n();
        //void* vf = alloc_KVector_n();
        KVector_n vm;
        KVector_n vf;
        apply_gametes_n(KN, vm, vf, KN->x1);
        {
            KArray_n a;
            apply_zygotes_n(KN, a, vm, vf);
            wmean = mean_fitness_n(KN, a);
        }
        //free_KVector_n(vf);
        //free_KVector_n(vm);
        //free_KArray_n(a);
    }
    return wmean;
}
Example #2
0
void
push_scanned_block (bdescr *bd, gen_workspace *ws)
{
    ASSERT(bd != NULL);
    ASSERT(bd->link == NULL);
    ASSERT(bd->gen == ws->gen);
    ASSERT(bd->u.scan == bd->free);

    if (bd->start + bd->blocks * BLOCK_SIZE_W - bd->free > WORK_UNIT_WORDS)
    {
        // a partially full block: put it on the part_list list.
        bd->link = ws->part_list;
        ws->part_list = bd;
        ws->n_part_blocks += bd->blocks;
        IF_DEBUG(sanity,
                 ASSERT(countBlocks(ws->part_list) == ws->n_part_blocks));
    }
    else
    {
        // put the scan block on the ws->scavd_list.
        bd->link = ws->scavd_list;
        ws->scavd_list = bd;
        ws->n_scavd_blocks += bd->blocks;
        IF_DEBUG(sanity,
                 ASSERT(countBlocks(ws->scavd_list) == ws->n_scavd_blocks));
    }
}
Example #3
0
/*///////////////////////////////////////////////////////////////*/
KScalar     stats_mean_fitness_self_progeny_n (KConfig_n KN)
/*
** Compute mean fitness of self progeny.  To do this with the
** KN->x1,x2 type of data structures, we have to generate
** self progeny to a temporary KArray_n, then examine the
** genotypes in that array for fitness.
**
** If there were no selfed progeny produced, then we of course
** have zero mean fitness due to selfed progeny.
*/
{
    const char* thisfunction = "stats_mean_fitness_self_progeny_n";
    KScalar wmean;
    IF_DEBUG(DEBUG_TRACE1) fprintf(stderr, "%s\n", thisfunction);
    if (KN->S == 0.0) {
        IF_DEBUG(DEBUG_TRACE1) fprintf(stderr, "%s: S==0.0, self wmean=0.0\n", 
                                      thisfunction);
        wmean = 0.0;
    } else {
        //void* a = alloc_KArray_n();
        KArray_n a;
        apply_self_progeny_n(KN, a, KN->x1);
        wmean = mean_fitness_n(KN, a);
        //free_KArray_n(a);
    }
    return wmean;
}
Example #4
0
/*///////////////////////////////////////////////////////////////*/
void        initiate_model_state_n  (KConfig_n KN)
{
    const char* thisfunction = "initiate_model_state_n";
    initiate_mut_term_n(KN);
    initiate_fitness_precomputed_n(KN);
    KN->generation = 0;
    if (!KN->option_nolethal) {
        if (KN->fit_s[0] == 1.0) {
            IF_DEBUG(DEBUG_LETHALS)
                fprintf(stderr, "%s: mutation class 0 is lethal, so KN->is_lethal[0]=1\n",
                       thisfunction);
            KN->is_lethal[0] = 1;
            KN->createlethal[0] = 0;
        }
        if (KN->fit_s[1] == 1.0) {
            IF_DEBUG(DEBUG_LETHALS)
                fprintf(stderr, "%s: mutation class 1 is lethal, so KN->is_lethal[1]=1\n",
                       thisfunction);
            KN->is_lethal[1] = 1;
            KN->createlethal[1] = 0;
        }
        IF_DEBUG(DEBUG_LETHALS)
            fprintf(stderr, "%s: KN->is_lethal[0]=%d\n", thisfunction, KN->is_lethal[0]);
        IF_DEBUG(DEBUG_LETHALS)
            fprintf(stderr, "%s: KN->is_lethal[1]=%d\n", thisfunction, KN->is_lethal[1]);
        IF_DEBUG(DEBUG_LETHALS)
            fprintf(stderr, "%s: if either of these are non-zero, expect normalization problems\n",
                   thisfunction);
    }
}
Example #5
0
int main (int argc, char *argv[])
{
    int i, j, b;

    bdescr *a[ARRSIZE];

    srand(SEED);

    hs_init(&argc, &argv);

   // repeatedly sweep though the array, allocating new random-sized
   // objects and deallocating the old ones.
   for (i=0; i < LOOPS; i++)
   {
       for (j=0; j < ARRSIZE; j++)
       {
           if (i > 0)
           {
               IF_DEBUG(block_alloc, debugBelch("A%d: freeing %p, %d blocks @ %p\n", j, a[j], a[j]->blocks, a[j]->start));
               freeGroup_lock(a[j]);
               DEBUG_ONLY(checkFreeListSanity());
           }
           b = (rand() % MAXALLOC) + 1;
           a[j] = allocGroup_lock(b);
           IF_DEBUG(block_alloc, debugBelch("A%d: allocated %p, %d blocks @ %p\n", j, a[j], b, a[j]->start));
           // allocating zero blocks isn't allowed
           DEBUG_ONLY(checkFreeListSanity());
       }
   }

   for (j=0; j < ARRSIZE; j++)
   {
       freeGroup_lock(a[j]);
   }
    
    // this time, sweep forwards allocating new blocks, and then
    // backwards deallocating them.
    for (i=0; i < LOOPS; i++)
    {
        for (j=0; j < ARRSIZE; j++)
        {
            b = (rand() % MAXALLOC) + 1;
            a[j] = allocGroup_lock(b);
            IF_DEBUG(block_alloc, debugBelch("B%d,%d: allocated %p, %d blocks @ %p\n", i, j, a[j], b, a[j]->start));
            DEBUG_ONLY(checkFreeListSanity());
        }
        for (j=ARRSIZE-1; j >= 0; j--)
        {
            IF_DEBUG(block_alloc, debugBelch("B%d,%d: freeing %p, %d blocks @ %p\n", i, j, a[j], a[j]->blocks, a[j]->start));
            freeGroup_lock(a[j]);
            DEBUG_ONLY(checkFreeListSanity());
        }
    }
    
    DEBUG_ONLY(checkFreeListSanity());

    hs_exit(); // will do a memory leak test

    exit(0);
}
isl_set *nfm_constraint_from_set(isl_ctx *ctx,
		nfm_constraint *constraints)
{
	isl_printer *p;

	assert(ctx);
	assert(constraints);

	IF_DEBUG(fprintf(stdout, "  Transforming a constraint into ISL set.\n"));

	p = isl_printer_to_str(ctx);

	p = isl_printer_print_pw_qpolynomial(p, constraints->constraint);
	char *str = isl_printer_get_str(p);
	IF_DEBUG(fprintf(stdout, "  The input Qpolynomianl constraint: %s\n", str));

	assert(str);

	/* Translate the qpolynomial into a map.  */
	char *set_str = (char *) malloc((strlen(str)+10)*sizeof(char));
	strcpy(set_str, str);
	IF_DEBUG2(fprintf(stdout, "  set_str=%s\n", set_str));
	size_t pos_arrow = strcspn(str, ">");
	set_str[pos_arrow-1] = ' ';
	set_str[pos_arrow] = ':';
	IF_DEBUG2(fprintf(stdout, "  set_str=%s\n", set_str));
	size_t pos_colon = strcspn(&(str[pos_arrow+1]), ":");
	if (strchr(&(str[pos_arrow+1]), ':') != NULL)
	{
		set_str[pos_arrow+1+pos_colon] = ' ';
		IF_DEBUG2(fprintf(stdout, "  set_str=%s\n", set_str));

		if (constraints->eq == 1)
			strcpy(&(set_str[pos_arrow+1+pos_colon]), "  = 0 and ");
		else
			strcpy(&(set_str[pos_arrow+1+pos_colon]), " >= 0 and ");

		IF_DEBUG2(fprintf(stdout, "  set_str=%s\n", set_str));
		strncpy(&(set_str[pos_arrow+pos_colon+10]), &(str[pos_arrow+1+pos_colon+1]), strlen(str) - pos_arrow - pos_colon);
		IF_DEBUG2(fprintf(stdout, "  set_str=%s\n", set_str));
	}
	else
	{
		size_t pos_bracket = strcspn(str, "}");
		set_str[pos_bracket] = ' ';
		if (constraints->eq == 1)
			strcat(&(set_str[pos_bracket]), " = 0 }");
		else
			strcat(&(set_str[pos_bracket]), " >= 0 }");
	}

	IF_DEBUG(fprintf(stdout, "  The Qpolynomial translated into a set is: %s\n", set_str));
	isl_set *set = isl_set_read_from_str(ctx, set_str);

	isl_printer_free(p);

	return set;
}
Example #7
0
void spl_to_playlist_t(LIBMTP_mtpdevice_t* device, PTPObjectInfo *oi,
                       const uint32_t id, LIBMTP_playlist_t * const pl)
{
  // Fill in playlist metadata
  // Use the Filename as the playlist name, dropping the ".spl" extension
  pl->name = malloc(sizeof(char)*(strlen(oi->Filename) -4 +1));
  memcpy(pl->name, oi->Filename, strlen(oi->Filename) -4);
  // Set terminating character
  pl->name[strlen(oi->Filename) - 4] = 0;
  pl->playlist_id = id;
  pl->parent_id = oi->ParentObject;
  pl->storage_id = oi->StorageID;
  pl->tracks = NULL;
  pl->no_tracks = 0;

  IF_DEBUG() printf("pl->name='%s'\n",pl->name);

  // open a temporary file
  char tmpname[] = "/tmp/mtp-spl2pl-XXXXXX";
  int fd = mkstemp(tmpname);
  if(fd < 0) {
    printf("failed to make temp file for %s.spl -> %s, errno=%s\n", pl->name, tmpname, strerror(errno));
    return;
  }
  // make sure the file will be deleted afterwards
  if(unlink(tmpname) < 0)
    printf("failed to delete temp file for %s.spl -> %s, errno=%s\n", pl->name, tmpname, strerror(errno));
  int ret = LIBMTP_Get_File_To_File_Descriptor(device, pl->playlist_id, fd, NULL, NULL);
  if( ret < 0 ) {
    // FIXME     add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_Playlist: Could not get .spl playlist file.");
    close(fd);
    printf("FIXME closed\n");
  }

  text_t* p = read_into_spl_text_t(device, fd);
  close(fd);

  // FIXME cache these somewhere else so we don't keep calling this!
  LIBMTP_folder_t *folders;
  LIBMTP_file_t *files;
  folders = LIBMTP_Get_Folder_List(device);
  files = LIBMTP_Get_Filelisting_With_Callback(device, NULL, NULL);

  // convert the playlist listing to track ids
  pl->no_tracks = trackno_spl_text_t(p);
  IF_DEBUG() printf("%u track%s found\n", pl->no_tracks, pl->no_tracks==1?"":"s");
  pl->tracks = malloc(sizeof(uint32_t)*(pl->no_tracks));
  tracks_from_spl_text_t(p, pl->tracks, folders, files);

  free_spl_text_t(p);

  // debug: add a break since this is the top level function call
  IF_DEBUG() printf("------------\n\n");
}
Example #8
0
/*
 * Update the register vif in the multicast routing daemon and the
 * kernel because the interface used initially to get its local address
 * is DOWN. register_vifi is the index to the Register vif which needs
 * to be updated. As a result the Register vif has a new uv_lcl_addr and
 * is UP (virtually :))
 */
int
update_reg_vif( mifi_t register_vifi )
{
    register struct uvif *v;
    register mifi_t vifi;

    /* Find the first useable vif with solid physical background */
    for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) {
	if (v->uv_flags & (VIFF_DISABLED | VIFF_DOWN | MIFF_REGISTER))
	    continue;
        /* Found. Stop the bogus Register vif first */
	stop_vif(register_vifi);
	add_phaddr(v, &uvifs[vifi].uv_linklocal->pa_addr,
		   &uvifs[vifi].uv_linklocal->pa_subnetmask,
		   &uvifs[vifi].uv_linklocal->pa_prefix); 
	start_vif(register_vifi);
	IF_DEBUG(DEBUG_PIM_REGISTER | DEBUG_IF)
	    log_msg(LOG_NOTICE, 0, "%s has come up; vif #%u now in service",
		uvifs[register_vifi].uv_name, register_vifi);
	return 0;
    }
    vifs_down = TRUE;
    log_msg(LOG_WARNING, 0, "Cannot start Register vif: %s",
	uvifs[vifi].uv_name);
    return(-1);
}
Example #9
0
void start_all_vifs()
{
	mifi_t vifi;
	struct uvif *v;
	u_int action;


	/* Start first the NON-REGISTER vifs */
	for (action = 0; ; action = MIFF_REGISTER) {
		for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) {
			/*
			 * If starting non-registers but the vif is a register
			 * or if starting registers, but the interface is not
			 * a register, then just continue.
			 */
			if ((v->uv_flags & MIFF_REGISTER) ^ action)
				continue;

			if (v->uv_flags & (VIFF_DISABLED | VIFF_DOWN)) {
				IF_DEBUG(DEBUG_IF)
					log_msg(LOG_DEBUG, 0,
					    "%s is %s; vif #%u out of service",
					    v->uv_name,
					    v->uv_flags & VIFF_DISABLED ? "DISABLED" : "DOWN",
					    vifi); 
				continue;
			}
			start_vif(vifi);
		}
		if (action == MIFF_REGISTER)
			break;
	}
}
Example #10
0
void *
stgMallocBytes (size_t n, char *msg)
{
    void *space;

    if ((space = malloc(n)) == NULL) {
      /* Quoting POSIX.1-2008 (which says more or less the same as ISO C99):
       *
       *   "Upon successful completion with size not equal to 0, malloc() shall
       *   return a pointer to the allocated space. If size is 0, either a null
       *   pointer or a unique pointer that can be successfully passed to free()
       *   shall be returned. Otherwise, it shall return a null pointer and set
       *   errno to indicate the error."
       *
       * Consequently, a NULL pointer being returned by `malloc()` for a 0-size
       * allocation is *not* to be considered an error.
       */
      if (n == 0) return NULL;

      /* don't fflush(stdout); WORKAROUND bug in Linux glibc */
      rtsConfig.mallocFailHook((W_) n, msg);
      stg_exit(EXIT_INTERNAL_ERROR);
    }
    IF_DEBUG(sanity, memset(space, 0xbb, n));
    return space;
}
Example #11
0
void c_foreach P3(int, flags, int, idx1, int, idx2) {
    IF_DEBUG(stack_in_use_as_temporary++);
    
    if (flags & 4) {
	CHECK_TYPES(sp, T_MAPPING, 2, F_FOREACH);
	
	push_refed_array(mapping_indices(sp->u.map));
	(++sp)->type = T_NUMBER;
	sp->u.lvalue = (sp-1)->u.arr->item;
	sp->subtype = (sp-1)->u.arr->size;
		    
	(++sp)->type = T_LVALUE;
	if (flags & 2)
	    sp->u.lvalue = &current_object->variables[idx1 + variable_index_offset];
	else
	    sp->u.lvalue = fp + idx1;
    } else 
    if (sp->type == T_STRING) {
	(++sp)->type = T_NUMBER;
	sp->u.lvalue_byte = (unsigned char *)((sp-1)->u.string);
	sp->subtype = SVALUE_STRLEN(sp - 1);
    } else {
	CHECK_TYPES(sp, T_ARRAY, 2, F_FOREACH);

	(++sp)->type = T_NUMBER;
	sp->u.lvalue = (sp-1)->u.arr->item;
	sp->subtype = (sp-1)->u.arr->size;
    }

    (++sp)->type = T_LVALUE;
    if (flags & 1)
	sp->u.lvalue = &current_object->variables[idx2 + variable_index_offset];
    else
	sp->u.lvalue = fp + idx2;
}
Example #12
0
void beam_catches_init(void)
{
    int i;

    bccix[0].tabsize   = DEFAULT_TABSIZE;
    bccix[0].free_list = -1;
    bccix[0].high_mark = 0;
    bccix[0].beam_catches = erts_alloc(ERTS_ALC_T_CODE,
				     sizeof(beam_catch_t)*DEFAULT_TABSIZE);
    IF_DEBUG(bccix[0].is_staging = 0);
    for (i=1; i<ERTS_NUM_CODE_IX; i++) {
	bccix[i] = bccix[i-1];
    }
     /* For initial load: */
    IF_DEBUG(bccix[erts_staging_code_ix()].is_staging = 1);
}
Example #13
0
/**
 * \file profile.hpp
 * \author Benjamin Segovia <benjamin.segovia@intel.com>
 */
#include "ir/profile.hpp"
#include "ir/function.hpp"
#include "sys/platform.hpp"

namespace gbe {
namespace ir {

  namespace ocl
  {
    const char *specialRegMean[] = {
        "local_id_0", "local_id_1", "local_id_2",
        "group_id_0", "group_id_1", "group_id_2",
        "num_groups_0", "num_groups_1", "num_groups_2",
        "local_size_0", "local_size_1", "local_size_2",
        "global_size_0", "global_size_1", "global_size_2",
        "global_offset_0", "global_offset_1", "global_offset_2",
        "stack_pointer",
        "block_ip",
        "barrier_id", "thread_number",
        "work_dimension", "sampler_info",
        "emask", "notemask", "barriermask", "retVal"
    };

#if GBE_DEBUG
#define DECL_NEW_REG(FAMILY, REG) \
   r = fn.newRegister(FAMILY_DWORD); \
   GBE_ASSERT(r == REG);
#else
#define DECL_NEW_REG(FAMILY, REG) \
   fn.newRegister(FAMILY_DWORD);
#endif /* GBE_DEBUG */
    static void init(Function &fn) {
      IF_DEBUG(Register r);
      DECL_NEW_REG(FAMILY_DWORD, lid0);
      DECL_NEW_REG(FAMILY_DWORD, lid1);
      DECL_NEW_REG(FAMILY_DWORD, lid2);
      DECL_NEW_REG(FAMILY_DWORD, groupid0);
      DECL_NEW_REG(FAMILY_DWORD, groupid1);
      DECL_NEW_REG(FAMILY_DWORD, groupid2);
      DECL_NEW_REG(FAMILY_DWORD, numgroup0);
      DECL_NEW_REG(FAMILY_DWORD, numgroup1);
      DECL_NEW_REG(FAMILY_DWORD, numgroup2);
      DECL_NEW_REG(FAMILY_DWORD, lsize0);
      DECL_NEW_REG(FAMILY_DWORD, lsize1);
      DECL_NEW_REG(FAMILY_DWORD, lsize2);
      DECL_NEW_REG(FAMILY_DWORD, gsize0);
      DECL_NEW_REG(FAMILY_DWORD, gsize1);
      DECL_NEW_REG(FAMILY_DWORD, gsize2);
      DECL_NEW_REG(FAMILY_DWORD, goffset0);
      DECL_NEW_REG(FAMILY_DWORD, goffset1);
      DECL_NEW_REG(FAMILY_DWORD, goffset2);
      DECL_NEW_REG(FAMILY_DWORD, stackptr);
      DECL_NEW_REG(FAMILY_WORD, blockip);
      DECL_NEW_REG(FAMILY_DWORD, barrierid);
      DECL_NEW_REG(FAMILY_DWORD, threadn);
      DECL_NEW_REG(FAMILY_DWORD, workdim);
      DECL_NEW_REG(FAMILY_WORD, samplerinfo);
      DECL_NEW_REG(FAMILY_WORD, emask);
      DECL_NEW_REG(FAMILY_WORD, notemask);
      DECL_NEW_REG(FAMILY_WORD, barriermask);
      DECL_NEW_REG(FAMILY_WORD, retVal);
    }
Example #14
0
int Types_RegisterTypedef(const char *Name, size_t NameLen, const tType *Type)
{
	DEBUG_NL("(Name=%.*s, Type=", (int)NameLen, Name);
	IF_DEBUG( Types_Print(stdout, Type) );
	DEBUG_S(")\n");
	tTypedef **pnp = &gpTypedefs;
	for( tTypedef *td = gpTypedefs; td; pnp = &td->Next, td = td->Next )
	{
		int cmp = strncmp(td->Name, Name, NameLen);
		if( cmp > 0 )
			break;
		if( cmp == 0 && strlen(td->Name) == NameLen )
		{
			if( Types_Compare(td->Base, Type) != 0 ) {
				// Error! Incompatible redefinition
				return -1;
			}
			// Compatible redefinition
			return 1;
		}
	}
	
	tTypedef *td = malloc( sizeof(tTypedef) + NameLen + 1 );
	td->Name = (char*)(td + 1);
	memcpy(td+1, Name, NameLen);
	((char*)(td+1))[NameLen] = 0;
	td->Base = Type;
	
	td->Next = *pnp;
	*pnp = td;
	
	return 0;
}
Example #15
0
/*
 * elapsed_time seconds have passed; perform all the events that should
 * happen.
 */
void timer_age_queue(int elapsed_time)
{
    struct timeout_q *ptr;

#ifdef CALLOUT_DEBUG
    IF_DEBUG(DEBUG_TIMEOUT)
	logit(LOG_DEBUG, 0, "aging queue (elapsed time %d):", elapsed_time);
    print_Q();
#endif
    
    for (ptr = Q; Q; ptr = Q) {
	if (ptr->time  > elapsed_time) {
	    ptr->time -= elapsed_time;
	    break;
	}

	/* ptr has expired, push Q */
	Q             = ptr->next;
	elapsed_time -= ptr->time;

	if (ptr->func)
	    ptr->func(ptr->data);
	free(ptr);
    }
}
Example #16
0
/**
 * Normal constructor for EventLoop instance.
 */
PHP_METHOD(EventLoop, __construct)
{
	int backend = EVFLAG_AUTO;
	event_loop_object *obj = (event_loop_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
	
	assert( ! obj->loop);
	
	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &backend) != SUCCESS) {
		return;
	}
	
	/* Check parameter */
	if(EVFLAG_AUTO       != backend &&
	   EVBACKEND_SELECT  != backend &&
	   EVBACKEND_POLL    != backend &&
	   EVBACKEND_EPOLL   != backend &&
	   EVBACKEND_KQUEUE  != backend &&
	   EVBACKEND_DEVPOLL != backend &&
	   EVBACKEND_PORT    != backend &&
	   EVBACKEND_ALL     != backend) {
		/* TODO: libev-specific exception class here */
		zend_throw_exception(NULL, "libev\\EventLoop: backend parameter must be "
			"one of the EventLoop::BACKEND_* constants.", 1 TSRMLS_DC);
		
		return;
	}
	
	obj->loop = ev_loop_new(backend);
	
	IF_DEBUG(ev_verify(obj->loop));
}
Example #17
0
File: Scav.c Project: bogiebro/ghc
void
scavenge_loop(void)
{
    rtsBool work_to_do;

loop:
    work_to_do = rtsFalse;

    // scavenge static objects 
    if (major_gc && gct->static_objects != END_OF_STATIC_LIST) {
	IF_DEBUG(sanity, checkStaticObjects(gct->static_objects));
	scavenge_static();
    }
    
    // scavenge objects in compacted generation
    if (mark_stack_bd != NULL && !mark_stack_empty()) {
	scavenge_mark_stack();
	work_to_do = rtsTrue;
    }
    
    // Order is important here: we want to deal in full blocks as
    // much as possible, so go for global work in preference to
    // local work.  Only if all the global work has been exhausted
    // do we start scavenging the fragments of blocks in the local
    // workspaces.
    if (scavenge_find_work()) goto loop;
    
    if (work_to_do) goto loop;
}
Example #18
0
/**
 * Find the track names (including path) for this playlist's track ids.
 * (ie: 12345 -> \Music\song.mp3)
 *
 * @param p the text to search
 * @param tracks list of track id's to look up
 * @param folders the folders list for the device
 * @param fiels the files list for the device
 * @see playlist_t_to_spl()
 */
static void spl_text_t_from_tracks(text_t** p,
                                   uint32_t* tracks,
                                   const uint32_t trackno,
                                   const uint32_t ver_major,
                                   const uint32_t ver_minor,
                                   char* dnse,
                                   LIBMTP_folder_t* folders,
                                   LIBMTP_file_t* files)
{

  // HEADER
  text_t* c = NULL;
  append_text_t(&c, "SPL PLAYLIST");
  *p = c; // save the top of the list!

  char vs[14]; // "VERSION 2.00\0"
  sprintf(vs,"VERSION %d.%02d",ver_major,ver_minor);

  append_text_t(&c, vs);
  append_text_t(&c, "");

  // TRACKS
  int i;
  char* f;
  for(i=0;i<trackno;i++) {
    discover_filepath_from_id(&f, tracks[i], folders, files);

    if(f != NULL) {
      append_text_t(&c, f);
      IF_DEBUG()
        printf("track %d = %s (%u)\n", i+1, f, tracks[i]);
    }
    else
      printf("failed to find filepath for track=%d\n", tracks[i]);
  }

  // FOOTER
  append_text_t(&c, "");
  append_text_t(&c, "END PLAYLIST");
  if(ver_major == 2) {
    append_text_t(&c, "");
    append_text_t(&c, "myDNSe DATA");
    if(dnse != NULL) {
      append_text_t(&c, dnse);
    }
    else {
      append_text_t(&c, "");
      append_text_t(&c, "");
    }
    append_text_t(&c, "END myDNSe");
  }

  c->next = NULL;

  // debug
  IF_DEBUG() {
    printf(".spl playlist:\n");
    print_spl_text_t(*p);
  }
}
Example #19
0
tType *Types_Register(const tType *Type)
{
	DEBUG("(Type=%p)", Type);
	DEBUG_NL("Type=");
	IF_DEBUG( Types_Print(stdout, Type) );
	DEBUG_S("\n");
	tType **retp = bsearch(&Type, gpTypeCache, giTypeCacheSize, sizeof(void*), Types_Compare_I);
	if(retp) {
		assert(*retp);
		DEBUG("RETURN %p (cached)", *retp);
		return *retp;
	}
	
	gpTypeCache = realloc(gpTypeCache, (giTypeCacheSize+1)*sizeof(void*));
	assert(gpTypeCache);
	tType *ret = malloc( sizeof(tType) );
	*ret = *Type;
	gpTypeCache[giTypeCacheSize] = ret;
	giTypeCacheSize ++;

	qsort(gpTypeCache, giTypeCacheSize, sizeof(void*), Types_Compare_I);

	DEBUG("RETURN %p (new)", ret);
	return ret;
}
Example #20
0
static void
free_mega_group (bdescr *mg)
{
    bdescr *bd, *prev;

    // Find the right place in the free list.  free_mblock_list is
    // sorted by *address*, not by size as the free_list is.
    prev = NULL;
    bd = free_mblock_list;
    while (bd && bd->start < mg->start) {
        prev = bd;
        bd = bd->link;
    }

    // coalesce backwards
    if (prev)
    {
        mg->link = prev->link;
        prev->link = mg;
        mg = coalesce_mblocks(prev);
    }
    else
    {
        mg->link = free_mblock_list;
        free_mblock_list = mg;
    }
    // coalesce forwards
    coalesce_mblocks(mg);

    IF_DEBUG(sanity, checkFreeListSanity());
}    
Example #21
0
/*///////////////////////////////////////////////////////////////*/
void        apply_apomixis_progeny_n    (KConfig_n KN,
                                         KArray_n& to, KArray_n& from)
/*
** Compute proportions of apomixis genotypes produced by population.
*/
{
    const char* thisfunction = "apply_apomixis_progeny_n";
    KInt i0, j0, i1, j1, n0, v0, n1, v1;
    IF_DEBUG(DEBUG_TRACE1) fprintf(stderr, "%s\n", thisfunction);
    if (KN->A == 0.0) {
        IF_DEBUG(DEBUG_TRACE1) fprintf(stderr, "%s: no apomixis\n", thisfunction);
        return;  /* nothing to add */
    }
    for (i0=0; i0 <= KN->MI0; i0++) {
        for (j0=0; j0 <= KN->MJ0; j0++) {
            for (i1=0; i1 <= KN->MI1; i1++) {
                for (j1=0; j1 <= KN->MJ1; j1++) {
                    if ((KN->is_lethal[0] && j0 > 0
                         && KN->createlethal[0] == 0)
                        || (KN->is_lethal[1] && j1 > 0
                            && KN->createlethal[1] == 0)) {
                        // don't do any more to a class that will die **
                        continue;
                    }
                    IF_DEBUG(DEBUG_TRACE2)
                        if (!(i0 % 10) && !(j0 % 10) &&
                            !(i1 % 10) && !(j1 % 10)) {
                            fprintf(stderr, "a[%d,%d,%d,%d] ", 
                                   i0, j0, i1, j1);
                            fflush(stderr);
                        }
                    /* identical load class only */
                    n0 = i0;
                    v0 = j0;
                    n1 = i1;
                    v1 = j1;
                    /* final addition to to(a)i0,j0,i1,j1 */
                    to[i0][j0][i1][j1] += 
                        a_apomixis_n(i0,j0,i1,j1,n0,v0,n1,v1) *
                        KN->A *
						from[n0][v0][n1][v1];
                }
            }
        }
    }
    IF_DEBUG(DEBUG_TRACE2) fprintf(stderr, "\n");
}
Example #22
0
void c_foreach(int  flags, int  idx1, int  idx2) {
    IF_DEBUG(stack_in_use_as_temporary++);
    
    if (flags & FOREACH_MAPPING) {
	CHECK_TYPES(sp, T_MAPPING, 2, F_FOREACH);
	
	push_refed_array(mapping_indices(sp->u.map));

	STACK_INC;
	sp->type = T_NUMBER;
	sp->u.lvalue = (sp-1)->u.arr->item;
	sp->subtype = (sp-1)->u.arr->size;
		    
	STACK_INC;
	sp->type = T_LVALUE;
	if (flags & FOREACH_LEFT_GLOBAL) {
	    sp->u.lvalue = &current_object->variables[idx1 + variable_index_offset];
	} else {
	    sp->u.lvalue = fp + idx1;
	}
    } else 
    if (sp->type == T_STRING) {
	STACK_INC;
	sp->type = T_NUMBER;
	sp->u.lvalue_byte = (unsigned char *)((sp-1)->u.string);
	sp->subtype = SVALUE_STRLEN(sp - 1);
    } else {
	CHECK_TYPES(sp, T_ARRAY, 2, F_FOREACH);

	STACK_INC;
	sp->type = T_NUMBER;
	sp->u.lvalue = (sp-1)->u.arr->item;
	sp->subtype = (sp-1)->u.arr->size;
    }

    if (flags & FOREACH_RIGHT_GLOBAL) {
	STACK_INC;
	sp->type = T_LVALUE;
	sp->u.lvalue = &current_object->variables[idx2 + variable_index_offset];
    } else if (flags & FOREACH_REF) {
	ref_t *ref = make_ref();
	svalue_t *loc = fp + idx2;

	/* foreach guarantees our target remains valid */
	ref->lvalue = 0;
	ref->sv.type = T_NUMBER;
	STACK_INC;
	sp->type = T_REF;
	sp->u.ref = ref;
	DEBUG_CHECK(loc->type != T_NUMBER && loc->type != T_REF, "Somehow a reference in foreach acquired a value before coming into scope");
	loc->type = T_REF;
	loc->u.ref = ref;
	ref->ref++;
    } else {
	STACK_INC;
	sp->type = T_LVALUE;
	sp->u.lvalue = fp + idx2;
    }
}
Example #23
0
static void upd_byte P2(int, offset, unsigned char, b)
{
    IF_DEBUG(UPDATE_PROGRAM_SIZE);
    DEBUG_CHECK2(offset > CURRENT_PROGRAM_SIZE,
		"patch offset %x larger than current program size %x.\n",
		offset, CURRENT_PROGRAM_SIZE);
    mem_block[A_PROGRAM].block[offset] = b;
}
Example #24
0
/*///////////////////////////////////////////////////////////////*/
void        apply_zygotes_n   (KConfig_n KN, KArray_n& to,
                               KVector_n& mgam, KVector_n& fgam)
/*
** Compute proportion of outcrossed zygotes produced by population.
*/
{
    const char* thisfunction = "apply_zygotes_n";
    KInt i0, i1, k0, k1;
    KScalar sum;    
    /* Combines proportions of male and female gametes into
	** expected genotypic classes.  Note that all classes 
	** L(,j>0) = 0.
	*/
    IF_DEBUG(DEBUG_TRACE1) fprintf(stderr, "%s\n", thisfunction);
    if (KN->O == 0.0) {
        IF_DEBUG(DEBUG_TRACE1) fprintf(stderr, "%s: no outcrossing\n",
                                      thisfunction);
        return;
    }
    for (i0=0; i0 <= KN->MI0; i0++) {
        for (i1=0; i1 <= KN->MI1; i1++) {
            IF_DEBUG(DEBUG_TRACE2)
                if (!(i0 % 10) && !(i1 % 10)) {
                    fprintf(stderr, "z[%d,0,%d,0] ", i0, i1);
                    fflush(stderr);
                }
            sum = 0.0;
            for (k0=0; k0 <= i0; k0++) {
                for (k1=0; k1 <= i1; k1++) {
                    sum += ((fgam[k0][k1] * mgam[i0-k0][i1-k1]) +
                            (fgam[k0][i1-k1] * mgam[i0-k0][k1]) +
                            (fgam[i0-k0][k1] * mgam[k0][i1-k1]) +
                            (fgam[i0-k0][i1-k1] * mgam[k0][k1]));
                }
            }
            /* Gamete pools can each sum to one (selfing and apomixis
            ** decrease the sum of K->fgam) so when we combine them
            ** into the zygote pool, we have to divide by 4 to get the
            ** proportions of zygotes.
            */
            /* note this adds the proportions to the 'to' array */
            to[i0][0][i1][0] += sum * 0.25;
        }
    }
    IF_DEBUG(DEBUG_TRACE2) fprintf(stderr, "\n");
}
static void upd_short P2(int, offset, short, l)
{
    IF_DEBUG(UPDATE_PROGRAM_SIZE);
    DEBUG_CHECK2(offset > CURRENT_PROGRAM_SIZE,
		 "patch offset %x larger than current program size %x.\n",
		 offset, CURRENT_PROGRAM_SIZE);
    COPY_SHORT(mem_block[current_block].block + offset, &l);
}
Example #26
0
/* 
 * Create a timer
 * @delay: Number of seconds for timeout
 * @action: Timer callback
 * @data: Optional callback data, must be a dynically allocated ptr
 */
int timer_set(int delay, cfunc_t action, void *data)
{
    struct timeout_q *ptr, *node, *prev;
    
#ifdef CALLOUT_DEBUG
    IF_DEBUG(DEBUG_TIMEOUT)
	logit(LOG_DEBUG, 0, "setting timer:");
    print_Q();
#endif
    
    /* create a node */	
    node = calloc(1, sizeof(struct timeout_q));
    if (!node) {
	logit(LOG_ERR, 0, "Ran out of memory in %s()", __func__);
	return -1;
    }

    node->func = action; 
    node->data = data;
    node->time = delay; 
    node->next = 0;	
    node->id   = next_id();
    
    prev = ptr = Q;
    
    /* insert node in the queue */
    
    /* if the queue is empty, insert the node and return */
    if (!Q)
	Q = node;
    else {
	/* chase the pointer looking for the right place */
	while (ptr) {
	    if (delay < ptr->time) {
		/* right place */
		node->next = ptr;
		if (ptr == Q)
		    Q = node;
		else
		    prev->next = node;
		ptr->time -= node->time;
		print_Q();

		return node->id;
	    }

	    /* keep moving */
	    delay -= ptr->time; node->time = delay;
	    prev = ptr;
	    ptr = ptr->next;
	}
	prev->next = node;
    }
    print_Q();

    return node->id;
}
Example #27
0
/*///////////////////////////////////////////////////////////////*/
void        compute_adults_initial_n    (KConfig_n KN)
/*
** Initiate adult frequencies to KN->x1
*/
{
    const char* thisfunction = "compute_adults_initial_n";
    IF_DEBUG(DEBUG_TRACE1) fprintf(stderr, "%s\n", thisfunction);
    apply_adults_initial_n(KN, KN->x1);
    KN->current_x = KN_CURRENT_X1;
}
Example #28
0
extern void DEBUG_LoadSymbols( const char *name )
{
    bfd* abfd;
    char **matching;

    bfd_init();
    abfd = bfd_openr(name, "default");
    if (abfd == NULL) {
        barf("can't open executable %s to get symbol table", name);
    }
    if (!bfd_check_format_matches (abfd, bfd_object, &matching)) {
        barf("mismatch");
    }

    {
        long storage_needed;
        asymbol **symbol_table;
        long number_of_symbols;
        long num_real_syms = 0;
        long i;

        storage_needed = bfd_get_symtab_upper_bound (abfd);

        if (storage_needed < 0) {
            barf("can't read symbol table");
        }
        symbol_table = (asymbol **) stgMallocBytes(storage_needed,"DEBUG_LoadSymbols");

        number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);

        if (number_of_symbols < 0) {
            barf("can't canonicalise symbol table");
        }

        if (add_to_fname_table == NULL)
            add_to_fname_table = allocHashTable();

        for( i = 0; i != number_of_symbols; ++i ) {
            symbol_info info;
            bfd_get_symbol_info(abfd,symbol_table[i],&info);
            if (isReal(info.type, info.name)) {
                insertHashTable(add_to_fname_table,
                                info.value, (void*)info.name);
                num_real_syms += 1;
            }
        }

        IF_DEBUG(interpreter,
                 debugBelch("Loaded %ld symbols. Of which %ld are real symbols\n",
                         number_of_symbols, num_real_syms)
                 );

        stgFree(symbol_table);
    }
}
Example #29
0
/*///////////////////////////////////////////////////////////////*/
void        stats_print_verbose_n   (KConfig_n KN)
/*
** Print all fields in the KStats_n structure, verbosely
*/
{
    const char* thisfunction = "stats_print_verbose_n";
    KMutClass m;
    IF_DEBUG(DEBUG_TRACE1) fprintf(stderr, "%s\n", thisfunction);
    fprintf(stdout, "stats begin ========================================\n");
    fprintf(stdout, "generations = %d (out of %d max)\n", KN->generation, 
           GENERATION_CUTOFF);
    fprintf(stdout, "S = %lg\n", KN->S);
    fprintf(stdout, "A = %lg\n", KN->A);
    fprintf(stdout, "O = %lg\n", KN->O);
    fprintf(stdout, "option_truncate = %d\n", KN->option_truncate);
    fprintf(stdout, "option_nolethal = %d\n", KN->option_nolethal);
    fprintf(stdout, "mutation classes = %d\n", KN->mutclasses);
    for (m=0; m < KN->mutclasses; m++) {
        fprintf(stdout, "U[%d] = %lg\n", m, KN->U[m]);
        fprintf(stdout, "fitness function[%d] = %s\n", m,
               get_fitness_function_name(KN->fitness_function[m]));
        fprintf(stdout, "fit_s[%d] = %lg\n", m, KN->fit_s[m]);
        fprintf(stdout, "fit_h[%d] = %lg\n", m, KN->fit_h[m]);
    }
    for (m=0; m < KN->mutclasses; m++) {
        fprintf(stdout, "mean_hetloci[%d] = %lg\n", m,
               KStats_n.mean_hetloci[m]);
        fprintf(stdout, "var_hetloci[%d] = %lg\n", m,
               KStats_n.var_hetloci[m]);
        fprintf(stdout, "mean_homloci[%d] = %lg\n", m,
               KStats_n.mean_homloci[m]);
        fprintf(stdout, "var_homloci[%d] = %lg\n", m,
               KStats_n.var_homloci[m]);
        fprintf(stdout, "mean_totmuts[%d] = %lg\n", m,
               KStats_n.mean_totmuts[m]);
        fprintf(stdout, "var_totmuts[%d] = %lg\n", m,
               KStats_n.var_totmuts[m]);
        fprintf(stdout, "var/mean totmuts[%d] = %lg\n", m,
               KStats_n.var_to_mean_totmuts_ratio[m]);
    }
    fprintf(stdout, "mean_fitness_self_progeny = %lg\n", 
           KStats_n.mean_fitness_self_progeny);
    fprintf(stdout, "mean_fitness_apomixis_progeny = %lg\n", 
           KStats_n.mean_fitness_apomixis_progeny);
    fprintf(stdout, "mean_fitness_outcross_progeny = %lg\n", 
           KStats_n.mean_fitness_outcross_progeny);
    fprintf(stdout, "population_mean_fitness = %lg\n", 
           KStats_n.population_mean_fitness);
    fprintf(stdout, "inbreeding_depression = %lg\n", 
           KStats_n.inbreeding_depression);
    fprintf(stdout, "secondary_selfing_rate = %lg\n", 
           KStats_n.secondary_selfing_rate);
    fprintf(stdout, "stats end ========================================\n");
}
Example #30
0
/*///////////////////////////////////////////////////////////////*/
void        apply_adults_initial_n  (KConfig_n KN, KArray_n& a)
/*
** Initiate adult frequencies
*/
{
    const char* thisfunction = "apply_adults_initial_n";
    IF_DEBUG(DEBUG_TRACE1) fprintf(stderr, "%s\n", thisfunction);
    fill_KArray_n(KN, a, 0.0);
    a[0][0][0][0] = 1.0;
    check_normalization_n(KN, a, thisfunction, "a");
}