Skip to content

Commit

Permalink
issue with borrowed reference
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Sep 5, 2018
1 parent 67708bc commit ba41931
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/bad_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ See also :ref:`Remove functions <remove-funcs>`.
Borrowed references
===================

A borrowed reference is a pointer which doesn't "hold" a reference. If the
object is destroyed, the borrowed reference becomes a dangling pointer: pointer
pointing to freed memory which might be reused by a new object.

Borrowed references can lead to bugs and crashes when misused. The
:ref:`Specialized list for small integers <specialized-list>` optimization is
incompatible with borrowed references, since the runtime cannot guess when the
temporary object should be destroyed.

CPython 3.7 has many functions and macros which return or use borrowed
references. For example, ``PyTuple_GetItem()`` returns a borrowed reference,
whereas ``PyTuple_SetItem()`` stores a borrowed reference (store an item into a
Expand Down
2 changes: 2 additions & 0 deletions doc/optimization_ideas.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ PyPy experimented Software Transactional Memory (STM) but the project has
been abandoned, `PyPy STM <http://doc.pypy.org/en/latest/stm.html>`_.


.. _specialized-list:

Specialized list for small integers
===================================

Expand Down

0 comments on commit ba41931

Please sign in to comment.