GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add allocator functions to c-api by bschoenmaeckers · Pull Request #8168 · RustPython/RustPython

Conversation

@bschoenmaeckers

@bschoenmaeckers bschoenmaeckers commented Jun 25, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Review Change Stack

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)
  • crates/capi/src/pymem.rs

📝 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

  • youknowone

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
  • X
  • Mastodon
  • Reddit
  • LinkedIn

Comment @coderabbitai help to get the list of available commands.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bschoenmaeckers
bschoenmaeckers force-pushed the c-api-mem branch from bc43086 to ea59686 Compare June 25, 2026 10:59
coderabbitai[bot]
coderabbitai Bot reviewed Jun 25, 2026
View reviewed changes

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
Comment thread crates/capi/src/pymem.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bschoenmaeckers
Add allocator functions to c-api
5e7a490
@bschoenmaeckers
bschoenmaeckers force-pushed the c-api-mem branch from ea59686 to 5e7a490 Compare June 25, 2026 11:11
ShaharNaveh
ShaharNaveh approved these changes Jun 25, 2026
View reviewed changes

@ShaharNaveh ShaharNaveh left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
youknowone
youknowone approved these changes Jun 25, 2026
View reviewed changes
@youknowone
youknowone merged commit dda5516 into RustPython:main Jun 25, 2026
26 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bschoenmaeckers
bschoenmaeckers deleted the c-api-mem branch June 25, 2026 13:34
youknowone pushed a commit that referenced this pull request Sep 16, 2026
@bschoenmaeckers
Add allocator functions to c-api (#8168)
ab3d050
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments
@youknowone youknowone youknowone approved these changes
@ShaharNaveh ShaharNaveh ShaharNaveh approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

3 participants

@bschoenmaeckers @youknowone @ShaharNaveh
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.