This bothered me for a while, but I didn't think too much about it and just copied the existing usage pattern. But it really doesn't make sense. We expect the compiler to align the section properly. But if it didn't align it, applying alignment after the fact would just cause our pointer to point to the middle of the structure. That'd be even worse than a misaligned pointer. Similarly, when doing pointer arithmetic, p++ should really result in a value with the appropriate alignment. This is the basic principle of C pointer addition. So we really shouldn't try to adjust the pointer ourselves. At most, we can assert that it is indeed aligned in tests.
23 lines
667 B
C
23 lines
667 B
C
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
|
|
#include "static-destruct.h"
|
|
|
|
void static_destruct_impl(const StaticDestructor *start, const StaticDestructor *end) {
|
|
if (!start)
|
|
return;
|
|
|
|
for (const StaticDestructor *d = start; d < end; d++)
|
|
switch (d->type) {
|
|
case STATIC_DESTRUCTOR_SIMPLE:
|
|
d->simple.destroy(d->simple.data);
|
|
break;
|
|
|
|
case STATIC_DESTRUCTOR_ARRAY:
|
|
array_cleanup(&d->array);
|
|
break;
|
|
|
|
default:
|
|
assert_not_reached();
|
|
}
|
|
}
|