10000 issue with borrowed reference · mscherer/pythoncapi@ba41931 · GitHub
[go: up one dir, main page]

Skip to content

Commit ba41931

Browse files
committed
issue with borrowed reference
1 parent 67708bc commit ba41931

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

doc/bad_api.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ See also :ref:`Remove functions <remove-funcs>`.
1515
Borrowed references
1616
===================
1717

18+
A borrowed reference is a pointer which doesn't "hold" a reference. If the
19+
object is destroyed, the borrowed reference becomes a dangling pointer: pointer
20+
pointing to freed memory which might be reused by a new object.
21+
22+
Borrowed references can lead to bugs and crashes when misused. The
23+
:ref:`Specialized list for small integers <specialized-list>` optimization is
24+
incompatible with borrowed references, since the runtime cannot guess when the
25+
temporary object should be destroyed.
26+
1827
CPython 3.7 has many functions and macros which return or use borrowed
1928
references. For example, ``PyTuple_GetItem()`` returns a borrowed reference,
2029
whereas ``PyTuple_SetItem()`` stores a borrowed reference (store an item into a

doc/optimization_ideas.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ PyPy experimented Software Transactional Memory (STM) but the project has
110110
been abandoned, `PyPy STM <http://doc.pypy.org/en/latest/stm.html>`_.
111111

112112

113+
.. _specialized-list:
114+
113115
Specialized list for small integers
114116
===================================
115117

0 commit comments

Comments
 (0)
0