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

Make HPy compatible with Python 3.11 #381

Merged
merged 3 commits into from
Nov 24, 2022

Conversation

fangerer
Copy link
Contributor

This resolves #288 .

Antonio's Hybrid-ABI PR #371, which is now merged, already solved the first problems we had with Python 3.11. However, that was not enough.
In particular, there was a subtle change in Python's PyType_FromSpec.... They do now copy the name from the type spec into a fresh buffer such that the type object owns that buffer and can free it (see https://github.com/python/cpython/blob/b5b3904f05e77f044f158307bc6bdd2bc1b670a2/Objects/typeobject.c#L3723).
However, we use tp_name to attach our HPyType_Extra struct.

In future, we might consider to use meta classes to avoid this hack.

I've now also added Python 3.11 to the CI (for main tests and PoC).

Copy link
Collaborator

@antocuni antocuni left a comment

Choose a reason for hiding this comment

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

LGTM

PyMem_Free(ht->_ht_tpname);
ht->_ht_tpname = (char *) extra;
ht->ht_type.tp_name = (const char *)extra->name;
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

wow, this is brilliant.
It's also a bit scary, because if someone by chance tries to access _ht_tpname you will get nonsense. But it seems that nobody is accessing it anyway, so I suppose it's fine 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. I checked the CPython code and it's really just used for freeing.
As I mentioned, we could maybe use a metaclass for HPy types to store the extra info. I'll investigate.

@fangerer fangerer merged commit a2e9303 into hpyproject:master Nov 24, 2022
@fangerer fangerer deleted the fa/py311_support branch November 24, 2022 22:33
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.

Unable to compile on Python 3.11 alpha 5
2 participants