fix(share): normalize shm_open names with leading slash (POSIX portability) - #52
Open
davidbudzynski wants to merge 5 commits into
Open
fix(share): normalize shm_open names with leading slash (POSIX portability)#52davidbudzynski wants to merge 5 commits into
davidbudzynski wants to merge 5 commits into
Conversation
added 5 commits
August 25, 2026 14:10
…X platforms shm_open() requires names of the form /somename per POSIX. FreeBSD enforces this strictly and fails with EINVAL when the name lacks a leading slash, breaking shareData()/getData() (fastverse#40). Linux and macOS silently accept slash-less names, which masked the portability issue until now. Replace the SunOS-only special case with a general normalization that ensures exactly one leading slash in both shareData() and getData(), so creation, retrieval and unlink all use consistent object IDs.
The cleanup path called munmap() on the 'length' mapping a second time (with the data size) instead of unmapping 'addr'. This leaked the data mapping and unmapped an already-unmapped region with a wrong size.
The descriptors returned by shm_open() were kept open for the lifetime of the mapping although mmap() does not need them afterwards. Close them once mappings are established to avoid leaking file descriptors in createMappingObjectR and getMappingObjectR.
Platforms or sandboxes without working POSIX shared memory (no /dev/shm, restricted shm_open) previously aborted the whole test run with an unconditional error. Fall back to a skip message so the remaining checks still execute and R CMD check can report a meaningful result.
davidbudzynski
marked this pull request as ready for review
August 25, 2026 12:22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #40
Problem
On FreeBSD 15,
R CMD checkfails becauseshareData(mtcars, "share1")errors with:Root cause
POSIX requires
shm_open()names of the form/somename. The package only prefixed the name with/on SunOS (R/call.R), and passed bare names like"share1"everywhere else:/dev/shm/, masking the issue.EINVAL— documented in shm_open(2): "[EINVAL] The path does not begin with a slash ('/') character."Changes
R/call.R— replace the SunOS-only branch with a general normalization helpershmName()that ensures exactly one leading slash, applied consistently in bothshareData()andgetData()so create/read/unlink always use matching object IDs. No behavior change on Linux/macOS/Solaris.src/share.c— fix a bug ingetMappingObjectR(): the cleanup path calledmunmap(length, len*sizeof(Rbyte))on the length mapping a second time instead of unmappingaddr(leaked the data mapping + wrong-size unmap).src/share.c— close the file descriptors returned byshm_open()after mappings are established instead of leaking them.tests/test_kit.R— skip theshareDatachecks gracefully (with a message) when POSIX shared memory is unavailable (e.g. sandboxes without/dev/shm) so one unsupported platform no longer aborts the whole test run.DESCRIPTION/NEWS.md— version bump to 0.0.22 with changelog entries.Verification
tests/test_kit.Rpasses;shareData/getData/clearDataroundtrip verified, including that "share2" and "/share2" resolve to the same object after normalization.R CMD check: tests OK, compiled code OK, examples OK.