Correct command purge

This commit is contained in:
louis 2015-03-01 16:30:13 +01:00
parent f032075623
commit b7cf368b6c
3 changed files with 8 additions and 14 deletions

View file

@ -51,8 +51,11 @@ void purge(void)
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_symbol);
if (!_heap->erase(string(getn())))
string name(((symbol*)_stack->back())->_value);
if (!_heap->erase(name))
ERR_CONTEXT(ret_unknown_variable);
else
_stack->pop_back();
}
void vars(void)

View file

@ -723,15 +723,6 @@ private:
_stack->push_back(&num, num.size(), cmd_binary);
}
// care: return value must be used before pushing something else in stack
char* getn()
{
/* warning, caller must check object type before */
char* a = ((ostring*)_stack->back())->_value;
_stack->pop_back();
return a;
}
int stack_size()
{
return _stack->size();

View file

@ -193,13 +193,13 @@ public:
//TODO gerer les pbs de memoire
blob = (struct local_var*)malloc(size + sizeof(local_var));
_map[name] = blob;
}
}
else if (size != blob->length)
{
//TODO gerer les pbs de memoire
blob = (struct local_var*)realloc(blob, size + sizeof(local_var));
_map[name] = blob;
}
}
blob->length = size;
blob->type= type;
memcpy(&blob->blob, obj, size);
@ -251,12 +251,12 @@ public:
return false;
}
bool erase(const string name)
bool erase(const string& name)
{
map<string, struct local_var*>::iterator i = _map.find(name);
if (i != _map.end())
{
free(i->second);
free(i->second);
_map.erase(i->first);
return true;
}