summaryrefslogtreecommitdiff
path: root/examples/embedding/main.c
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <yamamoto@midokura.com>2024-02-09 14:03:00 +0900
committerDamien George <damien@micropython.org>2024-02-15 10:07:32 +1100
commitd2a3cd7ac4283045b3692ae8d83afe833fbe65e6 (patch)
tree4379ef4e3cd9056098eb28c230dd622aa2cf4fba /examples/embedding/main.c
parentbe8d660fc24c3390aedd156b796a3a88ae737ae9 (diff)
embed: Improve stack top estimation.
Obtaining the stack-top via a few function calls may yield a pointer which is too deep within the stack. So require the user to obtain it from a higher level (or via some other means). Fixes issue #11781. Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Diffstat (limited to 'examples/embedding/main.c')
-rw-r--r--examples/embedding/main.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/examples/embedding/main.c b/examples/embedding/main.c
index ee673fc93..753058036 100644
--- a/examples/embedding/main.c
+++ b/examples/embedding/main.c
@@ -31,7 +31,14 @@ static char heap[8 * 1024];
int main() {
// Initialise MicroPython.
- mp_embed_init(&heap[0], sizeof(heap));
+ //
+ // Note: &stack_top below should be good enough for many cases.
+ // However, depending on environment, there might be more appropriate
+ // ways to get the stack top value.
+ // eg. pthread_get_stackaddr_np, pthread_getattr_np,
+ // __builtin_frame_address/__builtin_stack_address, etc.
+ int stack_top;
+ mp_embed_init(&heap[0], sizeof(heap), &stack_top);
// Run the example scripts (they will be compiled first).
mp_embed_exec_str(example_1);