MeterLogger
mem.h
Go to the documentation of this file.
1 /*
2  * ESPRSSIF MIT License
3  *
4  * Copyright (c) 2016 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
5  *
6  * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
7  * it is free of charge, to any person obtaining a copy of this software and associated
8  * documentation files (the "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11  * to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or
14  * substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  *
23  */
24 
25 #ifndef __MEM_H__
26 #define __MEM_H__
27 
28 /* Note: check_memleak_debug_enable is a weak function inside SDK.
29  * please copy following codes to user_main.c.
30 #include "mem.h"
31 
32 bool ICACHE_FLASH_ATTR check_memleak_debug_enable(void)
33 {
34  return MEMLEAK_DEBUG_ENABLE;
35 }
36 */
37 
38 #ifndef MEMLEAK_DEBUG
39 #define MEMLEAK_DEBUG_ENABLE 0
40 #define os_free(s) vPortFree(s, "", 0)
41 #define os_malloc(s) pvPortMalloc(s, "", 0)
42 #define os_calloc(s) pvPortCalloc(s, "", 0);
43 #define os_realloc(p, s) pvPortRealloc(p, s, "", 0)
44 #define os_zalloc(s) pvPortZalloc(s, "", 0)
45 #else
46 #define MEMLEAK_DEBUG_ENABLE 1
47 
48 #define os_free(s) \
49 do{\
50  static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
51  vPortFree(s, mem_debug_file, __LINE__);\
52 }while(0)
53 
54 #define os_malloc(s) \
55  ({ \
56  static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
57  pvPortMalloc(s, mem_debug_file, __LINE__); \
58  })
59 
60 #define os_calloc(s) \
61  ({ \
62  static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
63  pvPortCalloc(s, mem_debug_file, __LINE__); \
64  })
65 
66 #define os_realloc(p, s) \
67  ({ \
68  static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
69  pvPortRealloc(p, s, mem_debug_file, __LINE__); \
70  })
71 
72 #define os_zalloc(s) \
73  ({ \
74  static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
75  pvPortZalloc(s, mem_debug_file, __LINE__); \
76  })
77 
78 #endif
79 
80 #endif
81