示例#1
0
static void cleanup (void)
{
    if (about_win)
        gtk_widget_destroy (about_win);
    if (config_win)
        gtk_widget_destroy (config_win);

    pthread_mutex_lock (& mutex);

    aud_config_clear_section ("ladspa");
    aud_set_string ("ladspa", "module_path", module_path);
    save_enabled_to_config ();
    close_modules ();

    index_free (modules);
    modules = NULL;
    index_free (plugins);
    plugins = NULL;
    index_free (loadeds);
    loadeds = NULL;

    g_free (module_path);
    module_path = NULL;

    pthread_mutex_unlock (& mutex);
}
示例#2
0
void
test_mem_index_read
(void)
{
   redirect_stderr();
   
   index_t * index = index_build("examples/repeats.fa", "test_base30");
   test_assert_critical(index != NULL);
   test_assert(index_ann_new(25, 1, 1, index) == 0);

   // Set alloc failure rate to 0.1.
   set_alloc_failure_rate_to(0.1);
   for (int i = 0; i < 1000; i++) {
      index_t * index_i = index_read("test_base30");
      index_free(index_i);
   }
   reset_alloc();

   // Set alloc countdown 0->10.
   for (int i = 0; i <= 200; i++) {
      set_alloc_failure_countdown_to(i);
      index_t * index_i = index_read("test_base30");
      index_free(index_i);
   }
   reset_alloc();

   index_free(index);
   unredirect_stderr();
}
示例#3
0
static void shift_rows (void * user, gint row, gint before)
{
    gint rows = index_count (user);
    g_return_if_fail (row >= 0 && row < rows);
    g_return_if_fail (before >= 0 && before <= rows);

    if (before == row)
        return;

    Index * move = index_new ();
    Index * others = index_new ();

    gint begin, end;
    if (before < row)
    {
        begin = before;
        end = row + 1;
        while (end < rows && ((Column *) index_get (user, end))->selected)
            end ++;
    }
    else
    {
        begin = row;
        while (begin > 0 && ((Column *) index_get (user, begin - 1))->selected)
            begin --;
        end = before;
    }

    for (gint i = begin; i < end; i ++)
    {
        Column * c = index_get (user, i);
        index_append (c->selected ? move : others, c);
    }

    if (before < row)
    {
        index_merge_append (move, others);
        index_free (others);
    }
    else
    {
        index_merge_append (others, move);
        index_free (move);
        move = others;
    }

    index_copy_set (move, 0, user, begin, end - begin);
    index_free (move);

    GtkWidget * list = (user == chosen) ? chosen_list : avail_list;
    audgui_list_update_rows (list, begin, end - begin);
    audgui_list_update_selection (list, begin, end - begin);
}
bool_t playlist_save (int list, const char * filename)
{
    AUDDBG ("Saving playlist %s.\n", filename);

    PluginHandle * plugin = get_plugin (filename, TRUE);
    if (! plugin)
        return FALSE;

    PlaylistPlugin * pp = plugin_get_header (plugin);
    g_return_val_if_fail (pp && PLUGIN_HAS_FUNC (pp, load), FALSE);

    bool_t fast = get_bool (NULL, "metadata_on_play");

    VFSFile * file = vfs_fopen (filename, "w");
    if (! file)
        return FALSE;

    char * title = playlist_get_title (list);

    int entries = playlist_entry_count (list);
    Index * filenames = index_new ();
    index_allocate (filenames, entries);
    Index * tuples = index_new ();
    index_allocate (tuples, entries);

    for (int i = 0; i < entries; i ++)
    {
        index_append (filenames, playlist_entry_get_filename (list, i));
        index_append (tuples, playlist_entry_get_tuple (list, i, fast));
    }

    bool_t success = pp->save (filename, file, title, filenames, tuples);

    vfs_fclose (file);
    str_unref (title);

    for (int i = 0; i < entries; i ++)
    {
        str_unref (index_get (filenames, i));
        Tuple * tuple = index_get (tuples, i);
        if (tuple)
            tuple_unref (tuple);
    }

    index_free (filenames);
    index_free (tuples);

    return success;
}
示例#5
0
文件: salloc.c 项目: ahamid/sartoris
/*
Free a given structure.
Ptr must be NOT NULL *only* if type is not THR, TSK or SMO.
*/
void sfree(void *ptr, int id, int type)
{
	if(type == SALLOC_TSK || type == SALLOC_THR || type == SALLOC_SMO)
	{		
		switch(type)
		{
			case SALLOC_TSK:
				if(!TST_PTR(id,tsk)) return; // not allocated
				csfree(GET_PTR(id,tsk), SALLOC2CONT_TYPE(type));
				break;
			case SALLOC_THR:
				if(!TST_PTR(id,thr)) return;
				csfree(GET_PTR(id,thr), SALLOC2CONT_TYPE(type));
				break;
			case SALLOC_SMO:
				if(!TST_PTR(id,smo)) return;
				csfree(GET_PTR(id,smo), SALLOC2CONT_TYPE(type));
				break;
			default:
				break;		
		}
		
		index_free(id, ALLOC2IDX(type));
	}
	else
	{
		csfree(ptr, SALLOC2CONT_TYPE(type));
	}
	ammount[type]--;
}
示例#6
0
static void scsi_disk_bdev_try_unbind(struct scsi_dev *sdev) {
	if (!sdev->attached) {
		sdev->bdev->privdata = NULL;
		index_free(&scsi_disk_idx, sdev->idx);
		block_dev_destroy(sdev->bdev);
	}
}
示例#7
0
static void free_presets (Index * presets)
{
    for (int p = 0; p < index_count (presets); p ++)
        equalizer_preset_free (index_get (presets, p));

    index_free (presets);
}
示例#8
0
int main(int ac, char** av)
{
  if (strcmp(av[1], "index") == 0)
  {
    do_index("../pic/india/trekearth.new/trekearth");
  }
  else if (strcmp(av[1], "tile") == 0)
  {
    struct mozaic_info mi;
    struct index_info ii;

    mi.tile_im = NULL;

    index_load(&ii, "../pic/india/trekearth.new/trekearth");
    /* index_load(&ii, "../pic/kiosked"); */

    /* do_tile("../pic/roland_15/main.jpg", &ii, &mi); */
    do_tile("../pic/roland_14/main_gimped.jpg", &ii, &mi);
    /* do_tile("../pic/face_1/main.jpg", &ii, &mi); */
    do_make(&ii, &mi);
    do_edit(&ii, &mi);

    cvSaveImage("/tmp/tile.jpg", mi.tile_im, NULL);
    do_save_mozaic(&mi, "/tmp/mozaic.til");

    cvReleaseImage(&mi.tile_im);
    cvReleaseImage(&mi.ycc_im);

    free(mi.tile_arr);
    index_free(&ii);
  }

  return 0;
}
示例#9
0
void shutdown_plugin_locked (LoadedPlugin * loaded)
{
    loaded->active = 0;

    if (! loaded->instances)
        return;

    PluginData * plugin = loaded->plugin;
    const LADSPA_Descriptor * desc = plugin->desc;

    int instances = index_count (loaded->instances);
    for (int i = 0; i < instances; i ++)
    {
        LADSPA_Handle * handle = index_get (loaded->instances, i);

        if (desc->deactivate)
            desc->deactivate (handle);

        desc->cleanup (handle);
    }

    for (int channel = 0; channel < ladspa_channels; channel ++)
    {
        g_free (loaded->in_bufs[channel]);
        g_free (loaded->out_bufs[channel]);
    }

    index_free (loaded->instances);
    loaded->instances = NULL;
    g_free (loaded->in_bufs);
    loaded->in_bufs = NULL;
    g_free (loaded->out_bufs);
    loaded->out_bufs = NULL;
}
示例#10
0
文件: index.c 项目: LuoZijun/mldonkey
static int add_new_word(index_struct *idx, char *word)
{
  int word_len = strlen(word);
  int w;
  int left;
  char *word_pos;
  word_struct* ws;

  if(idx->next_word == idx->dict_len){
  /* must reallocate the dictionnary */
    int old_size = idx->dict_len;
    int new_size = old_size * 2;
    word_struct** new_dict = index_alloc(sizeof(word_struct*) * new_size);

    memcpy(new_dict, idx->dict, sizeof(word_struct*) * old_size);
    index_free(idx->dict);
    idx->dict = new_dict;
    idx->dict_len = new_size;
  }
  w = idx->next_word;
  idx->next_word++;

  ws = index_alloc(sizeof(word_struct) + word_len + 1);
  idx->dict[w] = ws;
  strncpy(ws->word_string, word, word_len);
  ws->word_string[word_len] = 0;

  return w;
}
示例#11
0
文件: hfile.c 项目: pipul/lab
index_t *index_load(int32_t fd, int32_t offset, int32_t size)
{
	int32_t id;
	int32_t len;
	index_t *l;
	int8_t *buffer, *ptr;
	meta_t *o;
	
	if (fd < 0 || offset < 0 || size < 0)
		return(NULL);
	if ((l = index_new()) == NULL)
		return(NULL);
	if ((buffer = malloc(size)) == NULL)
		__ERROR_LOG(B_ERROR);
	lseek(fd,offset,SEEK_SET);
	if (size != read(fd,buffer,size))
		__ERROR_LOG(R_ERROR);

	ptr = buffer;
	l->magic = *(uint64_t *)ptr;
	ptr = ptr + sizeof(uint64_t);
	if (l->magic != crc32_encode(ptr,size - sizeof(uint64_t)))
		__ERROR_LOG(C_ERROR);

	id = 0;		/* inode id */
	while (ptr - buffer < size) {
		if ((o = meta_new()) == NULL)
			break;
		o->offset = *(int32_t *)ptr;
		ptr = ptr + sizeof(int32_t);

		o->blocksize = *(int32_t *)ptr;
		ptr = ptr + sizeof(int32_t);

		len = *(int32_t *)ptr;
		ptr = ptr + sizeof(int32_t);
		o->key = sdsnnew(ptr,len);
		ptr = ptr + len;

		if (o->key == NULL) {
			meta_free(o);
			continue;
		}
		o->id = id++;
		index_add(l,o);
	}

	free(buffer);
	return(l);

C_ERROR:
R_ERROR:
	free(buffer);
B_ERROR:
	index_free(l);
	return(NULL);
}
示例#12
0
static void destroy_cb (void)
{
    window = NULL;
    chosen_list = NULL;
    avail_list = NULL;

    gint rows = index_count (chosen);
    for (gint row = 0; row < rows; row ++)
        g_slice_free (Column, index_get (chosen, row));
    index_free (chosen);
    chosen = NULL;

    rows = index_count (avail);
    for (gint row = 0; row < rows; row ++)
        g_slice_free (Column, index_get (avail, row));
    index_free (avail);
    avail = NULL;
}
示例#13
0
文件: ubasic.c 项目: CobooGuo/ubasic
/*---------------------------------------------------------------------------*/
void
ubasic_init(const char *program)
{
  program_ptr = program;
  for_stack_ptr = gosub_stack_ptr = 0;
  index_free();
  tokenizer_init(program);
  ended = 0;
}
示例#14
0
bool_t playlist_load (const char * filename, char * * title,
 Index * * filenames_p, Index * * tuples_p)
{
    AUDDBG ("Loading playlist %s.\n", filename);

    PluginHandle * plugin = get_plugin (filename, FALSE);
    if (! plugin)
        return FALSE;

    PlaylistPlugin * pp = plugin_get_header (plugin);
    g_return_val_if_fail (pp && PLUGIN_HAS_FUNC (pp, load), FALSE);

    VFSFile * file = vfs_fopen (filename, "r");
    if (! file)
        return FALSE;

    Index * filenames = index_new ();
    Index * tuples = index_new ();
    bool_t success = pp->load (filename, file, title, filenames, tuples);

    vfs_fclose (file);

    if (! success)
    {
        index_free (filenames);
        index_free (tuples);
        return FALSE;
    }

    if (index_count (tuples))
        g_return_val_if_fail (index_count (tuples) == index_count (filenames),
         FALSE);
    else
    {
        index_free (tuples);
        tuples = NULL;
    }

    * filenames_p = filenames;
    * tuples_p = tuples;
    return TRUE;
}
示例#15
0
文件: ubasic.c 项目: CobooGuo/ubasic
/*---------------------------------------------------------------------------*/
void
ubasic_init_peek_poke(const char *program, peek_func peek, poke_func poke)
{
  program_ptr = program;
  for_stack_ptr = gosub_stack_ptr = 0;
  index_free();
  peek_function = peek;
  poke_function = poke;
  tokenizer_init(program);
  ended = 0;
}
示例#16
0
/*---------------------------------------------------------------------------*/
void ubasic_init(const char *program)
{
  int i;
  program_ptr = program;
  for_stack_ptr = gosub_stack_ptr = 0;
  index_free();
  tokenizer_init(program);
  data_position = program_ptr;
  data_seek = 1;
  ended = 0;
  for (i = 0; i < MAX_STRING; i++)
    strings[i] = nullstr;
}
示例#17
0
void pw_col_save (void)
{
    Index * index = index_new ();

    for (int i = 0; i < pw_num_cols; i ++)
        index_insert (index, -1, (void *) pw_col_keys[pw_cols[i]]);

    char * columns = index_to_str_list (index, " ");
    aud_set_str ("gtkui", "playlist_columns", columns);
    str_unref (columns);

    index_free (index);
}
示例#18
0
void
test_mem_index_build
(void)
{
   redirect_stderr();
   // Set alloc failure rate to 0.1.
   set_alloc_failure_rate_to(0.1);
   for (int i = 0; i < 1000; i++) {
      index_t * index = index_build("examples/repeats.fa", "test_base20");
      index_free(index);
   }
   reset_alloc();

   // Set alloc countdown 0->10.
   for (int i = 0; i <= 200; i++) {
      set_alloc_failure_countdown_to(i);
      index_t * index = index_build("examples/repeats.fa", "test_base20");
      index_free(index);
   }
   reset_alloc();
   unredirect_stderr();
}
示例#19
0
文件: hfile.c 项目: pipul/lab
void index_destroy(index_t *l)
{
	meta_t *m;

	if (!l)
		return;
	while (l->_head->forward[0]) {
		m = l->_head->forward[0]->forward[0];
		meta_destroy(l->_head->forward[0]);
		l->_head->forward[0] = m;
	}
	meta_destroy(l->_head);
	index_free(l);
}
示例#20
0
static void usb_dev_free(struct usb_dev *dev) {
    int i;

    for (i = 0; i < USB_DEV_MAX_ENDP; i++) {
        struct usb_endp *endp = dev->endpoints[i];
        if (endp) {
            dev->endpoints[i] = NULL;
            usb_endp_free(endp);
        }
    }

    index_free(&dev->hcd->enumerator, dev->idx);
    pool_free(&usb_devs, dev);
}
示例#21
0
void plot_index_free(plot_args_t* plotargs, void* baton) {
	plotindex_t* args = (plotindex_t*)baton;
	int i;
	for (i=0; i<pl_size(args->indexes); i++) {
		index_t* index = pl_get(args->indexes, i);
		index_free(index);
	}
	pl_free(args->indexes);
	for (i=0; i<pl_size(args->qidxes); i++) {
		qidxfile* qidx = pl_get(args->qidxes, i);
		qidxfile_close(qidx);
	}
	pl_free(args->qidxes);
	free(args);
}
示例#22
0
static int tmpfs_delete(struct node *node) {
	struct tmpfs_file_info *fi;
	struct nas *nas;

	nas = node->nas;
	fi = nas->fi->privdata;

	if (!node_is_directory(node)) {
		index_free(&tmpfs_file_idx, fi->index);
		pool_free(&tmpfs_file_pool, fi);
	}

	vfs_del_leaf(node);

	return 0;
}
示例#23
0
static void close_plugin (PluginData * plugin)
{
    int count = index_count (plugin->controls);
    for (int i = 0; i < count; i ++)
    {
        ControlData * control = index_get (plugin->controls, i);
        g_free (control->name);
        g_slice_free (ControlData, control);
    }

    g_free (plugin->path);
    index_free (plugin->controls);
    g_array_free (plugin->in_ports, 1);
    g_array_free (plugin->out_ports, 1);
    g_slice_free (PluginData, plugin);
}
示例#24
0
static void
import_winamp_file(const gchar * filename)
{
    VFSFile * file = open_vfs_file (filename, "r");
    if (! file)
        return;

    Index * list = aud_import_winamp_eqf (file);
    if (! list)
        goto CLOSE;

    index_merge_append (equalizer_presets, list);
    index_free (list);

    aud_equalizer_write_preset_file(equalizer_presets, "eq.preset");

CLOSE:
    vfs_fclose(file);
}
示例#25
0
void _readone_test(char *key)
{
	int ret;
	struct slice sk;
	struct slice sv;
	struct index *idx;

	idx = _get_idx();
	sk.len = KSIZE;
	sk.data = key;

	ret = index_get(idx, &sk, &sv);
	if (ret) {
		__DEBUG(LEVEL_INFO, "Get Key:<%s>--->value is :<%s>", key, sv.data);
		free(sv.data);
	} else 
		__DEBUG(LEVEL_INFO, "Get Key:<%s>, but value is NULL", key);
	index_free(idx);
}
示例#26
0
void _write_test(long int count)
{
	int i;
	double cost;
	long long start, end;
	struct slice sk, sv;
	struct index *idx;

	char key[KSIZE];
	char val[VSIZE];

	idx = _get_idx();
	printf("count : %ld, idx : %p\n", count, idx);

	start = _ustime();
	for (i = 0; i < count; i++) {
		_random_key(key, KSIZE);
		snprintf(val, VSIZE, "val:%d", i);

		sk.len = KSIZE;
		sk.data = key;
		sv.len = VSIZE;
		sv.data = val;

		index_add(idx, &sk, &sv);
		if ((i % 10000) == 0) {
			fprintf(stderr, "random write finished %d ops%30s\r", i, "");
			fflush(stderr);
		}
	}

	index_free(idx);

	end = _ustime();
	cost = end - start;

	printf(LINE);
	printf("|Random-Write	(done:%ld): %.6f sec/op; %.1f writes/sec(estimates); cost:%.3f(sec)\n",
			count,
			(double)(cost / count),
			(double)(count / cost),
			cost);
}
示例#27
0
static void
import_winamp_file(const gchar * filename)
{
    VFSFile * file = open_vfs_file (filename, "r");
    if (! file)
        return;

    Index * list = aud_import_winamp_presets (file);
    if (! list)
        goto CLOSE;

    index_copy_insert (list, 0, equalizer_presets, -1, -1);
    index_free (list);

    aud_equalizer_write_presets (equalizer_presets, "eq.preset");

CLOSE:
    vfs_fclose(file);
}
示例#28
0
文件: handle.c 项目: 01org/murphy
void *mdb_handle_delete(mdb_handle_map_t *hmap, mdb_handle_t h)
{
    uint32_t  useid = HANDLE_USEID(h);
    int       index = HANDLE_INDEX(h);
    void     *old_data;

    MDB_CHECKARG(hmap && h != MDB_HANDLE_INVALID, NULL);


    if (!(old_data = index_free(&hmap->indextbl, useid,index))) {
        /* errno has been set by index_free() */
        return NULL;
    }

    if (freemap_free(&hmap->freemap, index) < 0) {
        /* errno has been set by freemap_free() */
        return NULL;
    }

    return old_data;
}
示例#29
0
static void do_search (void)
{
    index_delete (items, 0, index_count (items));

    if (! database)
        return;

    SearchState state;

    for (int f = 0; f < FIELDS; f ++)
        state.items[f] = index_new ();

    /* effectively limits number of search terms to 32 */
    state.mask = (1 << index_count (search_terms)) - 1;

    g_hash_table_foreach (database, search_cb, & state);

    int total = 0;

    for (int f = 0; f < FIELDS; f ++)
    {
        int count = index_count (state.items[f]);
        if (count > MAX_RESULTS - total)
            count = MAX_RESULTS - total;

        if (count)
        {
            index_sort (state.items[f], item_compare);
            index_copy_insert (state.items[f], 0, items, -1, count);
            total += count;
        }

        index_free (state.items[f]);
    }

    g_array_set_size (selection, total);
    memset (selection->data, 0, selection->len);
    if (selection->len > 0)
        selection->data[0] = 1;
}
示例#30
0
void _read_test(long int count)
{
	int hint_count = 0;
	int i;
	int ret;
	double cost;
	char key[KSIZE];
	long long start, end;
	struct slice sk;
	struct slice sv;
	struct index *idx;

	idx = _get_idx();
	start = _ustime();
	for(i = 0; i < count; i++) {
		_random_key(key, KSIZE);
		sk.len = KSIZE;
		sk.data = key;
		ret = index_get(idx, &sk, &sv);
		if(ret) {
			hint_count++;
			free(sv.data);
		}
		if((i%10000) == 0) {
			fprintf(stderr, "random read finished %d ops%30s\r", i, "");
			fflush(stderr);
		}
	}
	index_free(idx);
	end = _ustime();
	cost = end - start;
	printf(LINE);
	printf("|Random-Read  (done:%ld): %.6f sec/op; %.1f reads/sec(estimated); cost:%.3f(sec)\n",
			count,
			(double)(cost/count),
			(double)(count/cost),
			cost);
	printf("hint_count : %d\n", hint_count );
}