summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Objects/memoryobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/tools/python3/Objects/memoryobject.c')
-rw-r--r--contrib/tools/python3/Objects/memoryobject.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/contrib/tools/python3/Objects/memoryobject.c b/contrib/tools/python3/Objects/memoryobject.c
index 535e0b3c1dc..d7586a2a458 100644
--- a/contrib/tools/python3/Objects/memoryobject.c
+++ b/contrib/tools/python3/Objects/memoryobject.c
@@ -1653,6 +1653,10 @@ fix_error_int(const char *fmt)
return -1;
}
+// UNPACK_TO_BOOL: Return 0 if PTR represents "false", and 1 otherwise.
+static const _Bool bool_false = 0;
+#define UNPACK_TO_BOOL(PTR) (memcmp((PTR), &bool_false, sizeof(_Bool)) != 0)
+
/* Accept integer objects or objects with an __index__() method. */
static long
pylong_as_ld(PyObject *item)
@@ -1788,7 +1792,7 @@ unpack_single(PyMemoryViewObject *self, const char *ptr, const char *fmt)
case 'l': UNPACK_SINGLE(ld, ptr, long); goto convert_ld;
/* boolean */
- case '?': UNPACK_SINGLE(ld, ptr, _Bool); goto convert_bool;
+ case '?': ld = UNPACK_TO_BOOL(ptr); goto convert_bool;
/* unsigned integers */
case 'H': UNPACK_SINGLE(lu, ptr, unsigned short); goto convert_lu;
@@ -2252,16 +2256,17 @@ memoryview.tobytes
Return the data in the buffer as a byte string.
-Order can be {'C', 'F', 'A'}. When order is 'C' or 'F', the data of the
-original array is converted to C or Fortran order. For contiguous views,
-'A' returns an exact copy of the physical memory. In particular, in-memory
-Fortran order is preserved. For non-contiguous views, the data is converted
-to C first. order=None is the same as order='C'.
+Order can be {'C', 'F', 'A'}. When order is 'C' or 'F', the data of
+the original array is converted to C or Fortran order. For
+contiguous views, 'A' returns an exact copy of the physical memory.
+In particular, in-memory Fortran order is preserved. For
+non-contiguous views, the data is converted to C first. order=None
+is the same as order='C'.
[clinic start generated code]*/
static PyObject *
memoryview_tobytes_impl(PyMemoryViewObject *self, const char *order)
-/*[clinic end generated code: output=1288b62560a32a23 input=0efa3ddaeda573a8]*/
+/*[clinic end generated code: output=1288b62560a32a23 input=119c70aa91791dc8]*/
{
Py_buffer *src = VIEW_ADDR(self);
char ord = 'C';
@@ -2301,8 +2306,8 @@ memoryview.hex
sep: object = NULL
An optional single character or byte to separate hex bytes.
bytes_per_sep: int = 1
- How many bytes between separators. Positive values count from the
- right, negative values count from the left.
+ How many bytes between separators. Positive values count from
+ the right, negative values count from the left.
Return the data in the buffer as a str of hexadecimal numbers.
@@ -2321,7 +2326,7 @@ Example:
static PyObject *
memoryview_hex_impl(PyMemoryViewObject *self, PyObject *sep,
int bytes_per_sep)
-/*[clinic end generated code: output=430ca760f94f3ca7 input=539f6a3a5fb56946]*/
+/*[clinic end generated code: output=430ca760f94f3ca7 input=94c2495f886c786b]*/
{
Py_buffer *src = VIEW_ADDR(self);
PyObject *bytes;
@@ -2835,7 +2840,7 @@ unpack_cmp(const char *p, const char *q, char fmt,
case 'l': CMP_SINGLE(p, q, long); return equal;
/* boolean */
- case '?': CMP_SINGLE(p, q, _Bool); return equal;
+ case '?': return UNPACK_TO_BOOL(p) == UNPACK_TO_BOOL(q);
/* unsigned integers */
case 'H': CMP_SINGLE(p, q, unsigned short); return equal;