Repository navigation
Consistent shm interface - #32
Merged
Merged
Conversation
C (dao.c/dao.h): introduce daoShmCreate/daoShmOpen/daoShmSetData/ daoShmGetData/... as the primary, better-named API, grouped by create / open-close / write / read / wait-synchronize. The old daoShmImageCreate/daoShmShm2Img/daoShmImage2Shm/... names are kept as thin forwarders for existing code, so nothing that already links against libdao breaks. Also gives daoShmImageCreateSem, previously declared in dao.h but never defined, a real implementation. Remove daoShm.h/daoShm.hpp's C sibling: unused anywhere in the repo, declared functions with signatures that no longer matched dao.c, and a stale lastNbArray[512] (the real struct is 2024). Python (daoShm.py): ctypes bindings now call the new C names, with argument order fixed to match. Public API (the `shm` class) is unchanged. Added README.md and example_shm.py. Julia (dao.jl): ccall wrappers renamed to match. Also fixes two real bugs found while doing this: IMAGE_METADATA.lastNbArray was declared as 512 elements against the real 2024, and both IMAGE and IMAGE_METADATA were missing trailing FIFO fields the C library writes to, meaning Julia was under-allocating the buffer it hands to C. Added a dao.close(), which didn't exist before. Added README.md and example_basic.jl; folded the old bare README stub into it. MATLAB (daomex.c/daoShm.m): calls renamed to match, one argument order fixed. Added close_shm/daoShm.close(), which didn't exist before - shm_init malloc'd an IMAGE and never freed it or called daoShmClose. Fixed a related bug that surfaced only once close was exercised: shm_init used malloc instead of calloc, so daoShmClose's free() calls on semReadPID/semWritePID ran against garbage pointers. Added README.md and example_basic.m; folded the old bare README stub into it. Removed the previously-committed compiled daomex.mex binary and added .gitignore for it. Rust: was an unbuilt stub (main.rs was literally "Hello, world!"); the existing build.rs/wrapper.h/Cargo.toml scaffold had real bugs (wrapper.h pointed at a build/include/dao.h path waf never creates, Cargo.toml had an invalid [build] rustflags block and bindgen in the wrong dependency section). Fixed the plumbing and added a safe Shm wrapper (src/lib.rs) over bindgen-generated bindings from the real dao.h, so the struct layout can't drift the way it did in Julia. main.rs is now a runnable example. Added README.md and .gitignore for target/ and Cargo.lock. Tested end-to-end (create/write/read/reopen/close) against a fresh build of libdao: Python and Julia directly, MATLAB via Octave/ mkoctfile, Rust via cargo build/run.
davetbarr
reviewed
Sep 24, 2026
davetbarr
left a comment
Collaborator
There was a problem hiding this comment.
Looks good ready to merge
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.
Summary
Adds a clearer primary API for daoShm in C and uses it from every language binding. The old API is kept: old C function names still work, so existing code keeps building and linking.
C library (
dao.h/dao.c)New primary functions, grouped by what they do:
daoShmCreate,daoShmCreate1D,daoShmCreateFifo,daoShmCreateSemdaoShmOpen,daoShmClosedaoShmSetData,daoShmSetDataQuiet,daoShmSetDataPart,daoShmSetDataPartFinalizedaoShmGetData,daoShmGetDataAt,daoShmGetDataNext,daoShmResetReadTail,daoShmCheckOverwritedaoShmWaitData,daoShmWaitSem,daoShmWaitSemTimeout,daoShmWaitCounter,daoShmWaitTargetCounter,daoShmPostSem,daoShmPostSemAlldaoShmImageCreate,daoShmShm2Img,daoShmImage2Shm,daoShmInit1D, ...) keeps its signature and now calls the new function. No struct, typedef or#definechanged indao.h, so theIMAGElayout is unchanged.daoShmImageCreateSemwas declared indao.hbut never defined. It now has an implementation.include/daoShm.h. Nothing in the repo used it, its signatures no longer matcheddao.c, and it had an out-of-datelastNbArray[512](the real size is 2024). Code that included it should includedao.h.daoShm.hppis unaffected.Python
shmclass API is unchanged.README.mdandexample_shm.py.Julia
ccallwrappers renamed to the new C names.IMAGE_METADATA.lastNbArraywas declared with 512 elements instead of 2024, and bothIMAGEandIMAGE_METADATAwere missing the trailing FIFO fields. Julia was passing C a buffer that was too small.dao.close().README.mdandexample_basic.jl, replacing the old one-line README.MATLAB
close_shm/daoShm.close(). Before this,shm_initallocated anIMAGEthat was never freed or closed.shm_initusedmallocinstead ofcalloc, sodaoShmClosecalledfree()on uninitialisedsemReadPID/semWritePIDpointers.daomex.mexbinary and added a.gitignorefor it.README.mdandexample_basic.m.Rust
main.rsonly printed "Hello, world!"). This PR fixes its build setup:wrapper.hnow points to the realdao.h.[build] rustflagsblock inCargo.toml.bindgenis now a build dependency.Shmwrapper (src/lib.rs). It uses bindings that bindgen generates fromdao.h, so the struct layout can't get out of sync with C the way Julia's did.main.rsis now a runnable example. AddedREADME.mdand a.gitignore.Testing
Tested create / write / read / reopen / close against a fresh build of libdao:
mkoctfilecargo build/cargo runImpact on existing code
daoShm*names: no changes needed.daoShm.h: switch todao.h. daoBase, daoHw and daoTools don't include it.close()are behaviour fixes. Existing scripts should still work.