Re: [Python-Dev] PyWeakref_GetObject() borrows its reference from... whom?

2016年10月10日 02:48:07 -0700

On Mon, Oct 10, 2016 at 8:35 PM, Larry Hastings <[email protected]> wrote:
> Huh? In all other circumstances, a "borrowed" reference is exactly that: X
> has a reference, and you are relying on X's reference to keep the object
> alive. Borrowing from a borrowed reference is simply a chain of these; Z
> borrows from Y, Y borrows from X, and X is the original person who did the
> incref. But you're borrowing from something specific, somebody who the API
> guarantees has a legitimate reference on the object and won't drop it while
> you're using it. I bet for every other spot in the API I can tell you from
> whom you're borrowing the reference.
Okay. Here's a test:
PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index)
Return value: Borrowed reference.
Presumably you own a reference to the list itself before you call
this, and the list has a reference to its items. But suppose another
thread clear()s the list immediately after you call this; whose
reference are you borrowing now? The list's is gone.
Or is this another API that will have to change post gilectomy?
ChrisA
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to