Beispiel #1
0
int 
open (const char *file)
{
  if (not_valid(file))
    exit (-1);

  lock_acquire(&file_lock);
  struct file_descriptor *file_d = malloc(sizeof(struct file_descriptor));
  struct file *f = filesys_open(file);
  struct thread *cur = thread_current();
  if (f == NULL)
    {
      lock_release(&file_lock);
      return -1;
    }
  file_d->file = f;
  file_d->fd = cur->fd;
  cur->fd = cur->fd + 1;
  list_push_back(&thread_current()->files,&file_d->elem);
  lock_release(&file_lock);
  return file_d->fd;
}
TEST(INSERTION, MIXING_TAIL_AND_HEAD) {
  list_t* list = list_create();
  char* baz    = strdup("baz");
  char* foo    = strdup("foo");

  // Inserting 1000 elements in head.
  for (size_t i = 0; i < 1000; ++i) {
    list_push_front(list, baz);
  }

  // Inserting 1000 elements in tail.
  for (size_t i = 0; i < 1000; ++i) {
    list_push_back(list, foo);
  }

  EXPECT_EQ(list_get_size(list), (1000 * 2));
  EXPECT_STREQ((const char*) list->head->element, baz);
  EXPECT_STREQ((const char*) list->tail->element, foo);
  free(baz);
  free(foo);
  list_destroy(list);
}
Beispiel #3
0
t_function* addr_to_name(t_proc *proc, unsigned long addr)
{
    t_function *func;

    if (function_list == NULL)
        function_list = list_create(NULL);

    func = list_search_data(function_list, &addr, (cmp)&compare_function_addr);
    if (func != NULL)
        return func;

    if ((func = calloc(1, sizeof(t_function))) == NULL)
        return NULL;

    func->is_syscall = false;
    func->addr = addr;
    if ((func->name = search_name_with_addr(proc, addr, &func->in_plt)) == NULL)
        asprintf(&func->name, "%#lx", addr);

    list_push_back(function_list, func);
    return func;
}
Beispiel #4
0
/* Sleeps for approximately TICKS timer ticks.  Interrupts must
   be turned on. */
void
timer_sleep (int64_t ticks) 
{
  enum intr_level old_level;
  int64_t start     = timer_ticks ();
  struct thread *t  = thread_current();

  if( ticks > 0 )
    {
    t->wake_up_ticks = ticks + start;
    
    /* add the thread to the wait list */
    old_level = intr_disable();
    list_push_back( &wait_list, &( t->elem_wait ) );
    intr_set_level( old_level );
    
    ASSERT (intr_get_level () == INTR_ON);

    /* block the thread */
    sema_down( &t->wait_sem );
    }
}
Beispiel #5
0
/* Iterates through LIST and removes all but the first in each
   set of adjacent elements that are equal according to LESS
   given auxiliary data AUX.  If DUPLICATES is non-null, then the
   elements from LIST are appended to DUPLICATES. */
void
list_unique (struct list *list, struct list *duplicates,
             list_less_func *less, void *aux)
{
  struct list_elem *elem, *next;

  ASSERT (list != NULL);
  ASSERT (less != NULL);
  if (list_empty (list))
    return;

  elem = list_begin (list);
  while ((next = list_next (elem)) != list_end (list))
    if (!less (elem, next, aux) && !less (next, elem, aux)) 
      {
        list_remove (next);
        if (duplicates != NULL)
          list_push_back (duplicates, next);
      }
    else
      elem = next;
}
Beispiel #6
0
struct ofpbuf *
requestforward(enum ofputil_protocol proto)
{
    struct ofputil_requestforward rf;

    memset(&rf, 0, sizeof(rf));
    rf.reason = OFPRFR_GROUP_MOD;

    struct ofputil_group_mod gm;
    struct ofpbuf acts;
    struct ofpact_ipv4 *a_set_field;
    struct ofpact_goto_table *a_goto;
    struct ofputil_bucket bckt;

    memset(&gm, 0, sizeof(gm));
    gm.command = OFPGC15_INSERT_BUCKET;
    gm.type = OFPGT11_SELECT;
    gm.group_id = 0xaaaaaaaa;
    gm.command_bucket_id = 0xbbbbbbbb;

    ofpbuf_init(&acts, 0x18);
    ofpact_put_STRIP_VLAN(&acts);
    a_set_field = ofpact_put_SET_IPV4_DST(&acts);
    a_set_field->ipv4 = inet_addr("192.168.2.9");

    bckt.weight = 0xcccc;
    bckt.watch_port = 0xdddd;
    bckt.watch_group = 0xeeeeeeee;
    bckt.bucket_id = 0x12345678;
    bckt.ofpacts = acts.data;
    bckt.ofpacts_len = acts.size;

    list_init(&(gm.buckets));
    list_push_back(&(gm.buckets), &(bckt.list_node));

    rf.group_mod = &gm;

    return ofputil_encode_requestforward(&rf, proto);
}
Beispiel #7
0
bool file_elem_spage_table (struct file *file, int32_t ofs, uint8_t *upage,
			     uint32_t read_bytes, uint32_t zero_bytes,
			     bool writable)
{
	struct spage_entry *se = malloc (sizeof (struct spage_entry));
	if (se == NULL)
		return false;

	se->type = 0;
	se->already_loaded = false;
	se->pinned = false;
	se->myfile = file;
	se->ofs = ofs;
	se->upage = upage;
	se->read_bytes = read_bytes;
	se->zero_bytes = zero_bytes;
	se->writable = writable;

	list_push_back (&thread_current ()->spage_list, &se->s_elem);
	return true;

}
Beispiel #8
0
static void vm_add_to_free_list(uint64_t physical_address, uint64_t num_pages) {
  // We can do this because we have identity mapping in the kernel
  // TODO: Figure out if there is a way to directly access physical memory/if
  // this is necessary

  // Search to determine where this block should be inserted
  FreeBlock *current = (FreeBlock *)list_head(&virtual_memory_data.free_list);
  while (current) {
    if (physical_address <= physical_end(current)) break;

    current = (FreeBlock *)list_next(&current->entry);
  }

  if (current && physical_address == physical_end(current)) {
    // We can combine
    current->num_pages += num_pages;
  } else {
    // Insert new chunk
    FreeBlock *new_block = (FreeBlock *)physical_address;
    new_block->num_pages = num_pages;

    if (current) {
      list_insert_before(&virtual_memory_data.free_list, &current->entry,
                         &new_block->entry);
    } else {
      // We couldn't find a block to insert this before
      list_push_back(&virtual_memory_data.free_list, &new_block->entry);
    }

    current = new_block;
  }

  // Coalesce if possible (current is now the block we created/added to)
  FreeBlock *next_block = (FreeBlock *)list_next(&current->entry);
  if (next_block && physical_end(current) == physical_start(next_block)) {
    list_remove(&virtual_memory_data.free_list, &next_block->entry);
    current->num_pages += next_block->num_pages;
  }
}
Beispiel #9
0
/* Schedules 'msg' to be sent on 'rpc' and returns 'rpc''s status (as with
 * jsonrpc_get_status()).
 *
 * If 'msg' cannot be sent immediately, it is appended to a buffer.  The caller
 * is responsible for ensuring that the amount of buffered data is somehow
 * limited.  (jsonrpc_get_backlog() returns the amount of data currently
 * buffered in 'rpc'.)
 *
 * Always takes ownership of 'msg', regardless of success. */
int
jsonrpc_send(struct jsonrpc *rpc, struct jsonrpc_msg *msg)
{
    struct ofpbuf *buf;
    struct json *json;
    size_t length;
    char *s;

    if (rpc->status) {
        jsonrpc_msg_destroy(msg);
        return rpc->status;
    }

    jsonrpc_log_msg(rpc, "send", msg);

    json = jsonrpc_msg_to_json(msg);
    s = json_to_string(json, 0);
    length = strlen(s);
    json_destroy(json);

    buf = xmalloc(sizeof *buf);
    ofpbuf_use(buf, s, length);
    buf->size = length;
    list_push_back(&rpc->output, &buf->list_node);
    rpc->output_count++;
    rpc->backlog += length;

    if (rpc->output_count >= 50) {
        VLOG_INFO_RL(&rl, "excessive sending backlog, jsonrpc: %s, num of"
                     " msgs: %"PRIuSIZE", backlog: %"PRIuSIZE".", rpc->name,
                     rpc->output_count, rpc->backlog);
    }

    if (rpc->backlog == length) {
        jsonrpc_run(rpc);
    }
    return rpc->status;
}
Beispiel #10
0
struct page *zero_new(void *addr, bool write)
{
	struct page *p;

	p = (struct page *) malloc(sizeof(struct page));

	if(p == NULL)
	{
		return NULL;
	}

	p->type = Z;
	p->dir = thread_current()->pagedir;
	p->f_addr = addr;
	p->load = false;
	p->write = write;

	lock_acquire(&lock_list);
	list_push_back(&pages, &p->elem);
	lock_release(&lock_list);

	return p;
}
mama_status
mamaPublisher_sendWithThrottle (mamaPublisher               publisher,
                                mamaMsg                     msg,
                                mamaThrottledSendCompleteCb sendCompleteCb,
                                void*                       closure)
{
    mamaPublisherImpl*       impl     = (mamaPublisherImpl*)publisher;
    struct publisherClosure* pClosure = NULL;

    if (!publisher) return MAMA_STATUS_NULL_ARG;

    if (!msg)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "mamaPublisher_sendWithThrottle(): NULL msg.");
        return MAMA_STATUS_INVALID_ARG;
    }

    pClosure = list_allocate_element (impl->mPendingActions);
    if (!pClosure) return MAMA_STATUS_NOMEM;

    list_push_back (impl->mPendingActions, pClosure);

    /*Initializse the closuse for the throttle*/
    pClosure->mPublisher            = publisher;
    pClosure->mSendCompleteCallback = sendCompleteCb;
    pClosure->mSendCompleteClosure  = closure;

    return mamaTransport_throttleAction (impl->mTport,
                                         MAMA_THROTTLE_DEFAULT,
                                         sendMsgAction,
                                         impl,
                                         msg, /*1st closure*/
                                         pClosure, /*2nd Closure*/
                                         0,
                                         &pClosure->mAction);
}
Beispiel #12
0
bool _solver_bfs_move(void *data, const maze *m, vec2 *pos) {
	bfs_data bfs = *((bfs_data *) data);
	list *neighbors;
	vec2 neigh;

	set_insert(bfs.visited, pos);
	neighbors = maze_get_neighbors(m, *pos);
	while (!list_is_empty(neighbors)) {
		list_pop_front(neighbors, &neigh);
		if (!map_contains_key(bfs.parent, &neigh)
			&& !set_contains(bfs.visited, &neigh)) {

			map_put(bfs.parent, &neigh, pos);
			list_push_back(bfs.queue, &neigh);
		}
	}
	list_destroy(neighbors);

	if (list_is_empty(bfs.queue)) {
		return false;
	}
	list_pop_front(bfs.queue, pos);
	return true;
}
Beispiel #13
0
struct frame* frame_table_set (void* upage, void* kpage){
	struct frame* frame_new;

	ASSERT(is_user_vaddr(upage));
	ASSERT(is_kernel_vaddr(kpage));

	// TODO: now, frame_find also use frame_lock. This is bad for speed
	// if kpage frame is already exist, go to else statement
	lock_acquire(&frame_lock);
	if(!frame_find(kpage)){
		frame_new = malloc(sizeof(struct frame));
		frame_new->process = thread_current();
		frame_new->upage = (void*)((int)upage&PAGE_MASK);
		frame_new->kpage = (void*)((int)kpage&PAGE_MASK);
		list_push_back(&frame_table, &(frame_new->table_elem));
		//printf("**** [frame_table_set] frame '%x', upage '%x', kpage '%x'\n",frame_new, frame_new->upage, frame_new->kpage);
		lock_release(&frame_lock);
		return frame_new;
	}
	else{
		lock_release(&frame_lock);
		return NULL;
	}
}
void
hashtable_assertvalid(struct hashtable* h)
{
    assert(h != NULL);
    /* Validate if the size of items in the hashtable is correct. */
    unsigned int count = 0;
    unsigned int i, j, size;
    struct list* chain;
    struct kv_pair* kv;
    for (i = 0; i < h->arraysize; ++i) {
        chain = h->vals[i];
        assert(chain != NULL);
        size = list_getsize(chain);
        count += size;
        /* check if key hashes to the correct index */
        for (j = 0; j < size; ++j) {
            kv = (struct kv_pair*)list_front(chain);
            assert(hash(kv->key, kv->keylen) % h->arraysize == i);
            list_pop_front(chain);
            list_push_back(chain, kv);
        }
    }
    assert(count == h->size);
}
Beispiel #15
0
int nl_stream_send(nl_stream_t *s, nl_buf_t *b)
{
    char *buf;
    size_t len;
    nl_encoder_t *e;
    nl_buf_t tosend;

    if (s->closed) {
        log_warning("#%d already closed", s->sock.fd);
        return -1;
    }

    buf = b->buf;
    len = b->len;
    for (e = s->encoders; e != NULL; e = e->next) {
        buf = e->encoder(e->data, buf, &len);
        if (buf == NULL) {
            return -1;
        }
    }

    tosend.buf = malloc(len);
    if (tosend.buf == NULL) {
        return -1;
    }
    memcpy(tosend.buf, buf, len);
    tosend.len = len;

    if (s->sock.connected && list_empty(s->tosend)) {
        nl_event_add(&s->sock.wev);
    }

    list_push_back(s->tosend, &tosend);

    return len;
}
Beispiel #16
0
/* Acquires LOCK, sleeping until it becomes available if
   necessary.  The lock must not already be held by the current
   thread.

   This function may sleep, so it must not be called within an
   interrupt handler.  This function may be called with
   interrupts disabled, but interrupts will be turned back on if
   we need to sleep. */
void
lock_acquire (struct lock *lock)
{
  ASSERT (lock != NULL);
  ASSERT (!intr_context ());
  ASSERT (!lock_held_by_current_thread (lock));

	if (!sema_try_down (&lock->semaphore))
  	{
			sema_down (&lock->sema_lock);
			thread_current ()->wait_lock = lock;			
			lock_donate_priority(thread_current(), lock);
			sema_up (&lock->sema_lock);

			sema_down (&lock->semaphore);
		}

  lock->holder = thread_current ();
  list_push_back (&(lock->holder->hold_locks), &lock->hold_elem);
 	
	sema_down (&lock->sema_lock);
	lock->holder->wait_lock = NULL;
  sema_up (&lock->sema_lock);
}
Beispiel #17
0
static int	_extract_peer_addresses(t_peer *peer, char **addresses)
{
  t_address	*addr;

  for (int i = 0; addresses[i]; i++)
    {
      if (addresses[i][0] == '\0')
	continue ;
      addr = address_alloc();
      if (!addr
	  || address_fill(addr, addresses[i]) != 0
	  || list_push_back(&(peer->addresses), addr) != 0)
	{
	  if (addr)
	    {
	      address_clean(addr);
	      free(addr);
	    }
	  list_clear(&(peer->addresses));
	  return (1);
	}
    }
  return (0);
}
void get_AllMusician(dataBase * self, list_t * ls)
{
    sqlite3_stmt * stmt;
    char * sql = "SELECT  * FROM musician ";
    int rc = sqlite3_prepare_v2(self->db, sql, strlen(sql), &stmt, NULL);
        while(1){
        rc = sqlite3_step(stmt);
        if(SQLITE_ERROR == rc){
            return;
        }
        else {
            if(SQLITE_DONE == rc){
                printf("\nRead request processed\n");
                break;
            }
            musician_t * fl = NULL;
            fl = malloc(sizeof(musician_t));
            fill_musician(stmt, fl);
            list_push_back(ls, fl);
        }
    }
    sqlite3_finalize(stmt);
    return;
}
Beispiel #19
0
/* Sleeps for approximately TICKS timer ticks.  Interrupts must
   be turned on. */
void
timer_sleep (int64_t ticks) 
{
  enum intr_level old_level;                                                     /* @A1A */      
  int64_t start = timer_ticks ();						    

  ASSERT (intr_get_level () == INTR_ON);
  /* while (timer_elapsed (start) < ticks)                                          @A1D */
  /* thread_yield ();				                                    @A1D */


  struct thread_duration *p = 						         /* @A1A */
     	       (struct thread_duration*) malloc(sizeof(struct thread_duration)); /* @A1A */
  if (p == NULL)
    PANIC ("couldn't allocate thread_duration");                                 /* @A1A */

  p->t = thread_current();                                                       /* @A1A */
  p->due = start + ticks;							 /* @A2A */				

  old_level = intr_disable (); 							 /* @A1A */
  list_push_back (&sleeping_list, &p->elem);                                     /* @A1A */
  thread_block ();						                 /* @A1A */
  intr_set_level (old_level);							 /* @A1A */	
}
Beispiel #20
0
/*! Initializes the swap allocator. */
void swalloc_init(void)
{
    uint32_t i;

    swap_disk = block_get_role(BLOCK_SWAP);
    swap_slots = block_size(swap_disk) / PAGE_SECTORS;

    /* Initialize swap table */
    uint32_t num_pages_used = sizeof(struct swap) * swap_slots;
    num_pages_used = (uint32_t) pg_round_up((void *) num_pages_used) / PGSIZE;

    /* Get pages for swap table */
    swap_list = palloc_get_multiple(PAL_ASSERT | PAL_PAGING | PAL_ZERO, num_pages_used);

    /* Initialize list */
    list_init(open_swap_list);
    /* Initialize swap entries */
    for (i = 0; i < swap_slots; ++i)
    {
        swap_list[i].start_sector = i * PAGE_SECTORS;
        swap_list[i].in_use = false;
        list_push_back(open_swap_list, &(swap_list[i].open_elem));
    }
}
Beispiel #21
0
void addFile_to_Folder(folder_t * genFold, file_t * newFile){
    list_push_back(genFold, newFile);
    genFold->file_count++;
    genFold->size_fold= genFold->size_fold+ newFile->size;
}
Beispiel #22
0
void addFolder_to_Folder(folder_t * genFold, folder_t * newFolder){
    list_push_back(genFold, newFolder);
    genFold->fold_count++;
    genFold->size_fold= genFold->size_fold+ newFolder->size_fold;
}
Beispiel #23
0
void changeSitFile(file_t * fil, folder_t * new_fold){
    list_push_back(new_fold, fil);
    list_pop_back(fil);
}
Beispiel #24
0
void parseline(list *instructions, list *labels) {
start:
    ;;
    dcpu16token tok = nexttoken();

    if (tok == T_COLON) {
        /* Label definition */
        if ((tok = nexttoken()) == T_IDENTIFIER) {
            dcpu16label *l = getnewlabel(labels, cur_tok.string);

            if (l->defined)
                error("Redefinition of label '%s' (%04X -> %04X) forbidden",
                        l->label, l->pc, pc);

            l->pc = pc;
            l->defined = 1;

            goto start;
        } else {
            error("Expected label, got %s", toktostr(tok));
        }
    } else if (is_instruction(tok)) {
        dcpu16instruction instr, *newinstr;

        instr.opcode = tok;
        instr.a = parseoperand(labels);

        if (!is_nonbasic_instruction(tok)) {
            if ((tok = nexttoken()) == T_COMMA) {
                instr.b = parseoperand(labels);
            } else {
                error("Expected ',', got %s", toktostr(tok));
            }
        }

        if ((tok = nexttoken()) != T_NEWLINE)
            error("Expected EOL, got %s", toktostr(tok));

        /*
         * All tokens valid, store instructions, advance PC
         */
        newinstr = malloc(sizeof(dcpu16instruction));
        memcpy(newinstr, &instr, sizeof(dcpu16instruction));

        newinstr->pc = pc;
        newinstr->line = curline;

        list_push_back(instructions, newinstr);

        pc += instruction_length(newinstr);

    } else if (is_macro(tok)) {
        if (tok == T_ORG) {
            if ((tok = nexttoken()) == T_NUMBER) {
                if (flag_paranoid && (cur_tok.number < pc)) {
                    warning("new origin precedes old origin! "
                            "This could cause already written code to be "
                            "overriden.");
                }

                pc = cur_tok.number;
            } else {
                error("Expected numeric, got %s", toktostr(tok));
            }
        } else if (tok == T_DAT) {
            /* All of the stuff we are about to read, neatly packed
             * into words */
            list_node *p = NULL;
            list *data = list_create();

            do {
                if ((tok = nexttoken()) == T_STRING) {
                    char *ptr = cur_tok.string;

                    while (*ptr != '\0') {
                        uint16_t *dat = malloc(sizeof(uint16_t));
                        *dat = *ptr++;

                        list_push_back(data, dat);
                    }
                } else if (tok == T_NUMBER) {
                    uint16_t *dat = malloc(sizeof(uint16_t));
                    *dat = cur_tok.number;

                    list_push_back(data, dat);
                } else {
                    error("Expected string or numeric, got %s", toktostr(tok));
                }

                if ((tok = nexttoken()) == T_COMMA)
                    continue;
                else if (tok == T_NEWLINE)
                    break;
                else
                    error("Expected ',' or EOL, got %s", toktostr(tok));
            } while (1);

            /*
            ram[pc++] = cur_tok.number;
            */
            for (p = list_get_root(data); p != NULL; p = p->next) {
                ram[pc++] = *((uint16_t*)p->data);
            }

            list_dispose(&data, &free);
        }
    } else if (tok == T_NEWLINE) {
        return;
    } else {
        error("Expected label-definition or opcode, got %s", toktostr(tok));
    }
}
Beispiel #25
0
bool add_types(struct symtable *syms, typedecllist_t typelist)
{
  bool correct = true;
  for(unsigned i = 0; i < typelist.size; ++i)
  {
    struct type_decl* type_decl = list_nth(typelist, i);
    struct type_def*  type_def  = type_decl->type_def;
    struct type* type = malloc(sizeof(struct type));
    type->name = strdup(type_decl->ident);
    switch(type_def->type_type)
    {
      case enum_type:
        {
          type->type_kind = enum_t;
          struct enum_type* _enum = malloc(sizeof(struct enum_type));
          _enum->idents = type_def->def.enum_def->identlist;
          type->type_val.enum_type = _enum;
          add_type(syms->types, type);
        }
        break;
      case array_type:
        {
          type->type_kind = array_t;

          struct array* array = malloc(sizeof(struct array));
          if((array->type = find_type(syms->types, type_def->def.array_def->elt_type))
              == NULL)
          {
            error(type_def->pos, "Unknown type");
            correct = false;
          }
          for(unsigned int i = 0; i < type_def->def.array_def->dims.size; ++i)
          {
            struct expr * dim = type_def->def.array_def->dims.data[i];
            if (!check_expr(dim, syms))
              break;
            switch(dim->exprtype)
            {
              case valtype:
                if(dim->val.val->valtype != inttype)
                {
                  error(type_def->pos, "dimension is not an integer");
                  correct = false;
                }
                break;
              case identtype:
                if(!equal_types(find_var(syms->variables, dim->val.ident)->type->name, TYPE_INT, syms))
                {
                  error(dim->pos, "identifier \"%s\" is not an integer", dim->val.ident);
                  correct = false;
                  break;
                }
                if(find_var(syms->variables, dim->val.ident)->type == NULL)
                {
                  error(type_def->pos, "identifier is undeclared");
                  correct = false;
                  break;
                }
                if(!find_var(syms->variables, dim->val.ident)->constante)
                {
                  error(type_def->pos, "identifier is not a constante");
                  correct = false;
                }
                break;
              default:
                error(type_def->pos, "array type is not an int or an indentifier");
                correct = false;

            }

          }
          array->dims = type_def->def.array_def->dims;
          /* list_init(array->dims); */
          /* for (unsigned i = 0; i < type_def->def.array_def->dims.size; ++i) */
          /* { */
          /*   list_push_back(array->dims, */
          /*       type_def->def.array_def->dims.data[i]); */
          /* } */
          type->type_val.array_type = array;
          add_type(syms->types, type);
        }
        break;
      case struct_type:
        {
          type->type_kind = records_t;

          struct records* record = malloc(sizeof(struct records));
          fieldlist_t fields;
          list_init(fields);

          vardecllist_t varlist = type_def->def.record_def->var_decl;

          for(unsigned int i = 0 ; i < varlist.size; ++i)
          {
            struct single_var_decl* var = list_nth(varlist, i);

            for(unsigned int j = 0; j < var->var_idents.size; ++j)
            {
              if (!find_type(syms->types, var->type_ident))
              {
                error(var->pos, "type %s doesn't exist", var->type_ident);
                correct = false;
              }
              else
              {
                struct field* field = malloc(sizeof(struct field));
                field->ident = strdup(list_nth(var->var_idents,j));
                field->type = strdup(var->type_ident);
                list_push_back(fields, field);
              }
            }
          }
          record->fields = fields;
          type->type_val.records_type = record;
          add_type(syms->types, type);
        }
        break;
      case pointer_type:
        {
          type->type_kind = pointer_t;
          type->type_val.pointer_type = malloc(sizeof(struct pointer));
          char *pointed_type = 
            type_decl->type_def->def.pointer_def->pointed_type_ident;;
          bool pointed_type_exists = false;
          if (strcmp(pointed_type, TYPE_INT) == 0
              || strcmp(pointed_type, TYPE_BOOLEAN) == 0
              || strcmp(pointed_type, TYPE_STRING) == 0
              || strcmp(pointed_type, TYPE_REAL) == 0
              || strcmp(pointed_type, TYPE_CHAR) == 0)
            pointed_type_exists = true;
          for(unsigned i = 0; i < typelist.size && !pointed_type_exists; ++i)
          {
            if (strcmp(typelist.data[i]->ident, pointed_type) == 0)
            {
              pointed_type_exists = true;
              break;
            }
          }
          if (pointed_type_exists)
          {
            type->type_val.pointer_type->type = strdup(pointed_type);
            add_type(syms->types, type);
          }
          else
          {
            error(type_decl->pos, "pointed type does not exist");
            correct = false;
          }
        }
        break;
    }
  }
  return correct;
}
Beispiel #26
0
void var_defines( struct module_t * module, char * const * e, int preprocess )
{
    string buf[ 1 ];

    string_new( buf );

    for ( ; *e; ++e )
    {
        char * val;

        if ( ( val = strchr( *e, '=' ) )
#if defined( OS_MAC )
            /* On the mac (MPW), the var=val is actually var\0val */
            /* Think different. */
            || ( val = *e + strlen( *e ) )
#endif
        )
        {
            LIST * l = L0;
            size_t const len = strlen( val + 1 );
            int const quoted = ( val[ 1 ] == '"' ) && ( val[ len ] == '"' ) &&
                ( len > 1 );

            if ( quoted && preprocess )
            {
                string_append_range( buf, val + 2, val + len );
                l = list_push_back( l, object_new( buf->value ) );
                string_truncate( buf, 0 );
            }
            else
            {
                char * p;
                char * pp;
                char split =
#if defined( OPT_NO_EXTERNAL_VARIABLE_SPLIT )
                    '\0'
#elif defined( OS_MAC )
                    ','
#else
                    ' '
#endif
                    ;

                /* Split *PATH at :'s, not spaces. */
                if ( val - 4 >= *e )
                {
                    if ( !strncmp( val - 4, "PATH", 4 ) ||
                        !strncmp( val - 4, "Path", 4 ) ||
                        !strncmp( val - 4, "path", 4 ) )
                        split = SPLITPATH;
                }

                /* Do the split. */
                for
                (
                    pp = val + 1;
                    preprocess && ( ( p = strchr( pp, split ) ) != 0 );
                    pp = p + 1
                )
                {
                    string_append_range( buf, pp, p );
                    l = list_push_back( l, object_new( buf->value ) );
                    string_truncate( buf, 0 );
                }

                l = list_push_back( l, object_new( pp ) );
            }

            /* Get name. */
            string_append_range( buf, *e, val );
            {
                OBJECT * const varname = object_new( buf->value );
                var_set( module, varname, l, VAR_SET );
                object_free( varname );
            }
            string_truncate( buf, 0 );
        }
    }
    string_free( buf );
}
Beispiel #27
0
void game_add_body(Body* body) {
  list_push_back(bodies, body);
}
void audioplayer_addComposition(audioplayer_t *player,composition_t * composition){
    list_push_back(player->compositions, composition);
}
Beispiel #29
0
Datei: tree.c Projekt: spolu/ur
int 
tree_read (state_t *ur, struct tree *tree, unsigned char sha1[20])
{
  int fd = -1, i;
  int blob_cnt = 0;
  int branch_cnt = 0;
  char * buf = NULL;
  char *name = NULL, *branch = NULL;
  unsigned char commit[20];
  struct blob_tree_entry *blob_entry = NULL;
  struct branch_tree_entry *branch_entry = NULL;

  tree_init (tree);

  if ((fd = object_open (ur, sha1)) < -1)
    goto error;
  
  buf = readline (fd);
  if (buf == NULL) goto error;
  blob_cnt = atoi (buf);
  free (buf); buf = NULL;

  for (i = 0; i < blob_cnt; i ++) 
    {        
      buf = readline (fd);
      if (buf == NULL) goto error;
      name = buf;
      buf = NULL;

      buf = readline (fd);
      if (buf == NULL) goto error;
      hex_to_sha1 (buf, commit);
      free (buf); buf = NULL;
      
      blob_entry = (struct blob_tree_entry *) malloc (sizeof (struct blob_tree_entry));
      if (blob_entry == NULL)
	goto error;
      
      blob_entry->name = name;
      memcpy (blob_entry->commit, commit, 20);

      list_push_back (&tree->blob_entries, &blob_entry->elem);

      name = NULL;
      blob_entry = NULL;
  }
  

  buf = readline (fd);
  if (buf == NULL) goto error;
  branch_cnt = atoi (buf);
  free (buf); buf = NULL;

  for (i = 0; i < branch_cnt; i ++) 
    {        
      buf = readline (fd);
      if (buf == NULL) goto error;
      name = buf;
      buf = NULL;

      buf = readline (fd);
      if (buf == NULL) goto error;
      branch = buf;
      buf = NULL;

      buf = readline (fd);
      if (buf == NULL) goto error;
      hex_to_sha1 (buf, commit);
      free (buf); buf = NULL;
      
      branch_entry = (struct branch_tree_entry *) malloc (sizeof (struct branch_tree_entry));
      if (branch_entry == NULL)
	goto error;
      
      branch_entry->name = name;
      branch_entry->branch = branch;
      memcpy (branch_entry->commit, commit, 20);

      list_push_back (&tree->branch_entries, &branch_entry->elem);

      name = NULL;
      branch = NULL;
      branch_entry = NULL;
  }

  close (fd);
  
  return 0;

 error:
  if (name != NULL) free (name);
  if (branch != NULL) free (branch);
  if (blob_entry != NULL) free (blob_entry);
  if (branch_entry != NULL) free (branch_entry);
  
  tree_destroy (tree);
  
  return -1;
}
Beispiel #30
0
int mmap(int fd, void *addr)
{

	struct thread *t = thread_current();
	struct mmap_file* mmap_f= malloc(sizeof(struct mmap_file)); // mmap_file allocate

	struct file *fp1 = process_get_file(fd);                    // get file for fd
	if(fp1 == NULL)
		return -1;


	if( !is_user_vaddr(addr)|| addr < (void *)0x08048000 ||
		   	   ((uint32_t)addr % PGSIZE)!= 0)return -1;
    // only on user address space, set address to aligned pagesize

	struct file *fp2 = file_reopen(fp1);       // fail for reopening
	if(fp2 == NULL || file_length(fp1) == 0)
	return -1;


	if(mmap_f != NULL){                        // fail for allocate space for mmap_file

			t->mapid++;
			mmap_f->file = fp2;
			mmap_f->mapid = t->mapid;
			list_init(&mmap_f->vme_list);

	}else return -1;

	int32_t offset = 0;
	uint32_t read_bytes = file_length(fp2);   //  to read the number of bytes
	
	uint32_t page_read_bytes;
	uint32_t page_zero_bytes;

	while(read_bytes > 0)
	{

		page_read_bytes = read_bytes < PGSIZE ? read_bytes : PGSIZE;  // over PGSIZE 4096
		page_zero_bytes = PGSIZE - page_read_bytes;

		// add_mmap_to_page
		struct vm_entry *entry = malloc(sizeof(struct vm_entry));
		if(entry == NULL)return -1;
		
		entry->file = fp2;                             // vme_entry initialize
		entry->offset = offset;
		entry->vaddr = addr;
		entry->read_bytes = page_read_bytes;
		entry->zero_bytes = page_zero_bytes;
		entry->is_loaded = false;
		entry->type = VM_FILE;
		entry->writable = true;
		
		list_push_back(&mmap_f->vme_list,&entry->mmap_elem);       // to push element to (mmap_file`s member) vme_list
		if(!insert_vme(&t->vm,entry))return -1;

		read_bytes -= page_read_bytes;                              // if read_bytes > PGSIZE -> decrease PGSIZE
		offset += page_read_bytes;
		addr += PGSIZE;

	}
	
	list_push_back(&t->mmap_list,&mmap_f->elem);                    //to push element to( struct thread`s member )mmap_list


	return t->mapid;
	
}