mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-10 07:10:06 +00:00
(main): Run tests for different alignments.
This commit is contained in:
parent
f3e7f6080f
commit
a602757647
@ -28,27 +28,37 @@ verbose_free (void *buf)
|
|||||||
int
|
int
|
||||||
main (void)
|
main (void)
|
||||||
{
|
{
|
||||||
struct obstack obs;
|
|
||||||
int i;
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
int align = 2;
|
||||||
|
|
||||||
obstack_init (&obs);
|
while (align <= 64)
|
||||||
obstack_alignment_mask (&obs) = ALIGN_MASK;
|
|
||||||
/* finish an empty object to take alignment into account */
|
|
||||||
obstack_finish (&obs);
|
|
||||||
|
|
||||||
/* let's allocate some objects and print their addresses */
|
|
||||||
for (i = 15; i > 0; --i)
|
|
||||||
{
|
{
|
||||||
void *obj = obstack_alloc (&obs, OBJECT_SIZE);
|
struct obstack obs;
|
||||||
|
int i;
|
||||||
|
int align_mask = align - 1;
|
||||||
|
|
||||||
printf ("obstack_alloc (%u) => %p \t%s\n", OBJECT_SIZE, obj,
|
printf ("\n Alignment mask: %d\n", align_mask);
|
||||||
((uintptr_t) obj & ALIGN_MASK) ? "(not aligned)" : "");
|
|
||||||
result |= ((uintptr_t) obj & ALIGN_MASK) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* clean up */
|
obstack_init (&obs);
|
||||||
obstack_free (&obs, 0);
|
obstack_alignment_mask (&obs) = align_mask;
|
||||||
|
/* finish an empty object to take alignment into account */
|
||||||
|
obstack_finish (&obs);
|
||||||
|
|
||||||
|
/* let's allocate some objects and print their addresses */
|
||||||
|
for (i = 15; i > 0; --i)
|
||||||
|
{
|
||||||
|
void *obj = obstack_alloc (&obs, OBJECT_SIZE);
|
||||||
|
|
||||||
|
printf ("obstack_alloc (%u) => %p \t%s\n", OBJECT_SIZE, obj,
|
||||||
|
((uintptr_t) obj & align_mask) ? "(not aligned)" : "");
|
||||||
|
result |= ((uintptr_t) obj & align_mask) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* clean up */
|
||||||
|
obstack_free (&obs, 0);
|
||||||
|
|
||||||
|
align <<= 1;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user