Skip to content

MOD-10248 - Less restrictive Rust allocator shim#6367

Merged
DarthB merged 2 commits intomasterfrom
less-restrictive-allocator-shims
Jun 24, 2025
Merged

MOD-10248 - Less restrictive Rust allocator shim#6367
DarthB merged 2 commits intomasterfrom
less-restrictive-allocator-shims

Conversation

@DarthB
Copy link
Contributor

@DarthB DarthB commented Jun 24, 2025

What is this?

We use the allocator shims to ensure that we have the same allocators when running benchmarks that compare the Rust and C implementations. This will also be used in Rust Unit tests, which link to C Code.

Why do we need this

The mempool_t C-code uses zero as an argument for' malloc', e.g., This PR fixes crashes that mempool_t is called from in Rust benchmarks or unit tests.

It is an extraction of: #6342

Describe the changes

Before this PR we panicked if the allocation functions in Rust were called with a zero size. However, that is too restrictive: The C standard permits this and leaves it open to the implementer to decide whether to return a nullptr or an actual address. The standard only states that the a pointer returned by malloc called with size zero must never be dereferenced.

We return a nullptr if size or count is a zero argument from now on.

C-Standard

Upon successful completion with size not equal to 0, malloc() shall return a pointer to the allocated space. If size is 0, either a null pointer or a unique pointer that can be successfully passed to free() shall be returned. Otherwise, it shall return a null pointer and set errno to indicate the error.

Mark if applicable

  • This PR introduces API changes
  • This PR introduces serialization changes

LukeMathWalker
LukeMathWalker previously approved these changes Jun 24, 2025
@codecov
Copy link

codecov bot commented Jun 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.88%. Comparing base (f0ecb9e) to head (242513e).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6367      +/-   ##
==========================================
+ Coverage   88.77%   88.88%   +0.11%     
==========================================
  Files         250      250              
  Lines       41497    41533      +36     
  Branches     3632     3668      +36     
==========================================
+ Hits        36837    36916      +79     
+ Misses       4611     4568      -43     
  Partials       49       49              
Flag Coverage Δ
flow 81.33% <ø> (-0.14%) ⬇️
unit 47.11% <100.00%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DarthB DarthB changed the title Less restrictive Rust allocator shim MOD-10248 - Less restrictive Rust allocator shim Jun 24, 2025
@DarthB DarthB added this pull request to the merge queue Jun 24, 2025
Merged via the queue into master with commit d93557e Jun 24, 2025
15 checks passed
@DarthB DarthB deleted the less-restrictive-allocator-shims branch June 24, 2025 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants