Repository navigation
Conversation
No libc malloc/calloc/realloc/free is left in the library. What replaces it depends on how far the pointer has to travel, and that ladder is documented at the top of the new src/helpers/raw_owned.rs. - ffiter_internal owns its per-column work arrays in an AlignedBytes/Vec arena instead of calloc'ing seventeen of them. cols[jj].array still receives a raw pointer, so no ABI change, but the buffers are released on every path and the sixteen allocations that stored their result unchecked now report MEMORY_ALLOCATION. - The ALLOCATIONS map moved behind helpers::raw_owned. It records the element size and alignment as well as the length and capacity, and there is no "assume the length" fallback: an unregistered pointer is reported in debug builds and leaked rather than freed on a guessed Layout. - The expression engine's node buffers come from the Rust allocator. NodeValue::Buffer carries an Owned saying how the block is released, so free_buffer hands back the right Layout, releases both of Allocate_Ptrs' allocations together, and cannot free a buffer a column node only borrows. The FREE! macro is gone and the Bits column arrays are Vecs on DataInfo. Fixes found on the way: - Compressed files were never recognised. The two-byte magic numbers for GZIP, PACK, LZW and LZH were transpiled from the C's octal escapes as if they were decimal, so file_is_compressed and mem_compress_open rejected every .gz, .Z and .bz2 file; and file_is_compressed read those bytes with a bare read(), treating a short read as "not compressed". - Memory-file buffers from mem_createmem (a Vec) were resized with the C realloc by stdin2mem, both compressed-open paths and the decompression grow callback. They route through owned_realloc now, and stdin2mem publishes the new address as it grows rather than leaving a stale one for its own error path to free. - Two frees on a guessed layout: fits_read_wcstab released an nelem-element f64 array as if it held ndim elements, and FITSfile::drop freed the six tile* pointers that TILE_STRUCTS owns. The latter is the double free that had test_copy_within_same_file ignored; it is un-ignored and passes. FITSfile's filename, headstart and tableptr are untouched: they are public C-ABI fields and keep their types and the struct layout. Verified with cargo test (35 binaries), the i686 check, clippy, rustdoc, and three scoped miri runs over every module touched -- 105, 218 and 174 tests, all clean. One new test is cfg_attr(miri, ignore) because the bzip2 path goes through fdopen.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #135 +/- ##
==========================================
+ Coverage 74.51% 74.72% +0.20%
==========================================
Files 96 97 +1
Lines 186951 186927 -24
==========================================
+ Hits 139306 139676 +370
+ Misses 47645 47251 -394 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Closes the
Remove use a malloc and freeTODO. No libcmalloc/calloc/realloc/freeis left in the library — the only survivors are five lines in cfileio's
#[cfg(test)]module, where the test deliberately plays the part of a C caller supplying its own
allocator through
fits_create_memfile, and so must free with the same one.The ladder
Layoutis the right primitive, but hand-rolling it at thirty call sites is a stepbackwards:
Vec<T>andBox<[T]>areLayout::array::<T>(n)with the bookkeepingalready correct. It ends up used in exactly three places. The reasoning is documented at
the top of the new
src/helpers/raw_owned.rs, andTRANSPILING.mdpoints at it so thenext transpile doesn't have to re-derive it.
Vec<T>/Box<[T]>, RAIIVec, takeas_mut_ptr()at the point of useBox<[T]>+slice_from_raw_parts_mutWhat changed
ffiter_internalowns its per-column work arrays in anAlignedBytes/Vecarenainstead of
callocing seventeen of them.cols[jj].arraystill receives a raw pointer,so no ABI change, but the buffers are released on every path (the C leaked them on its
early returns) and the sixteen allocations that stored their result without a null check
are now fallible and report
MEMORY_ALLOCATION.ALLOCATIONSmap moved behindhelpers::raw_owned. It records the element sizeand alignment as well as the length and capacity, and there is no "assume the length"
fallback any more: an unregistered pointer is reported in debug builds and leaked rather
than freed on a guessed
Layout.NodeValue::Buffercarries an
Owneddescribing how the block is released —Nonefor a column node'sborrowed view into
varData,Block(Layout)for a numeric row buffer,BlockAndTextfor the row-pointer array plus the character block behind it. So
free_bufferhands backthe right
Layout, releases both ofAllocate_Ptrs' allocations together (four callsites no longer have to free the character block by hand first), and structurally cannot
free a buffer a column node only borrows — an invariant that was previously maintained by
every caller remembering to write
if node.is_computed(). TheFREE!macro is gone.FITSfile'sfilename,headstartandtableptrare untouched. They are public C-ABIfields; their types and the struct layout are unchanged. Only how the block is reclaimed
moved, from an open-coded
remove()-or-guess tofree_registered.Bugs found on the way
None of these were what I went looking for.
The two-byte magic numbers for GZIP, PACK, LZW and LZH were transpiled from the C's
octal escapes (
"\037\213") as if they were decimal, sofile_is_compressedandmem_compress_openrejected every.gz,.Zand.bz2file — the wholecompress://driver was unreachable. And
file_is_compressedread those two bytes with a bareread(), which is allowed to come back short, and treated a short read as "notcompressed". Miri caught the second one.
mem_creatememallocates the memory-file buffer as aVec,but
stdin2mem, both compressed-open paths and the decompression grow callback resizedit with raw
libc::realloc— exactly whatowned_realloc's own doc comment says mustnot happen. They route through
owned_reallocnow, andstdin2mempublishes the newaddress as it grows instead of leaving a stale one behind for its own error path to free.
fits_read_wcstabreleased annelem-elementf64array as if it heldndimelements —
ndimis the number of axes, not the element count.FITSfile::dropfreed the sixtile*pointers thatTILE_STRUCTSowns. This isthe double free that had
test_copy_within_same_file#[ignore]d; it is un-ignored andpasses, including under miri.
New coverage: two tests open a compressed file end to end through the
compress://driver,one of them sized so the driver's buffer estimate overshoots and the trim path runs — that
is the regression test for the cross-allocator free.
Verification
cargo testgreen across all 35 binaries. 32-biti686check clean. No new clippywarnings (the 82 pre-existing doc-indent ones are unchanged). rustdoc and
check_docs.pyclean. Miri ran in three scoped passes over everything touched — 105, 218 and 174 tests —
all clean: no UB, no leaks, no unsupported operations. One new test is
#[cfg_attr(miri, ignore)]because the bzip2 path goes throughfdopen, the gapTODO.mdalready documents.
The full ~5h miri suite has not been run;
TODO.mdasks for one after changes toaliasing-sensitive code, so that is worth doing before release.