From d92618a82c23ba4dd1db8d7b650ffd0c34cc8be3 Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Fri, 15 Dec 2023 14:44:33 -0500 Subject: [PATCH] Prefer aligned_alloc over posix_memalign aligned_alloc is more cleaner and portable. --- src/io.c | 5 +---- tests/dispatch_io.c | 2 +- tests/dispatch_read2.c | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/io.c b/src/io.c index e31e28c82..70c6721be 100644 --- a/src/io.c +++ b/src/io.c @@ -2374,10 +2374,7 @@ _dispatch_operation_perform(dispatch_operation_t op) } op->buf = _aligned_malloc(op->buf_siz, siInfo.dwPageSize); #else - err = posix_memalign(&op->buf, (size_t)PAGE_SIZE, op->buf_siz); - if (err != 0) { - goto error; - } + op->buf = aligned_alloc((size_t)PAGE_SIZE, op->buf_siz) #endif _dispatch_op_debug("buffer allocated", op); } else if (op->direction == DOP_DIR_WRITE) { diff --git a/tests/dispatch_io.c b/tests/dispatch_io.c index fbfcb6055..a5a1cea67 100644 --- a/tests/dispatch_io.c +++ b/tests/dispatch_io.c @@ -398,7 +398,7 @@ test_async_read(char *path, size_t size, int option, dispatch_queue_t queue, buffer = _aligned_malloc(size, si.dwPageSize); #else size_t pagesize = (size_t)sysconf(_SC_PAGESIZE); - posix_memalign((void **)&buffer, pagesize, size); + buffer = aligned_alloc(pagesize, size); #endif ssize_t r = dispatch_test_fd_read(fd, buffer, size); if (r == -1) { diff --git a/tests/dispatch_read2.c b/tests/dispatch_read2.c index 0e4535961..401fb4f62 100644 --- a/tests/dispatch_read2.c +++ b/tests/dispatch_read2.c @@ -91,7 +91,7 @@ dispatch_read2(dispatch_fd_t fd, buffer = _aligned_malloc(bufsiz, pagesize); #else size_t pagesize = (size_t)sysconf(_SC_PAGESIZE); - posix_memalign((void **)&buffer, pagesize, bufsiz); + buffer = aligned_alloc(pagesize, bufsiz); #endif ssize_t actual = dispatch_test_fd_read(fd, buffer, bufsiz); if (actual == -1) {