From 6dced2d157b91a6cc035ff7472f5a5168ee0a87e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Wed, 12 Feb 2020 13:45:37 +0100 Subject: [PATCH] [python/test] Do not use such a big python heap --- apps/code/app.h | 4 +++- python/test/mandelbrot.cpp | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/code/app.h b/apps/code/app.h index 43f8d5202..327fc4ed4 100644 --- a/apps/code/app.h +++ b/apps/code/app.h @@ -69,13 +69,15 @@ public: void deinitPython(); VariableBoxController * variableBoxController() { return &m_variableBoxController; } + + static constexpr int k_pythonHeapSize = 16384; + private: /* Python delegate: * MicroPython requires a heap. To avoid dynamic allocation, we keep a working * buffer here and we give to controllers that load Python environment. We * also memoize the last Python user to avoid re-initiating MicroPython when * unneeded. */ - static constexpr int k_pythonHeapSize = 16384; char m_pythonHeap[k_pythonHeapSize]; const void * m_pythonUser; diff --git a/python/test/mandelbrot.cpp b/python/test/mandelbrot.cpp index b8c3b676f..99e183634 100644 --- a/python/test/mandelbrot.cpp +++ b/python/test/mandelbrot.cpp @@ -2,6 +2,7 @@ #include #include #include +#include class TestExecutionEnvironment : public MicroPython::ExecutionEnvironment { @@ -13,8 +14,8 @@ void TestExecutionEnvironment::printText(const char * text, size_t length) { quiz_print(text); } -static constexpr int k_pythonHeapSize = 16384; -static char s_pythonHeap[k_pythonHeapSize*100]; +static constexpr int s_pythonHeapSize = Code::App::k_pythonHeapSize; +static char s_pythonHeap[s_pythonHeapSize]; static const char * s_mandelbrotScript = R"(# def mandelbrot(N_iteration): @@ -61,7 +62,7 @@ QUIZ_CASE(python_mandelbrot) { constexpr size_t bufferSize = 500; char buffer[bufferSize]; inlineToBeSingleInput(buffer, bufferSize, s_mandelbrotScript); - MicroPython::init(s_pythonHeap, s_pythonHeap + k_pythonHeapSize); + MicroPython::init(s_pythonHeap, s_pythonHeap + s_pythonHeapSize); TestExecutionEnvironment env; env.runCode(buffer); MicroPython::deinit();