*** empty log message ***

This commit is contained in:
hyung-hwan 2006-04-19 03:42:08 +00:00
parent 4a6dcb79f2
commit 38ff71c2f2
4 changed files with 33 additions and 58 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: map.c,v 1.12 2006-04-18 14:49:42 bacon Exp $ * $Id: map.c,v 1.13 2006-04-19 03:42:08 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -143,7 +143,8 @@ xp_awk_pair_t* xp_awk_map_put (xp_awk_map_t* map, xp_char_t* key, void* val)
return px; return px;
} }
int xp_awk_map_putx (xp_awk_map_t* map, xp_char_t* key, void* val, xp_awk_pair_t** px) int xp_awk_map_putx (
xp_awk_map_t* map, xp_char_t* key, void* val, xp_awk_pair_t** px)
{ {
xp_awk_pair_t* pair; xp_awk_pair_t* pair;
xp_size_t hc; xp_size_t hc;
@ -155,12 +156,6 @@ int xp_awk_map_putx (xp_awk_map_t* map, xp_char_t* key, void* val, xp_awk_pair_t
{ {
if (xp_strcmp(pair->key,key) == 0) if (xp_strcmp(pair->key,key) == 0)
{ {
if (pair->key != key)
{
xp_free ((xp_char_t*)pair->key);
pair->key = key;
}
if (px != XP_NULL) if (px != XP_NULL)
*px = xp_awk_map_setpair (map, pair, val); *px = xp_awk_map_setpair (map, pair, val);
else else
@ -174,7 +169,13 @@ int xp_awk_map_putx (xp_awk_map_t* map, xp_char_t* key, void* val, xp_awk_pair_t
pair = (xp_awk_pair_t*) xp_malloc (xp_sizeof(xp_awk_pair_t)); pair = (xp_awk_pair_t*) xp_malloc (xp_sizeof(xp_awk_pair_t));
if (pair == XP_NULL) return -1; /* error */ if (pair == XP_NULL) return -1; /* error */
pair->key = key; /*pair->key = key;*/
pair->key = xp_strdup (key); /* duplicate the key if it is new */
if (pair->key == XP_NULL)
{
xp_free (pair);
return -1; /* error */
}
pair->val = val; pair->val = val;
pair->next = map->buck[hc]; pair->next = map->buck[hc];
map->buck[hc] = pair; map->buck[hc] = pair;
@ -196,12 +197,6 @@ xp_awk_pair_t* xp_awk_map_set (xp_awk_map_t* map, xp_char_t* key, void* val)
{ {
if (xp_strcmp(pair->key,key) == 0) if (xp_strcmp(pair->key,key) == 0)
{ {
if (pair->key != key)
{
xp_free ((xp_char_t*)pair->key);
pair->key = key;
}
return xp_awk_map_setpair (map, pair, val); return xp_awk_map_setpair (map, pair, val);
} }
pair = pair->next; pair = pair->next;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c,v 1.84 2006-04-18 16:04:54 bacon Exp $ * $Id: parse.c,v 1.85 2006-04-19 03:42:08 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -412,6 +412,8 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
xp_awk_nde_t* body; xp_awk_nde_t* body;
xp_awk_func_t* func; xp_awk_func_t* func;
xp_size_t nargs; xp_size_t nargs;
xp_awk_pair_t* pair;
int n;
/* eat up the keyword 'function' and get the next token */ /* eat up the keyword 'function' and get the next token */
if (__get_token(awk) == -1) return XP_NULL; if (__get_token(awk) == -1) return XP_NULL;
@ -582,8 +584,8 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
return XP_NULL; return XP_NULL;
} }
/* TODO: consider if the parameters should be saved for some reasons.. */ /* TODO: consider if the parameter names should be saved for some reasons.. */
nargs = xp_awk_tab_getsize(&awk->parse.params); nargs = xp_awk_tab_getsize (&awk->parse.params);
/* parameter names are not required anymore. clear them */ /* parameter names are not required anymore. clear them */
xp_awk_tab_clear (&awk->parse.params); xp_awk_tab_clear (&awk->parse.params);
@ -595,12 +597,12 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
return XP_NULL; return XP_NULL;
} }
func->name = name_dup; func->name = XP_NULL; /* function name set below */
func->nargs = nargs; func->nargs = nargs;
func->body = body; func->body = body;
xp_assert (xp_awk_map_get(&awk->tree.funcs, name_dup) == XP_NULL); n = xp_awk_map_putx (&awk->tree.funcs, name_dup, func, &pair);
if (xp_awk_map_put(&awk->tree.funcs, name_dup, func) == XP_NULL) if (n < 0)
{ {
xp_free (name_dup); xp_free (name_dup);
xp_awk_clrpt (body); xp_awk_clrpt (body);
@ -608,6 +610,12 @@ static xp_awk_nde_t* __parse_function (xp_awk_t* awk)
PANIC (awk, XP_AWK_ENOMEM); PANIC (awk, XP_AWK_ENOMEM);
} }
/* duplicate functions should have been detected previously */
xp_assert (n != 0);
func->name = pair->key; /* do some trick to save a string. */
xp_free (name_dup);
return body; return body;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: run.c,v 1.59 2006-04-18 16:04:58 bacon Exp $ * $Id: run.c,v 1.60 2006-04-19 03:42:08 bacon Exp $
*/ */
#include <xp/awk/awk_i.h> #include <xp/awk/awk_i.h>
@ -761,32 +761,11 @@ static xp_awk_val_t* __do_assignment (
if (var->type == XP_AWK_NDE_NAMED) if (var->type == XP_AWK_NDE_NAMED)
{ {
xp_awk_pair_t* pair; int n;
xp_char_t* name;
pair = xp_awk_map_get (&awk->run.named, var->id.name); n = xp_awk_map_putx (
if (pair == XP_NULL) &awk->run.named, var->id.name, val, XP_NULL);
{ if (n < 0) PANIC (awk, XP_AWK_ENOMEM);
name = xp_strdup (var->id.name);
if (name == XP_NULL)
{
xp_awk_freeval (awk, val);
awk->errnum = XP_AWK_ENOMEM;
return XP_NULL;
}
}
else
{
name = pair->key;
}
if (xp_awk_map_put(&awk->run.named, name, val) == XP_NULL)
{
xp_free (name);
xp_awk_freeval (awk, val);
awk->errnum = XP_AWK_ENOMEM;
return XP_NULL;
}
xp_awk_refupval (val); xp_awk_refupval (val);
} }
@ -912,21 +891,14 @@ static xp_awk_val_t* __do_assignment_map (
/* /*
xp_printf (XP_TEXT("**** index str=>%s, map->ref=%d, map->type=%d\n"), str, map->ref, map->type); xp_printf (XP_TEXT("**** index str=>%s, map->ref=%d, map->type=%d\n"), str, map->ref, map->type);
*/ */
n = xp_awk_map_putx(map->map, str, val, XP_NULL); n = xp_awk_map_putx (map->map, str, val, XP_NULL);
if (n < 0) if (n < 0)
{ {
xp_free (str); xp_free (str);
PANIC (awk, XP_AWK_ENOMEM); PANIC (awk, XP_AWK_ENOMEM);
} }
if (n == 0)
{
/* the value for the existing key has changed.
* str is freed only if the key is in the map.
* otherwise, it will be taken by the map */
xp_free (str); xp_free (str);
}
xp_awk_refupval (val); xp_awk_refupval (val);
return val; return val;
} }

View File

@ -17,8 +17,8 @@ function sum (i)
BEGIN BEGIN
{ {
x = sum (10000000); //x = sum (10000000);
//s = sum (100); x = sum (100);
s = x; s = x;
ss = z; ss = z;
} }