Пример #1
0
// Main testing
int main( int argc, char **argv )
{
    printf("Running basic tests, you can run your own these are just examples..\n");
    printf("Initializing memory to 2048bytes\n");
    start_memory(2048);

    // Attempt to get memory
    printf("The following test the get memory function\n");
    printf("The address for 2bytes of memory is %p\n", get_memory(2));
    int testSize = sizeof(testStruct);
    printf("Size is %d", testSize);
    testStruct *test1 = get_memory(testSize);
    printf(" and address is %p\n", (void *)test1);

    printf("Size is %d", testSize);
    testStruct *test2 = get_memory(testSize);
    printf(" and address is %p\n", (void *)test2);

    printf("Size is %d", testSize);
    testStruct *test3 = get_memory(testSize);
    printf(" and address is %p\n", (void *)test3);

    // Test release memory on third struct
    release_memory(test3);

    // Test end_memory on remaining structs
    printf("Testing release memory on remaining stuff, should display leaks and free everything\n");
    end_memory();


    printf("End of testing\n");
    // Exit main
    return 1;
}
Пример #2
0
Файл: gc.c Проект: CRogers/obc
void *scratch_alloc(unsigned size, bool atomic) {
    unsigned alloc_size = round_up(size, SCRATCH_ALIGN);
    uchar *p;

    if (scratch_free + alloc_size > scratch_limit) {
        if (alloc_size > SCRATCH_CHUNK
                || scratch_free + 4*GC_PAGESIZE <= scratch_limit)
            /* Avoid discarding a largish piece */
            return get_memory(alloc_size);

        scratch_free = get_memory(SCRATCH_CHUNK);
        scratch_limit = scratch_free + SCRATCH_CHUNK;
    }

    if (alloc_size % GC_PAGESIZE == 0) {
        scratch_limit -= alloc_size;
        p = scratch_limit;
    } else {
        p = scratch_free;
        scratch_free += alloc_size;
    }

    ASSERT((unsigned) p % SCRATCH_ALIGN == 0);

    return p;
}
Пример #3
0
/*
 * Add lex structure for an included config file.
 */
static inline LEX *lex_add(LEX *lf,
                           const char *filename,
                           FILE *fd,
                           BPIPE *bpipe,
                           LEX_ERROR_HANDLER *scan_error,
                           LEX_WARNING_HANDLER *scan_warning)
{
   LEX *nf;

   Dmsg1(100, "open config file: %s\n", filename);
   nf = (LEX *)malloc(sizeof(LEX));
   if (lf) {
      memcpy(nf, lf, sizeof(LEX));
      memset(lf, 0, sizeof(LEX));
      lf->next = nf;                  /* if have lf, push it behind new one */
      lf->options = nf->options;      /* preserve user options */
      /*
       * preserve err_type to prevent bareos exiting on 'reload'
       * if config is invalid. Fixes bug #877
       */
      lf->err_type = nf->err_type;
   } else {
      lf = nf;                        /* start new packet */
      memset(lf, 0, sizeof(LEX));
      lex_set_error_handler_error_type(lf, M_ERROR_TERM);
   }

   if (scan_error) {
      lf->scan_error = scan_error;
   } else {
      lex_set_default_error_handler(lf);
   }

   if (scan_warning) {
      lf->scan_warning = scan_warning;
   } else {
      lex_set_default_warning_handler(lf);
   }

   lf->fd = fd;
   lf->bpipe = bpipe;
   lf->fname = bstrdup(filename);
   lf->line = get_memory(1024);
   lf->str = get_memory(256);
   lf->str_max_len = sizeof_pool_memory(lf->str);
   lf->state = lex_none;
   lf->ch = L_EOL;

   return lf;
}
Пример #4
0
void bmsg(UAContext *ua, const char *fmt, va_list arg_ptr)
{
   BSOCK *bs = ua->UA_sock;
   int maxlen, len;
   POOLMEM *msg = NULL;

   if (bs) {
      msg = bs->msg;
   }
   if (!msg) {
      msg = get_memory(5000);
   }

   maxlen = sizeof_pool_memory(msg) - 1;
   if (maxlen < 4999) {
      msg = realloc_pool_memory(msg, 5000);
      maxlen = 4999;
   }
   len = bvsnprintf(msg, maxlen, fmt, arg_ptr);
   if (len < 0 || len >= maxlen) {
      pm_strcpy(msg, _("Message too long to display.\n"));
      len = strlen(msg);
   }

   if (bs) {
      bs->msg = msg;
      bs->msglen = len;
      bs->send();
   } else {                           /* No UA, send to Job */
      Jmsg(ua->jcr, M_INFO, 0, "%s", msg);
      free_pool_memory(msg);
   }

}
Пример #5
0
int decode_and_or_EG(unsigned char **lina, Bit32u *src, Bit32u *dst,
		     u_int *bytes, u_int *srcmem, u_int *dstmem, Bit8u op)
{
    int reg;
    
    decode_rm(dst, dstmem, &reg, lina);		/* past r/m */
    
    if (op==0x08 || op==0x20) {
	*bytes = 1;
    } else {
	*bytes = opa.opb;
    }
    *srcmem = 0; /* not strictly true; what if we OR mem and reg? */
    if (*dstmem) {
	if (get_memory(opa.seg, *dst, src, *bytes) != 0)
	    return -1;
    } else {
	*src = get_reg(*dst, *bytes);
    }
    if (op == 0x08 || op == 0x09) {
	*src |= get_reg(reg, *bytes);
    } else {
	*src &= (get_reg(reg, *bytes) | ~masks[*bytes]);
    }
    
    return 0;
}
Пример #6
0
/*
 * Setup inflation for auto inflation of data streams.
 */
static bool setup_auto_inflation(DCR *dcr)
{
   JCR *jcr = dcr->jcr;
   uint32_t decompress_buf_size;

   if (jcr->buf_size == 0) {
      jcr->buf_size = DEFAULT_NETWORK_BUFFER_SIZE;
   }

   setup_decompression_buffers(jcr, &decompress_buf_size);
   if (decompress_buf_size > 0) {
      /*
       * See if we need to create a new compression buffer or make sure the existing is big enough.
       */
      if (!jcr->compress.inflate_buffer) {
         jcr->compress.inflate_buffer = get_memory(decompress_buf_size);
         jcr->compress.inflate_buffer_size = decompress_buf_size;
      } else {
         if (decompress_buf_size > jcr->compress.inflate_buffer_size) {
            jcr->compress.inflate_buffer = realloc_pool_memory(jcr->compress.inflate_buffer, decompress_buf_size);
            jcr->compress.inflate_buffer_size = decompress_buf_size;
         }
      }
   } else {
      return false;
   }

   return true;
}
Пример #7
0
int main(int argc, const char *argv[])
{
	char *str=NULL;
	str=get_memory();
	printf("%s\n",str);
	return 0;
}
Пример #8
0
/*******************************************************************************
 *  Member Function: Push
 *  Comments: Place item onto the tail of the queue
 *  Arguments: the item
 *  Return: Return 1 if successful, 0 if not, 2 if єlement is in the queue
 ******************************************************************************/
int queue::Push(int v)
{  
   if (!Full() )
   {       // Make sure queue is not full
      if (unique == 1) 
      {
         for (int i = 0; i < tail; i++) 
         {
            // only unique elements
            if (data[i] == v)
            return 2;
         }
      }
      data[tail] = v;       // insert element into queue
      sum += v;
      tail++;               // increment tail pointer
      return 1;             // Item was inserted, so return 1
   } else {
      get_memory(&data, size, size*2);
      data[tail] = v;       // insert element into queue
      sum += v;
      tail++;               // increment tail pointer
      return 1;             // Item was inserted, so return 1
   }
   return 0;                // queue was full, so return 0
}
Пример #9
0
/*
 * Save current working directory.
 * Returns: true if OK
 *          false if failed
 */
bool saveCWD::save(JCR *jcr)
{
   release();                                /* clean up */
   if (!fchdir_failed) {
      m_fd = open(".", O_RDONLY);
      if (m_fd < 0) {
         berrno be;
         Jmsg1(jcr, M_ERROR, 0, _("Cannot open current directory: ERR=%s\n"), be.bstrerror());
         m_saved = false;
         return false;
      }
   }

   if (fchdir_failed) {
      POOLMEM *buf = get_memory(5000);
      m_cwd = (POOLMEM *)getcwd(buf, sizeof_pool_memory(buf));
      if (m_cwd == NULL) {
         berrno be;
         Jmsg1(jcr, M_ERROR, 0, _("Cannot get current directory: ERR=%s\n"), be.bstrerror());
         free_pool_memory(buf);
         m_saved = false;
         return false;
      }
   }
   m_saved = true;
   return true;
}
Пример #10
0
/*
 * Put a volume label into the block
 *
 *  Returns: false on failure
 *           true  on success
 */
static bool write_volume_label_to_block(DCR *dcr)
{
   DEVICE *dev = dcr->dev;
   DEV_BLOCK *block = dcr->block;
   DEV_RECORD rec;
   JCR *jcr = dcr->jcr;

   Dmsg0(130, "write Label in write_volume_label_to_block()\n");

   memset(&rec, 0, sizeof(rec));
   rec.data = get_memory(SER_LENGTH_Volume_Label);
   empty_block(block);                /* Volume label always at beginning */

   create_volume_label_record(dcr, dev, &rec);

   block->BlockNumber = 0;
   if (!write_record_to_block(dcr, &rec)) {
      free_pool_memory(rec.data);
      Jmsg1(jcr, M_FATAL, 0, _("Cannot write Volume label to block for device %s\n"),
         dev->print_name());
      return false;
   } else {
      Dmsg2(130, "Wrote label of %d bytes to block. Vol=%s\n", rec.data_len,
            dcr->VolumeName);
   }
   free_pool_memory(rec.data);
   return true;
}
Пример #11
0
/*
 * Update File Attributes in the catalog with data sent by the Storage daemon.
 */
void catalog_update(JCR *jcr, BSOCK *bs)
{
   if (!jcr->res.pool->catalog_files) {
      return;                         /* user disabled cataloging */
   }

   if (jcr->is_job_canceled()) {
      goto bail_out;
   }

   if (!jcr->db) {
      POOLMEM *omsg = get_memory(bs->msglen+1);
      pm_strcpy(omsg, bs->msg);
      bs->fsend(_("1994 Invalid Catalog Update: %s"), omsg);
      Jmsg1(jcr, M_FATAL, 0, _("Invalid Catalog Update; DB not open: %s"), omsg);
      free_memory(omsg);
      goto bail_out;
   }

   update_attribute(jcr, bs->msg, bs->msglen);

bail_out:
   if (jcr->is_job_canceled()) {
      cancel_storage_daemon_job(jcr);
   }
}
Пример #12
0
static void
_print_config(void)
{
	int days, hours, mins, secs;
	char name[128];

	gethostname_short(name, sizeof(name));
	printf("NodeName=%s ", name);

	get_cpuinfo(&conf->actual_cpus,
		    &conf->actual_boards,
	            &conf->actual_sockets,
	            &conf->actual_cores,
	            &conf->actual_threads,
	            &conf->block_map_size,
	            &conf->block_map, &conf->block_map_inv);
	printf("CPUs=%u Boards=%u SocketsPerBoard=%u CoresPerSocket=%u "
	       "ThreadsPerCore=%u ",
	       conf->actual_cpus, conf->actual_boards, conf->actual_sockets,
	       conf->actual_cores, conf->actual_threads);

	get_memory(&conf->real_memory_size);
	get_tmp_disk(&conf->tmp_disk_space, "/tmp");
	printf("RealMemory=%u TmpDisk=%u\n",
	       conf->real_memory_size, conf->tmp_disk_space);

	get_up_time(&conf->up_time);
	secs  =  conf->up_time % 60;
	mins  = (conf->up_time / 60) % 60;
	hours = (conf->up_time / 3600) % 24;
	days  = (conf->up_time / 86400);
	printf("UpTime=%u-%2.2u:%2.2u:%2.2u\n", days, hours, mins, secs);
}
/* Updates the load graph when the timeout expires */
static gboolean
load_graph_update (gpointer user_data)
{
	LoadGraph * const g = static_cast<LoadGraph*>(user_data);

	if (g->render_counter == g->frames_per_unit - 1) {
		std::rotate(&g->data[0], &g->data[LoadGraph::NUM_POINTS - 1], &g->data[LoadGraph::NUM_POINTS]);

		switch (g->type) {
		case LOAD_GRAPH_CPU:
			get_load(g);
			break;
		case LOAD_GRAPH_MEM:
			get_memory(g);
			break;
		case LOAD_GRAPH_NET:
			get_net(g);
			break;
		default:
			g_assert_not_reached();
		}
	}

	if (g->draw)
		load_graph_draw (g);

	g->render_counter++;

	if (g->render_counter >= g->frames_per_unit)
		g->render_counter = 0;

	return TRUE;
}
Пример #14
0
/*
 * Uses a cuadratic function to return the distances between each intersection
 * and the eye, if any. Otherwise, it returns a NULL pointer. If there is only
 * one intersection, the array will contain the same distance twice. The first
 * distance is the one of the intersection that is nearest to the eye.
 * NOTE: A cuadratic function is described with the following formula
 * (A (+ and -) sqrt(B^2 - 4AC)) / 2A
 *
 * a: A term of the cuadratic function
 * b: B term of the cuadratic function
 * c: C term of the cuadratic function
 */
long double* do_cuadratic_function(long double a, long double b, long double c)
{
	long double discr, sqrt_discr, t1, t2;
	long double * distances;

	discr = pow(b, 2) - 4 * a * c;
	// There isn't any intersection
	if (discr < 0) return NULL;
	// Continues if there is at least one intersection
    distances = get_memory(sizeof(long double) * 2, NULL);
    sqrt_discr = sqrt(discr);
    t1 = (- b - sqrt_discr) / (2 * a);
    t2 = (- b + sqrt_discr) / (2 * a);
    // Object in front of us
    if(t1 > 0 && t2 > 0)
    {
        distances[0] = t1;
        distances[1] = t2;
        return distances;
    }
    // Object behind us
    else if(t1 < 0 && t2 < 0)
    {
        free(distances);
        return NULL;
    }
    // We are inside the object!
    else
    {
        distances[0] = t2;
        distances[1] = t2;
        return distances;
    }
}
Пример #15
0
int main(void)
{
	int a = 3, b = 5;
	unsigned long long c = -1, d = 500;
	int *p;

	std::cout<<"Test 1"<<std::endl;
	std::cout<<"max of "<<a<<" and "<<b<<" is: "<<get_max(a, b)<<std::endl;
	std::cout<<"max of "<<c<<" and "<<d<<" is: "<<get_max(c, d)<<std::endl;
	std::cout<<std::endl;

#ifdef GET_TYPE_ERROR
	std::cout<<"Test 2"<<std::endl;
	std::cout<<"allocated memory value = "<<*get_memory()<<std::endl;
	std::cout<<std::endl;
#endif /* GET_TYPE_ERROR */

	p = get_memory<int>();
	std::cout<<"Test 2 bis (define GET_TYPE_ERROR for first)"<<std::endl;
	std::cout<<"allocated int value = "<<*p<<", at address "<<p<<std::endl;
	std::cout<<std::endl;

	free(p);
	return 0;
}
Пример #16
0
/*
 * For compression we enable all used compressors in the fileset.
 */
bool adjust_compression_buffers(JCR *jcr)
{
   findFILESET *fileset = jcr->ff->fileset;
   uint32_t compress_buf_size = 0;

   if (fileset) {
      int i, j;

      for (i = 0; i < fileset->include_list.size(); i++) {
         findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
         for (j = 0; j < incexe->opts_list.size(); j++) {
            findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);

            if (!setup_compression_buffers(jcr, me->compatible, fo->Compress_algo,
                                           &compress_buf_size)) {
               return false;
            }
         }
      }

      if (compress_buf_size > 0) {
         jcr->compress.deflate_buffer = get_memory(compress_buf_size);
         jcr->compress.deflate_buffer_size = compress_buf_size;
      }
   }

   return true;
}
Пример #17
0
void get_matrices()
{
        int i,j;
        char *string=(char *)malloc(2048*sizeof(char));
        char *tokenPtr;
	get_memory();
        for (i=1;i<=m;i++){
                fgets(string,2048,stdin);
		//printf ( "%s\n",string);
                tokenPtr=strtok(string," ");
                for (j=1;tokenPtr!=NULL;j++)
		{
                        A[i][j]=atoi(tokenPtr);
			printf ( "%d ",A[i][j]);
                        tokenPtr=strtok(NULL," ");
		}
        }
/*        for (i=1;i<=p;i++){
                fgets(string,2048,stdin);
		printf ( "%s \n",string);
                tokenPtr=strtok(string," ");
                for (j=1;tokenPtr!=NULL;j++)
		{
                        B[i][j]=atoi(tokenPtr);
			printf ( "%d \n",B[i][j]);
                        tokenPtr=strtok(NULL," ");
		}
        }
*/
}
Пример #18
0
unsigned int Emulator::get_int(int addr, int size)
{
	u_int8_t memb = 0;
	u_int16_t memw = 0;
	u_int32_t memd = 0;
	switch (size)
	{
		case 1:
			return get_memory((char *) &memb, addr, size) ? memb : 0;
		case 2:
			return get_memory((char *) &memw, addr, size) ? memw : 0;
		case 4:
			return get_memory((char *) &memd, addr, size) ? memd : 0;
		default:;
	}
	return 0;
}
Пример #19
0
     void Calculator::calculate()
     {

     double operand2     = m_stk.pop().toDouble();
     QString strOperation = m_stk.pop();
     double operand1     = m_stk.pop().toDouble();
     double Result_d     = 0;
     if (strOperation == "+") {
     Result_d  = operand1+operand2;
     }
     if (strOperation == "-")
     {
     Result_d  = operand1-operand2;
     }
     if (strOperation == "/")
     {
     Result_d  = operand1 / operand2;
     }
     if (strOperation == "*")
     {
     Result_d  = operand1 * operand2;
     }
     if (strOperation == "Pow")
     {
       Result_d=qPow(operand1,operand2);
     }
     if (strOperation == "M-")
     {
     subs_memory(operand1);
     }
     if (strOperation == "M+")
     {
     add_memory(operand1);
     }
     if (strOperation == "MS")
     {
     reset_memory();
     }
     if (strOperation == "Sqrt")
     {
     Result_d=qSqrt(operand1);
     }
     if (strOperation == "ln")
     {
     Result_d=qLn(operand1);
     }
     if (strOperation == "MR")
     {
      Result_d=get_memory();

     }
     if (strOperation == "abs")
     {
      Result_d=qAbs(operand1);

     }
     m_plcd->display(Result_d );
     }
Пример #20
0
/* % gcc -DDEBUG_MODULE get_mach_stat.c -I../../.. -g -DUSE_CPU_SPEED	*/
int
main(int argc, char * argv[])
{
	int error_code;
	uint16_t sockets, cores, threads;
	uint16_t block_map_size;
	uint16_t *block_map, *block_map_inv;
	struct config_record this_node;
	char node_name[MAX_SLURM_NAME];
	float speed;
	uint16_t testnumproc = 0;
	uint32_t up_time = 0;
	int days, hours, mins, secs;
	char* _cpuinfo_path = "/proc/cpuinfo";

	if (argc > 1) {
	    	_cpuinfo_path = argv[1];
		testnumproc = 1024;	/* since may not match test host */
	}
	debug3("%s:", _cpuinfo_path);

	error_code = get_mach_name(node_name);
	if (error_code != 0)
		exit(1);    /* The show is all over without a node name */

	error_code += get_procs(&this_node.cpus);
	error_code += get_cpuinfo(MAX(this_node.cpus, testnumproc),
				  &this_node.sockets,
				  &this_node.cores,
				  &this_node.threads,
				  &block_map_size,
				  &block_map, &block_map_inv);
	xfree(block_map);	/* not used here */
	xfree(block_map_inv);	/* not used here */
	error_code += get_memory(&this_node.real_memory);
	error_code += get_tmp_disk(&this_node.tmp_disk, "/tmp");
	error_code += get_up_time(&up_time);
#ifdef USE_CPU_SPEED
	error_code += get_speed(&speed);
#endif

	debug3("");
	debug3("NodeName=%s CPUs=%u Sockets=%u Cores=%u Threads=%u",
		node_name, this_node.cpus,
		this_node.sockets, this_node.cores, this_node.threads);
	debug3("\tRealMemory=%u TmpDisk=%u Speed=%f",
		this_node.real_memory, this_node.tmp_disk, speed);
	secs  = up_time % 60;
	mins  = (up_time / 60) % 60;
	hours = (up_time / 3600) % 24;
	days  = (up_time / 86400);
	debug3("\tUpTime=%u=%u-%2.2u:%2.2u:%2.2u",
	       up_time, days, hours, mins, secs);
	if (error_code != 0)
		debug3("get_mach_stat error_code=%d encountered", error_code);
	exit (error_code);
}
Пример #21
0
static void do_extract(char *devname)
{
   struct stat statp;

   enable_backup_privileges(NULL, 1);

   jcr = setup_jcr("bextract", devname, bsr, director, VolumeName, 1); /* acquire for read */
   if (!jcr) {
      exit(1);
   }
   dev = jcr->read_dcr->dev;
   if (!dev) {
      exit(1);
   }
   dcr = jcr->read_dcr;

   /* Make sure where directory exists and that it is a directory */
   if (stat(where, &statp) < 0) {
      berrno be;
      Emsg2(M_ERROR_TERM, 0, _("Cannot stat %s. It must exist. ERR=%s\n"),
         where, be.bstrerror());
   }
   if (!S_ISDIR(statp.st_mode)) {
      Emsg1(M_ERROR_TERM, 0, _("%s must be a directory.\n"), where);
   }

   free(jcr->where);
   jcr->where = bstrdup(where);
   attr = new_attr(jcr);

   compress_buf = get_memory(compress_buf_size);

   acl_data.last_fname = get_pool_memory(PM_FNAME);
   xattr_data.last_fname = get_pool_memory(PM_FNAME);

   read_records(dcr, record_cb, mount_next_read_volume);
   /* If output file is still open, it was the last one in the
    * archive since we just hit an end of file, so close the file.
    */
   if (is_bopen(&bfd)) {
      set_attributes(jcr, attr, &bfd);
   }
   free_attr(attr);

   free_pool_memory(acl_data.last_fname);
   free_pool_memory(xattr_data.last_fname);

   clean_device(jcr->dcr);
   dev->term();
   free_dcr(dcr);
   free_jcr(jcr);

   printf(_("%u files restored.\n"), num_files);
   return;
}
Пример #22
0
/*
 * For decompression we use the same decompression buffer for each algorithm.
 */
bool adjust_decompression_buffers(JCR *jcr)
{
   uint32_t decompress_buf_size;

   setup_decompression_buffers(jcr, &decompress_buf_size);

   jcr->compress.inflate_buffer = get_memory(decompress_buf_size);
   jcr->compress.inflate_buffer_size = decompress_buf_size;

   return true;
}
Пример #23
0
void exe_irmovl(y86_address pc, struct decode_table *dte)
{
    byte regs = get_memory(pc+1);
    reg_num rB = extract_rB(regs);
    y86_register v = get_memory_4(pc+2, INSTRUCTION_FETCH);
    sprintf(operands, "0x%08X,%s",v, reg_name[rB]);
    PrintPart1(pc, dte, operands);

    set_Register(rB, v);
    PrintPart2();
}
Пример #24
0
Файл: gc.c Проект: CRogers/obc
/* find_block -- find a free block of specified size */
static header *find_block(unsigned size, unsigned objsize) {
    header *h = NULL, *h2;
    int i = min(size/GC_PAGESIZE, BIG_BLOCK);

    ASSERT(size % GC_PAGESIZE == 0);

    do {
        for (headers(h2, free_list[i])) {
            /* This always succeeds for small blocks, and gives
            first-fit allocation for big blocks. */
            if (size <= h2->h_size) {
                h = h2;
                break;
            }
        }
        i++;
    } while (h == NULL && i <= BIG_BLOCK);

    if (h == NULL) {
        /* No suitable block was found.  Get a big chunk. */
        unsigned chunk = max(size, CHUNK_SIZE);
        GC_TRACE("[ex]");
        ASSERT(chunk % GC_PAGESIZE == 0);
        h = alloc_header();
        h->h_memory = (uchar *) get_memory(chunk);
        h->h_size = chunk;
        /* Add to the free list for merging and page table setup */
        h = free_block(h, FALSE);
    }

    ASSERT(h->h_memory != NULL && h->h_size >= size);
    unlink(h);

    if (size < h->h_size) {
        /* Split the block, and return the waste to the free
           list.  It's best to use header h for the waste: that
           way, we don't have to reset lots of page table
           entries when we chip a small piece off a big block. */
        h2 = alloc_header();
        h2->h_memory = h->h_memory;
        h2->h_size = size;
        page_setup(h2->h_memory, size, h2);

        h->h_memory += size;
        h->h_size -= size;
        make_free(h);

        h = h2;
    }

    h->h_objsize = objsize;
    h->h_epoch = gencount;
    return h;
}
void
do_pgr_driving_many_to_dist(
        pgr_edge_t  *data_edges, size_t total_tuples,
        int64_t  *start_vertex, size_t s_len,
        float8 distance,
        bool directedFlag,
        bool equiCostFlag,
        General_path_element_t **ret_path, size_t *path_count,
        char ** err_msg) {
    try {
        graphType gType = directedFlag? DIRECTED: UNDIRECTED;
        const auto initial_size = total_tuples;

        std::deque< Path >paths;
        std::set< int64_t > s_start_vertices(start_vertex, start_vertex + s_len);
        std::vector< int64_t > start_vertices(s_start_vertices.begin(), s_start_vertices.end());

        if (directedFlag) {
            Pgr_base_graph< DirectedGraph > digraph(gType, initial_size);
            digraph.graph_insert_data(data_edges, total_tuples);
            pgr_drivingDistance(digraph, paths, start_vertices, distance, equiCostFlag);
        } else {
            Pgr_base_graph< UndirectedGraph > undigraph(gType, initial_size);
            undigraph.graph_insert_data(data_edges, total_tuples);
            pgr_drivingDistance(undigraph, paths, start_vertices, distance, equiCostFlag);
        }

        size_t count(count_tuples(paths));


        if (count == 0) {
            *err_msg = strdup("NOTICE: No return values was found");
            *ret_path = noResult(path_count, (*ret_path));
            return;
        }
        *ret_path = get_memory(count, (*ret_path));
        auto trueCount(collapse_paths(ret_path, paths));
        *path_count = trueCount;


#ifndef DEBUG
        *err_msg = strdup("OK");
#else
        *err_msg = strdup(log.str().c_str());
#endif
        return;

    } catch ( ... ) {
        *err_msg = strdup("Caught unknown expection!");
        *ret_path = noResult(path_count, (*ret_path));
        return;
    }
}
Пример #26
0
/*******************************************************************************
 *  Member Operator: overloading of assignment
 *  Comments: compare the size of the queues if needs more memory, get it.
 *  Arguments: a queue
 *  Return: Returns this
 ******************************************************************************/
queue& queue::operator = (const queue& Q) 
{
   if (size < Q.size)
      get_memory(&data, size, Q.size);

   memcpy(data, Q.data, sizeof(int)*Q.tail);
   size = Q.size;
   tail = Q.tail;
   unique = Q.unique;
   sum = Q.sum;
   return(*this);
}
Пример #27
0
int emu_bound(unsigned char *lina)
{
    unsigned char *orig_lina = lina;
    u_int addr, is_addr, array_index, lower_bound, upper_bound;

    lina ++;		/* move up to RM byte */
    decode_rm(&addr, &is_addr, &array_index, &lina);
    ASSERT(is_addr);
    /* addr now points to the m16&16 or m32&32; lina is at next instr */
    if (get_memory(opa.seg, addr, &lower_bound, opa.opb) ||
	get_memory(opa.seg, addr+opa.opb, &upper_bound, opa.opb))
	return -1;

    if (array_index < lower_bound || array_index > (upper_bound + opa.opb)) {
	set_guest_exc(EXC_BR, 0);
	return -1;
    }

    REG(eip) += lina-orig_lina;
    return 0;
}
Пример #28
0
void *malloc(size_t size) {
    if (size == 0) {
        return (void*) 0;
    }
    struct header* ptr = (struct header*) get_memory(size + sizeof(struct header));
    ptr->size = size;
    ptr->freed = 0;
    if (tail == NULL) {

    }
    return (void*) (ptr + 1);
}
Пример #29
0
void exe_popl(y86_address pc, struct decode_table *dte)
{
    byte regs = get_memory(pc+1);
    reg_num rA = extract_rA(regs);
    sprintf(operands, "%s", reg_name[rA]);
    PrintPart1(pc, dte, operands);

    y86_address sp_add = get_Register(ESP);
    y86_register val = get_memory_4(sp_add, DATA_READ);
    set_Register(ESP, sp_add + 4);
    set_Register(rA, val);
    PrintPart2();
}
Пример #30
0
void exe_rmmovl(y86_address pc, struct decode_table *dte)
{
    byte regs = get_memory(pc+1);
    reg_num rA = extract_rA(regs);
    reg_num rB = extract_rB(regs);
    y86_address d = get_memory_4(pc+2, INSTRUCTION_FETCH);
    sprintf(operands, "%s,0x%08X(%s)", reg_name[rA], d, reg_name[rB]);
    PrintPart1(pc, dte, operands);

    y86_address dst = get_Register(rB) + d;
    set_memory_4(dst, get_Register(rA), DATA_STORE);
    PrintPart2();
}