Skip to content

Add minimal C-api implementation that builds with Pyo3#7562

Draft
bschoenmaeckers wants to merge 137 commits into
RustPython:mainfrom
bschoenmaeckers:c-api
Draft

Add minimal C-api implementation that builds with Pyo3#7562
bschoenmaeckers wants to merge 137 commits into
RustPython:mainfrom
bschoenmaeckers:c-api

Conversation

@bschoenmaeckers
Copy link
Copy Markdown
Contributor

This is my shot at implementing a minimal Cpython compatible C-api. I've implemented the bare minimum to get the included Pyo3 example running where most of the api is stubbed. I'm not familiar with the rest of the RustPython code base so let me know what you think and where I did stupid things.

Please take extra care reviewing the pylifecycle.rs & pystate.rs files where I try to setup the RustPython interpreter.

xref #5604

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 5, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: e7f60fce-81df-43f3-a038-f9151637f2d1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

@youknowone
Copy link
Copy Markdown
Member

Could you try with hpy if you dont mind? We are looking for sustainable way

@bschoenmaeckers
Copy link
Copy Markdown
Contributor Author

Could you try with hpy if you dont mind? We are looking for sustainable way

That would require significant changes in codebase that are using the CPython api spec. I would like to explore the possibility to use the ab3/abi3t api. Would you be willing to accept that?

Copy link
Copy Markdown
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way will not work.

Just in case, the code can be generated, but I hope we carefully review the decisions. unlikely-to-happen decisions must be reviewed and justified by document(comment) the decisions.
If you are not familiar enough to the project to decide good way, please start from a smaller and simpler issue.

We only need abi3t, because we are compatible to free-threading.

We have to minimize the surface of C API. if HPy helps it, we need HPy.

Ideally c api must be very thin wrappers to RustPython features. "code" must not be included in this crate.

Comment thread crates/capi/src/object.rs Outdated
Comment thread crates/capi/src/pystate.rs Outdated
@bschoenmaeckers
Copy link
Copy Markdown
Contributor Author

Ideally c api must be very thin wrappers to RustPython features. "code" must not be included in this crate.

I wanted to create as little of modificaties to the existing code base without significant motivation. But I definitely agree with you.

Comment thread crates/capi/src/pylifecycle.rs
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[ ] lib: cpython/Lib/ctypes
[ ] test: cpython/Lib/test/test_ctypes (TODO: 10)
[x] test: cpython/Lib/test/test_stable_abi_ctypes.py

dependencies:

  • ctypes (native: _ctypes, ctypes._aix, ctypes._endian, ctypes.macholib.dyld, ctypes.macholib.dylib, ctypes.macholib.framework, importlib.machinery, itertools, nt, sys)
    • shutil (native: _winapi, errno, grp, nt, posix, pwd, sys, zlib)
    • sysconfig (native: _sysconfig, _winapi, importlib.machinery, importlib.util, os.path, sys)
    • warnings (native: _contextvars, _thread, _warnings, builtins, sys)
    • os, re, struct, subprocess, tempfile, types

dependent tests: (34 tests)

  • ctypes: test_android test_buffer test_bytes test_code test_codecs test_ctypes test_genericalias test_io test_ntpath test_os test_ssl test_venv
    • platform: test__locale test__osx_support test_asyncio test_baseexception test_builtin test_cmath test_fcntl test_math test_mimetypes test_platform test_posix test_regrtest test_shutil test_socket test_strptime test_sysconfig test_time test_winreg test_wsgiref
      • pydoc: test_enum test_pydoc
    • webbrowser: test_webbrowser

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

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.

3 participants