Exemplo n.º 1
0
/* Read the input data from all of the available sources.  This means
   the environment variables PATH_INFO and QUERY_STRING, the contents
   of standard input, if there is any, and the arguments passed into
   the CGI program.  Nothing is returned, the symbols and values are
   simply interned. The program arguments are returned in the item
   PROGRAM-ARGUMENTS. */
void
forms_input_data (int argc, char *argv[])
{
  register int i;
  int content_length = 0;
  char *env_item;
  char *data_string = (char *)NULL;
  int data_string_size = 0, data_string_index = 0;
  Symbol *symbol;
  Package *package;

  posted_variables = symbol_get_package ("POSTED");

  /* First, get the program arguments if there are any. */
  if (argc != 1)
    {
      symbol = symbol_intern ("PROGRAM-ARGUMENTS");
      symbol->values = (char **)xmalloc (argc * sizeof (char *));
      symbol->values_slots = argc;
      symbol->values_index = 0;

      for (i = 1; i < argc; i++)
	symbol->values[symbol->values_index++] = strdup (argv[i]);

      symbol->values[symbol->values_index] = (char *)NULL;
    }

  /* Now get all of the environment variables. */
  package = symbol_get_package ("ENV");
  for (i = 0; environ != (char **)NULL && environ[i] != (char *)NULL; i++)
    {
      char *name, *value;

      name = strdup (environ[i]);
      value = strchr (name, '=');

      if (value)
	{
	  *value = '\0';
	  value++;
	  value = strdup (value);
	}

      symbol = symbol_intern_in_package (package, name);

      if (value)
	{
	  symbol->values = (char **)xmalloc
	    ((symbol->values_slots = 2) * sizeof (char *));
	  symbol->values[0] = value;
	  symbol->values[1] = (char *)NULL;
	  symbol->values_index = 1;
	}

      free (name);
    }

  /* If there is any input available from standard input, then read it
     now. */
  if (((env_item = getenv ("CONTENT_LENGTH")) != (char *)NULL) &&
      ((content_length = atoi (env_item)) != 0))
    {
      int offset = 0;

      data_string = (char *)xmalloc (1 + (data_string_size = content_length));

      while (content_length != 0)
	{
	  int amount_read =
	    read (fileno (stdin), data_string + offset, content_length);

	  if (amount_read == -1)
	    abort ();

	  content_length -= amount_read;
	  offset += amount_read;
	}

      data_string[offset] = '\0';
      data_string_index = offset;
    }

  /* If any input is coming from QUERY_STRING or PATH_INFO, get it now. */
  {
    char *names[3] = { "QUERY_STRING", "PATH_INFO", (char *)NULL };

    for (i = 0; names[i]; i++)
      {
	if (((env_item = getenv (names[i])) != (char *)NULL) &&
	    (*env_item != '\0'))
	  {
	    int max_len;

	    if ((strcmp (names[i], "PATH_INFO") == 0) &&
		*env_item == '/')
	      env_item++;

	    max_len = data_string_index + strlen (env_item) + 3;

	    if (max_len > data_string_size)
	      data_string = (char *)xrealloc
		(data_string, (data_string_size = max_len));

	    if (data_string_index != 0)
	      data_string[data_string_index++] = '&';

	    strcpy (data_string + data_string_index, env_item);
	    data_string_index += strlen (env_item);
	    data_string[data_string_index] = '\0';
	  }
      }
  }

  /* DATA_STRING may contain any number of name/value pairs, including
     none.  If there are any, intern them now. */
  if (data_string)
    {
      package = posted_variables;

      forms_parse_data_string (data_string, package);

      /* Copy the parsed symbols into the default package. */
      {
	Package *default_pack = 
	  symbol_get_package_hash (DEFAULT_PACKAGE_NAME, 577);
	Symbol **symbols = symbol_package_symbols ("POSTED");

	if (symbols != (Symbol **)NULL)
	  {
	    for (i = 0; symbols[i] != (Symbol *)NULL; i++)
	      symbol_copy (symbols[i], default_pack);
	  }
      }

      free (data_string);
    }
}
Exemplo n.º 2
0
int
limare_draw_arrays(struct limare_state *state, int mode, int start, int count)
{
	struct draw_info *draw;
	int i;

	if (!state->plb) {
		printf("%s: Error: plb member is not set up yet.\n", __func__);
		return -1;
	}


	/* Todo, check whether attributes all have data attached! */

	for (i = 0; i < state->vertex_uniform_count; i++) {
		struct symbol *symbol = state->vertex_uniforms[i];

		if (symbol->data)
			continue;

		if (!strcmp(symbol->name, "gl_mali_ViewportTransform")) {
			if (limare_gl_mali_ViewPortTransform(state, symbol))
				return -1;
		} else {
			printf("%s: Error: vertex uniform %s is empty.\n",
			       __func__, symbol->name);

			return -1;
		}
	}

	if (state->draw_count >= 32) {
		printf("%s: Error: too many draws already!\n", __func__);
		return -1;
	}

	if (state->draw_mem_size < 0x1000) {
		printf("%s: Error: no more space available!\n", __func__);
		return -1;
	}

	draw = draw_create_new(state, state->draw_mem_offset, 0x1000,
			       mode, start, count);
	state->draws[state->draw_count] = draw;

	state->draw_mem_offset += 0x1000;
	state->draw_mem_size -= 0x1000;
	state->draw_count++;

	vs_info_attach_shader(draw, state->vertex_binary->shader,
			      state->vertex_binary->shader_size / 16);

	plbu_info_attach_shader(draw, state->fragment_binary->shader,
				state->fragment_binary->shader_size / 4);

	for (i = 0; i < state->vertex_attribute_count; i++) {
		struct symbol *symbol =
			symbol_copy(state->vertex_attributes[i], start, count);

		if (symbol)
			vs_info_attach_attribute(draw, symbol);

	}

	for (i = 0; i < state->vertex_varying_count; i++) {
		struct symbol *symbol =
			symbol_copy(state->vertex_varyings[i], 0, count);

		if (symbol)
			vs_info_attach_varying(draw, symbol);
	}

	if (vs_info_attach_uniforms(draw, state->vertex_uniforms,
				    state->vertex_uniform_count,
				    state->vertex_uniform_size))
		return -1;

	if (plbu_info_attach_uniforms(draw, state->fragment_uniforms,
				      state->fragment_uniform_count,
				      state->fragment_uniform_size))
		return -1;

	vs_commands_draw_add(state, draw);
	vs_info_finalize(state, draw->vs);

	plbu_info_render_state_create(draw);
	plbu_commands_draw_add(state, draw);

	return 0;
}
Exemplo n.º 3
0
GPtrArray *
profile_func_create_caller_list     (ProfileFunc	     *func)
{
    GPtrArray *result = g_ptr_array_new ();
    GHashTable *callers_by_symbol = g_hash_table_new_full (
	symbol_hash, symbol_equal,
	(GDestroyNotify)symbol_free, NULL);
    GHashTable *marked_callers = g_hash_table_new (g_direct_hash, g_direct_equal);
    ProfileFunc *spontaneous = NULL;
    ProfileNode *node;
    
    for (node = func->node; node != NULL; node = node->next)
    {
	if (node->parent)
	{
	    if (!g_hash_table_lookup (callers_by_symbol, node->parent->symbol))
	    {
		ProfileFunc *caller = g_new (ProfileFunc, 1);
		
		caller->total = 0;
		caller->self = 0;
		caller->node = node->parent;
		
		g_hash_table_insert (
		    callers_by_symbol, symbol_copy (node->parent->symbol), caller);
		g_ptr_array_add (result, caller);
	    }
	}
	else
	{
	    if (!spontaneous)
	    {
		spontaneous = g_new (ProfileFunc, 1);
		spontaneous->total = 0;
		spontaneous->self = 0;
		spontaneous->node = NULL;
		g_ptr_array_add (result, spontaneous);
	    }
	}
    }
    
    for (node = func->node; node != NULL; node = node->next)
    {
	ProfileNode *top_caller_node;
	ProfileNode *top_callee_node;
	ProfileFunc *caller;
	ProfileNode *n;
	
	if (!node->parent)
	{
	    g_assert (spontaneous);
	    caller = spontaneous;
	}
	else
	    caller = g_hash_table_lookup (callers_by_symbol, node->parent->symbol);
	
	/* find topmost node/parent pair identical to this node/parent */
	top_caller_node = node->parent;
	top_callee_node = node;
	for (n = node->parent; n && n->parent != NULL; n = n->parent)
	{
	    if (symbol_equal (n->symbol, node->symbol) &&
		symbol_equal (n->parent->symbol, top_caller_node->symbol))
	    {
		top_caller_node = n->parent;
		top_callee_node = n;
	    }
	}
	if (!g_hash_table_lookup (marked_callers, top_caller_node))
	{
	    caller->total += top_callee_node->total;
	    
	    g_hash_table_insert (marked_callers, top_caller_node, GINT_TO_POINTER (1));
	}
	
	if (node->self > 0)
	    caller->self += node->self;
    }
    
    g_hash_table_destroy (marked_callers);
    g_hash_table_destroy (callers_by_symbol);
    
    return result;
}
Exemplo n.º 4
0
static void
profile_add_stack_trace (Profile *profile, GList *stack, guint size)
{
    GList *list;
    GPtrArray *roots = profile->roots;
    ProfileNode *parent = NULL;
    GHashTable *seen_symbols = g_hash_table_new_full (symbol_hash, symbol_equal,
						      (GDestroyNotify)symbol_free, NULL);

    for (list = stack; list != NULL; list = list->next)
    {
	StackNode *element = list->data;
	ProfileNode *match = NULL;
	const char *symbol =
	    process_locate_symbol (profile->process, GPOINTER_TO_SIZE(element->address));
	int i;

	for (i = 0; i < roots->len; ++i)
	{
	    ProfileNode *node = roots->pdata[i];
	    
	    if (symbol_equal (node->symbol, symbol))
		match = node;
	}
	
	if (!match)
	{
	    ProfileNode *next_node;
	    
	    match = g_new (ProfileNode, 1);
	    
	    match->symbol = symbol_copy (symbol);
	    match->total = 0;
	    match->self = 0;
	    
	    if (g_hash_table_lookup (seen_symbols, symbol))
		match->toplevel = FALSE;
	    else
		match->toplevel = TRUE;
	    
	    next_node = g_hash_table_lookup (profile->nodes_by_symbol, symbol);
	    if (next_node)
		match->next = next_node;
	    else
		match->next = NULL;
	    g_hash_table_insert (profile->nodes_by_symbol, symbol_copy (symbol), match);
	    
	    match->children = g_ptr_array_new ();
	    match->parent = parent;
	    
	    g_ptr_array_add (roots, match);
	}
	
	g_hash_table_insert (seen_symbols, symbol_copy (symbol), GINT_TO_POINTER (1));
	
	match->total += size;
	if (!list->next)
	    match->self += size;
	
	parent = match;
	roots = match->children;
    }
    
    g_hash_table_destroy (seen_symbols);
}
Exemplo n.º 5
0
static void
add_trace_to_tree (GPtrArray *roots, GList *trace, guint size)
{
    GList *list;
    GList *nodes_to_unmark = NULL;
    GList *nodes_to_unmark_recursive = NULL;
    ProfileDescendantTreeNode *parent = NULL;
    
    GHashTable *seen_symbols = g_hash_table_new_full (symbol_hash, symbol_equal,
						      (GDestroyNotify)symbol_free, NULL);
    
    for (list = trace; list != NULL; list = list->next)
    {
	int i;
	ProfileNode *node = list->data;
	ProfileDescendantTreeNode *match = NULL;
	
	for (i = 0; i < roots->len; ++i)
	{
	    ProfileDescendantTreeNode *tree_node = roots->pdata[i];
	    
	    if (symbol_equal (tree_node->symbol, node->symbol))
		match = tree_node;
	}
	
	if (!match)
	{
	    ProfileDescendantTreeNode *seen_tree_node;
	    
	    seen_tree_node = g_hash_table_lookup (seen_symbols, node->symbol);
	    
	    if (seen_tree_node)
	    {
		ProfileDescendantTreeNode *node;
		
		g_assert (parent);
		
		for (node = parent; node != seen_tree_node->parent; node = node->parent)
		{
		    node->non_recursion -= size;
		    --node->marked_non_recursive;
		}
		
		match = seen_tree_node;
		
		g_hash_table_destroy (seen_symbols);
		seen_symbols = g_hash_table_new_full (symbol_hash, symbol_equal,
						      (GDestroyNotify)symbol_free, NULL);
		
		for (node = match; node != NULL; node = node->parent)
		    g_hash_table_insert (seen_symbols, symbol_copy (node->symbol), node);
		
	    }
	}
	
	if (!match)
	{
	    match = g_new (ProfileDescendantTreeNode, 1);
	    
	    match->symbol = symbol_copy (node->symbol);
	    match->non_recursion = 0;
	    match->total = 0;
	    match->self = 0;
	    match->children = g_ptr_array_new ();
	    match->marked_non_recursive = 0;
	    match->marked_total = FALSE;
	    match->parent = parent;
	    
	    g_ptr_array_add (roots, match);
	}
	
	if (!match->marked_non_recursive)
	{
	    nodes_to_unmark = g_list_prepend (nodes_to_unmark, match);
	    match->non_recursion += size;
	    ++match->marked_non_recursive;
	}
	
	if (!match->marked_total)
	{
	    nodes_to_unmark_recursive = g_list_prepend (
		nodes_to_unmark_recursive, match);
	    
	    match->total += size;
	    match->marked_total = TRUE;
	}
	
	if (!list->next)
	    match->self += size;
	
	g_hash_table_insert (seen_symbols, symbol_copy (node->symbol), match);
	
	roots = match->children;
	parent = match;
    }
    
    g_hash_table_destroy (seen_symbols);
    
    for (list = nodes_to_unmark; list != NULL; list = list->next)
    {
	ProfileDescendantTreeNode *tree_node = list->data;
	
	tree_node->marked_non_recursive = 0;
    }
    
    for (list = nodes_to_unmark_recursive; list != NULL; list = list->next)
    {
	ProfileDescendantTreeNode *tree_node = list->data;
	
	tree_node->marked_total = FALSE;
    }
    
    g_list_free (nodes_to_unmark);
}