| 1 | /* |
| 2 | * Copyright (C) 2004 Dizzy |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef INCLUDED_XALLOC_TYPES |
| 20 | |
| 21 | namespace pvpgn |
| 22 | { |
| 23 | |
| 24 | /* out of memory callback function */ |
| 25 | typedef int(*t_oom_cb)(void); |
| 26 | |
| 27 | } |
| 28 | |
| 29 | #define INCLUDED_XALLOC_TYPES |
| 30 | |
| 31 | #endif /* INCLUDED_XALLOC_TYPES */ |
| 32 | |
| 33 | #ifndef INCLUDED_XALLOC_PROTOS |
| 34 | #define INCLUDED_XALLOC_PROTOS |
| 35 | |
| 36 | #ifndef XALLOC_SKIP |
| 37 | #include <cstdlib> |
| 38 | |
| 39 | namespace pvpgn |
| 40 | { |
| 41 | |
| 42 | |
| 43 | #define xmalloc(size) xmalloc_real(size,__FILE__,__LINE__) |
| 44 | void *xmalloc_real(std::size_t size, const char *fn, unsigned ln); |
| 45 | #define xcalloc(no,size) xcalloc_real(no,size,__FILE__,__LINE__) |
| 46 | void *xcalloc_real(std::size_t nmemb, std::size_t size, const char *fn, unsigned ln); |
| 47 | #define xrealloc(ptr,size) xrealloc_real(ptr,size,__FILE__,__LINE__) |
| 48 | void *xrealloc_real(void *ptr, std::size_t size, const char *fn, unsigned ln); |
| 49 | #define xstrdup(str) xstrdup_real(str,__FILE__,__LINE__) |
| 50 | char *xstrdup_real(const char *str, const char *fn, unsigned ln); |
| 51 | #define xfree(ptr) xfree_real(ptr,__FILE__,__LINE__) |
| 52 | void xfree_real(void *ptr, const char *fn, unsigned ln); |
| 53 | void xalloc_setcb(t_oom_cb cb); |
| 54 | |
| 55 | } |
| 56 | |
| 57 | #else /* XALLOC_SKIP */ |
| 58 | |
| 59 | #define xmalloc(size) malloc(size) |
| 60 | #define xcalloc(no,size) calloc(no,size) |
| 61 | #define xrealloc(ptr,size) std::realloc(ptr,size) |
| 62 | #define xstrdup(str) strdup(str) |
| 63 | #define xfree(ptr) free(ptr) |
| 64 | #define xalloc_setcb(cb) |
| 65 | |
| 66 | #endif |
| 67 | |
| 68 | #endif /* INCLUDED_XALLOC_PROTOS */ |