@@ -227,32 +227,32 @@ platform-dependent.
227227+--------+--------------------------+--------------------+----------------+------------+
228228| ``c `` | :c:expr: `char ` | bytes of length 1 | 1 | |
229229+--------+--------------------------+--------------------+----------------+------------+
230- | ``b `` | :c:expr: `signed char ` | integer | 1 | \( 1), \( 2) |
230+ | ``b `` | :c:expr: `signed char ` | int | 1 | \( 2) |
231231+--------+--------------------------+--------------------+----------------+------------+
232- | ``B `` | :c:expr: `unsigned char ` | integer | 1 | \( 2) |
232+ | ``B `` | :c:expr: `unsigned char ` | int | 1 | \( 2) |
233233+--------+--------------------------+--------------------+----------------+------------+
234234| ``? `` | :c:expr: `_Bool ` | bool | 1 | \( 1) |
235235+--------+--------------------------+--------------------+----------------+------------+
236- | ``h `` | :c:expr: `short ` | integer | 2 | \( 2) |
236+ | ``h `` | :c:expr: `short ` | int | 2 | \( 2) |
237237+--------+--------------------------+--------------------+----------------+------------+
238- | ``H `` | :c:expr: `unsigned short ` | integer | 2 | \( 2) |
238+ | ``H `` | :c:expr: `unsigned short ` | int | 2 | \( 2) |
239239+--------+--------------------------+--------------------+----------------+------------+
240- | ``i `` | :c:expr: `int ` | integer | 4 | \( 2) |
240+ | ``i `` | :c:expr: `int ` | int | 4 | \( 2) |
241241+--------+--------------------------+--------------------+----------------+------------+
242- | ``I `` | :c:expr: `unsigned int ` | integer | 4 | \( 2) |
242+ | ``I `` | :c:expr: `unsigned int ` | int | 4 | \( 2) |
243243+--------+--------------------------+--------------------+----------------+------------+
244- | ``l `` | :c:expr: `long ` | integer | 4 | \( 2) |
244+ | ``l `` | :c:expr: `long ` | int | 4 | \( 2) |
245245+--------+--------------------------+--------------------+----------------+------------+
246- | ``L `` | :c:expr: `unsigned long ` | integer | 4 | \( 2) |
246+ | ``L `` | :c:expr: `unsigned long ` | int | 4 | \( 2) |
247247+--------+--------------------------+--------------------+----------------+------------+
248- | ``q `` | :c:expr: `long long ` | integer | 8 | \( 2) |
248+ | ``q `` | :c:expr: `long long ` | int | 8 | \( 2) |
249249+--------+--------------------------+--------------------+----------------+------------+
250- | ``Q `` | :c:expr: `unsigned long | integer | 8 | \( 2) |
250+ | ``Q `` | :c:expr: `unsigned long | int | 8 | \( 2) |
251251| | long` | | | |
252252+--------+--------------------------+--------------------+----------------+------------+
253- | ``n `` | :c:type: `ssize_t ` | integer | | \( 3) |
253+ | ``n `` | :c:type: `ssize_t ` | int | | \( 2), \( 3) |
254254+--------+--------------------------+--------------------+----------------+------------+
255- | ``N `` | :c:type: `size_t ` | integer | | \( 3) |
255+ | ``N `` | :c:type: `size_t ` | int | | \( 2), \( 3) |
256256+--------+--------------------------+--------------------+----------------+------------+
257257| ``e `` | :c:expr: `_Float16 ` | float | 2 | \( 4), \( 6) |
258258+--------+--------------------------+--------------------+----------------+------------+
@@ -264,7 +264,7 @@ platform-dependent.
264264+--------+--------------------------+--------------------+----------------+------------+
265265| ``p `` | :c:expr: `char[] ` | bytes | | \( 8) |
266266+--------+--------------------------+--------------------+----------------+------------+
267- | ``P `` | :c:expr: `void \* ` | integer | | \( 5) |
267+ | ``P `` | :c:expr: `void \* ` | int | | \( 2), \( 5) |
268268+--------+--------------------------+--------------------+----------------+------------+
269269
270270.. versionchanged :: 3.3
@@ -329,27 +329,31 @@ Notes:
329329 The ``'p' `` format character encodes a "Pascal string", meaning a short
330330 variable-length string stored in a *fixed number of bytes *, given by the count.
331331 The first byte stored is the length of the string, or 255, whichever is
332- smaller. The bytes of the string follow. If the string passed in to
332+ smaller. The bytes of the string follow. If the byte string passed in to
333333 :func: `pack ` is too long (longer than the count minus 1), only the leading
334- ``count-1 `` bytes of the string are stored. If the string is shorter than
334+ ``count-1 `` bytes of the string are stored. If the byte string is shorter than
335335 ``count-1 ``, it is padded with null bytes so that exactly count bytes in all
336336 are used. Note that for :func: `unpack `, the ``'p' `` format character consumes
337- ``count `` bytes, but that the string returned can never contain more than 255
337+ ``count `` bytes, but that the :class: ` !bytes ` object returned can never contain more than 255
338338 bytes.
339+ When packing, arguments of types :class: `bytes ` and :class: `bytearray `
340+ are accepted.
339341
340342(9)
341343 For the ``'s' `` format character, the count is interpreted as the length of the
342- bytes , not a repeat count like for the other format characters; for example,
344+ byte string , not a repeat count like for the other format characters; for example,
343345 ``'10s' `` means a single 10-byte string mapping to or from a single
344346 Python byte string, while ``'10c' `` means 10
345347 separate one byte character elements (e.g., ``cccccccccc ``) mapping
346348 to or from ten different Python byte objects. (See :ref: `struct-examples `
347349 for a concrete demonstration of the difference.)
348- If a count is not given, it defaults to 1. For packing, the string is
350+ If a count is not given, it defaults to 1. For packing, the byte string is
349351 truncated or padded with null bytes as appropriate to make it fit. For
350- unpacking, the resulting bytes object always has exactly the specified number
351- of bytes. As a special case, ``'0s' `` means a single, empty string (while
352+ unpacking, the resulting :class: ` ! bytes` object always has exactly the specified number
353+ of bytes. As a special case, ``'0s' `` means a single, empty byte string (while
352354 ``'0c' `` means 0 characters).
355+ When packing, arguments of types :class: `bytes ` and :class: `bytearray `
356+ are accepted.
353357
354358A format character may be preceded by an integral repeat count. For example,
355359the format string ``'4h' `` means exactly the same as ``'hhhh' ``.
0 commit comments