summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Minichmayr <markus@tapkey.com>2022-02-25 20:44:13 +0100
committerMarkus Minichmayr <markus@tapkey.com>2022-02-25 20:50:08 +0100
commitdc203c3d92d25e23e7f6442756e37a8945b18e30 (patch)
treee49a58d16c6aca915db203184fa31b9babf47f2f
parente5f8690a34a8effbcc034f0a3009e30f9a47509e (diff)
downloadlibical-git-dc203c3d92d25e23e7f6442756e37a8945b18e30.tar.gz
test-malloc - Export functions and access global members only via getters to allow accessing the same statistics from across multiple modules in case of dynamic linking. Previously the test executables couldn't access the statistics generated withing the libical shared library, because it didn't share the global statistics variable.
-rw-r--r--src/test/test-malloc.c7
-rw-r--r--src/test/test-malloc.h17
2 files changed, 17 insertions, 7 deletions
diff --git a/src/test/test-malloc.c b/src/test/test-malloc.c
index 55e5a097..3c61d1ee 100644
--- a/src/test/test-malloc.c
+++ b/src/test/test-malloc.c
@@ -177,3 +177,10 @@ void testmalloc_reset() {
void testmalloc_set_max_successful_allocs(int n) {
global_testmalloc_remaining_attempts = n;
}
+
+void testmalloc_get_statistics(struct testmalloc_statistics* statistics) {
+
+ if (statistics) {
+ *statistics = global_testmalloc_statistics;
+ }
+}
diff --git a/src/test/test-malloc.h b/src/test/test-malloc.h
index f92055d0..a68df8aa 100644
--- a/src/test/test-malloc.h
+++ b/src/test/test-malloc.h
@@ -20,6 +20,8 @@ FILE: test-malloc.h
#include <stdint.h>
+#include "libical_ical_export.h"
+
struct testmalloc_statistics {
int malloc_cnt;
int realloc_cnt;
@@ -34,33 +36,34 @@ struct testmalloc_statistics {
int blocks_allocated;
};
-extern struct testmalloc_statistics global_testmalloc_statistics;
-
/** 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().
*/
-void *test_malloc(size_t size);
+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().
*/
-void *test_realloc(void *p, size_t size);
+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.
*/
-void test_free(void *p);
+LIBICAL_ICAL_EXPORT void test_free(void *p);
/** Resets the memory management statistics and sets the number of successful
* allocations limit to infinite.
*/
-void testmalloc_reset();
+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.
*/
-void testmalloc_set_max_successful_allocs(int n);
+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 */