1 /** 2 * Compiler implementation of the 3 * $(LINK2 http://www.dlang.org, D programming language). 4 * 5 * Copyright: Copyright (C) 1985-1998 by Symantec 6 * Copyright (C) 2000-2020 by The D Language Foundation, All Rights Reserved 7 * Authors: $(LINK2 http://www.digitalmars.com, Walter Bright) 8 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) 9 * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/backend/mem.d, backend/mem.d) 10 * Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/backend/mem.d 11 */ 12 13 14 module dmd.backend.mem; 15 16 import core.stdc.stdlib : malloc, calloc, realloc, free; 17 import core.stdc..string : strdup; 18 19 extern (C): 20 21 nothrow: 22 @nogc: 23 24 char* mem_strdup(const char* p) { return strdup(p); } 25 void* mem_malloc(size_t u) { return malloc(u); } 26 void* mem_fmalloc(size_t u) { return malloc(u); } 27 void* mem_calloc(size_t u) { return calloc(u, 1); } 28 void* mem_realloc(void* p, size_t u) { return realloc(p, u); } 29 void mem_free(void* p) { free(p); } 30 31 extern (C++) 32 { 33 void mem_free_cpp(void *); 34 alias mem_freefp = mem_free_cpp; 35 } 36 37 version (MEM_DEBUG) 38 { 39 alias mem_fstrdup = mem_strdup; 40 alias mem_fcalloc = mem_calloc; 41 alias mem_fmalloc = mem_malloc; 42 alias mem_ffree = mem_free; 43 } 44 else 45 { 46 char *mem_fstrdup(const(char) *); 47 void *mem_fcalloc(size_t); 48 void *mem_fmalloc(size_t); 49 void mem_ffree(void *) { } 50 } 51