dg pb schrieb am 02.09.25 um 11:10:
You can declare the object struct yourself, cast the list object and
extract the array pointer.
You may also just use "&PyList_GET_ITEM(L, 0)" to get the pointer to the
first item and then treat it as the first entry of a "PyObject*" array.
However, note that this may not trivially work well and safely on recent
Python releases, especially in freethreading runtimes and with the recent
changes in refcounting. If it's for your local testing, that's probably
something you can live with, but a production-ready PyPI package might not
want to go that low. It's not unheard of, but it would mean that you'd have
to track CPython's core development branch to keep it working over time.
And it probably won't work on other Python implementations like PyPy.
Stefan