aboutsummaryrefslogtreecommitdiff
path: root/py/malloc.c
diff options
context:
space:
mode:
authormux <freelancer.c@gmail.com>2014-04-03 23:55:12 +0200
committermux <freelancer.c@gmail.com>2014-04-03 23:55:12 +0200
commit4f7e9f5c445b5c0b262d9dfb8fceda4830f4844b (patch)
tree5c36d2f8e7fed3ff6bb0be15678a3063817c2081 /py/malloc.c
parent094d450003185e64f14560ba3c107e02621c056c (diff)
Implement del
Diffstat (limited to 'py/malloc.c')
-rw-r--r--py/malloc.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/py/malloc.c b/py/malloc.c
index 27eaac108..b0094a254 100644
--- a/py/malloc.c
+++ b/py/malloc.c
@@ -31,6 +31,7 @@ STATIC int peak_bytes_allocated = 0;
#undef free
#undef realloc
#define malloc gc_alloc
+#define malloc_mp_obj gc_alloc_mp_obj
#define free gc_free
#define realloc gc_realloc
#endif // MICROPY_ENABLE_GC
@@ -53,6 +54,24 @@ void *m_malloc(int num_bytes) {
return ptr;
}
+void *m_malloc_mp_obj(int num_bytes) {
+ if (num_bytes == 0) {
+ return NULL;
+ }
+ void *ptr = malloc_mp_obj(num_bytes);
+ if (ptr == NULL) {
+ printf("could not allocate memory, allocating %d bytes\n", num_bytes);
+ return NULL;
+ }
+#if MICROPY_MEM_STATS
+ total_bytes_allocated += num_bytes;
+ current_bytes_allocated += num_bytes;
+ UPDATE_PEAK();
+#endif
+ DEBUG_printf("malloc %d : %p\n", num_bytes, ptr);
+ return ptr;
+}
+
void *m_malloc0(int num_bytes) {
void *ptr = m_malloc(num_bytes);
if (ptr != NULL) {