tree-wide: get rid of most uses of ALIGN_PTR
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.
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "memory-util.h"
|
||||
#include "static-destruct.h"
|
||||
|
||||
void static_destruct_impl(const StaticDestructor *start, const StaticDestructor *end) {
|
||||
if (!start)
|
||||
return;
|
||||
|
||||
for (const StaticDestructor *d = ALIGN_PTR(start); d < end; d = ALIGN_PTR(d + 1))
|
||||
for (const StaticDestructor *d = start; d < end; d++)
|
||||
switch (d->type) {
|
||||
case STATIC_DESTRUCTOR_SIMPLE:
|
||||
d->simple.destroy(d->simple.data);
|
||||
|
||||
@@ -44,6 +44,8 @@ typedef struct StaticDestructor {
|
||||
};
|
||||
} StaticDestructor;
|
||||
|
||||
assert_cc(sizeof(StaticDestructor) % sizeof(void*) == 0);
|
||||
|
||||
#define STATIC_DESTRUCTOR_REGISTER(variable, func) \
|
||||
_STATIC_DESTRUCTOR_REGISTER(UNIQ, variable, func)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user