1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
typedef struct git_pool_page git_pool_page;
/**
* Chunked allocator.
*
* A `git_pool` can be used when you want to cheaply allocate
* multiple items of the same type and are willing to free them
* all together with a single call. The two most common cases
* are a set of fixed size items (such as lots of OIDs) or a
* bunch of strings.
*
* Internally, a `git_pool` allocates pages of memory and then
* deals out blocks from the trailing unused portion of each page.
* The pages guarantee that the number of actual allocations done
* will be much smaller than the number of items needed.
*
* For examples of how to set up a `git_pool` see `git_pool_init`.
*/
typedef struct git_pool;
/**
* Debug chunked allocator.
*
* Acts just like `git_pool` but instead of actually pooling allocations it
* passes them through to `git__malloc`. This makes it possible to easily debug
* systems that use `git_pool` using valgrind.
*
* In order to track allocations during the lifetime of the pool we use a
* `git_vector`. When the pool is deallocated everything in the vector is
* freed.
*
* `API is exactly the same as the standard `git_pool` with one exception.
* Since we aren't allocating pages to hand out in chunks we can't easily
* implement `git_pool__open_pages`.
*/
typedef struct git_pool;
/**
* Initialize a pool.
*
* To allocation strings, use like this:
*
* git_pool_init(&string_pool, 1);
* my_string = git_pool_strdup(&string_pool, your_string);
*
* To allocate items of fixed size, use like this:
*
* git_pool_init(&pool, sizeof(item));
* my_item = git_pool_malloc(&pool, 1);
*
* Of course, you can use this in other ways, but those are the
* two most common patterns.
*/
extern int ;
/**
* Free all items in pool
*/
extern void ;
/**
* Swap two pools with one another
*/
extern void ;
/**
* Allocate space for one or more items from a pool.
*/
extern void *;
extern void *;
/**
* Allocate space and duplicate string data into it.
*
* This is allowed only for pools with item_size == sizeof(char)
*/
extern char *;
/**
* Allocate space and duplicate a string into it.
*
* This is allowed only for pools with item_size == sizeof(char)
*/
extern char *;
/**
* Allocate space and duplicate a string into it, NULL is no error.
*
* This is allowed only for pools with item_size == sizeof(char)
*/
extern char *;
/**
* Allocate space for the concatenation of two strings.
*
* This is allowed only for pools with item_size == sizeof(char)
*/
extern char *;
/*
* Misc utilities
*/
extern uint32_t ;
extern bool ;
/**
* This function is being called by our global setup routines to
* initialize the system pool size.
*
* @return 0 on success, <0 on failure
*/
extern int ;