Line | Branch | Exec | Source |
---|---|---|---|
1 | /* GATE PROJECT LICENSE: | ||
2 | +----------------------------------------------------------------------------+ | ||
3 | | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> | | ||
4 | | All rights reserved. | | ||
5 | | | | ||
6 | | Redistribution and use in source and binary forms, with or without | | ||
7 | | modification, are permitted provided that the following conditions are met:| | ||
8 | | | | ||
9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
10 | | this list of conditions and the following disclaimer. | | ||
11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
12 | | notice, this list of conditions and the following disclaimer in the | | ||
13 | | documentation and/or other materials provided with the distribution. | | ||
14 | | | | ||
15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
26 | +----------------------------------------------------------------------------+ | ||
27 | */ | ||
28 | |||
29 | #include "gate/handles.h" | ||
30 | |||
31 | 30 | void* gate_handlestore_create(gate_handlestore_t* store, gate_size_t handlesize) | |
32 | { | ||
33 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if (!store) |
34 | { | ||
35 | ✗ | return NULL; | |
36 | } | ||
37 | 30 | gate_mem_clear(store, sizeof(gate_handlestore_t)); | |
38 | |||
39 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 17 times.
|
30 | if (handlesize > sizeof(store->data)) |
40 | { | ||
41 | /* handle is allocated on heap */ | ||
42 | 13 | store->ptr = gate_mem_alloc(handlesize); | |
43 | } | ||
44 | else | ||
45 | { | ||
46 | /* handle is embedded */ | ||
47 | 17 | store->ptr = (void*)&store->data[0]; | |
48 | } | ||
49 | 30 | return store->ptr; | |
50 | } | ||
51 | 26 | void gate_handlestore_destroy(gate_handlestore_t* store) | |
52 | { | ||
53 |
3/4✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✓ Branch 3 taken 13 times.
|
26 | if (store->ptr && (store->ptr != (void*)&store->data[0])) |
54 | { | ||
55 | /* handle on heap -> deallocate */ | ||
56 | 13 | gate_mem_dealloc(store->ptr); | |
57 | } | ||
58 | 26 | gate_mem_clear(store, sizeof(gate_handlestore_t)); | |
59 | 26 | } | |
60 | 195 | void* gate_handlestore_access(gate_handlestore_t* store) | |
61 | { | ||
62 | 195 | return store->ptr; | |
63 | } | ||
64 | |||
65 | 4 | void gate_handlestore_move(gate_handlestore_t* target_store, gate_handlestore_t* source_store) | |
66 | { | ||
67 | 4 | gate_mem_clear(target_store, sizeof(gate_handlestore_t)); | |
68 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (source_store) |
69 | { | ||
70 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (source_store->ptr == (void*)&source_store->data[0]) |
71 | { | ||
72 | 4 | gate_mem_copy(&target_store->data[0], &source_store->data[0], sizeof(target_store->data)); | |
73 | 4 | target_store->ptr = &target_store->data[0]; | |
74 | } | ||
75 | else | ||
76 | { | ||
77 | ✗ | target_store->ptr = source_store->ptr; | |
78 | } | ||
79 | 4 | gate_mem_clear(source_store, sizeof(gate_handlestore_t)); | |
80 | } | ||
81 | 4 | } | |
82 | |||
83 |