Coverage Report

Created: 2025-12-31 06:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/botan/build/include/public/botan/allocator.h
Line
Count
Source
1
/*
2
* (C) 2023 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6
7
#ifndef BOTAN_ALLOCATOR_HELPERS_H_
8
#define BOTAN_ALLOCATOR_HELPERS_H_
9
10
#include <botan/types.h>
11
12
namespace Botan {
13
14
/*
15
* Define BOTAN_MALLOC_FN
16
*/
17
#if defined(__clang__) || defined(__GNUG__)
18
   #define BOTAN_MALLOC_FN __attribute__((malloc))
19
#elif defined(_MSC_VER)
20
   #define BOTAN_MALLOC_FN __declspec(restrict)
21
#else
22
   #define BOTAN_MALLOC_FN
23
#endif
24
25
/**
26
* Allocate a memory buffer by some method. This should only be used for
27
* primitive types (uint8_t, uint32_t, etc).
28
*
29
* @param elems the number of elements
30
* @param elem_size the size of each element
31
* @return pointer to allocated and zeroed memory, or throw std::bad_alloc on failure
32
*/
33
BOTAN_PUBLIC_API(2, 3) BOTAN_MALLOC_FN void* allocate_memory(size_t elems, size_t elem_size);
34
35
/**
36
* Free a pointer returned by allocate_memory
37
* @param p the pointer returned by allocate_memory
38
* @param elems the number of elements, as passed to allocate_memory
39
* @param elem_size the size of each element, as passed to allocate_memory
40
*/
41
BOTAN_PUBLIC_API(2, 3) void deallocate_memory(void* p, size_t elems, size_t elem_size);
42
43
/**
44
* Ensure the allocator is initialized
45
*/
46
void BOTAN_UNSTABLE_API initialize_allocator();
47
48
class Allocator_Initializer final {
49
   public:
50
2
      Allocator_Initializer() { initialize_allocator(); }
51
};
52
53
}  // namespace Botan
54
55
#endif