https://github.com/python/cpython/commit/6c4cd44ae31c7107c51ba9567bf43c33fed07cd3
commit: 6c4cd44ae31c7107c51ba9567bf43c33fed07cd3
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: ZeroIntensity <[email protected]>
date: 2026-09-21T18:11:55Z
summary:

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

(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 b65887e2eca1b1..e39e398b85151f 100644
--- a/Doc/library/ctypes.rst
+++ b/Doc/library/ctypes.rst
@@ -953,6 +953,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