Skip to content

Add memoryview support to c-api#8240

Merged
youknowone merged 1 commit into
RustPython:mainfrom
bschoenmaeckers:c-api-memoryview
Jul 9, 2026
Merged

Add memoryview support to c-api#8240
youknowone merged 1 commit into
RustPython:mainfrom
bschoenmaeckers:c-api-memoryview

Conversation

@bschoenmaeckers

@bschoenmaeckers bschoenmaeckers commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added support for creating Python memory views from existing objects.
    • Exposed a new memory view type check for use by the C-API layer.
  • Tests

    • Added coverage to verify memory views can be created from bytes and return the original data correctly.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

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: e471bd3c-748b-4176-b173-b089b5c52e71

📥 Commits

Reviewing files that changed from the base of the PR and between 6a118b3 and b5be40e.

📒 Files selected for processing (2)
  • crates/capi/src/lib.rs
  • crates/capi/src/memoryobject.rs

📝 Walkthrough

Walkthrough

Adds a new memoryobject module to the capi crate, exposing the PyMemoryView_FromObject unsafe extern "C" function that converts a raw PyObject pointer into a PyMemoryView, along with a PyMemoryView_Check helper and an accompanying test.

Changes

Memoryview C-API

Layer / File(s) Summary
Module registration and PyMemoryView_FromObject implementation
crates/capi/src/lib.rs, crates/capi/src/memoryobject.rs
Adds pub mod memoryobject; export and implements PyMemoryView_FromObject, which wraps object-to-memoryview conversion via with_vm, plus PyMemoryView_Check via define_py_check! and a test validating bytes-to-memoryview-to-bytes round-tripping.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: youknowone, ShaharNaveh

🚥 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 clearly matches the main change: adding memoryview support to the C API.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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.

@youknowone youknowone merged commit bf98131 into RustPython:main Jul 9, 2026
26 checks passed
@bschoenmaeckers bschoenmaeckers deleted the c-api-memoryview branch July 9, 2026 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants