-
Notifications
You must be signed in to change notification settings - Fork 787
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
Use PyType_Spec for creating new types in Rust #1132
Conversation
8f82c49
to
b291801
Compare
First I'm sorry that the approach I told does not work since we cannot merge this branch to I'm for the
#[cfg(Py_LIMITED_API)]
fn initialize_tp_obj_additional(type_object: &mut ffi::PyType_Object) {}
#[cfg(not(Py_LIMITED_API))]
fn initialize_tp_obj_additional(type_object: &mut ffi::PyType_Object) {
type_object.~ = ...;
}
And another related thing is:
|
Ah I forgot an important point: currently we ourselves allocate type objects. |
Why is it a problem that pyo3 allocates it's own type objects now? This PR switches to I will go through and finish porting all the other callbacks now. |
b291801
to
024f888
Compare
Ok, it's now far enough along that |
Ah I see how you changed |
It automatically sets that flag for us (very nice of it!) /~https://github.com/python/cpython/blob/master/Objects/typeobject.c#L2949 |
024f888
to
4f20747
Compare
Ok, going to bed now. I start working on buffers, but it's not working, and I don't really know why. I suppose next step is |
python/cpython#22031 ... but I didn't realize it's
only true since June! Not in any released Python.
…On Tue, Sep 1, 2020 at 12:37 AM Yuji Kanagawa ***@***.***> wrote:
@alex </~https://github.com/alex>
[image: image]
<https://user-images.githubusercontent.com/16046705/91795268-2cbbbe00-ec58-11ea-970f-e55d6b50798e.png>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1132 (comment)>, or
unsubscribe
</~https://github.com/notifications/unsubscribe-auth/AAAAGBBSSP7Y2GQL6Y4IMNTSDR267ANCNFSM4QRDGBGQ>
.
--
All that is necessary for evil to succeed is for good people to do nothing.
|
5ce76e9
to
51ab1d7
Compare
Here's a new issue I could use some feedback on. /~https://github.com/PyO3/pyo3/blob/master/tests/test_class_attributes.rs#L54-L60 is currently failing on this branch, because the mutation is allowed. Currently on However, on this branch, the type now has the |
🤔 Class immutability is a nice property, but I'm not sure we can preserve the existing behavior without doing something like creating a metaclass. That's probably overly complicated for now, so I'd be cautiously ok for this feature to go. (At least in the short term, maybe with an issue to track restoring it?) Might want to wait to see what @kngwyu says too. |
Ok, then we're on to the next failing test: /~https://github.com/PyO3/pyo3/blob/master/tests/test_class_basics.rs#L122-L141 This fails because it expects that Personally I think this is a bit more correct, |
51ab1d7
to
b6eb8b8
Compare
I think the only possible fix is having two functions: #[cfg(Py_LIMITED_API)]
pub(crate) fn initialize_type_object<T>(...) {}
#[cfg(not(Py_LIMITED_API))]
pub(crate) fn initialize_type_object<T>(...) {}
This test is not so important and you can either opt-in it by |
I'm trying very hard to as little duplicate code paths as well, so i"ll remove the test. Here's the next one: /~https://github.com/PyO3/pyo3/blob/master/tests/test_class_basics.rs#L10-L19 Yet again, CPython has completely different behavior for heap types: /~https://github.com/python/cpython/blob/v3.8.2/Objects/typeobject.c#L4972-L4988 they appear to always get a |
I wondered about this but would vote against splitting the |
Default |
yeah, that works -- is there an example of a raw callback raising an exception that I can use? |
The safest way might be to do something like
and trust the optimizer to remove all the gubbins :) |
that'll work. |
Just as a quick thought, once we've got this ready, should we potentially avoid merging it until after the It looks like it might touch a fair bit of core code, and given the test coverage on PyO3 is... improving (😄)... it might be wiser to avoid merging until we've released |
That sounds reasonable to me. |
IIRC |
Good news/bad news! The good news is that /~https://github.com/python/cpython/blob/master/Objects/typeobject.c#L2891-L2986 this enforcement is pretty core to |
677cc63
to
9a42221
Compare
https://bugs.python.org/issue38140 seems to suggest that there's no way to set |
7d770b7
to
95975b5
Compare
I found a workaround... just set |
a6fd81e
to
7622744
Compare
Ok, |
7622744
to
8592e01
Compare
At this point all of |
locally on CPython the examples tests pass, so it might be a pypy bug :-/ |
I cannot understand why you removed some tests. I feel we're not agreed with that point. |
I definitely agree it's not an appropriate solution, and I think we need a better one before this could be merged. Here's what happened for each of the tests I changed/removed:
The thing all of these have in common is that CPython treats a heap type different than a static type. |
Thank you for listing them. |
8592e01
to
f0bbff5
Compare
I added |
f0bbff5
to
4004620
Compare
Tests are now green :-) |
Thank you, let me use some time to create a continuation PR |
This is a proof of concept -- implements just enough of it to prove the idea works! There's still a lot of missing elements of this (look at all the commented out code!)
Before I went too much further and implemented all the different function pointers, I wanted to check in and see if this approach looked ok.