diff options
author | Stefan Krah <skrah@bytereef.org> | 2015-08-08 11:38:10 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2015-08-08 11:38:10 (GMT) |
commit | 0c51595a784787d8e198af910cb6d79172ee52bb (patch) | |
tree | 56d21e209ab26a91c65cad305097fdf6bd8f1b45 /Objects | |
parent | 917c2c36542131dd81f2b5b4d185c50d3b15546f (diff) | |
download | cpython-0c51595a784787d8e198af910cb6d79172ee52bb.zip cpython-0c51595a784787d8e198af910cb6d79172ee52bb.tar.gz cpython-0c51595a784787d8e198af910cb6d79172ee52bb.tar.bz2 |
Issue #15944: memoryview: Allow arbitrary formats when casting to bytes.
Original patch by Martin Panter.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/memoryobject.c | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index 54fd05f..74cad7d 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -1197,13 +1197,6 @@ cast_to_1D(PyMemoryViewObject *mv, PyObject *format) assert(view->strides == mv->ob_array + view->ndim); assert(view->suboffsets == mv->ob_array + 2*view->ndim); - if (get_native_fmtchar(&srcchar, view->format) < 0) { - PyErr_SetString(PyExc_ValueError, - "memoryview: source format must be a native single character " - "format prefixed with an optional '@'"); - return ret; - } - asciifmt = PyUnicode_AsASCIIString(format); if (asciifmt == NULL) return ret; @@ -1216,7 +1209,8 @@ cast_to_1D(PyMemoryViewObject *mv, PyObject *format) goto out; } - if (!IS_BYTE_FORMAT(srcchar) && !IS_BYTE_FORMAT(destchar)) { + if ((get_native_fmtchar(&srcchar, view->format) < 0 || + !IS_BYTE_FORMAT(srcchar)) && !IS_BYTE_FORMAT(destchar)) { PyErr_SetString(PyExc_TypeError, "memoryview: cannot cast between two non-byte formats"); goto out; |