Skip to content
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

Initial support for Python 3.11 beta #279

Merged
merged 3 commits into from
Oct 9, 2022

Conversation

Techcable
Copy link
Contributor

This is obviously experimental but it works okay.

All the tests pass and the example prints the following:

$ cargo run --example hello --features python-3-11
Hello nicholas, I'm Python 3.11.0b1 (v3.11.0b1:8d32a5c8c4, May 6 2022, 22:45:29) [Clang 13.0.0 (clang-1300.0.29.30)]

I figure it's best to be proactive with these change, so that way we are ready as soon as 3.11 proper is released (October I think).

MAin difference in 3.11 that frame object is now private (and lazy loaded).
This results in a performance improvement but makes it harder for debuggers.
Also the internal ordering of code objects has completely changed as well.

@Techcable
Copy link
Contributor Author

Techcable commented May 14, 2022

If you want, you are free to merge right now. I just figured we'd wait until 3.11 was more developed.....

@dgrunwald
Copy link
Owner

We should wait for the RC which typically is ABI-compatible with the final release.
Can you rebase your branch onto the current master? I've fixed the failure with Rust 1.41.1.

This is obviously experimental but it works okay.
MAin difference is that frame object is now private (and lazy loaded)
and the internal ordering of code objects has completely changed as well
The ordering of the fields has completely changed, so we give it
a different definition.
@Techcable
Copy link
Contributor Author

Techcable commented Jun 19, 2022

We should wait for the RC which typically is ABI-compatible with the final release.

I agree. We should wait to the RC before pulling this.

Can you rebase your branch onto the current master? I've fixed the failure with Rust 1.41.1.

Done! Tests still appear to be failing though. This fixes most of the tests. However there is something about "ast-json" on 2.7 nightly

//
// the justification for the reordering was "optimization"
pub struct PyCodeObject {
pub ob_base: PyObject,
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't this be PyVarObject?

pub co_names: *mut PyObject,
pub co_exceptiontable: *mut PyObject,
pub co_flags: c_int,
pub co_warmup: c_int,
Copy link
Owner

Choose a reason for hiding this comment

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

The fields around here changed since you created this pull request

pub co_name: *mut PyObject,
pub co_qualname: *mut PyObject,
pub co_linetable: *mut PyObject,
pub co_weakreflist: *mut PyObject,
Copy link
Owner

Choose a reason for hiding this comment

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

More fields were inserted here

@@ -169,6 +220,7 @@ pub unsafe fn PyCode_Check(op: *mut PyObject) -> c_int {
}

#[inline]
#[cfg(not(Py_3_11))] // TODO: Implemengt again (fields are private)
Copy link
Owner

Choose a reason for hiding this comment

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

?

@@ -21,6 +21,9 @@ extern "C" {
arg2: *mut *mut PyObject,
arg3: *mut *mut PyObject,
) -> ();
#[cfg(Py_3_11)]
pub fn PyErr_GetHandledException() -> *mut PyObject;
pub fn PyErr_SetHandledException(exc: *mut PyObject);
Copy link
Owner

Choose a reason for hiding this comment

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

Missing #[cfg(Py_3_11)]?

@dgrunwald
Copy link
Owner

I'm continuing work on python 3.11 support on https://github.com/dgrunwald/rust-cpython/tree/py3.11

@dgrunwald dgrunwald merged commit e261be5 into dgrunwald:master Oct 9, 2022
@Techcable
Copy link
Contributor Author

Awesome! Thanks 👍

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