-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add minimal C-api implementation that builds with Pyo3 #7562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bschoenmaeckers
wants to merge
160
commits into
RustPython:main
Choose a base branch
from
bschoenmaeckers:c-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,138
−46
Draft
Changes from all commits
Commits
Show all changes
160 commits
Select commit
Hold shift + click to select a range
54156f6
export c api
bschoenmaeckers 2250a1c
type mapping v1
bschoenmaeckers bc96211
Type mapping v2
bschoenmaeckers 46307f6
Implement type flags
bschoenmaeckers b08d41a
Implement `PyUnicode_FromStringAndSize`
bschoenmaeckers 34c13f4
Do not use `C-unwind`
bschoenmaeckers 24b2c63
implement `PyLong_AsLong`
bschoenmaeckers 384b378
Add `with_vm` helper
bschoenmaeckers f49e859
Move `PyThreadState` to `pystate.rs`
bschoenmaeckers e18eef7
Basic multi-threading support
bschoenmaeckers 565bf5e
Cleanup
bschoenmaeckers 85b2928
Attach thread in `Py_InitializeEx`
bschoenmaeckers c603d37
Map RustPython type flags to CPython type flags
bschoenmaeckers cee9403
Use `*const Py<PyType>` instead of `*mut PyTypeObject`
bschoenmaeckers 0a50fcc
Implement `PyUnicode_AsUTF8AndSize`
bschoenmaeckers f588979
Implement `PyType_GetName`
bschoenmaeckers edaca0c
Implement alternative `PyLong` constructors
bschoenmaeckers e4c8bd7
Move `init_static_type_pointers` to `pylifecycle.rs`
bschoenmaeckers 26c2777
Add support for `None`, `True`, `False`, `Ellipsis` & `NotImplemented`
bschoenmaeckers 09466e2
Add support for PyBytes
bschoenmaeckers 94cc39b
Add basic exception support
bschoenmaeckers 2ef64d2
Add import support
bschoenmaeckers 55b1e14
Add basic call support
bschoenmaeckers 2a7a82e
Use pyo3 as test harness
bschoenmaeckers 96e16b1
Fix pyo3 by correctly setting `PYO3_CONFIG_FILE`
bschoenmaeckers e351fb2
Fix python bool creation test
bschoenmaeckers 2fece20
Implement `PyUnicode_EqualToUTF8AndSize`
bschoenmaeckers e56029d
Add `PyExc_SystemError`
bschoenmaeckers 9702a47
Compile to dynamic lib
bschoenmaeckers 738d4d4
Add test for static type pointers
bschoenmaeckers 8ad7e0c
Streamline returning PyResult
bschoenmaeckers 32faf14
Fix some clippy warning
bschoenmaeckers a34ced9
Use bounded channel for vm request response
bschoenmaeckers 5a8c57b
Test creating a new (heap) exception type
bschoenmaeckers 3dda576
Don't check for NULL in `Py_DecRef`/`Py_IncRef`
bschoenmaeckers a1b3af6
Add basic `PyDict` support
bschoenmaeckers 3c7ef8f
Implement minimal tuple functions
bschoenmaeckers 5625ba3
Implement `PyObject_Repr` & `PyObject_Str`
bschoenmaeckers ea45d78
Implement `PyObject_GetAttr`
bschoenmaeckers fcbc6b9
Implement `PyUnicode_InternInPlace`
bschoenmaeckers ff9d385
Add support for running python source code
bschoenmaeckers 7b36240
Make all modules private
bschoenmaeckers 8805658
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers c4b8ea3
Implement `PyErr_SetString`
bschoenmaeckers dc56590
Add basic support for `PyList`
bschoenmaeckers 47ed41d
Support `PyLong_AsLong` for non `PyInt` types
bschoenmaeckers 375a170
Add support for `PyComplex`
bschoenmaeckers fe8107a
Implement c_variadic `PyObject_CallMethodObjArgs`
bschoenmaeckers 2f6fc50
Implement `PyCapsule`
bschoenmaeckers 52442ae
Allow creating empty tuples
bschoenmaeckers 537fc69
Implement `PyCMethod_New`
bschoenmaeckers 62485f6
Add `PyMethodPointer` union
bschoenmaeckers 61de6bf
Also support `NoArgs` CFunction's
bschoenmaeckers 248ea52
Fix error return of `PyCFunction`
bschoenmaeckers ad0d1af
Add `PyDict` iter support
bschoenmaeckers d81ad21
Add more `Exception` type statics
bschoenmaeckers 6cd7fc9
Add support for `set`, `get`, & `del` on any object
bschoenmaeckers d228a78
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers ae3f3db
Refactor `FfiResult`
bschoenmaeckers 4d23f7c
Fix unset exception types
bschoenmaeckers 56f3823
Add `PyBaseObject_Type` static
bschoenmaeckers 4f6798a
Add `PyObject_SetAttr`
bschoenmaeckers 685c4b7
Add `PyObject_GenericGetDict` & `PyObject_GenericSetDict`
bschoenmaeckers ac50f2b
Fix some clippy warning
bschoenmaeckers 16e1193
Merge branch 'main' into c-api
bschoenmaeckers 9e931f7
Add `PyObject_SetAttrString`
bschoenmaeckers 384e15e
Add `PyObject_GC_UnTrack`
bschoenmaeckers 09aab0a
Implement `Py_IS_TYPE`
bschoenmaeckers 7ee1e27
Add all exception statics
bschoenmaeckers 661e7bd
Implement `PyObject_Vectorcall`
bschoenmaeckers 65c80c8
Add `PyObject_GetAttrString`
bschoenmaeckers d2c2c63
Use custom RustPython build of `PyO3`
bschoenmaeckers b4bc0d8
Add basic support for new classes
bschoenmaeckers 2dc9a82
Add support for class attributes
bschoenmaeckers 3fad7e4
Add basic support for PyO3 class methods
bschoenmaeckers a07b7c6
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers 842f54d
Add `PyTuple_FromArray` & `PyTuple_Pack`
bschoenmaeckers 2e03e5d
Add `PyFloat` support
bschoenmaeckers 535861b
Add `Py_NewRef`
bschoenmaeckers 1ff142b
Add `PyLong_AsUnsignedLongLong`
bschoenmaeckers f2e824a
Add `PyNumber_Index`
bschoenmaeckers 59a5fa6
Fix float test
bschoenmaeckers b8a3646
Implement `PyTraceBack_Print`
bschoenmaeckers 8d7b7d7
Implement `PyUnicode_AsEncodedString`
bschoenmaeckers 708c657
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers 646eaf7
Merge branch 'main' into c-api
bschoenmaeckers c49725a
Add `PyList_Append`
bschoenmaeckers d969389
Add type check functions
bschoenmaeckers d25d6c8
Add `PyObject_Call`
bschoenmaeckers 5ea41e1
Add support for `FASTCALL`/`STATIC`/`CLASS` c functions
bschoenmaeckers 6745ce4
Add module definition support
bschoenmaeckers c7b4f40
Implement `PyTuple_GetSlice`
bschoenmaeckers 7d3e502
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers 931bdd8
Implement `Py_GetVersion`
bschoenmaeckers 020a5c9
Implement `PyCapsule_IsValid`
bschoenmaeckers efda7cc
Refactor c function trampolines
bschoenmaeckers 88b4bbc
Implement `PyList_Insert`
bschoenmaeckers 1a3e888
Implement `PyList_Reverse`
bschoenmaeckers 1835268
Allow `PyBytes_FromStringAndSize` with uninitialized bytes
bschoenmaeckers 0f39fa4
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers 2562f9d
Add basic capi error support
bschoenmaeckers 40d97ea
Add missing symbols to make tests compile again
bschoenmaeckers 6b79cb5
Add `pyerrors` to dictionary
bschoenmaeckers 71438c6
Return exception in `Py_GetConstantBorrowed`
bschoenmaeckers d708bfe
Remove `allow(dead_code)`
bschoenmaeckers bbf3656
Fix windows
bschoenmaeckers bccd38e
Load stdlib when calling `Py_InitializeEx`
bschoenmaeckers 9e20cf7
Debug tests
bschoenmaeckers 268856b
Revert "Load stdlib when calling `Py_InitializeEx`"
bschoenmaeckers 8432c17
Disable tests on windows for now
bschoenmaeckers 130321e
Truncate `PyType_GetFlags` to be always 32 bits
bschoenmaeckers 30ac061
Add test for exception type checking
bschoenmaeckers 4e4f7df
Remove subclass type flags
bschoenmaeckers 9bf8c25
Update PyO3 to main branch
bschoenmaeckers a5b3e87
Add type check functions
bschoenmaeckers 84f87d6
Add bool object functions
bschoenmaeckers 9306c66
Add exact type check macros
bschoenmaeckers b75b430
Implement `PyExceptionClass_Check`
bschoenmaeckers f8bd659
Add self support to `PyNativeFunction`
bschoenmaeckers 22985ca
Merge remote-tracking branch 'origin/main' into capi-errors
bschoenmaeckers b2c2f69
Use latest pyo3 to make test work on windows
bschoenmaeckers d18d259
Revert "Use latest pyo3 to make test work on windows"
bschoenmaeckers 72e4a31
Merge branch 'capi-errors' into c-api
bschoenmaeckers 0f60694
Add todo list
bschoenmaeckers 2efb3b3
Update var_arg functions
bschoenmaeckers 365eb11
Fix `ctypes.py_object` handling
bschoenmaeckers 9363b97
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers 397f6f5
Refactor `build_method_def`
bschoenmaeckers a15972b
Implement `build_method_def` for `METH_O`
bschoenmaeckers aff5c7f
Extract callable convertions from `build_method_def`
bschoenmaeckers f2b889d
Make PyMethodDef members public
bschoenmaeckers 83ca45e
Add `PyCFunction_New` & `PyCFunction_NewEx`
bschoenmaeckers 265991f
Fix self handling in `METH_NOARGS` functions
bschoenmaeckers 93b4012
Fix handling of self in `METH_O` functions
bschoenmaeckers b3a8511
Implement `PyObject_IsSubclass` & `PyObject_IsInstance`
bschoenmaeckers e4ca8c3
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers cf7a8ef
Discard `self` on static functions
bschoenmaeckers bbc0e59
Merge branch 'main' into c-api
bschoenmaeckers 8ccc53f
Merge branch 'main' into c-api
bschoenmaeckers 98a3d2c
Merge branch 'main' into c-api
bschoenmaeckers e7af38e
Fix `Py_GetVersion`
bschoenmaeckers 722c09d
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers a8acad3
Rename `pycapsule`
bschoenmaeckers 80ea418
Implement remaining capsule functions
bschoenmaeckers ed052f0
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers 2447d82
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers 961bfc4
Update todo list
bschoenmaeckers a15e80b
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers ca4a7c4
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers 31b9fe4
Merge branch 'main' into c-api
bschoenmaeckers dcb5973
Update pyo3
bschoenmaeckers cedee14
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers 16a34b9
Implement `PyDict_SetDefaultRef`
bschoenmaeckers 5eb6a98
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers ea5efa7
Add agent skill
bschoenmaeckers 6bf855f
Add `set` object functions to c-api
bschoenmaeckers 7f6c466
Add mapping c-api functions
bschoenmaeckers 4d819d3
Add number protocol functions
bschoenmaeckers 7a19dcf
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers 6e1ca79
Merge remote-tracking branch 'origin/main' into c-api
bschoenmaeckers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| # 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` | ||
| - `PyObject_GetIter` | ||
| - `PyObject_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` | ||
|
|
||
| ## `pyerrors.h` | ||
|
|
||
| RustPython C API target: `crates/capi/src/pyerrors.rs` | ||
|
|
||
| - `PyException_SetContext` | ||
| - `PyUnicodeDecodeError_Create` | ||
|
|
||
| ## `pystate.h` | ||
|
|
||
| RustPython C API target: `crates/capi/src/pystate.rs` | ||
|
|
||
| - `PyInterpreterState_Get` | ||
| - `PyInterpreterState_GetID` | ||
|
|
||
| ## `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` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
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.
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.
As this will be stabilised very soon. I was planning to removing this feature entirely before merging this.