Skip to content

Replace valloc() usages in portable code #405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2320,7 +2320,10 @@ _dispatch_operation_perform(dispatch_operation_t op)
}
op->buf = _aligned_malloc(op->buf_siz, siInfo.dwPageSize);
#else
op->buf = valloc(op->buf_siz);
err = posix_memalign(&op->buf, (size_t)PAGE_SIZE, op->buf_siz);
if (err != 0) {
goto error;
}
#endif
_dispatch_op_debug("buffer allocated", op);
} else if (op->direction == DOP_DIR_WRITE) {
Expand Down
4 changes: 3 additions & 1 deletion tests/dispatch_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ test_async_read(char *path, size_t size, int option, dispatch_queue_t queue,
case DISPATCH_ASYNC_READ_ON_CONCURRENT_QUEUE:
case DISPATCH_ASYNC_READ_ON_SERIAL_QUEUE:
dispatch_async(queue, ^{
char* buffer = valloc(size);
char* buffer = NULL;
size_t pagesize = (size_t)sysconf(_SC_PAGESIZE);
posix_memalign((void **)&buffer, pagesize, size);
ssize_t r = read(fd, buffer, size);
if (r == -1) {
test_errno("async read error", errno, 0);
Expand Down
4 changes: 3 additions & 1 deletion tests/dispatch_read2.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ dispatch_read2(dispatch_fd_t fd,
__block int err = 0;
dispatch_source_set_event_handler(reader, ^{
const ssize_t bufsiz = 1024*512; // 512KB buffer
char *buffer = valloc(bufsiz);
char *buffer = NULL;
size_t pagesize = (size_t)sysconf(_SC_PAGESIZE);
posix_memalign((void **)&buffer, pagesize, bufsiz);
ssize_t actual = read(fd, buffer, bufsiz);
if (actual == -1) {
err = errno;
Expand Down