Freeciv-3.3
Loading...
Searching...
No Matches
mem.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifndef FC__MEM_H
15#define FC__MEM_H
16
17#ifdef __cplusplus
18extern "C" {
19#endif /* __cplusplus */
20
21#include <stdlib.h> /* size_t; actually stddef.h, but stdlib.h
22 * might be more reliable? --dwp */
23
24/* utility */
25#include "log.h"
26#include "support.h" /* fc__warn_unused_result */
27
28/* fc_malloc(), fc_realloc(), fc_calloc():
29 * fc_ stands for freeciv; the return value is checked,
30 * and freeciv-specific processing occurs if it is nullptr:
31 * a log message, possibly cleanup, and ending with exit(EXIT_FAILURE)
32 */
33
34#define fc_malloc(sz) fc_real_malloc((sz), "malloc", \
35 __FC_LINE__, __FILE__)
36#define fc_realloc(ptr,sz) fc_real_realloc((ptr), (sz), "realloc", \
37 __FC_LINE__, __FILE__)
38#define fc_calloc(n,esz) fc_real_calloc((n), (esz), "calloc", \
39 __FC_LINE__, __FILE__)
40
41#define FC_FREE(ptr) do { free(ptr); (ptr) = nullptr; } while (FALSE)
42
43#define fc_strdup(str) real_fc_strdup((str), "strdup", __FC_LINE__, __FILE__)
44
45/***********************************************************************/
46
47/* You shouldn't call these functions directly;
48 * use the macros above instead.
49 */
50void *fc_real_malloc(size_t size,
51 const char *called_as, int line, const char *file)
53void *fc_real_realloc(void *ptr, size_t size,
54 const char *called_as, int line, const char *file)
56void *fc_real_calloc(size_t nelem, size_t elsize,
57 const char *called_as, int line, const char *file)
59
60char *real_fc_strdup(const char *str,
61 const char *called_as, int line, const char *file)
63
64#ifdef __cplusplus
65}
66#endif /* __cplusplus */
67
68#endif /* FC__MEM_H */
#define str
Definition astring.c:76
char * incite_cost
Definition comments.c:76
void * fc_real_malloc(size_t size, const char *called_as, int line, const char *file) fc__warn_unused_result
Definition mem.c:73
void * fc_real_calloc(size_t nelem, size_t elsize, const char *called_as, int line, const char *file) fc__warn_unused_result
Definition mem.c:132
char * real_fc_strdup(const char *str, const char *called_as, int line, const char *file) fc__warn_unused_result
Definition mem.c:148
void * fc_real_realloc(void *ptr, size_t size, const char *called_as, int line, const char *file) fc__warn_unused_result
Definition mem.c:101
size_t size
Definition specvec.h:72
#define fc__warn_unused_result
Definition support.h:109