On 5 August 2018 at 18:06, Ronald Oussoren <
ronaldoussoren@mac.com> wrote:
I’m not sure if I understand this, ctypes and cffi are used to access C APIs
without writing C code including the CPython API (see for example
<https://github.com/abarnert/superhackyinternals/blob/master/internals.py>).
The code code below should be mostly equivalent to the Cython example posted
earlier:
import unittest
import ctypes
from ctypes import pythonapi
class PyObject(ctypes.Structure):
_fields_ = (
('ob_refcnt', ctypes.c_ssize_t),
)
pythonapi.PyList_Append.argtypes = [ctypes.py_object, ctypes.py_object]
def refcount(v):
return PyObject.from_address(id(v)).ob_refcnt
The quoted code is what I was referring to in:
====
ctypes & cffi likely wouldn't help as much in the case, since they
don't eliminate the need to come up with custom code for parts 3 & 4,
they just let you write that logic in Python rather than C.
====