diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 0c11e628b..c2c7763ca 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -1,6 +1,7 @@ #include "apps_container.h" #include "global_preferences.h" #include +#include #include extern "C" { @@ -181,6 +182,7 @@ void AppsContainer::run() { activeApp()->snapshot()->reset(); } switchTo(appSnapshotAtIndex(0)); + Poincare::Tidy(); activeApp()->displayWarning(I18n::Message::AppMemoryFull, true); } Container::run(); diff --git a/poincare/include/poincare/init.h b/poincare/include/poincare/init.h index c39522205..2959f87f2 100644 --- a/poincare/include/poincare/init.h +++ b/poincare/include/poincare/init.h @@ -5,6 +5,8 @@ namespace Poincare { void init(); +void Tidy(); + } #endif diff --git a/poincare/include/poincare/integer.h b/poincare/include/poincare/integer.h index 5ca098ed9..6d59e8a98 100644 --- a/poincare/include/poincare/integer.h +++ b/poincare/include/poincare/integer.h @@ -39,6 +39,7 @@ public: static Integer Overflow(bool negative) { return Integer((native_uint_t *)nullptr, k_maxNumberOfDigits+1, negative); } static Integer BuildInteger(native_uint_t * digits, uint16_t numberOfDigits, bool negative, bool enableOverflow = false); ~Integer(); + static void TidyIntegerBuffer(); #if POINCARE_TREE_LOG diff --git a/poincare/src/init.cpp b/poincare/src/init.cpp index 607caebbf..b8875954b 100644 --- a/poincare/src/init.cpp +++ b/poincare/src/init.cpp @@ -1,4 +1,5 @@ #include +#include #include namespace Poincare { @@ -9,4 +10,9 @@ void init() { TreePool::RegisterPool(&pool); } +void Tidy() { + // Clean Integer + Integer::TidyIntegerBuffer(); +} + } diff --git a/poincare/src/integer.cpp b/poincare/src/integer.cpp index bd74a3d2b..3722bb866 100644 --- a/poincare/src/integer.cpp +++ b/poincare/src/integer.cpp @@ -54,6 +54,10 @@ void Integer::log(std::ostream & stream) const { static uint16_t sbusyIntegerBuffer = 0; static native_uint_t sIntegerBuffer[(Integer::k_maxNumberOfDigits+1)*Integer::k_maxNumberOfIntegerSimutaneously]; +void Integer::TidyIntegerBuffer() { + sbusyIntegerBuffer = 0; +} + native_uint_t * Integer::allocDigits(int numberOfDigits) { assert(numberOfDigits <= k_maxNumberOfDigits+1); uint16_t bitIndex = 1 << (16-1); diff --git a/poincare/test/parser.cpp b/poincare/test/parser.cpp index d401ec7d6..9c9f4b3c8 100644 --- a/poincare/test/parser.cpp +++ b/poincare/test/parser.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -47,6 +48,7 @@ QUIZ_CASE(poincare_parser_memory_exhaustion) { a.addChildAtIndexInPlace(e, 0, a.numberOfChildren()); } } else { + Poincare::Tidy(); memoryFailureHasBeenHandled = true; } } diff --git a/poincare/test/tree/tree_handle.cpp b/poincare/test/tree/tree_handle.cpp index 05445dbff..5952e829c 100644 --- a/poincare/test/tree/tree_handle.cpp +++ b/poincare/test/tree/tree_handle.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include "blob_node.h" @@ -72,6 +73,7 @@ QUIZ_CASE(tree_handle_memory_failure) { tree = PairByReference(tree, BlobByReference(1)); } } else { + Poincare::Tidy(); memoryFailureHasBeenHandled = true; } quiz_assert(memoryFailureHasBeenHandled); diff --git a/quiz/src/runner.cpp b/quiz/src/runner.cpp index 05eecb8aa..b58971f52 100644 --- a/quiz/src/runner.cpp +++ b/quiz/src/runner.cpp @@ -1,9 +1,9 @@ #include "quiz.h" #include "symbols.h" #include +#include #include #include -#include #include #include