From b7cf368b6c96bcc25cc82d86e4bd96b8b66fdc0a Mon Sep 17 00:00:00 2001 From: louis Date: Sun, 1 Mar 2015 16:30:13 +0100 Subject: [PATCH] Correct command purge --- src/rpn-store.h | 5 ++++- src/rpn.cpp | 9 --------- src/stack.h | 8 ++++---- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/rpn-store.h b/src/rpn-store.h index 444c4d8..7cdf7e6 100644 --- a/src/rpn-store.h +++ b/src/rpn-store.h @@ -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) diff --git a/src/rpn.cpp b/src/rpn.cpp index da9306b..8ff6152 100644 --- a/src/rpn.cpp +++ b/src/rpn.cpp @@ -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(); diff --git a/src/stack.h b/src/stack.h index d4ed3f8..8b03ff3 100644 --- a/src/stack.h +++ b/src/stack.h @@ -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::iterator i = _map.find(name); if (i != _map.end()) { - free(i->second); + free(i->second); _map.erase(i->first); return true; }