-
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
85
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.
Draft
Changes from 1 commit
Commits
Show all changes
85 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 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
Move
init_static_type_pointers to pylifecycle.rs
- Loading branch information
commit e4c8bd74f2fbdc19e32c0061cfe219a4056b2c87
There are no files selected for viewing
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
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.
This is also somewhat cursed. I want to be able to create
ThreadedVirtualMachinescoped to the thread wherePyGILState_Ensureis called. This may be from a different thread than where the main interpreter is running. So I need a way to share theInterpreterbetween different threads.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.
I'd like to understand why
rustpython_vm::vm::thread::with_vmis not enough but this is requiredUh oh!
There was an error while loading. Please reload this page.
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.
This is so I can call
PyGILState_Ensurefrom any thread, without holding a reference to aInterpreter. This may happen when creating a new thread usingstd::thread::spawn, and trying to run python code in there. See mytest_new_threadtestcase.RustPython/crates/capi/src/pystate.rs
Lines 61 to 75 in 56f3823