On Tue, Oct 11, 2016 at 4:03 AM, Paul Moore <p.f.mo...@gmail.com> wrote: > On 10 October 2016 at 17:49, MRAB <pyt...@mrabarnett.plus.com> wrote: >> If you lookup something in a dict, it'll be a borrowed reference. >> >> If the dict is globals() and there's no GIL, another thread could delete the >> item while your code had the borrowed reference. >> >> It looks like there might be a lot that will need to changed post gilectomy! > > It seems to me that the whole concept of a borrowed reference may be > risky in a post-GIL world. There may be occasional cases where it's > possible to prove that borrowing is safe, but I suspect they'll be > pretty rare.
Not really. If you have an object that forever owns a reference to another object, it's safe to return borrowed references. A quick search for 'borrowed' showed up these perfectly safe[1] examples: PyObject* PyFunction_GetGlobals(PyObject *op) Return value: Borrowed reference. -- a function's __globals__ attribute is read-only -- though its __code__ is not, so possibly PyFunction_GetCode may be dangerous?? PyObject* PyTuple_GetItem(PyObject *p, Py_ssize_t pos) Return value: Borrowed reference. -- as mentioned previously, tuples are immutable and thus safe PyObject* PyMethod_Function(PyObject *meth) Return value: Borrowed reference. PyObject* PyMethod_Self(PyObject *meth) Return value: Borrowed reference. -- a bound method's __func__ and __self__ attributes are read-only In these cases, it's easy to see what reference you're borrowing, and it's not a problem. ChrisA [1] As far as I know! _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com