Skip to content
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
2 changes: 1 addition & 1 deletion src/copy2shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ SEXP allocate_from_shm(SEXP name, SEXP type, SEXP length, SEXP size,
#else
// used on macOS, which reports the size in multiples of page size
long pagesize = sysconf(_SC_PAGESIZE);
size_t pages = (size_t) asReal(size) / pagesize + 1;
size_t pages = ((size_t) asReal(size) - 1) / pagesize + 1;

if (sb.st_size != pages * pagesize) {
close(fd);
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test-copy2shm.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,26 @@ test_that("MADV_HUGEPAGE does not cause issues", {
expect_identical(allocate_from_shm(copy2shm(1:10, gen_posix_name())), 1:10)
options(opt_bak)
})

test_that("allocate_from_shm works close to page size boundary", {
skip_on_os("windows")

PAGESIZE = system2("getconf", "PAGESIZE", stdout = TRUE)
skip_if(!is.null(attr(PAGESIZE, "status")))
page_size <- as.integer(PAGESIZE)
shm_name <- gen_posix_name()

# estimate header size
x <- as.raw(rep(0, page_size))
s <- copy2shm(x, shm_name)
header_size <- s[["size"]] - page_size
allocate_from_shm(s)

expect_no_error(
for (i in seq(-64, 64, 8)) {
x <- as.raw(rep(0, page_size - header_size + i))
s <- copy2shm(x, shm_name)
allocate_from_shm(s)
}
)
})
Loading