예제 #1
0
파일: run.c 프로젝트: ameenross/dex
static void run_command(const struct command *cmds, char **av)
{
	const struct command *cmd = find_command(cmds, av[0]);
	const char *pf;
	char **args;

	if (!cmd) {
		PTR_ARRAY(array);
		const char *alias_name = av[0];
		const char *alias_value = find_alias(alias_name);
		struct error *err = NULL;
		int i;

		if (alias_value == NULL) {
			error_msg("No such command or alias: %s", alias_name);
			return;
		}
		if (!parse_commands(&array, alias_value, &err)) {
			error_msg("Parsing alias %s: %s", alias_name, err->msg);
			error_free(err);
			ptr_array_free(&array);
			return;
		}

		/* remove NULL */
		array.count--;

		for (i = 1; av[i]; i++)
			ptr_array_add(&array, xstrdup(av[i]));
		ptr_array_add(&array, NULL);

		run_commands(cmds, &array);
		ptr_array_free(&array);
		return;
	}

	if (config_file && cmds == commands && !allowed_command(cmd->name)) {
		error_msg("Command %s not allowed in config file.", cmd->name);
		return;
	}

	// By default change can't be merged with previous on.
	// Any command can override this by calling begin_change() again.
	begin_change(CHANGE_MERGE_NONE);

	current_command = cmd;
	args = av + 1;
	pf = parse_args(args, cmd->flags, cmd->min_args, cmd->max_args);
	if (pf)
		cmd->cmd(pf, args);
	current_command = NULL;

	end_change();
}
예제 #2
0
파일: run.c 프로젝트: ameenross/dex
void handle_command(const struct command *cmds, const char *cmd)
{
	struct error *err = NULL;
	PTR_ARRAY(array);

	if (!parse_commands(&array, cmd, &err)) {
		error_msg("%s", err->msg);
		error_free(err);
		ptr_array_free(&array);
		return;
	}

	run_commands(cmds, &array);
	ptr_array_free(&array);
}
예제 #3
0
파일: spawn.c 프로젝트: nellynette/dex
static void handle_error_msg(struct compiler *c, char *str)
{
	int i, len;

	for (i = 0; str[i]; i++) {
		if (str[i] == '\n') {
			str[i] = 0;
			break;
		}
		if (str[i] == '\t')
			str[i] = ' ';
	}
	len = i;
	if (len == 0)
		return;

	for (i = 0; i < c->error_formats.count; i++) {
		const struct error_format *p = c->error_formats.ptrs[i];
		PTR_ARRAY(m);

		if (!regexp_exec_sub(&p->re, str, len, &m, 0))
			continue;
		if (!p->ignore) {
			struct message *msg = new_message(m.ptrs[p->msg_idx]);
			msg->file = p->file_idx < 0 ? NULL : xstrdup(m.ptrs[p->file_idx]);
			msg->u.location.line = p->line_idx < 0 ? 0 : atoi(m.ptrs[p->line_idx]);
			msg->u.location.column = p->column_idx < 0 ? 0 : atoi(m.ptrs[p->column_idx]);
			add_message(msg);
		}
		ptr_array_free(&m);
		return;
	}
	add_message(new_message(str));
}
예제 #4
0
파일: state.c 프로젝트: kwatch/rubinius
void state_object_become(STATE, cpu c, OBJECT from, OBJECT to) {
  ptr_array roots;

  state->current_stack = c->stack_top;
  state->current_sp =    c->sp_ptr;

  roots = _gather_roots(state, c);

  object_memory_setup_become(state, state->om, from, to);

  /* If from is young, then all the refs are from other young objects
     or the remember set, so we just need to mutate in the young space. */
  if(from->gc_zone == YoungObjectZone) {
    object_memory_collect(state, state->om, roots);
  } else {
    object_memory_major_collect(state, state->om, roots);
  }

  object_memory_clear_become(state, state->om);

  memcpy(state->global, roots->array, sizeof(struct rubinius_globals));
  cpu_update_roots(state, c, roots, NUM_OF_GLOBALS);

  ptr_array_free(roots);

}
예제 #5
0
/**
 * g_ptr_array_unref:
 * @array: A #GPtrArray.
 *
 * Atomically decrements the reference count of @array by one. If the
 * reference count drops to 0, the effect is the same as calling
 * g_ptr_array_free() with @free_segment set to %TRUE. This function
 * is MT-safe and may be called from any thread.
 *
 * Since: 2.22
 **/
void
g_ptr_array_unref (GPtrArray *array)
{
  GRealPtrArray *rarray = (GRealPtrArray*) array;
  g_return_if_fail (array);

  if (g_atomic_int_dec_and_test (&rarray->ref_count))
    ptr_array_free (array, FREE_SEGMENT);
}
예제 #6
0
파일: state.c 프로젝트: kwatch/rubinius
void state_collect(STATE, cpu c) {
  ptr_array roots;
  int stats = state->gc_stats;
  struct timeval start, fin;

  cpu_task_flush(state, c);

  if(stats) {
    gettimeofday(&start, NULL);
  }

  cpu_flush_ip(c);
  cpu_flush_sp(c);

  state->current_stack = c->stack_top;
  state->current_sp =    c->sp_ptr;

  /* HACK: external_ivars needs to be moved out of being a generic
      global and being a special case one so that it's references
      can't keep objects alive. */

  cpu_sampler_suspend(state);
  object_memory_formalize_contexts(state, state->om);
  roots = _gather_roots(state, c);
  object_memory_collect(state, state->om, roots);
  memcpy(state->global, roots->array, sizeof(struct rubinius_globals));
  cpu_update_roots(state, c, roots, NUM_OF_GLOBALS);

  object_memory_reset_contexts(state, state->om);

  ptr_array_free(roots);

  baker_gc_find_lost_souls(state, state->om->gc);
  cpu_sampler_resume(state);

  if(stats) {
    double elapse;
    gettimeofday(&fin, NULL);
    elapse =  (fin.tv_sec - start.tv_sec);
    elapse += (((double)fin.tv_usec - start.tv_usec) / 1000000);
    printf("[GC Y %f secs, %ldK total, %3dK used, %4d tenured, %d]\n",
      elapse,
      (long int)(state->om->gc->current->size / 1024),
      (unsigned int)(((uintptr_t)state->om->gc->current->current - (uintptr_t)state->om->gc->current->address) / 1024),
      state->om->last_tenured,
      state->om->gc->num_collection
    );
  }

  cpu_task_flush(state, c);
  cpu_hard_cache(state, c);
  cpu_cache_sp(c);
}
예제 #7
0
파일: state.c 프로젝트: kwatch/rubinius
void state_major_collect(STATE, cpu c) {
  ptr_array roots;
  int stats = state->gc_stats;
  struct timeval start, fin;

  cpu_task_flush(state, c);

  state_collect(state, c);

  if(stats) {
    gettimeofday(&start, NULL);
  }

  cpu_flush_ip(c);
  cpu_flush_sp(c);

  /* HACK: external_ivars needs to be moved out of being a generic
      global and being a special case one so that it's references
      can't keep objects alive. */

  state->current_stack = c->stack_top;
  state->current_sp =    c->sp_ptr;

  cpu_sampler_suspend(state);
  roots = _gather_roots(state, c);
  object_memory_major_collect(state, state->om, roots);
  memcpy(state->global, roots->array, sizeof(struct rubinius_globals));
  cpu_update_roots(state, c, roots, NUM_OF_GLOBALS);

  ptr_array_free(roots);
  cpu_sampler_suspend(state);

  if(stats) {
    double elapse;
    gettimeofday(&fin, NULL);
    elapse =  (fin.tv_sec - start.tv_sec);
    elapse += (((double)fin.tv_usec - start.tv_usec) / 1000000);

    printf("[GC M %f secs, %d freed, %d total, %d segments, %6dK total]\n", 
      elapse,
      state->om->ms->last_freed, state->om->ms->last_marked,
      state->om->ms->num_chunks,
      state->om->ms->allocated_bytes / 1024
      );
  }

  cpu_task_flush(state, c);
  cpu_hard_cache(state, c);
  cpu_cache_sp(c);
}
예제 #8
0
static void euler_dtor(void* context)
{
  euler_ode_t* integ = context;
  if (integ->f1 != NULL)
    polymec_free(integ->f1);
  if (integ->f2 != NULL)
    polymec_free(integ->f2);
  polymec_free(integ->x_new);
  polymec_free(integ->x_old);
  if (integ->newton != NULL)
    newton_solver_free(integ->newton);
  ptr_array_free(integ->observers);
  if ((integ->context != NULL) && (integ->dtor != NULL))
    integ->dtor(integ->context);
  polymec_free(integ);
}
예제 #9
0
/**
 * g_ptr_array_free:
 * @array: a #GPtrArray.
 * @free_seg: if %TRUE the actual pointer array is freed as well.
 * @Returns: the pointer array if @free_seg is %FALSE, otherwise %NULL.
 *           The pointer array should be freed using g_free().
 *
 * Frees the memory allocated for the #GPtrArray. If @free_seg is %TRUE
 * it frees the memory block holding the elements as well. Pass %FALSE
 * if you want to free the #GPtrArray wrapper but preserve the
 * underlying array for use elsewhere. If the reference count of @array
 * is greater than one, the #GPtrArray wrapper is preserved but the
 * size of @array will be set to zero.
 *
 * <note><para>If array contents point to dynamically-allocated
 * memory, they should be freed separately if @free_seg is %TRUE and no
 * #GDestroyNotify function has been set for @array.</para></note>
 **/
gpointer*
g_ptr_array_free (GPtrArray *farray,
		  gboolean   free_segment)
{
  GRealPtrArray *array = (GRealPtrArray*) farray;
  ArrayFreeFlags flags;

  g_return_val_if_fail (array, NULL);

  flags = (free_segment ? FREE_SEGMENT : 0);

  /* if others are holding a reference, preserve the wrapper but do free/return the data */
  if (!g_atomic_int_dec_and_test (&array->ref_count))
    flags |= PRESERVE_WRAPPER;

  return ptr_array_free (farray, flags);
}
예제 #10
0
void fe_mesh_free(fe_mesh_t* mesh)
{
  tagger_free(mesh->elem_sets);
  tagger_free(mesh->face_sets);
  tagger_free(mesh->edge_sets);
  tagger_free(mesh->node_sets);
  tagger_free(mesh->side_sets);

  if (mesh->face_nodes != NULL)
  {
    polymec_free(mesh->face_nodes);
    polymec_free(mesh->face_node_offsets);
  }

  ptr_array_free(mesh->blocks);
  string_array_free(mesh->block_names);
  int_array_free(mesh->block_elem_offsets);
  polymec_free(mesh->node_coords);
  polymec_free(mesh);
}
예제 #11
0
void amr_grid_free(amr_grid_t* grid)
{
  int_ptr_unordered_map_free(grid->pending_data);
  for (int n = 0; n < 6; ++n)
  {
    if (grid->neighbor_interpolators[n] != NULL)
      amr_grid_interpolator_free(grid->neighbor_interpolators[n]);
  }
  if (grid->coarse_interpolator != NULL)
    amr_grid_interpolator_free(grid->coarse_interpolator);
  if (grid->fine_interpolator != NULL)
    amr_grid_interpolator_free(grid->fine_interpolator);
  polymec_free(grid->patch_types);
  polymec_free(grid->remote_owners);
  if (grid->local_patch_indices != NULL)
    polymec_free(grid->local_patch_indices);

  if (grid->cell_ex != NULL)
    exchanger_free(grid->cell_ex);
  if (grid->x_face_ex != NULL)
    exchanger_free(grid->x_face_ex);
  if (grid->y_face_ex != NULL)
    exchanger_free(grid->y_face_ex);
  if (grid->z_face_ex != NULL)
    exchanger_free(grid->z_face_ex);
  if (grid->x_edge_ex != NULL)
    exchanger_free(grid->x_edge_ex);
  if (grid->y_edge_ex != NULL)
    exchanger_free(grid->y_edge_ex);
  if (grid->z_edge_ex != NULL)
    exchanger_free(grid->z_edge_ex);
  if (grid->node_ex != NULL)
    exchanger_free(grid->node_ex);

  for (int centering = 0; centering < 8; ++centering)
    ptr_array_free(grid->local_buffers[centering]);

  polymec_free(grid);
}
예제 #12
0
void free_array(void *a, int rank) {

    if (a)
        ptr_array_free((void **) a, rank, 0);
}
예제 #13
0
void amr_data_hierarchy_free(amr_data_hierarchy_t* data)
{
  ptr_array_free(data->grid_data);
  polymec_free(data);
}
예제 #14
0
파일: main.c 프로젝트: huynhrene/dex
int main(int argc, char *argv[])
{
	const char *term = getenv("TERM");
	const char *home = getenv("HOME");
	const char *tag = NULL;
	const char *rc = NULL;
	const char *command = NULL;
	char *command_history_filename;
	char *search_history_filename;
	char *editor_dir;
	bool read_rc = true;
	int i;

	if (!home)
		home = "";
	home_dir = xstrdup(home);

	for (i = 1; i < argc; i++) {
		const char *opt = argv[i];

		if (opt[0] != '-' || !opt[1])
			break;
		if (!opt[2]) {
			switch (opt[1]) {
			case 'R':
				read_rc = false;
				continue;
			case 't':
				tag = opt_arg(opt, argv[++i]);
				continue;
			case 'r':
				rc = opt_arg(opt, argv[++i]);
				continue;
			case 'c':
				command = opt_arg(opt, argv[++i]);
				continue;
			case 'V':
				printf("%s %s\nWritten by Timo Hirvonen\n", program, version);
				return 0;
			}
			if (opt[1] == '-') {
				i++;
				break;
			}
		}
		printf("Usage: %s [-R] [-V] [-c command] [-t tag] [-r rcfile] [file]...\n", argv[0]);
		return 1;
	}

	if (!isatty(1)) {
		fprintf(stderr, "stdout doesn't refer to a terminal\n");
		return 1;
	}
	if (term == NULL || term[0] == 0) {
		fprintf(stderr, "TERM not set\n");
		return 1;
	}
	switch (term_init(term)) {
	case -1:
		fprintf(stderr, "terminal is hardcopy\n");
		return 1;
	case -2:
		fprintf(stderr, "terminal could not be found\n");
		return 1;
	case -3:
		fprintf(stderr, "terminfo database could not be found\n");
		return 1;
	}

	// create this early. needed if lock-files is true
	editor_dir = editor_file("");
	mkdir(editor_dir, 0755);
	free(editor_dir);

	setlocale(LC_CTYPE, "");
	charset = nl_langinfo(CODESET);
	if (streq(charset, "UTF-8"))
		term_utf8 = true;

	exec_builtin_rc(builtin_rc);
	fill_builtin_colors();

	// NOTE: syntax_changed() uses window. should possibly create window after reading rc
	window = new_window();
	root_frame = new_root_frame(window);

	if (read_rc) {
		if (rc) {
			read_config(commands, rc, true);
		} else {
			char *filename = editor_file("rc");
			if (read_config(commands, filename, false)) {
				free(filename);
				filename = xsprintf("%s/rc", pkgdatadir);
				read_config(commands, filename, true);
			}
			free(filename);
		}
	}

	update_all_syntax_colors();
	sort_aliases();

	/* Terminal does not generate signals for control keys. */
	set_signal_handler(SIGINT, SIG_IGN);
	set_signal_handler(SIGQUIT, SIG_IGN);
	set_signal_handler(SIGPIPE, SIG_IGN);

	/* Terminal does not generate signal for ^Z but someone can send
	 * us SIGTSTP nevertheless. SIGSTOP can't be caught.
	 */
	set_signal_handler(SIGTSTP, handle_sigtstp);

	set_signal_handler(SIGCONT, handle_sigcont);
	set_signal_handler(SIGWINCH, handle_sigwinch);

	load_file_history();
	command_history_filename = editor_file("command-history");
	search_history_filename = editor_file("search-history");
	history_load(&command_history, command_history_filename, command_history_size);
	history_load(&search_history, search_history_filename, search_history_size);
	if (search_history.count)
		search_set_regexp(search_history.ptrs[search_history.count - 1]);

	/* Initialize terminal but don't update screen yet.  Also display
	 * "Press any key to continue" prompt if there were any errors
	 * during reading configuration files.
	 */
	term_raw();
	if (nr_errors) {
		any_key();
		clear_error();
	}

	editor_status = EDITOR_RUNNING;

	for (; i < argc; i++)
		window_open_buffer(window, argv[i], false, NULL);
	if (window->views.count == 0)
		window_open_empty_buffer(window);
	set_view(window->views.ptrs[0]);

	if (command || tag)
		resize();

	if (command)
		handle_command(commands, command);
	if (tag) {
		PTR_ARRAY(array);
		ptr_array_add(&array, xstrdup("tag"));
		ptr_array_add(&array, xstrdup(tag));
		ptr_array_add(&array, NULL);
		run_commands(commands, &array);
		ptr_array_free(&array);
	}
	resize();
	main_loop();
	ui_end();

	// unlock files and add files to file history
	remove_frame(root_frame);

	history_save(&command_history, command_history_filename);
	history_save(&search_history, search_history_filename);
	free(command_history_filename);
	free(search_history_filename);
	save_file_history();
	return 0;
}