Use Py_SET_REFCNT in _cffi_backend.c to support nogil Python
It would be convenient to be able to install cffi in nogil fork of CPython from the source distribution on PyPI. The only change necessary is to use the Py_SET_REFCNT macro instead of modifying the ob_refcnt
field directly.
I've included the patch below because I don't think non-project developers can propose merge requests.
diff -r 91fb2c254308 -r 0d5f4523e308 c/_cffi_backend.c
--- a/c/_cffi_backend.c Tue Mar 29 11:48:33 2022 +0200
+++ b/c/_cffi_backend.c Tue Apr 12 13:41:21 2022 -0700
@@ -4635,7 +4635,7 @@
/* the 'value' in unique_cache doesn't count as 1, but don't use
Py_DECREF(x) here because it will confuse debug builds into thinking
there was an extra DECREF in total. */
- ((PyObject *)x)->ob_refcnt--;
+ Py_SET_REFCNT(x, Py_REFCNT(x) - 1);
return (PyObject *)x;
error: