GeezerVison is showing github.com — Add allocator functions to c-api by bschoenmaeckers · Pull Request #8168 · RustPython/RustPython
Conversation
bschoenmaeckers
commented
Jun 25, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary by CodeRabbit
-
New Features
- Added Python-compatible C API memory allocation/free entry points, including both standard and “raw” variants.
- Standard variants normalize zero-size allocation requests, while raw variants pass sizes through directly.
-
Chores
- Updated the spelling dictionary to recognize the new term introduced by these changes.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Jun 25, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 8dbf6876-848a-4092-8bc7-492a90c527dd
📥 Commits
Reviewing files that changed from the base of the PR and between ea59686 and 5e7a490.
⛔ Files ignored due to path filters (1)
Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
.cspell.dict/cpython.txt
crates/capi/Cargo.toml
crates/capi/src/lib.rs
crates/capi/src/pymem.rs
✅ Files skipped from review due to trivial changes (3)
- .cspell.dict/cpython.txt
- crates/capi/Cargo.toml
- crates/capi/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (1)
📝 Walkthrough
Walkthrough
The crate adds a new public pymem module and exports PyMem_* and PyMem_Raw* C-ABI allocation functions backed by libc.
Changes
C API pymem exports
| Layer / File(s) |
Summary |
Crate wiring crates/capi/Cargo.toml, crates/capi/src/lib.rs, .cspell.dict/cpython.txt |
libc is added as a workspace dependency, pymem is publicly exported from the crate module list, and pymem is added to the CPython cspell word list. |
PyMem FFI shims crates/capi/src/pymem.rs |
Eight exported allocation and free functions are added, with PyMem_* normalizing zero sizes before calling libc and PyMem_Raw* forwarding arguments directly. |
Sequence Diagram(s)
sequenceDiagram
participant CCaller
participant PymemRs
participant Libc
CCaller->>PymemRs: call PyMem_* or PyMem_Raw*
PymemRs->>Libc: malloc/calloc/realloc/free
Libc-->>PymemRs: allocation result or completion
PymemRs-->>CCaller: return pointer or void
Loading
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~10 minutes
Suggested reviewers
Poem
A bunny hopped through pymem night,
With libc hops, all neat and right.
PyMem_* sprang out with care,
Raw memory juggling in the air.
🐇✨
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name |
Status |
Explanation |
| Description Check |
✅ Passed |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
✅ Passed |
The title accurately summarizes the main change: adding allocator functions to the c-api. |
| Docstring Coverage |
✅ Passed |
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
| Linked Issues check |
✅ Passed |
Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check |
✅ Passed |
Check skipped because no linked issues were found for this pull request. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment @coderabbitai help to get the list of available commands.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/capi/src/pymem.rs`:
- Around line 4-15: Normalize zero-size inputs in the CPython memory wrappers so
they satisfy the C-API contract: update PyMem_Malloc, PyMem_Calloc, and
PyMem_Realloc to treat zero-byte requests as 1-byte allocations and ensure
realloc with a zero new_size does not free the block. Apply the same zero-size
normalization consistently to PyMem_RawMalloc, PyMem_RawCalloc, and
PyMem_RawRealloc so all memory entry points in pymem.rs behave the same way
instead of forwarding raw zero values directly to libc.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: a41f31dc-588b-4ce4-9d78-2a6eb0c7ed5b
📥 Commits
Reviewing files that changed from the base of the PR and between 870ad2d and bc43086.
⛔ Files ignored due to path filters (1)
Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
crates/capi/Cargo.toml
crates/capi/src/lib.rs
crates/capi/src/pymem.rs
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|