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

HPyType_FromSpec: disallow setting any tp_flags not supported by HPy #305

Open
steve-s opened this issue Mar 14, 2022 · 1 comment
Open

Comments

@steve-s
Copy link
Contributor

steve-s commented Mar 14, 2022

Currently HPy just copies HPyType_Spec flags to PyType_Spec:

// ctx_type.c: (simplified)
spec->flags = hpyspec->flags;

and the user is expected to use at least HPy_TPFLAGS_DEFAULT in their HPyType_Spec, which exposes CPython specific flags in HPy headers:

// hpytype.h:
/* All types are dynamically allocated */
#define _Py_TPFLAGS_HEAPTYPE (1UL << 9)
#define _Py_TPFLAGS_HAVE_VERSION_TAG (1UL << 18)
#define HPy_TPFLAGS_DEFAULT (_Py_TPFLAGS_HEAPTYPE | _Py_TPFLAGS_HAVE_VERSION_TAG)
  • This allows users to use CPython specific flags via HPy and reduce portability -- I suggest to test the flags against a mask that contains only the flags supported by HPy (currently: HPy_TPFLAGS_BASETYPE and HPy_TPFLAGS_HAVE_GC).
  • Would it be safer to treat 0 as the default value? We can still also treat what was HPy_TPFLAGS_DEFAULT as another way of specifying it, but without exposing a constant for it (and maybe with a warning?).
    • alternatively we can fail for 0 and suggest to use HPy_TPFLAGS_DEFAULT
@steve-s
Copy link
Contributor Author

steve-s commented Apr 12, 2022

In general, it is a question if we should use flags in HPy. Maybe HPy should have bool (or int?) fields in HPyType_Spec for individual flags instead: that is safer, easier to use and migration from CPython API should be simple enough.

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

No branches or pull requests

1 participant