diff options
author | Damien George <damien.p.george@gmail.com> | 2018-02-19 00:26:14 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-02-19 00:26:14 +1100 |
commit | 7b2a9b059a4c60252b37f61cdbc2a28e375438a5 (patch) | |
tree | 51b5b37a6b17f89ccdef55c3921942a323cf2465 | |
parent | 3759aa2cc98c96b869f3db5c4ac51778d3726669 (diff) | |
download | micropython-7b2a9b059a4c60252b37f61cdbc2a28e375438a5.tar.gz micropython-7b2a9b059a4c60252b37f61cdbc2a28e375438a5.zip |
py/pystack: Use "pystack exhausted" as error msg for out of pystack mem.
Using the message "maximum recursion depth exceeded" for when the pystack
runs out of memory can be misleading because the pystack can run out for
reasons other than deep recursion (although in most cases pystack
exhaustion is probably indirectly related to deep recursion). And it's
important to give the user more precise feedback as to the reason for the
error: if they know precisely that the pystack was exhausted then they have
a chance to increase the amount of memory available to the pystack (as
opposed to not knowing if it was the C stack or pystack that ran out).
Also, C stack exhaustion is more serious than pystack exhaustion because it
could have been that the C stack overflowed and overwrote/corrupted some
data and so the system must be restarted. The pystack can never corrupt
data in this way so pystack exhaustion does not require a system restart.
Knowing the difference between these two cases is therefore important.
The actual exception type for pystack exhaustion remains as RuntimeError so
that programatically it behaves the same as a C stack exhaustion.
-rw-r--r-- | py/pystack.c | 3 | ||||
-rw-r--r-- | py/qstrdefs.h | 4 |
2 files changed, 6 insertions, 1 deletions
diff --git a/py/pystack.c b/py/pystack.c index 767c307e9a..552e59d537 100644 --- a/py/pystack.c +++ b/py/pystack.c @@ -43,7 +43,8 @@ void *mp_pystack_alloc(size_t n_bytes) { #endif if (MP_STATE_THREAD(pystack_cur) + n_bytes > MP_STATE_THREAD(pystack_end)) { // out of memory in the pystack - mp_raise_recursion_depth(); + nlr_raise(mp_obj_new_exception_arg1(&mp_type_RuntimeError, + MP_OBJ_NEW_QSTR(MP_QSTR_pystack_space_exhausted))); } void *ptr = MP_STATE_THREAD(pystack_cur); MP_STATE_THREAD(pystack_cur) += n_bytes; diff --git a/py/qstrdefs.h b/py/qstrdefs.h index 1b480c9c75..a609058120 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -52,3 +52,7 @@ Q(<genexpr>) Q(<string>) Q(<stdin>) Q(utf-8) + +#if MICROPY_ENABLE_PYSTACK +Q(pystack exhausted) +#endif |