Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
54156f6
export c api
bschoenmaeckers Apr 4, 2026
2250a1c
type mapping v1
bschoenmaeckers Apr 5, 2026
bc96211
Type mapping v2
bschoenmaeckers Apr 5, 2026
46307f6
Implement type flags
bschoenmaeckers Apr 5, 2026
b08d41a
Implement `PyUnicode_FromStringAndSize`
bschoenmaeckers Apr 5, 2026
34c13f4
Do not use `C-unwind`
bschoenmaeckers Apr 5, 2026
24b2c63
implement `PyLong_AsLong`
bschoenmaeckers Apr 5, 2026
384b378
Add `with_vm` helper
bschoenmaeckers Apr 5, 2026
f49e859
Move `PyThreadState` to `pystate.rs`
bschoenmaeckers Apr 5, 2026
e18eef7
Basic multi-threading support
bschoenmaeckers Apr 5, 2026
565bf5e
Cleanup
bschoenmaeckers Apr 5, 2026
85b2928
Attach thread in `Py_InitializeEx`
bschoenmaeckers Apr 5, 2026
c603d37
Map RustPython type flags to CPython type flags
bschoenmaeckers Apr 7, 2026
cee9403
Use `*const Py<PyType>` instead of `*mut PyTypeObject`
bschoenmaeckers Apr 7, 2026
0a50fcc
Implement `PyUnicode_AsUTF8AndSize`
bschoenmaeckers Apr 7, 2026
f588979
Implement `PyType_GetName`
bschoenmaeckers Apr 7, 2026
edaca0c
Implement alternative `PyLong` constructors
bschoenmaeckers Apr 7, 2026
e4c8bd7
Move `init_static_type_pointers` to `pylifecycle.rs`
bschoenmaeckers Apr 7, 2026
26c2777
Add support for `None`, `True`, `False`, `Ellipsis` & `NotImplemented`
bschoenmaeckers Apr 7, 2026
09466e2
Add support for PyBytes
bschoenmaeckers Apr 8, 2026
94cc39b
Add basic exception support
bschoenmaeckers Apr 8, 2026
2ef64d2
Add import support
bschoenmaeckers Apr 8, 2026
55b1e14
Add basic call support
bschoenmaeckers Apr 8, 2026
2a7a82e
Use pyo3 as test harness
bschoenmaeckers Apr 8, 2026
96e16b1
Fix pyo3 by correctly setting `PYO3_CONFIG_FILE`
bschoenmaeckers Apr 9, 2026
e351fb2
Fix python bool creation test
bschoenmaeckers Apr 9, 2026
2fece20
Implement `PyUnicode_EqualToUTF8AndSize`
bschoenmaeckers Apr 9, 2026
e56029d
Add `PyExc_SystemError`
bschoenmaeckers Apr 9, 2026
9702a47
Compile to dynamic lib
bschoenmaeckers Apr 9, 2026
738d4d4
Add test for static type pointers
bschoenmaeckers Apr 9, 2026
8ad7e0c
Streamline returning PyResult
bschoenmaeckers Apr 9, 2026
32faf14
Fix some clippy warning
bschoenmaeckers Apr 9, 2026
a34ced9
Use bounded channel for vm request response
bschoenmaeckers Apr 9, 2026
5a8c57b
Test creating a new (heap) exception type
bschoenmaeckers Apr 9, 2026
3dda576
Don't check for NULL in `Py_DecRef`/`Py_IncRef`
bschoenmaeckers Apr 9, 2026
a1b3af6
Add basic `PyDict` support
bschoenmaeckers Apr 9, 2026
3c7ef8f
Implement minimal tuple functions
bschoenmaeckers Apr 9, 2026
5625ba3
Implement `PyObject_Repr` & `PyObject_Str`
bschoenmaeckers Apr 9, 2026
ea45d78
Implement `PyObject_GetAttr`
bschoenmaeckers Apr 9, 2026
fcbc6b9
Implement `PyUnicode_InternInPlace`
bschoenmaeckers Apr 9, 2026
ff9d385
Add support for running python source code
bschoenmaeckers Apr 10, 2026
7b36240
Make all modules private
bschoenmaeckers Apr 10, 2026
8805658
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers Apr 10, 2026
c4b8ea3
Implement `PyErr_SetString`
bschoenmaeckers Apr 10, 2026
dc56590
Add basic support for `PyList`
bschoenmaeckers Apr 10, 2026
47ed41d
Support `PyLong_AsLong` for non `PyInt` types
bschoenmaeckers Apr 10, 2026
375a170
Add support for `PyComplex`
bschoenmaeckers Apr 10, 2026
fe8107a
Implement c_variadic `PyObject_CallMethodObjArgs`
bschoenmaeckers Apr 10, 2026
2f6fc50
Implement `PyCapsule`
bschoenmaeckers Apr 11, 2026
52442ae
Allow creating empty tuples
bschoenmaeckers Apr 11, 2026
537fc69
Implement `PyCMethod_New`
bschoenmaeckers Apr 11, 2026
62485f6
Add `PyMethodPointer` union
bschoenmaeckers Apr 11, 2026
61de6bf
Also support `NoArgs` CFunction's
bschoenmaeckers Apr 11, 2026
248ea52
Fix error return of `PyCFunction`
bschoenmaeckers Apr 11, 2026
ad0d1af
Add `PyDict` iter support
bschoenmaeckers Apr 11, 2026
d81ad21
Add more `Exception` type statics
bschoenmaeckers Apr 11, 2026
6cd7fc9
Add support for `set`, `get`, & `del` on any object
bschoenmaeckers Apr 13, 2026
d228a78
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers Apr 13, 2026
ae3f3db
Refactor `FfiResult`
bschoenmaeckers Apr 13, 2026
4d23f7c
Fix unset exception types
bschoenmaeckers Apr 13, 2026
56f3823
Add `PyBaseObject_Type` static
bschoenmaeckers Apr 13, 2026
4f6798a
Add `PyObject_SetAttr`
bschoenmaeckers Apr 13, 2026
685c4b7
Add `PyObject_GenericGetDict` & `PyObject_GenericSetDict`
bschoenmaeckers Apr 13, 2026
ac50f2b
Fix some clippy warning
bschoenmaeckers Apr 13, 2026
16e1193
Merge branch 'main' into c-api
bschoenmaeckers Apr 14, 2026
9e931f7
Add `PyObject_SetAttrString`
bschoenmaeckers Apr 14, 2026
384e15e
Add `PyObject_GC_UnTrack`
bschoenmaeckers Apr 14, 2026
09aab0a
Implement `Py_IS_TYPE`
bschoenmaeckers Apr 15, 2026
7ee1e27
Add all exception statics
bschoenmaeckers Apr 16, 2026
661e7bd
Implement `PyObject_Vectorcall`
bschoenmaeckers Apr 16, 2026
65c80c8
Add `PyObject_GetAttrString`
bschoenmaeckers Apr 16, 2026
d2c2c63
Use custom RustPython build of `PyO3`
bschoenmaeckers Apr 17, 2026
b4bc0d8
Add basic support for new classes
bschoenmaeckers Apr 17, 2026
2dc9a82
Add support for class attributes
bschoenmaeckers Apr 17, 2026
3fad7e4
Add basic support for PyO3 class methods
bschoenmaeckers Apr 20, 2026
a07b7c6
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers Apr 20, 2026
842f54d
Add `PyTuple_FromArray` & `PyTuple_Pack`
bschoenmaeckers Apr 20, 2026
2e03e5d
Add `PyFloat` support
bschoenmaeckers Apr 20, 2026
535861b
Add `Py_NewRef`
bschoenmaeckers Apr 20, 2026
1ff142b
Add `PyLong_AsUnsignedLongLong`
bschoenmaeckers Apr 20, 2026
f2e824a
Add `PyNumber_Index`
bschoenmaeckers Apr 20, 2026
59a5fa6
Fix float test
bschoenmaeckers Apr 20, 2026
b8a3646
Implement `PyTraceBack_Print`
bschoenmaeckers Apr 22, 2026
8d7b7d7
Implement `PyUnicode_AsEncodedString`
bschoenmaeckers Apr 22, 2026
708c657
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers Apr 22, 2026
646eaf7
Merge branch 'main' into c-api
bschoenmaeckers Apr 28, 2026
c49725a
Add `PyList_Append`
bschoenmaeckers Apr 28, 2026
d969389
Add type check functions
bschoenmaeckers Apr 28, 2026
d25d6c8
Add `PyObject_Call`
bschoenmaeckers Apr 28, 2026
5ea41e1
Add support for `FASTCALL`/`STATIC`/`CLASS` c functions
bschoenmaeckers Apr 28, 2026
6745ce4
Add module definition support
bschoenmaeckers Apr 28, 2026
c7b4f40
Implement `PyTuple_GetSlice`
bschoenmaeckers Apr 29, 2026
7d3e502
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers Apr 29, 2026
931bdd8
Implement `Py_GetVersion`
bschoenmaeckers Apr 29, 2026
020a5c9
Implement `PyCapsule_IsValid`
bschoenmaeckers Apr 29, 2026
efda7cc
Refactor c function trampolines
bschoenmaeckers Apr 29, 2026
88b4bbc
Implement `PyList_Insert`
bschoenmaeckers Apr 30, 2026
1a3e888
Implement `PyList_Reverse`
bschoenmaeckers Apr 30, 2026
1835268
Allow `PyBytes_FromStringAndSize` with uninitialized bytes
bschoenmaeckers May 1, 2026
0f39fa4
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers May 1, 2026
2562f9d
Add basic capi error support
bschoenmaeckers May 5, 2026
40d97ea
Add missing symbols to make tests compile again
bschoenmaeckers May 5, 2026
6b79cb5
Add `pyerrors` to dictionary
bschoenmaeckers May 5, 2026
71438c6
Return exception in `Py_GetConstantBorrowed`
bschoenmaeckers May 5, 2026
d708bfe
Remove `allow(dead_code)`
bschoenmaeckers May 5, 2026
bbf3656
Fix windows
bschoenmaeckers May 5, 2026
bccd38e
Load stdlib when calling `Py_InitializeEx`
bschoenmaeckers May 5, 2026
9e20cf7
Debug tests
bschoenmaeckers May 5, 2026
268856b
Revert "Load stdlib when calling `Py_InitializeEx`"
bschoenmaeckers May 6, 2026
8432c17
Disable tests on windows for now
bschoenmaeckers May 6, 2026
130321e
Truncate `PyType_GetFlags` to be always 32 bits
bschoenmaeckers May 6, 2026
30ac061
Add test for exception type checking
bschoenmaeckers May 6, 2026
4e4f7df
Remove subclass type flags
bschoenmaeckers May 6, 2026
9bf8c25
Update PyO3 to main branch
bschoenmaeckers May 9, 2026
a5b3e87
Add type check functions
bschoenmaeckers May 9, 2026
84f87d6
Add bool object functions
bschoenmaeckers May 9, 2026
9306c66
Add exact type check macros
bschoenmaeckers May 9, 2026
b75b430
Implement `PyExceptionClass_Check`
bschoenmaeckers May 9, 2026
f8bd659
Add self support to `PyNativeFunction`
bschoenmaeckers May 9, 2026
22985ca
Merge remote-tracking branch 'origin/main' into capi-errors
bschoenmaeckers May 9, 2026
b2c2f69
Use latest pyo3 to make test work on windows
bschoenmaeckers May 9, 2026
d18d259
Revert "Use latest pyo3 to make test work on windows"
bschoenmaeckers May 10, 2026
72e4a31
Merge branch 'capi-errors' into c-api
bschoenmaeckers May 10, 2026
0f60694
Add todo list
bschoenmaeckers May 10, 2026
2efb3b3
Update var_arg functions
bschoenmaeckers May 11, 2026
365eb11
Fix `ctypes.py_object` handling
bschoenmaeckers May 11, 2026
9363b97
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers May 12, 2026
397f6f5
Refactor `build_method_def`
bschoenmaeckers May 12, 2026
a15972b
Implement `build_method_def` for `METH_O`
bschoenmaeckers May 12, 2026
aff5c7f
Extract callable convertions from `build_method_def`
bschoenmaeckers May 12, 2026
f2b889d
Make PyMethodDef members public
bschoenmaeckers May 12, 2026
83ca45e
Add `PyCFunction_New` & `PyCFunction_NewEx`
bschoenmaeckers May 12, 2026
265991f
Fix self handling in `METH_NOARGS` functions
bschoenmaeckers May 12, 2026
93b4012
Fix handling of self in `METH_O` functions
bschoenmaeckers May 12, 2026
b3a8511
Implement `PyObject_IsSubclass` & `PyObject_IsInstance`
bschoenmaeckers May 12, 2026
e4ca8c3
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers May 12, 2026
cf7a8ef
Discard `self` on static functions
bschoenmaeckers May 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell.dict/cpython.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ pybuilddir
pycore
pyinner
pydecimal
pyerrors
Pyfunc
pylifecycle
pymain
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,15 @@ jobs:
uses: ./.github/actions/install-macos-deps

- name: run rust tests
run: cargo test --workspace ${{ env.WORKSPACE_EXCLUDES }} --features threading ${{ env.CARGO_ARGS }}
run: cargo test --workspace --exclude rustpython-capi ${{ env.WORKSPACE_EXCLUDES }} --features threading ${{ env.CARGO_ARGS }}
env:
INSTA_WORKSPACE_ROOT: ${{ github.workspace }}

- name: run c-api tests
working-directory: crates/capi
run: cargo test
if: runner.os != 'Windows' # Requires pyo3 0.29+ on Windows

- run: cargo doc --locked
if: runner.os == 'Linux'

Expand Down
18 changes: 7 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ lto = "thin"

[patch.crates-io]
parking_lot_core = { git = "https://github.com/youknowone/parking_lot", branch = "rustpython" }
pyo3-ffi = { git = "https://github.com/PyO3/pyo3" }
# REDOX START, Uncomment when you want to compile/check with redoxer
# REDOX END

Expand Down Expand Up @@ -256,7 +257,7 @@ pkcs8 = "0.10"
proc-macro2 = "1.0.105"
psm = "0.1"
pymath = { version = "0.2.0", features = ["mul_add", "malachite-bigint", "complex"] }
pyo3 = "0.28"
pyo3 = { git = "https://github.com/PyO3/pyo3" }
quote = "1.0.45"
radium = "1.1.1"
rand = "0.9"
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_ctypes/test_python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@


class PythonAPITestCase(unittest.TestCase):
# TODO: RUSTPYTHON - requires pythonapi (Python C API)
@unittest.expectedFailure
def test_PyBytes_FromStringAndSize(self):
PyBytes_FromStringAndSize = pythonapi.PyBytes_FromStringAndSize

Expand Down
8 changes: 7 additions & 1 deletion crates/capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ license.workspace = true
crate-type = ["cdylib", "rlib"]

[dependencies]
rustpython-vm = { workspace = true, features = ["threading"] }
bitflags.workspace = true
num-complex.workspace = true
rustpython-vm = { workspace = true, features = ["threading", "compiler"] }
rustpython-stdlib = {workspace = true, features = ["threading"] }

[dev-dependencies]
pyo3 = { workspace = true, features = ["auto-initialize", "abi3"] }

[features]
# Enable PyObject_CallMethodObjArgs variadic function, which is only available on nightly Rust.
nightly = []

[lints]
workspace = true

Expand Down
213 changes: 213 additions & 0 deletions crates/capi/capi_todo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
# Unimplemented C API functions

Mapping source: `pyo3-ffi/src/*.rs`, which mirrors the CPython header split used by the C API.

## `abstract.h`

RustPython C API target: `crates/capi/src/abstract_.rs`

- `PyIter_Check`
- `PyIter_NextItem`
- `PyIter_Send`
- `PyMapping_Items`
- `PyMapping_Keys`
- `PyMapping_Size`
- `PyMapping_Values`
- `PyNumber_Add`
- `PyNumber_Lshift`
- `PyNumber_Or`
- `PyNumber_Rshift`
- `PyNumber_Subtract`
- `PyObject_GetIter`
- `PyObject_Size`
- `PySequence_Check`
- `PySequence_Concat`
- `PySequence_Count`
- `PySequence_DelItem`
- `PySequence_DelSlice`
- `PySequence_GetItem`
- `PySequence_GetSlice`
- `PySequence_InPlaceConcat`
- `PySequence_InPlaceRepeat`
- `PySequence_Index`
- `PySequence_List`
- `PySequence_Repeat`
- `PySequence_SetItem`
- `PySequence_SetSlice`
- `PySequence_Size`
- `PySequence_Tuple`

## `bytearrayobject.h`

RustPython C API target: `crates/capi/src/bytearrayobject.rs` (not present yet)

- `PyByteArray_AsString`
- `PyByteArray_Check`
- `PyByteArray_FromObject`
- `PyByteArray_FromStringAndSize`
- `PyByteArray_Resize`
- `PyByteArray_Size`

## `descrobject.h`

RustPython C API target: `crates/capi/src/descrobject.rs` (not present yet)

- `PyDictProxy_New`

## `dictobject.h`

RustPython C API target: `crates/capi/src/dictobject.rs`

- `PyDict_Contains`
- `PyDict_Copy`
- `PyDict_DelItem`
- `PyDict_Items`
- `PyDict_Keys`
- `PyDict_Merge`
- `PyDict_MergeFromSeq2`
- `PyDict_Update`
- `PyDict_Values`

## `genericaliasobject.h`

RustPython C API target: `crates/capi/src/genericaliasobject.rs` (not present yet)

- `Py_GenericAlias`

## `import.h`

RustPython C API target: `crates/capi/src/import.rs`

- `PyImport_ExecCodeModuleEx`

## `listobject.h`

RustPython C API target: `crates/capi/src/listobject.rs`

- `PyList_AsTuple`
- `PyList_GetSlice`
- `PyList_SetSlice`
- `PyList_Sort`

## `longobject.h`

RustPython C API target: `crates/capi/src/longobject.rs`

- `PyLong_AsUnsignedLongLongMask`

## `modsupport.h`

RustPython C API target: `crates/capi/src/modsupport.rs` (not present yet)

- `PyModule_ExecDef`
- `PyModule_FromDefAndSpec2`

## `moduleobject.h`

RustPython C API target: `crates/capi/src/moduleobject.rs`

- `PyModule_GetFilenameObject`
- `PyModule_NewObject`

## `object.h`

RustPython C API target: `crates/capi/src/object.rs`

- `PyCallable_Check`
- `PyObject_ClearWeakRefs`
- `PyObject_Dir`
- `PyObject_GenericGetAttr`
- `PyObject_GetOptionalAttr`
- `PyObject_RichCompare`
- `PyType_GetModuleName`

## `osmodule.h`

RustPython C API target: `crates/capi/src/osmodule.rs` (not present yet)

- `PyOS_FSPath`

## `pybuffer.h`

RustPython C API target: `crates/capi/src/pybuffer.rs` (not present yet)

- `PyBuffer_FromContiguous`
- `PyBuffer_GetPointer`
- `PyBuffer_IsContiguous`
- `PyBuffer_Release`
- `PyBuffer_ToContiguous`
- `PyObject_GetBuffer`

## `pycapsule.h`

RustPython C API target: `crates/capi/src/capsule.rs`

- `PyCapsule_GetContext`
- `PyCapsule_Import`
- `PyCapsule_SetContext`
- `PyCapsule_SetPointer`

## `pyerrors.h`

RustPython C API target: `crates/capi/src/pyerrors.rs`

- `PyException_GetCause`
- `PyException_GetContext`
- `PyException_SetContext`
- `PyUnicodeDecodeError_Create`

## `pystate.h`

RustPython C API target: `crates/capi/src/pystate.rs`

- `PyInterpreterState_Get`
- `PyInterpreterState_GetID`

## `setobject.h`

RustPython C API target: `crates/capi/src/setobject.rs` (not present yet)

- `PyFrozenSet_Check`
- `PyFrozenSet_New`
- `PySet_Add`
- `PySet_Check`
- `PySet_Clear`
- `PySet_Contains`
- `PySet_Discard`
- `PySet_New`
- `PySet_Pop`
- `PySet_Size`

## `sliceobject.h`

RustPython C API target: `crates/capi/src/sliceobject.rs` (not present yet)

- `PySlice_AdjustIndices`
- `PySlice_New`
- `PySlice_Unpack`

## `unicodeobject.h`

RustPython C API target: `crates/capi/src/unicodeobject.rs`

- `PyUnicode_AsUTF8String`
- `PyUnicode_DecodeFSDefaultAndSize`
- `PyUnicode_EncodeFSDefault`
- `PyUnicode_FromEncodedObject`

## `warnings.h`

RustPython C API target: `crates/capi/src/warnings.rs` (not present yet)

- `PyErr_WarnEx`
- `PyErr_WarnExplicit`

## `weakrefobject.h`

RustPython C API target: `crates/capi/src/weakrefobject.rs` (not present yet)

- `PyWeakref_CheckProxy`
- `PyWeakref_CheckRef`
- `PyWeakref_GetRef`
- `PyWeakref_NewProxy`
- `PyWeakref_NewRef`
2 changes: 1 addition & 1 deletion crates/capi/pyo3-rustpython.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
implementation=CPython
implementation=RustPython
version=3.14
shared=true
abi3=true
Expand Down
Loading
Loading