summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2023-01-27 18:18:55 -0800
committerGitHub <noreply@github.com>2023-01-27 18:18:55 -0800
commit7ea5bcd0f05cbcb0621a6ce0e6312a97bbb4d13e (patch)
tree83dd80d7a5a6143775cd51b5ec1607948f383153
parent75f608b0da534fbd0652bf97e34fb8da31059593 (diff)
parent8f1f38224d1136d920156be08f3548fa3c9ad83b (diff)
downloadlibpcap-7ea5bcd0f05cbcb0621a6ce0e6312a97bbb4d13e.tar.gz
Merge pull request #1158 from jrtc27/gencode-alignment
gencode: Unify NetBSD and non-NetBSD alignment, and make more general
-rw-r--r--gencode.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/gencode.c b/gencode.c
index 87a6e962..59201aac 100644
--- a/gencode.c
+++ b/gencode.c
@@ -232,6 +232,26 @@ struct chunk {
void *m;
};
+/*
+ * A chunk can store any of:
+ * - a string (guaranteed alignment 1 but present for completeness)
+ * - a block
+ * - an slist
+ * - an arth
+ * For this simple allocator every allocated chunk gets rounded up to the
+ * alignment needed for any chunk.
+ */
+struct chunk_align {
+ char dummy;
+ union {
+ char c;
+ struct block b;
+ struct slist s;
+ struct arth a;
+ } u;
+};
+#define CHUNK_ALIGN (offsetof(struct chunk_align, u))
+
/* Code generator state */
struct _compiler_state {
@@ -600,13 +620,8 @@ newchunk_nolongjmp(compiler_state_t *cstate, size_t n)
int k;
size_t size;
-#ifndef __NetBSD__
- /* XXX Round up to nearest long. */
- n = (n + sizeof(long) - 1) & ~(sizeof(long) - 1);
-#else
- /* XXX Round up to structure boundary. */
- n = ALIGN(n);
-#endif
+ /* Round up to chunk alignment. */
+ n = (n + CHUNK_ALIGN - 1) & ~(CHUNK_ALIGN - 1);
cp = &cstate->chunks[cstate->cur_chunk];
if (n > cp->n_left) {