Skip to content

Commit b0b7518

Browse files
committed
Merge pull request adafruit#270 from pfalcon/down-with-calloc
Get rid of calloc().
2 parents e8d2c3c + 58ff93b commit b0b7518

4 files changed

Lines changed: 4 additions & 23 deletions

File tree

py/malloc.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stdio.h>
22
#include <stdlib.h>
3+
#include <string.h>
34

45
#include "misc.h"
56
#include "mpconfig.h"
@@ -37,20 +38,10 @@ void *m_malloc(int num_bytes) {
3738
}
3839

3940
void *m_malloc0(int num_bytes) {
40-
if (num_bytes == 0) {
41-
return NULL;
42-
}
43-
void *ptr = calloc(1, num_bytes);
44-
if (ptr == NULL) {
45-
printf("could not allocate memory, allocating %d bytes\n", num_bytes);
46-
return NULL;
41+
void *ptr = m_malloc(num_bytes);
42+
if (ptr != NULL) {
43+
memset(ptr, 0, num_bytes);
4744
}
48-
#if MICROPY_MEM_STATS
49-
total_bytes_allocated += num_bytes;
50-
current_bytes_allocated += num_bytes;
51-
UPDATE_PEAK();
52-
#endif
53-
DEBUG_printf("malloc0 %d : %p\n", num_bytes, ptr);
5445
return ptr;
5546
}
5647

stm/malloc0.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ void *realloc(void *ptr, size_t n) {
2929

3030
#endif
3131

32-
void *calloc(size_t sz, size_t n) {
33-
char *ptr = malloc(sz * n);
34-
for (int i = 0; i < sz * n; i++) {
35-
ptr[i] = 0;
36-
}
37-
return ptr;
38-
}
39-
4032
void *malloc(size_t n) {
4133
return gc_alloc(n);
4234
}

stm/std.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ void __assert_func(void);
44

55
void *malloc(size_t n);
66
void free(void *ptr);
7-
void *calloc(size_t sz, size_t n);
87
void *realloc(void *ptr, size_t n);
98

109
void *memcpy(void *dest, const void *src, size_t n);

teensy/std.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ void __assert_func(void);
44

55
void *malloc(size_t n);
66
void free(void *ptr);
7-
void *calloc(size_t sz, size_t n);
87
void *realloc(void *ptr, size_t n);
98

109
void *memcpy(void *dest, const void *src, size_t n);

0 commit comments

Comments
 (0)