diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-04 10:52:59 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-04 10:52:59 +0000 |
commit | 6902eeda259a5ed8fe3a5ce5cb19ba9207549d33 (patch) | |
tree | d018a0c7a42e03d0705efedbd116ac5de3ad886d /py/malloc.c | |
parent | 072cf022e007e03a8b850a7197585403868923ab (diff) | |
download | micropython-6902eeda259a5ed8fe3a5ce5cb19ba9207549d33.tar.gz micropython-6902eeda259a5ed8fe3a5ce5cb19ba9207549d33.zip |
py: Add m_malloc_fail function to handle memory allocation error.
A malloc/realloc fail now throws MemoryError.
Diffstat (limited to 'py/malloc.c')
-rw-r--r-- | py/malloc.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/py/malloc.c b/py/malloc.c index 27eaac1088..4cf1b71db0 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -41,8 +41,7 @@ void *m_malloc(int num_bytes) { } void *ptr = malloc(num_bytes); if (ptr == NULL) { - printf("could not allocate memory, allocating %d bytes\n", num_bytes); - return NULL; + return m_malloc_fail(num_bytes); } #if MICROPY_MEM_STATS total_bytes_allocated += num_bytes; @@ -68,8 +67,7 @@ void *m_realloc(void *ptr, int old_num_bytes, int new_num_bytes) { } void *new_ptr = realloc(ptr, new_num_bytes); if (new_ptr == NULL) { - printf("could not allocate memory, reallocating %d bytes\n", new_num_bytes); - return NULL; + return m_malloc_fail(new_num_bytes); } #if MICROPY_MEM_STATS // At first thought, "Total bytes allocated" should only grow, |