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

Flag incompatibility with CPython 3.10 #292

Closed
rlamy opened this issue Feb 16, 2022 · 2 comments · Fixed by #304
Closed

Flag incompatibility with CPython 3.10 #292

rlamy opened this issue Feb 16, 2022 · 2 comments · Fixed by #304

Comments

@rlamy
Copy link
Member

rlamy commented Feb 16, 2022

We are using these HPy-specific flags:

#define HPy_TPFLAGS_INTERNAL_PURE (1UL << 8)

#define HPy_TPFLAGS_INTERNAL_IS_HPY_TYPE (1UL << 7)

However, these bits have been reused in CPython 3.10, which added a bunch of flags, including:

/* Disallow creating instances of the type: set tp_new to NULL and don't create
 * the "__new__" key in the type dictionary. */
#define Py_TPFLAGS_DISALLOW_INSTANTIATION (1UL << 7)

/* Set if the type object is immutable: type attributes cannot be set nor deleted */
#define Py_TPFLAGS_IMMUTABLETYPE (1UL << 8)

In the short term, we could probably get by using two of the few remaining free values instead, but that's probably not sustainable in the long term, and I think we should stop assuming we can put anything in type->tp_flags.

@steve-s
Copy link
Contributor

steve-s commented Feb 28, 2022

What if we put those flags into the extra allocated memory in HPyType_Extra_t? We can put there also some magic to be able to assert whether type is HPy managed. Edit: ok we need to mark the types not only for asserts. Then we need at least HPy_TPFLAGS_INTERNAL_PURE

@fangerer
Copy link
Contributor

fangerer commented Mar 3, 2022

As discussed in our dev call on March 3rd, 2022 (see https://github.com/hpyproject/hpy/wiki/dev-call-20220303) we shoudl move most HPy-specific flags to HPyType_Extra_t.
As @steve-s mentioned, we will need a way to identify a pure HPy type. Our idea was to ask CPython to reserve one bit for us. We don't necessarily expect that to be accepted but we would at least expect that they point us to a possible solution.
One idea is that we use a well-known function for, e.g., tp_dealloc. We could still allow custom destructors but always use a well-known one in tp_dealloc and store the custom one in HPyType_Extra_t as well.

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 a pull request may close this issue.

3 participants