Debian Codegraph @

lib/grn_alloc.h

raw symbols SCIP
1 /*
2 Copyright(C) 2009-2016 Brazil
3 Copyright(C) 2019 Kouhei Sutou <[email protected]>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #pragma once
21
22 #include "grn.h"
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 uint32_t grn_alloc_count(void);
29
30 void grn_alloc_init_from_env(void);
31
32 void grn_alloc_init_ctx_impl(grn_ctx *ctx);
33 void grn_alloc_fin_ctx_impl(grn_ctx *ctx);
34
35 void grn_alloc_info_init(void);
36 void grn_alloc_info_fin(void);
37
38 void grn_alloc_info_dump(grn_ctx *ctx);
39 void grn_alloc_info_free(grn_ctx *ctx);
40
41 #define GRN_MALLOC(s) grn_malloc(ctx,s,__FILE__,__LINE__,__FUNCTION__)
42 #define GRN_CALLOC(s) grn_calloc(ctx,s,__FILE__,__LINE__,__FUNCTION__)
43 #define GRN_REALLOC(p,s) grn_realloc(ctx,p,s,__FILE__,__LINE__,__FUNCTION__)
44 #define GRN_STRDUP(s) grn_strdup(ctx,s,__FILE__,__LINE__,__FUNCTION__)
45 #define GRN_GMALLOC(s) grn_malloc(&grn_gctx,s,__FILE__,__LINE__,__FUNCTION__)
46 #define GRN_GCALLOC(s) grn_calloc(&grn_gctx,s,__FILE__,__LINE__,__FUNCTION__)
47 #define GRN_GREALLOC(p,s) grn_realloc(&grn_gctx,p,s,__FILE__,__LINE__,__FUNCTION__)
48 #define GRN_GSTRDUP(s) grn_strdup(&grn_gctx,s,__FILE__,__LINE__,__FUNCTION__)
49 #define GRN_FREE(p) grn_free(ctx,p,__FILE__,__LINE__,__FUNCTION__)
50 #define GRN_MALLOCN(t,n) ((t *)(GRN_MALLOC(sizeof(t) * (n))))
51 #define GRN_GFREE(p) grn_free(&grn_gctx,p,__FILE__,__LINE__,__FUNCTION__)
52 #define GRN_GMALLOCN(t,n) ((t *)(GRN_GMALLOC(sizeof(t) * (n))))
53
54 #define GRN_CTX_ALLOC(ctx,s) grn_ctx_calloc(ctx,s,__FILE__,__LINE__,__FUNCTION__)
55 #define GRN_CTX_FREE(ctx,p) grn_ctx_free(ctx,p,__FILE__,__LINE__,__FUNCTION__)
56 #define GRN_CTX_ALLOC_L(ctx,s) grn_ctx_alloc_lifo(ctx,s,f,__FILE__,__LINE__,__FUNCTION__)
57 #define GRN_CTX_FREE_L(ctx,p) grn_ctx_free_lifo(ctx,p,__FILE__,__LINE__,__FUNCTION__)
58
59 void *grn_ctx_malloc(grn_ctx *ctx,
60 size_t size,
61 const char *file,
62 int line,
63 const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2);
64 void *grn_ctx_calloc(grn_ctx *ctx,
65 size_t size,
66 const char *file,
67 int line,
68 const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2);
69 void *grn_ctx_realloc(grn_ctx *ctx,
70 void *ptr,
71 size_t size,
72 const char *file,
73 int line,
74 const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(3);
75 char *grn_ctx_strdup(grn_ctx *ctx, const char *s,
76 const char* file, int line, const char *func);
77 void grn_ctx_free(grn_ctx *ctx, void *ptr,
78 const char* file, int line, const char *func);
79 void *grn_ctx_alloc_lifo(grn_ctx *ctx,
80 size_t size,
81 const char *file,
82 int line,
83 const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2);
84 void grn_ctx_free_lifo(grn_ctx *ctx, void *ptr,
85 const char* file, int line, const char *func);
86
87 GRN_API void *grn_malloc(grn_ctx *ctx,
88 size_t size,
89 const char *file,
90 int line,
91 const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2);
92 GRN_API void *grn_calloc(grn_ctx *ctx,
93 size_t size,
94 const char *file,
95 int line,
96 const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2);
97 GRN_API void *grn_realloc(grn_ctx *ctx,
98 void *ptr,
99 size_t size,
100 const char *file,
101 int line,
102 const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(3);
103 GRN_API char *grn_strdup(grn_ctx *ctx, const char *s, const char* file, int line, const char *func);
104 GRN_API void grn_free(grn_ctx *ctx, void *ptr, const char *file, int line, const char *func);
105
106 GRN_API void *grn_malloc_default(grn_ctx *ctx,
107 size_t size,
108 const char *file,
109 int line,
110 const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2);
111 void *grn_calloc_default(grn_ctx *ctx,
112 size_t size,
113 const char *file,
114 int line,
115 const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(2);
116 void *grn_realloc_default(grn_ctx *ctx,
117 void *ptr,
118 size_t size,
119 const char *file,
120 int line,
121 const char *func) GRN_ATTRIBUTE_ALLOC_SIZE(3);
122 GRN_API char *grn_strdup_default(grn_ctx *ctx, const char *s, const char* file, int line, const char *func);
123 GRN_API void grn_free_default(grn_ctx *ctx, void *ptr, const char* file, int line, const char *func);
124
125 bool grn_fail_malloc_should_fail(size_t size,
126 const char *file,
127 int line,
128 const char *func);
129 void *grn_malloc_fail(grn_ctx *ctx, size_t size, const char* file, int line, const char *func);
130 void *grn_calloc_fail(grn_ctx *ctx, size_t size, const char* file, int line, const char *func);
131 void *grn_realloc_fail(grn_ctx *ctx, void *ptr, size_t size, const char* file, int line, const char *func);
132 char *grn_strdup_fail(grn_ctx *ctx, const char *s, const char* file, int line, const char *func);
133
134 #ifdef __cplusplus
135 }
136 #endif