Skip to content

Commit d132600

Browse files
committed
libc: Only define some macros when they are not defined
1 parent 082f420 commit d132600

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

include/espressif/esp_libc.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ long atol(const char *s);
7272
unsigned long os_random(void);
7373
int os_get_random(unsigned char *buf, size_t len);
7474

75+
#ifndef os_printf
7576
/* NOTE: don't use printf_opt in irq handler, for test */
7677
#define os_printf(fmt, ...) do { \
7778
static const char flash_str[] ICACHE_RODATA_ATTR STORE_ATTR = fmt; \
7879
printf(flash_str, ##__VA_ARGS__); \
7980
} while(0)
81+
#endif
8082

8183
/* Note: check_memleak_debug_enable is a weak function inside SDK.
8284
* please copy following codes to user_main.c.
@@ -90,43 +92,67 @@ bool ICACHE_FLASH_ATTR check_memleak_debug_enable(void)
9092

9193
#ifndef MEMLEAK_DEBUG
9294
#define MEMLEAK_DEBUG_ENABLE 0
95+
#ifndef os_free
9396
#define os_free(s) free(s)
97+
#endif
98+
99+
#ifndef os_malloc
94100
#define os_malloc(s) malloc(s)
95-
#define os_calloc(p, s) calloc(p, s);
101+
#endif
102+
103+
#ifndef os_calloc
104+
#define os_calloc(p, s) calloc(p, s)
105+
#endif
106+
107+
#ifndef os_realloc
96108
#define os_realloc(p, s) realloc(p, s)
109+
#endif
110+
111+
#ifndef os_zalloc
97112
#define os_zalloc(s) zalloc(s)
113+
#endif
98114
#else
99115
#define MEMLEAK_DEBUG_ENABLE 1
100116

117+
#ifndef os_free
101118
#define os_free(s) \
102119
do{\
103120
static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
104121
vPortFree(s, mem_debug_file, __LINE__);\
105122
}while(0)
123+
#endif
106124

125+
#ifndef os_malloc
107126
#define os_malloc(s) \
108127
({ \
109128
static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
110129
pvPortMalloc(s, mem_debug_file, __LINE__); \
111130
})
131+
#endif
112132

133+
#ifndef os_calloc
113134
#define os_calloc(p, s) \
114135
({ \
115136
static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
116137
pvPortCalloc(p, s, mem_debug_file, __LINE__); \
117138
})
139+
#endif
118140

141+
#ifndef os_realloc
119142
#define os_realloc(p, s) \
120143
({ \
121144
static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
122145
pvPortRealloc(p, s, mem_debug_file, __LINE__); \
123146
})
147+
#endif
124148

149+
#ifndef os_zalloc
125150
#define os_zalloc(s) \
126151
({ \
127152
static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
128153
pvPortZalloc(s, mem_debug_file, __LINE__); \
129154
})
155+
#endif
130156

131157
#endif
132158

0 commit comments

Comments
 (0)