Debian Codegraph @

src/common/xalloc.cpp

raw symbols SCIP
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 #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/
20 #ifndef XALLOC_SKIP
21 #define XALLOC_INTERNAL_ACCESScxx . . $ `src/common/xalloc.cpp:21:9`!
22 #include "xalloc.h"cxx . . $ `<file>/src/common/xalloc.h`/
23 #undef XALLOC_INTERNAL_ACCESScxx . . $ `src/common/xalloc.cpp:21:9`!
24
25 #include "compat/strdup.h"cxx . . $ `<file>/src/compat/strdup.h`/
26 #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/
27 #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/
28
29 namespace pvpgncxx . . $ pvpgn/
30 {
31
32 static t_oom_cbcxx . . $ pvpgn/t_oom_cb# oom_cbcxx . . $ pvpgn/oom_cb. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
33
34 void *xmalloc_realcxx . . $ pvpgn/xmalloc_real(52bcf60a46ca15fc).(stdcxx . . $ std/::size_tcxx . . $ std/size_t# size, const char *fn, unsigned ln)
35 {
36 void *res;
37
38 res = malloc(size);
39 if (!res) {
40 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_fatalcxx . . $ pvpgn/eventlog_level_fatal., __FUNCTION__, "out of memory (from {}:{})", fn, ln);
41 if (oom_cbcxx . . $ pvpgn/oom_cb. && oom_cbcxx . . $ pvpgn/oom_cb.() && (res = malloc(size))) return res;
42 stdcxx . . $ std/::abort();
43 }
44
45 return res;
46 }
47
48 void *xcalloc_realcxx . . $ pvpgn/xcalloc_real(9afb910d5acaab39).(stdcxx . . $ std/::size_tcxx . . $ std/size_t# nmemb, stdcxx . . $ std/::size_tcxx . . $ std/size_t# size, const char *fn, unsigned ln)
49 {
50 void *res;
51
52 res = calloc(nmemb, size);
53 if (!res) {
54 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_fatalcxx . . $ pvpgn/eventlog_level_fatal., __FUNCTION__, "out of memory (from {}:{})", fn, ln);
55 if (oom_cbcxx . . $ pvpgn/oom_cb. && oom_cbcxx . . $ pvpgn/oom_cb.() && (res = calloc(nmemb, size))) return res;
56 stdcxx . . $ std/::abort();
57 }
58
59 return res;
60 }
61
62 void *xrealloc_realcxx . . $ pvpgn/xrealloc_real(80a3422ae320a217).(void *ptr, stdcxx . . $ std/::size_tcxx . . $ std/size_t# size, const char *fn, unsigned ln)
63 {
64 void *res;
65
66 res = stdcxx . . $ std/::realloc(ptr, size);
67 if (!res) {
68 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_fatalcxx . . $ pvpgn/eventlog_level_fatal., __FUNCTION__, "out of memory (from {}:{})", fn, ln);
69 if (oom_cbcxx . . $ pvpgn/oom_cb. && oom_cbcxx . . $ pvpgn/oom_cb.() && (res = stdcxx . . $ std/::realloc(ptr, size))) return res;
70 stdcxx . . $ std/::abort();
71 }
72
73 return res;
74 }
75
76 char *xstrdup_realcxx . . $ pvpgn/xstrdup_real(daaded16d514aa0b).(const char *str, const char *fn, unsigned ln)
77 {
78 char *res;
79
80 res = strdup(str);
81 if (!res) {
82 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_fatalcxx . . $ pvpgn/eventlog_level_fatal., __FUNCTION__, "out of memory (from {}:{})", fn, ln);
83 if (oom_cbcxx . . $ pvpgn/oom_cb. && oom_cbcxx . . $ pvpgn/oom_cb.() && (res = strdup(str))) return res;
84 stdcxx . . $ std/::abort();
85 }
86
87 return res;
88 }
89
90 void xfree_realcxx . . $ pvpgn/xfree_real(6359c8b694546919).(void *ptr, const char *fn, unsigned ln)
91 {
92 if (!ptr) {
93 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL ptr (from {}:{})", fn, ln);
94 return;
95 }
96
97 free(ptr);
98 }
99
100 void xalloc_setcbcxx . . $ pvpgn/xalloc_setcb(231822f2a2a10318).(t_oom_cbcxx . . $ pvpgn/t_oom_cb# cb)
101 {
102 oom_cbcxx . . $ pvpgn/oom_cb. = cb;
103 }
104
105 }
106
107 #endif /* XALLOC_SKIP */