Skip to content

Commit 4fee35a

Browse files
committed
docs/glossary: Describe the callee-owned tuple concept.
1 parent bb04755 commit 4fee35a

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

docs/library/uselect.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ Methods
7878

7979
.. method:: poll.ipoll(timeout=-1, flags=0)
8080

81-
Like :meth:`poll.poll`, but instead returns an iterator which yields
82-
`callee-owned tuples`. This function provides efficient, allocation-free
81+
Like :meth:`poll.poll`, but instead returns an iterator which yields a
82+
`callee-owned tuple`. This function provides an efficient, allocation-free
8383
way to poll on streams.
8484

8585
If *flags* is 1, one-shot behavior for events is employed: streams for

docs/reference/glossary.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@ Glossary
1515
may also refer to "boardless" ports like
1616
:term:`Unix port <MicroPython Unix port>`).
1717

18+
callee-owned tuple
19+
A tuple returned by some builtin function/method, containing data
20+
which is valid for a limited time, usually until next call to the
21+
same function (or a group of related functions). After next call,
22+
data in the tuple may be changed. This leads to the following
23+
restriction on the usage of callee-owned tuples - references to
24+
them cannot be stored. The only valid operation is extracting
25+
values from them (including making a copy). Callee-owned tuples
26+
is a MicroPython-specific construct (not available in the general
27+
Python language), introduced for memory allocation optimization.
28+
The idea is that callee-owned tuple is allocated once and stored
29+
on the callee side. Subsequent calls don't require allocation,
30+
allowing to return multiple values when allocation is not possible
31+
(e.g. in interrupt context) or not desirable (because allocation
32+
inherently leads to memory fragmentation). Note that callee-owned
33+
tuples are effectively mutable tuples, making an exception to
34+
Python's rule that tuples are immutable. (It may be interesting
35+
why tuples were used for such a purpose then, instead of mutable
36+
lists - the reason for that is that lists are mutable from user
37+
application side too, so a user could do things to a callee-owned
38+
list which the callee doesn't expect and could lead to problems;
39+
a tuple is protected from this.)
40+
1841
CPython
1942
CPython is the reference implementation of Python programming
2043
language, and the most well-known one, which most of the people

0 commit comments

Comments
 (0)