Example #1
0
File: vis.c Project: ewqasd200g/vis
void vis_free(Vis *vis) {
	if (!vis)
		return;
	if (vis->event && vis->event->vis_quit)
		vis->event->vis_quit(vis);
	vis->event = NULL;
	while (vis->windows)
		vis_window_close(vis->windows);
	file_free(vis, vis->command_file);
	file_free(vis, vis->search_file);
	file_free(vis, vis->error_file);
	for (int i = 0; i < LENGTH(vis->registers); i++)
		register_release(&vis->registers[i]);
	vis->ui->free(vis->ui);
	map_free(vis->cmds);
	map_free_full(vis->usercmds);
	map_free(vis->options);
	map_free(vis->actions);
	map_free(vis->keymap);
	buffer_release(&vis->input_queue);
	for (int i = 0; i < VIS_MODE_INVALID; i++)
		map_free(vis_modes[i].bindings);
	array_release_full(&vis->motions);
	array_release_full(&vis->textobjects);
	free(vis);
}
Example #2
0
static void printfile(struct protstream *out, const struct dlist *dl)
{
    struct stat sbuf;
    FILE *f;
    unsigned long size;
    struct message_guid guid2;
    const char *msg_base = NULL;
    size_t msg_len = 0;

    assert(dlist_isfile(dl));

    f = fopen(dl->sval, "r");
    if (!f) {
        syslog(LOG_ERR, "IOERROR: Failed to read file %s", dl->sval);
        prot_printf(out, "NIL");
        return;
    }
    if (fstat(fileno(f), &sbuf) == -1) {
        syslog(LOG_ERR, "IOERROR: Failed to stat file %s", dl->sval);
        prot_printf(out, "NIL");
        fclose(f);
        return;
    }
    size = sbuf.st_size;
    if (size != dl->nval) {
        syslog(LOG_ERR, "IOERROR: Size mismatch %s (%lu != " MODSEQ_FMT ")",
               dl->sval, size, dl->nval);
        prot_printf(out, "NIL");
        fclose(f);
        return;
    }

    map_refresh(fileno(f), 1, &msg_base, &msg_len, sbuf.st_size,
                "new message", 0);

    message_guid_generate(&guid2, msg_base, msg_len);

    if (!message_guid_equal(&guid2, dl->gval)) {
        syslog(LOG_ERR, "IOERROR: GUID mismatch %s",
               dl->sval);
        prot_printf(out, "NIL");
        fclose(f);
        map_free(&msg_base, &msg_len);
        return;
    }

    prot_printf(out, "%%{");
    prot_printastring(out, dl->part);
    prot_printf(out, " ");
    prot_printastring(out, message_guid_encode(dl->gval));
    prot_printf(out, " %lu}\r\n", size);
    prot_write(out, msg_base, msg_len);
    fclose(f);
    map_free(&msg_base, &msg_len);
}
Example #3
0
void parse_free(void)
{
    named_buffer_free(s->initial_named_buffer);
    map_free(s->initial_symbols);

    named_buffer_free(s->named_buffer);
    chunkpool_free(s->atom_pool);
    chunkpool_free2(s->vec_pool, (cb_free*)free_vec_pool);
    named_buffer_free(s->named_buffer);
    map_free(s->sym_table);
    scanner_free();
    expr_free();
}
Example #4
0
void pen_free(pen_struct *ps) {
    if (!ps)
        return;
    if (ps->map)
        map_free(ps->map);
    x_free(ps);
}
Example #5
0
int main (int argc, char *argv[]) {
    FILE *res_map, *res_cpu;
    int i, num, nret;
    int64_t *A, *B;
    int64_t tm;
    int mapnum = 0;

    if ((res_map = fopen ("res_map", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map'\n");
        exit (1);
        }

    if ((res_cpu = fopen ("res_cpu", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu'\n");
        exit (1);
        }

    if (argc < 2) {
	fprintf (stderr, "need number of elements (up to %d) as arg\n", SZ);
	exit (1);
	}

    if (sscanf (argv[1], "%d", &num) < 1) {
	fprintf (stderr, "need number of elements (up to %d) as arg\n", SZ);
	exit (1);
	}

    if (num > SZ) {
	fprintf (stderr, "need number of elements (up to %d) as arg\n", SZ);
	exit (1);
	}

    A = (int64_t*) Cache_Aligned_Allocate (SZ * sizeof (int64_t));
    B = (int64_t*) Cache_Aligned_Allocate (SZ * sizeof (int64_t));

    srandom (99);

    for (i=0; i<SZ; i++) {
        A[2*i] = random () & 0xffff;
        A[2*i+1] = A[2*i] + 100000;
	}

    map_allocate (1);

    // call the MAP routine
    subr (A, B, num, &nret, &tm, mapnum);

    printf ("combined DMA and compute time: %lld clocks\n", tm);

    for (i=0; i<nret; i++)
        fprintf (res_map, "%lld\n", B[i]);

    for (i=0; i<num; i++)
	if (A[i] > 30000)
            fprintf (res_cpu, "%lld\n", A[i]*17);

    map_free (1);

    exit(0);
    }
Example #6
0
struct mddev_dev *load_containers(void)
{
	struct mdstat_ent *mdstat = mdstat_read(0, 0);
	struct mdstat_ent *ent;
	struct mddev_dev *d;
	struct mddev_dev *rv = NULL;
	struct map_ent *map = NULL, *me;

	if (!mdstat)
		return NULL;

	for (ent = mdstat; ent; ent = ent->next)
		if (ent->metadata_version &&
		    strncmp(ent->metadata_version, "external:", 9) == 0 &&
		    !is_subarray(&ent->metadata_version[9])) {
			d = xmalloc(sizeof(*d));
			memset(d, 0, sizeof(*d));
			me = map_by_devnm(&map, ent->dev);
			if (me)
				d->devname = xstrdup(me->path);
			else if (asprintf(&d->devname, "/dev/%s", ent->dev) < 0) {
				free(d);
				continue;
			}
			d->next = rv;
			rv = d;
		}
	free_mdstat(mdstat);
	map_free(map);

	return rv;
}
static void
Map_dealloc(Map* self)
{            
    map_free(&self->map);
    
    Py_TYPE(self)->tp_free((PyObject*)self);
}
Example #8
0
void acc_sqlite_exit() {
  if (acc_sqlite != NULL) {
    map_free(acc_sqlite->db_files_map);
    free(acc_sqlite);
    acc_sqlite = NULL;
  }
}
Example #9
0
File: main.c Project: emilis/Craft
void ensure_chunks(Chunk *chunks, int *chunk_count, int p, int q, int force) {
    int count = *chunk_count;
    for (int i = 0; i < count; i++) {
        Chunk *chunk = chunks + i;
        if (chunk_distance(chunk, p, q) >= DELETE_CHUNK_RADIUS) {
            map_free(&chunk->map);
            glDeleteBuffers(1, &chunk->position_buffer);
            glDeleteBuffers(1, &chunk->normal_buffer);
            glDeleteBuffers(1, &chunk->uv_buffer);
            Chunk *other = chunks + (--count);
            memcpy(chunk, other, sizeof(Chunk));
        }
    }
    int n = CREATE_CHUNK_RADIUS;
    for (int i = -n; i <= n; i++) {
        for (int j = -n; j <= n; j++) {
            int a = p + i;
            int b = q + j;
            if (!find_chunk(chunks, count, a, b)) {
                make_chunk(chunks + count, a, b);
                count++;
                if (!force) {
                    *chunk_count = count;
                    return;
                }
            }
        }
    }
    *chunk_count = count;
}
Example #10
0
File: data.c Project: fave-r/Zappy
int	init_map(t_zap *data)
{
  int	i;
  int	j;

  if ((data->map = malloc(data->width * sizeof(t_content *))) == NULL)
    return (1);
  i = -1;
  while (++i < data->width)
    {
      if ((data->map[i] = malloc(data->length * sizeof(t_content))) == NULL)
	return (map_free(data->map, data->width));
      j = -1;
      while (++j < data->length)
	{
	  data->map[i][j].food = rand() % 10;
	  data->map[i][j].linemate = rand() % 8;
	  data->map[i][j].deraumere = rand() % 8;
	  data->map[i][j].sibur = rand() % 6;
	  data->map[i][j].mendiane = rand() % 5;
	  data->map[i][j].phiras = rand() % 4;
	  data->map[i][j].thystame = rand() % 2;
	}
    }
  print_data(data);
  return (0);
}
Example #11
0
int main() {
  {
    struct map map;

    map_init(&map);

    char key1[] = "This is a really long key.",
         key2[] = "Another key.";

    assertError("map_set (1)", map_set(&map, key1, sizeof key1, (void*)123));
    assertEq("Key is now retrievable", map_get(&map, key1, sizeof key1), (void*)123);

    assertError("map_set (2)", map_set(&map, key2, sizeof key2, (void*)456));
    assertEq("New key is now retrievable", map_get(&map, key2, sizeof key2), (void*)456);
    assertEq("Old key is still retrievable (1)", map_get(&map, key1, sizeof key1), (void*)123);

    assertError("map_set existing", map_set(&map, key1, sizeof key1, (void*)789));
    assertEq("Key has updated value", map_get(&map, key1, sizeof key1), (void*)789);
    assertEq("Old key is still retrievable (2)", map_get(&map, key2, sizeof key2), (void*)456);

    assertError("map_set small key (1)", map_set(&map, (void*)1, 0, (void*)10));
    assertError("map_set small key (2)", map_set(&map, (void*)2, 0, (void*)20));
    assertEq("Can retrieve short key (1)", map_get(&map, (void*)1, 0), (void*)10);
    assertEq("Can retrieve short key (2)", map_get(&map, (void*)2, 0), (void*)20);

    map_free(&map);
  }
}
Example #12
0
int main()
{
  //printf("Some random hashes:\n");
  //printf("\tBazinga: %d\n", map_hash_key("Bazinga"));
  //printf("\tFlabagoobie: %d\n", map_hash_key("Flabagoobie"));
  //printf("\tScooby: %d\n", map_hash_key("Scooby"));
  //printf("\tMcDooby: %d\n", map_hash_key("McDooby"));
  //printf("\tagnizaB: %d\n", map_hash_key("agnizaB"));

  Map map;
  map_init(&map);

  map_set(&map, "bazinga", "bazonga");
  map_set(&map, "zabinga", "zabonga");
  map_set(&map, "zabniga", "maponya");
  map_set(&map, "kabanooga", "daboogawoofa");

  MapItem *item;

  print_map(&map);
  map_get(&map, "abzinga");

  printf("================================\n");

  print_map(&map);
  map_free(&map);
}
Example #13
0
int map_lock(struct map_ent **melp)
{
	while (lf == NULL) {
		struct stat buf;
		lf = open_map(MAP_LOCK);
		if (lf == NULL)
			return -1;
		if (flock(fileno(lf), LOCK_EX) != 0) {
			fclose(lf);
			lf = NULL;
			return -1;
		}
		if (fstat(fileno(lf), &buf) != 0 ||
		    buf.st_nlink == 0) {
			/* The owner of the lock unlinked it,
			 * so we have a lock on a stale file,
			 * try again
			 */
			fclose(lf);
			lf = NULL;
		}
	}
	if (*melp)
		map_free(*melp);
	map_read(melp);
	return 0;
}
int main()
{
	map m;
	int items_number = 10;
	int total_items_number = 10;
	char *unknown, *unknown_substring;

	//~const char *keys[] = {"aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj"};
	//~const char *values[] = {"foo", "bar", "toto", "tata", "something", "10", "truc", "3.14", "moi", "vous"};
	const char *keys[] = {"ddd", "aaa", "ggg", "ccc", "eee", "fff", "bbb", "jjj", "iii", "hhh"};
	const char *values[] = {"foo", "bar", "toto", "tata", "something", "10", "truc", "3.14", "moi", "vous"};

	map_init(&m, total_items_number);

	int i;
	for (i = 0; i < items_number; i++) {
		map_add_entry(keys[i], (char *) values[i], &m);
		printf("map_get_entry access: key: %s, value %s\n", keys[i], (char *) map_get_entry(keys[i], &m));
	}

	// try to add an element in a full map
	if (map_add_entry("11th", (char *) "unwanted value", &m) == MAP_FULL) {
		printf("Map full while trying to insert %s\n", "11th");
	}

	// try to get an unexisting element
	unknown = (char *) map_get_entry("uuu", &m);
	if (unknown != NULL) {
		printf("%s\n", unknown);
	}
	else {
		printf("'uuu' is not in the map\n");
	}

	printf("before, for the key 'ddd', the value was '%s'\n", (char *) map_get_entry("ddd", &m));
	map_add_entry("ddd", (char *) "new ddd", &m);
	printf("and after, for the key 'ddd', the value is '%s'\n", (char *) map_get_entry("ddd", &m));


	map_delete_entry("aaa", &m);
	unknown = (char *) map_get_entry("aaa", &m);
	if (unknown != NULL) {
		printf("\"aaa\" is still in the map\n");
	}
	else {
		printf("'aaa' is not in the map\n");
	}

	// e is the beginning of the key eee
	unknown_substring = (char *) map_get_entry("e", &m);
	if (unknown_substring != NULL) {
		printf("\"e\" is in the map\n");
	}
	else {
		printf("e' is not in the map\n");
	}

	map_free(&m);
	return 0;
}
Example #15
0
int map_update(struct map_ent **mpp, char *devnm, char *metadata,
	       int *uuid, char *path)
{
	struct map_ent *map, *mp;
	int rv;

	if (mpp && *mpp)
		map = *mpp;
	else
		map_read(&map);

	for (mp = map ; mp ; mp=mp->next)
		if (strcmp(mp->devnm, devnm) == 0) {
			strcpy(mp->metadata, metadata);
			memcpy(mp->uuid, uuid, 16);
			free(mp->path);
			mp->path = path ? xstrdup(path) : NULL;
			mp->bad = 0;
			break;
		}
	if (!mp)
		map_add(&map, devnm, metadata, uuid, path);
	if (mpp)
		*mpp = NULL;
	rv = map_write(map);
	map_free(map);
	return rv;
}
Example #16
0
int
main(int argc, char** argv)
{
  if(argc != 2) {
    fprintf(stderr, "usage: simulator <n-threads>\n");
    return EXIT_FAILURE;
  }
  
  NTHREADS = atoi(argv[1]);
  
  map = map_read(stdin);
  
  if(!map) {
    fprintf(stderr, "Failed to read map\n");
    exit(EXIT_FAILURE);
  }
  
  //map_print(map, stdout);
  
  simulate();
  
  //map_print(map, stdout);
  map_output(map, stdout);
  
  map_free(map);
  
  return EXIT_SUCCESS;
}
Example #17
0
static int map_probe(struct obc_session *session)
{
	struct map_data *map;
	const char *path;

	path = obc_session_get_path(session);

	DBG("%s", path);

	map = g_try_new0(struct map_data, 1);
	if (!map)
		return -ENOMEM;

	map->session = obc_session_ref(session);
	map->messages = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
								map_msg_remove);

	set_notification_registration(map, true);

	if (!g_dbus_register_interface(conn, path, MAP_INTERFACE, map_methods,
					NULL, NULL, map, map_free)) {
		map_free(map);

		return -ENOMEM;
	}

	return 0;
}
Example #18
0
OMX_ERRORTYPE
tiz_map_init (tiz_map_t ** app_map,
              tiz_map_cmp_f a_pf_cmp,
              tiz_map_free_f a_pf_free, tiz_soa_t * ap_soa)
{
  tiz_map_t *p_map = NULL;

  assert (NULL != app_map);
  assert (NULL != a_pf_cmp);

  if (NULL == (p_map = (tiz_map_t *) map_calloc (ap_soa, sizeof (tiz_map_t))))
    {
      return OMX_ErrorInsufficientResources;
    }


  if (NULL == (p_map->p_tree = avl_new_avl_tree (map_compare, p_map)))
    {
      map_free (ap_soa, p_map);
      p_map = NULL;
      return OMX_ErrorInsufficientResources;
    }

  p_map->size = 0;
  p_map->pf_cmp = a_pf_cmp;
  p_map->pf_free = a_pf_free;
  p_map->p_soa = ap_soa;

  *app_map = p_map;

  return OMX_ErrorNone;
}
Example #19
0
void html_template_repository_empty(void)
{
    if (repos != NULL) {
        map_free(repos->templates);
        free(repos);
        repos = NULL;
    }
}
Example #20
0
void OccupancyMap::setMap(const nav_msgs::OccupancyGrid &grid) {
  if (map_ != NULL) {
    map_free(map_);
  }
  map_ = map_alloc();
  ROS_ASSERT(map_);
  convertMap(grid, map_, max_free_threshold_, min_occupied_threshold_);
}
Example #21
0
void
graphics_free(graphics gfx) {
  struct graphics_t *g = gfx;
  SDL_DestroyWindow(g->window);
  SDL_DestroyRenderer(g->renderer);
  map_free(g->sprite_sheets);
  free(g);
}
Example #22
0
int main (int argc, char *argv[]) {
    FILE *res_map, *res_cpu;
    int i, num;
    int64_t *A0, *A1, *B;
    int64_t tm;
    int mapnum = 0;

    if ((res_map = fopen ("res_map", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map'\n");
        exit (1);
        }

    if ((res_cpu = fopen ("res_cpu", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu'\n");
        exit (1);
        }

    if (argc < 2) {
	fprintf (stderr, "need number of elements as arg\n");
	exit (1);
	}

    if (sscanf (argv[1], "%d", &num) < 1) {
	fprintf (stderr, "need number of elements as arg\n");
	exit (1);
	}

    if ((num < 1) || (num > MAX_OBM_SIZE)) {
        fprintf (stderr, "number of elements must be in the range 1 through %d\n", MAX_OBM_SIZE);
	exit (1);
	}

    A0 = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t));
    A1 = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t));
    B = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t));

    srandom (99);

    for (i=0; i<num; i++) {
        A0[i] = random ();
        A1[i] = random ();
	}

    map_allocate (1);

    subr (A0, A1, B, num, &tm, mapnum);

    printf ("%lld clocks\n", tm);

    for (i=0; i<num; i++) {
        fprintf (res_map, "%lld\n", B[i]);
        fprintf (res_cpu, "%lld\n", A0[i]+A1[i]);
	}

    map_free (1);

    exit(0);
    }
Example #23
0
File: sack.c Project: Tojaj/hawkey
static Map *
free_map_fully(Map *m)
{
    if (m) {
	map_free(m);
	solv_free(m);
    }
    return NULL;
}
Example #24
0
void map_remove(struct map_ent **mapp, char *devnm)
{
	if (devnm[0] == 0)
		return;

	map_delete(mapp, devnm);
	map_write(*mapp);
	map_free(*mapp);
}
Example #25
0
static void load_game(const gchar * file, gboolean is_reload)
{
	const gchar *gamefile;
	GameParams *new_params;
	gchar *new_filename;
	gint i;

	if (file == NULL)
		gamefile = default_game;
	else
		gamefile = file;

	new_params = params_load_file(gamefile);
	if (new_params == NULL) {
		error_dialog(_("Failed to load '%s'"), file);
		return;
	}

	if (file == NULL) {
		g_free(new_params->title);
		new_params->title = g_strdup("Untitled");
		map_free(new_params->map);
		new_params->map = map_new();
		for (i = 0; i < 6; i++) {
			map_modify_row_count(new_params->map,
					     MAP_MODIFY_INSERT,
					     MAP_MODIFY_ROW_BOTTOM);
		}
		for (i = 0; i < 11; i++) {
			map_modify_column_count(new_params->map,
						MAP_MODIFY_INSERT,
						MAP_MODIFY_COLUMN_RIGHT);
		}
		new_params->map->chits =
		    g_array_new(FALSE, FALSE, sizeof(gint));
		new_filename = NULL;
	} else {
		new_filename = g_strdup(file);
		config_set_string("editor/last-game", new_filename);
	}

	guimap_reset(gmap);
	if (params != NULL)
		params_free(params);
	params = new_params;
	apply_params(params);
	if (open_filename != NULL)
		g_free(open_filename);
	open_filename = new_filename;
	map_move_robber(gmap->map, -1, -1);
	fill_map(gmap->map);
	if (is_reload) {
		scale_map(gmap);
		guimap_display(gmap);
	}
	update_resize_buttons();
}
Example #26
0
File: type.c Project: klkblake/abcc
internal
void print_type(FILE *file, Type *type, TypePtrU64Map *vars) {
	TypePtrB1Map seen = {};
	U8Array buf = {};
	print_type_(type, 0, &seen, vars, &buf);
	fwrite(buf.data, 1, buf.size, file);
	map_free(&seen);
	array_free(&buf);
}
Example #27
0
int main (int argc, char *argv[]) {
    FILE *res_map, *res_cpu;
    int i, num;
    double *D_src, res, acc;
    int64_t tm;
    int mapnum = 0;

    if ((res_map = fopen ("res_map.flt", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map.flt'\n");
        exit (1);
        }

    if ((res_cpu = fopen ("res_cpu.flt", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu.flt'\n");
        exit (1);
        }

    if (argc < 2) {
	fprintf (stderr, "need number of elements as arg\n");
	exit (1);
	}

    if (sscanf (argv[1], "%d", &num) < 1) {
	fprintf (stderr, "need number of elements as arg\n");
	exit (1);
	}

    if ((num < 1) || (num > MAX_OBM_SIZE)) {
        fprintf (stderr, "number of elements must be in the range 1 through %d\n", MAX_OBM_SIZE);
	exit (1);
	}

    D_src = (double*) malloc (num * sizeof (double));

    srandom (99);

    acc = 0.0;

    for (i=0; i<num; i++) {
        D_src[i] = (double)random() / random();
	acc += D_src[i];
	}

    fprintf (res_cpu, "%lf\n", acc);

    map_allocate (1);

    subr (D_src, &res, num, &tm, mapnum);

    printf ("%lld clocks\n", tm);

    fprintf (res_map, "%lf\n", res);

    map_free (1);

    exit(0);
    }
Example #28
0
static Map *
free_map_fully(Map *m)
{
    if (m == NULL)
        return NULL;
    map_free(m);
    g_free(m);
    return NULL;
}
Example #29
0
static int anon_contig_new(struct vir_region *region)
{
        u32_t allocflags;
	phys_bytes new_pages, new_page_cl, cur_ph;
	phys_bytes p, pages;

        allocflags = vrallocflags(region->flags);

	pages = region->length/VM_PAGE_SIZE;

	assert(physregions(region) == 0);

	for(p = 0; p < pages; p++) {
		struct phys_block *pb = pb_new(MAP_NONE);
		struct phys_region *pr = NULL;
		if(pb)
			pr = pb_reference(pb, p * VM_PAGE_SIZE, region, &mem_type_anon_contig);
		if(!pr) {
			if(pb) pb_free(pb);
			map_free(region);
			return ENOMEM;
		}
	}

	assert(physregions(region) == pages);

	if((new_page_cl = alloc_mem(pages, allocflags)) == NO_MEM) {
		map_free(region);
		return ENOMEM;
	}

	cur_ph = new_pages = CLICK2ABS(new_page_cl);

	for(p = 0; p < pages; p++) {
		struct phys_region *pr = physblock_get(region, p * VM_PAGE_SIZE);
		assert(pr);
		assert(pr->ph);
		assert(pr->ph->phys == MAP_NONE);
		assert(pr->offset == p * VM_PAGE_SIZE);
		pr->ph->phys = cur_ph + pr->offset;
	}

	return OK;
}
Example #30
0
static void dtor(void *priv)
{
	struct _world *world = priv;
	cvar_ns_save(world->cvars);
	cvar_ns_free(world->cvars);
	light_free(world->light);
	chopper_free(world->apache);
	map_free(world->map);
	free(world);
}