hpy icon indicating copy to clipboard operation
hpy copied to clipboard

HPyField_Load() should handle NULL gracefully

Open rlamy opened this issue 4 years ago • 2 comments

Currently, HPyField_Load() segfaults when the field is HPyField_NULL, which is annoying to handle. I see 2 options:

  • HPyField_Load should return HPy_NULL for a null field.
  • Leave HPyField_Load unchanged, but introduce HPyField_XLoad that behaves like the above.

rlamy avatar Nov 30 '21 20:11 rlamy

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

antocuni avatar Dec 01 '21 10:12 antocuni

I think this relates to #297

fangerer avatar Mar 03 '22 15:03 fangerer