hpy
hpy copied to clipboard
HPyField_Load() should handle NULL gracefully
Currently, HPyField_Load() segfaults when the field is HPyField_NULL, which is annoying to handle. I see 2 options:
HPyField_Loadshould returnHPy_NULLfor a null field.- Leave
HPyField_Loadunchanged, but introduceHPyField_XLoadthat behaves like the above.
For CPython, this boils down to whether to use Py_INCREF or Py_XINCREF here:
https://github.com/hpyproject/hpy/blob/c7d36aa3e08c32a49703b3afd22ac1bdc932f2aa/hpy/devel/include/hpy/cpython/misc.h#L219-L224
I would be nice to have the safest API, but at the same time introducing XLoad could give some performance benefits.
A quick way to check whether it matters nowadays is e.g. to take an arbitrary C extension, replace all Py_INCREF with Py_XINCREF, recompile and see if/how much slower it becomes.
This should give us a rough idea of the performance costs
I think this relates to #297