https://github.com/python/cpython/commit/2ecf528f682319e0cba3bd38562d2ef25450beb7
commit: 2ecf528f682319e0cba3bd38562d2ef25450beb7
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: ZeroIntensity <[email protected]>
date: 2026-09-21T18:10:48Z
summary:

[3.13] gh-92347: Document pitfalls of `ctypes.pointer` iteration (GH-157801) 
(GH-157927)

(cherry picked from commit a3e389d46d9ce9e60d2eb6fdf2f903b5f90b0f4e)

Co-authored-by: Peter Bierma <[email protected]>

files:
M Doc/library/ctypes.rst

diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst
index 99d25aef257334..985472a8d2f76d 100644
--- a/Doc/library/ctypes.rst
+++ b/Doc/library/ctypes.rst
@@ -835,6 +835,15 @@ Generally you only use this feature if you receive a 
pointer from a C function,
 and you *know* that the pointer actually points to an array instead of a single
 item.
 
+.. warning::
+
+   Because pointer objects support subscription, they implicitly support
+   :term:`iteration <iterator>`. Unless doing this in a controlled manner,
+   such as by manually calling :func:`next` on a :func:`pointer` iterator, this
+   will typically lead to infinite loops or crashes, because ctypes has no way
+   of knowing when to stop iteration. In other words, a ``pointer`` iterator
+   will infinitely yield arbitrary memory.
+
 Behind the scenes, the :func:`pointer` function does more than simply create
 pointer instances, it has to create pointer *types* first. This is done with 
the
 :func:`POINTER` function, which accepts any :mod:`ctypes` type, and returns a

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to