diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-25 03:03:34 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-27 00:03:55 +0300 |
commit | 23668698cba9bf861c697e65e3d07f9433396b8b (patch) | |
tree | 7b87345f47610c70e7b5a3559b387e822936573e /py/stackctrl.h | |
parent | 91b576d1472b481f02a9f9f20dd263ef606a186a (diff) | |
download | micropython-23668698cba9bf861c697e65e3d07f9433396b8b.tar.gz micropython-23668698cba9bf861c697e65e3d07f9433396b8b.zip |
py: Add portable framework to query/check C stack usage.
Such mechanism is important to get stable Python functioning, because Python
function calling is handled with C stack. The idea is to sprinkle
STACK_CHECK() calls in places where there can be C recursion.
TODO: Add more STACK_CHECK()'s.
Diffstat (limited to 'py/stackctrl.h')
-rw-r--r-- | py/stackctrl.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/py/stackctrl.h b/py/stackctrl.h new file mode 100644 index 0000000000..a9a8d2e2d8 --- /dev/null +++ b/py/stackctrl.h @@ -0,0 +1,41 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2014 Paul Sokolovsky + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +void stack_ctrl_init(); +uint stack_usage(); + +#if MICROPY_STACK_CHECK + +void stack_set_limit(uint limit); +void stack_check(); +#define STACK_CHECK() stack_check() + +#else + +#define stack_set_limit(limit) +#define STACK_CHECK() + +#endif |