1 // A shared library
2 #ifndef _GNU_SOURCE
3 #define _GNU_SOURCE
4 #endif
5 #ifndef STATIC
6 #include <libcwd/sys.h>
7 #include "alloctag_debug.h"
8 #endif
9 #include <cstdlib>
10 
static_test_symbol(void)11 static void* static_test_symbol(void)
12 {
13   void* ptr = malloc(300);
14 #ifndef STATIC
15   AllocTag(ptr, "Allocated inside static_test_symbol");
16 #endif
17   return ptr;
18 }
19 
global_test_symbol(bool do_static)20 void* global_test_symbol(bool do_static)
21 {
22   if (do_static)
23     return static_test_symbol();
24   void* ptr = malloc(310);
25 #ifndef STATIC
26   AllocTag(ptr, "Allocated inside global_test_symbol");
27 #endif
28   return ptr;
29 }
30 
realloc1000_no_AllocTag(void * p)31 void* realloc1000_no_AllocTag(void* p)
32 {
33   return realloc(p, 1000);
34 }
35 
realloc1000_with_AllocTag(void * p)36 void* realloc1000_with_AllocTag(void* p)
37 {
38   void* res = realloc(p, 1000);
39 #ifndef STATIC
40   AllocTag(res, "realloc1000_with_AllocTag");
41 #endif
42   return res;
43 }
44 
new1000(size_t s)45 void* new1000(size_t s)
46 {
47   char* res = new char[s];
48 #ifndef STATIC
49   AllocTag(res, "new1000");
50 #endif
51   return res;
52 }
53 
54