]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
dad253b4 AS |
2 | /* |
3 | * qpb_allocator.c | |
4 | * | |
5 | * @copyright Copyright (C) 2016 Sproute Networks, Inc. | |
6 | * | |
7 | * @author Avneesh Sachdev <avneesh@sproute.com> | |
dad253b4 AS |
8 | */ |
9 | ||
b45ac5f5 DL |
10 | #ifdef HAVE_CONFIG_H |
11 | #include "config.h" | |
12 | #endif | |
13 | ||
dad253b4 AS |
14 | #include "linear_allocator.h" |
15 | ||
16 | #include "qpb_allocator.h" | |
17 | ||
18 | /* | |
19 | * _qpb_alloc | |
20 | */ | |
d62a17ae | 21 | static void *_qpb_alloc(void *allocator_data, size_t size) |
dad253b4 | 22 | { |
d62a17ae | 23 | return linear_allocator_alloc(allocator_data, size); |
dad253b4 AS |
24 | } |
25 | ||
26 | /* | |
27 | * _qpb_free | |
28 | */ | |
d62a17ae | 29 | static void _qpb_free(void *allocator_data, void *ptr) |
dad253b4 | 30 | { |
d62a17ae | 31 | linear_allocator_free(allocator_data, ptr); |
dad253b4 AS |
32 | } |
33 | ||
a805d3bb | 34 | static ProtobufCAllocator allocator_template = {_qpb_alloc, _qpb_free, NULL}; |
dad253b4 AS |
35 | |
36 | /* | |
37 | * qpb_allocator_init_linear | |
38 | * | |
39 | * Initialize qpb_allocator_t with the given linear allocator. | |
40 | */ | |
d62a17ae | 41 | void qpb_allocator_init_linear(qpb_allocator_t *allocator, |
42 | linear_allocator_t *linear_allocator) | |
dad253b4 | 43 | { |
d62a17ae | 44 | *allocator = allocator_template; |
45 | allocator->allocator_data = linear_allocator; | |
dad253b4 | 46 | } |