From 65e2cf18bfdd64afc7b9aa34bca7bee2f06e78c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Moskal?= Date: Wed, 2 Oct 2019 07:37:38 +0200 Subject: [PATCH] Allow globals in reclaimed bluetooth memory (#2455) --- libs/core/codal.cpp | 3 +++ libs/core/pxt.h | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/libs/core/codal.cpp b/libs/core/codal.cpp index 13a0f156..a214ab00 100644 --- a/libs/core/codal.cpp +++ b/libs/core/codal.cpp @@ -28,6 +28,9 @@ MicroBitEvent lastEvent; void platform_init() { microbit_seed_random(); seedRandom(microbit_random(0x7fffffff)); +} + +void initMicrobitGC() { if (device_heap_size(1) > NON_GC_HEAP_RESERVATION + 4) gcPreAllocateBlock(device_heap_size(1) - NON_GC_HEAP_RESERVATION); } diff --git a/libs/core/pxt.h b/libs/core/pxt.h index 33d26480..76677b84 100644 --- a/libs/core/pxt.h +++ b/libs/core/pxt.h @@ -54,12 +54,22 @@ static inline int max_(int a, int b) { return b; } +void initMicrobitGC(); + } // namespace pxt using namespace pxt; #define DEVICE_EVT_ANY 0 +#undef PXT_MAIN +#define PXT_MAIN \ + int main() { \ + pxt::initMicrobitGC(); \ + pxt::start(); \ + return 0; \ + } + #endif // vim: ts=2 sw=2 expandtab