Hello all… thanks for reading.
I’m porting some pure Python to a C extension. Have a couple of burning questions, for which I’m struggling to find answers:
1- Is there a good strategy for tracking PyObject reference counts during development that I am overlooking?
2- Why is there no PyList_Pop/Remove, et al (and I say “et al” b/c certainly this one seeminly odd omittence means there are probably others). When I first got my feet wet, it seemed like a magical land where the API lined up nicely with my knowledge of Python. But these sorts of omitteneces seem strange to me. And why would we have PyDict_DelItem() and not some basic list operations?
Right now, my workaround is (based on https://stackoverflow.com/questions/54721487/how-to-pop-element-from-pylistobject/54724545#54724545):
static inline PyObject* list_pop(PyObject *lst) {
return PyObject_CallMethod(lst, "pop", "n", Py_SIZE(lst) - 1);
}
static inline PyObject* list_remove(PyObject *lst, int i) {
return PyObject_CallMethod(lst, "remove", "n", i);
}
The Stack Overflow answer mentions implementing the underlying code, which I can probably muster (if after this port it proves to be a significant bottleneck, which I doubt), but still: why no already-done implementation in the API? I looked at the underlying code and it seems like all the peices are there, but I mean, they’d have to be in order for the Python methods to work…