blob: 04858bae226126e90add2241b886ae0d9220a4f6 (
plain)
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
|
/*======================================================================
FILE: test-malloc.h
SPDX-FileCopyrightText: 2018-2022, Markus Minichmayr <markus@tapkey.com>
SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
======================================================================*/
#ifndef TESTMALLOC_H
#define TESTMALLOC_H
#include <stdint.h>
#include "libical_ical_export.h"
struct testmalloc_statistics {
int malloc_cnt;
int realloc_cnt;
int free_cnt;
int malloc_failed_cnt;
int realloc_failed_cnt;
int free_failed_cnt;
size_t mem_allocated_max;
size_t mem_allocated_current;
int blocks_allocated;
};
/** Allocates the specified amount of memory and returns a pointer to the allocated memory.
* Memory allocated using this function must be freed using test_free().
* The number of allocations that can be made using this function can be limited via
* testmalloc_set_max_successful_allocs().
*/
LIBICAL_ICAL_EXPORT void *test_malloc(size_t size);
/** Resizes the specified buffer.
* Can only be used with memory that has previously been allocated using test_malloc().
*/
LIBICAL_ICAL_EXPORT void *test_realloc(void *p, size_t size);
/** Frees a block of memory that has previously been allocated via the test_malloc() function. Specifying memory that
* has not been allocated via test_malloc() causes an assertion.
*/
LIBICAL_ICAL_EXPORT void test_free(void *p);
/** Resets the memory management statistics and sets the number of successful
* allocations limit to infinite.
*/
LIBICAL_ICAL_EXPORT void testmalloc_reset();
/** Sets the maximum number of malloc or realloc attemts that will succeed. If
* the number is negative, no limit will be applied.
*/
LIBICAL_ICAL_EXPORT void testmalloc_set_max_successful_allocs(int n);
/** Gets current memory allocation statistics. */
LIBICAL_ICAL_EXPORT void testmalloc_get_statistics(struct testmalloc_statistics *statistics);
#endif /* !TESTMALLOC_H */
|