summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-01-29 10:12:19 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-01-29 10:12:19 (GMT)
commita339e86dc052f6fca7adcde4ea7cefd4c265b5b3 (patch)
treee243d1ec9c5cd213bdb6fc2d228139a76edee1ee /Doc
parent4b40c3e69ecd49121563b19cbe16e406c822a0ec (diff)
downloadcpython-a339e86dc052f6fca7adcde4ea7cefd4c265b5b3.zip
cpython-a339e86dc052f6fca7adcde4ea7cefd4c265b5b3.tar.gz
cpython-a339e86dc052f6fca7adcde4ea7cefd4c265b5b3.tar.bz2
Issue #19023: Document ctypes array and pointer classes
Also add some more tests. Based on patch by Sye van der Veen.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/ctypes.rst58
1 files changed, 54 insertions, 4 deletions
diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst
index 99a2c4d..386a44d 100644
--- a/Doc/library/ctypes.rst
+++ b/Doc/library/ctypes.rst
@@ -708,8 +708,8 @@ Pointer instances are created by calling the :func:`pointer` function on a
>>> pi = pointer(i)
>>>
-Pointer instances have a :attr:`contents` attribute which returns the object to
-which the pointer points, the ``i`` object above::
+Pointer instances have a :attr:`~_Pointer.contents` attribute which
+returns the object to which the pointer points, the ``i`` object above::
>>> pi.contents
c_long(42)
@@ -2512,6 +2512,56 @@ other data types containing pointer type fields.
Arrays and pointers
^^^^^^^^^^^^^^^^^^^
-Not yet written - please see the sections :ref:`ctypes-pointers` and section
-:ref:`ctypes-arrays` in the tutorial.
+.. class:: Array(\*args)
+
+ Abstract base class for arrays.
+
+ The recommended way to create concrete array types is by multiplying any
+ :mod:`ctypes` data type with a positive integer. Alternatively, you can subclass
+ this type and define :attr:`_length_` and :attr:`_type_` class variables.
+ Array elements can be read and written using standard
+ subscript and slice accesses; for slice reads, the resulting object is
+ *not* itself an :class:`Array`.
+
+
+ .. attribute:: _length_
+
+ A positive integer specifying the number of elements in the array.
+ Out-of-range subscripts result in an :exc:`IndexError`. Will be
+ returned by :func:`len`.
+
+
+ .. attribute:: _type_
+
+ Specifies the type of each element in the array.
+
+
+ Array subclass constructors accept positional arguments, used to
+ initialize the elements in order.
+
+
+.. class:: _Pointer
+
+ Private, abstract base class for pointers.
+
+ Concrete pointer types are created by calling :func:`POINTER` with the
+ type that will be pointed to; this is done automatically by
+ :func:`pointer`.
+
+ If a pointer points to an array, its elements can be read and
+ written using standard subscript and slice accesses. Pointer objects
+ have no size, so :func:`len` will raise :exc:`TypeError`. Negative
+ subscripts will read from the memory *before* the pointer (as in C), and
+ out-of-range subscripts will probably crash with an access violation (if
+ you're lucky).
+
+
+ .. attribute:: _type_
+
+ Specifies the type pointed to.
+
+ .. attribute:: contents
+
+ Returns the object to which to pointer points. Assigning to this
+ attribute changes the pointer to point to the assigned object.