mirror of
https://github.com/louisrubet/rpn
synced 2025-01-01 18:20:06 +01:00
Correct command purge
This commit is contained in:
parent
f032075623
commit
b7cf368b6c
3 changed files with 8 additions and 14 deletions
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue