hpyproject / hpy

HPy: a better API for Python
https://hpyproject.org
MIT License
1.02k stars 52 forks source link

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

Open steve-s opened 2 years ago

steve-s commented 2 years ago

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)
steve-s commented 2 years ago

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.