hpyproject / hpy

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

HPyField_Load() should handle NULL gracefully #266

Open rlamy opened 2 years ago

rlamy commented 2 years ago

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

antocuni commented 2 years ago

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

fangerer commented 2 years ago

I think this relates to #297