pull-in func-params branch

This commit is contained in:
BVK Chaitanya 2010-05-19 11:01:04 +05:30
commit 3ad4f2418d
3 changed files with 28 additions and 13 deletions

View file

@ -67,7 +67,7 @@ struct grub_script_arg
/* An argument vector. */ /* An argument vector. */
struct grub_script_argv struct grub_script_argv
{ {
int argc; unsigned argc;
char **args; char **args;
}; };

View file

@ -20,13 +20,29 @@
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/script_sh.h> #include <grub/script_sh.h>
#define ARG_ALLOCATION_UNIT (32 * sizeof (char)) static unsigned
#define ARGV_ALLOCATION_UNIT (8 * sizeof (void*)) round_up_exp (unsigned v)
{
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
if (sizeof (v) > 4)
v |= v >> 32;
v++;
v += (v == 0);
return v;
}
void void
grub_script_argv_free (struct grub_script_argv *argv) grub_script_argv_free (struct grub_script_argv *argv)
{ {
int i; unsigned i;
if (argv->args) if (argv->args)
{ {
@ -48,7 +64,7 @@ grub_script_argv_next (struct grub_script_argv *argv)
if (argv->argc == 0) if (argv->argc == 0)
{ {
p = grub_malloc (ALIGN_UP (2 * sizeof (char *), ARG_ALLOCATION_UNIT)); p = grub_malloc (2 * sizeof (char *));
if (! p) if (! p)
return 1; return 1;
@ -62,8 +78,7 @@ grub_script_argv_next (struct grub_script_argv *argv)
if (! argv->args[argv->argc - 1]) if (! argv->args[argv->argc - 1])
return 0; return 0;
p = grub_realloc (p, ALIGN_UP ((argv->argc + 1) * sizeof (char *), p = grub_realloc (p, round_up_exp ((argv->argc + 1) * sizeof (char *)));
ARG_ALLOCATION_UNIT));
if (! p) if (! p)
return 1; return 1;
@ -86,8 +101,7 @@ grub_script_argv_append (struct grub_script_argv *argv, const char *s)
a = p ? grub_strlen (p) : 0; a = p ? grub_strlen (p) : 0;
b = grub_strlen (s); b = grub_strlen (s);
p = grub_realloc (p, ALIGN_UP ((a + b + 1) * sizeof (char), p = grub_realloc (p, round_up_exp ((a + b + 1) * sizeof (char)));
ARG_ALLOCATION_UNIT));
if (! p) if (! p)
return 1; return 1;

View file

@ -98,7 +98,7 @@ grub_script_env_get (const char *name, grub_script_arg_type_t type)
} }
else if (grub_strcmp (name, "*") == 0) else if (grub_strcmp (name, "*") == 0)
{ {
int i; unsigned i;
for (i = 0; ! errors && i < scope->argv.argc; i++) for (i = 0; ! errors && i < scope->argv.argc; i++)
if (type == GRUB_SCRIPT_ARG_TYPE_VAR) if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
@ -118,7 +118,7 @@ grub_script_env_get (const char *name, grub_script_arg_type_t type)
} }
else if (grub_strcmp (name, "@") == 0) else if (grub_strcmp (name, "@") == 0)
{ {
int i; unsigned i;
for (i = 0; ! errors && i < scope->argv.argc; i++) for (i = 0; ! errors && i < scope->argv.argc; i++)
{ {
@ -311,6 +311,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
grub_snprintf (errnobuf, sizeof (errnobuf), "%d", grub_errno); grub_snprintf (errnobuf, sizeof (errnobuf), "%d", grub_errno);
grub_env_set ("?", errnobuf); grub_env_set ("?", errnobuf);
grub_script_argv_free (&argv);
grub_print_error (); grub_print_error ();
return 0; return 0;
@ -377,8 +378,8 @@ grub_script_execute_cmdif (struct grub_script_cmd *cmd)
grub_err_t grub_err_t
grub_script_execute_cmdfor (struct grub_script_cmd *cmd) grub_script_execute_cmdfor (struct grub_script_cmd *cmd)
{ {
int i; unsigned i;
int result; grub_err_t result;
struct grub_script_argv argv; struct grub_script_argv argv;
struct grub_script_cmdfor *cmdfor = (struct grub_script_cmdfor *) cmd; struct grub_script_cmdfor *cmdfor = (struct grub_script_cmdfor *) cmd;