riscv: Fix feenvupdate with FE_DFL_ENV (BZ 31022)
[glibc.git] / malloc / tst-obstack.c
blobd80f471fa03103736e58293333a99e333d8e0fea
1 #include <obstack.h>
2 #include <stdint.h>
3 #include <stdio.h>
4 #include <stdlib.h>
6 #define obstack_chunk_alloc verbose_malloc
7 #define obstack_chunk_free verbose_free
8 #define ALIGN_BOUNDARY 64
9 #define ALIGN_MASK (ALIGN_BOUNDARY - 1)
10 #define OBJECT_SIZE 1000
12 static void *
13 verbose_malloc (size_t size)
15 void *buf = malloc (size);
16 printf ("malloc (%zu) => %p\n", size, buf);
17 return buf;
20 static void
21 verbose_free (void *buf)
23 printf ("free (%p)\n", buf);
24 free (buf);
27 static int
28 do_test (void)
30 int result = 0;
31 int align = 2;
33 while (align <= 64)
35 struct obstack obs;
36 int i;
37 int align_mask = align - 1;
39 printf ("\n Alignment mask: %d\n", align_mask);
41 obstack_init (&obs);
42 obstack_alignment_mask (&obs) = align_mask;
43 /* finish an empty object to take alignment into account */
44 obstack_finish (&obs);
46 /* let's allocate some objects and print their addresses */
47 for (i = 15; i > 0; --i)
49 void *obj = obstack_alloc (&obs, OBJECT_SIZE);
51 printf ("obstack_alloc (%u) => %p \t%s\n", OBJECT_SIZE, obj,
52 ((uintptr_t) obj & align_mask) ? "(not aligned)" : "");
53 result |= ((uintptr_t) obj & align_mask) != 0;
56 /* clean up */
57 obstack_free (&obs, 0);
59 align <<= 1;
62 return result;
65 #define TEST_FUNCTION do_test ()
66 #include "../test-skeleton.c"