Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(15)

Side by Side Diff: Objects/memoryobject.c

Issue 15944: memoryviews and ctypes
Patch Set: Created 4 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_memoryview.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Memoryview object implementation */ 1 /* Memoryview object implementation */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include "pystrhex.h" 4 #include "pystrhex.h"
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 7
8 /****************************************************************************/ 8 /****************************************************************************/
9 /* ManagedBuffer Object */ 9 /* ManagedBuffer Object */
10 /****************************************************************************/ 10 /****************************************************************************/
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 PyObject *asciifmt; 1189 PyObject *asciifmt;
1190 char srcchar, destchar; 1190 char srcchar, destchar;
1191 Py_ssize_t itemsize; 1191 Py_ssize_t itemsize;
1192 int ret = -1; 1192 int ret = -1;
1193 1193
1194 assert(view->ndim >= 1); 1194 assert(view->ndim >= 1);
1195 assert(Py_SIZE(mv) == 3*view->ndim); 1195 assert(Py_SIZE(mv) == 3*view->ndim);
1196 assert(view->shape == mv->ob_array); 1196 assert(view->shape == mv->ob_array);
1197 assert(view->strides == mv->ob_array + view->ndim); 1197 assert(view->strides == mv->ob_array + view->ndim);
1198 assert(view->suboffsets == mv->ob_array + 2*view->ndim); 1198 assert(view->suboffsets == mv->ob_array + 2*view->ndim);
1199
1200 if (get_native_fmtchar(&srcchar, view->format) < 0) {
1201 PyErr_SetString(PyExc_ValueError,
1202 "memoryview: source format must be a native single character "
1203 "format prefixed with an optional '@'");
1204 return ret;
1205 }
1206 1199
1207 asciifmt = PyUnicode_AsASCIIString(format); 1200 asciifmt = PyUnicode_AsASCIIString(format);
1208 if (asciifmt == NULL) 1201 if (asciifmt == NULL)
1209 return ret; 1202 return ret;
1210 1203
1211 itemsize = get_native_fmtchar(&destchar, PyBytes_AS_STRING(asciifmt)); 1204 itemsize = get_native_fmtchar(&destchar, PyBytes_AS_STRING(asciifmt));
1212 if (itemsize < 0) { 1205 if (itemsize < 0) {
1213 PyErr_SetString(PyExc_ValueError, 1206 PyErr_SetString(PyExc_ValueError,
1214 "memoryview: destination format must be a native single " 1207 "memoryview: destination format must be a native single "
1215 "character format prefixed with an optional '@'"); 1208 "character format prefixed with an optional '@'");
1216 goto out; 1209 goto out;
1217 } 1210 }
1218 1211
1219 if (!IS_BYTE_FORMAT(srcchar) && !IS_BYTE_FORMAT(destchar)) { 1212 if ((get_native_fmtchar(&srcchar, view->format) < 0 ||
1213 !IS_BYTE_FORMAT(srcchar)) && !IS_BYTE_FORMAT(destchar)) {
1220 PyErr_SetString(PyExc_TypeError, 1214 PyErr_SetString(PyExc_TypeError,
1221 "memoryview: cannot cast between two non-byte formats"); 1215 "memoryview: cannot cast between two non-byte formats");
1222 goto out; 1216 goto out;
1223 } 1217 }
1224 if (view->len % itemsize) { 1218 if (view->len % itemsize) {
1225 PyErr_SetString(PyExc_TypeError, 1219 PyErr_SetString(PyExc_TypeError,
1226 "memoryview: length is not a multiple of itemsize"); 1220 "memoryview: length is not a multiple of itemsize");
1227 goto out; 1221 goto out;
1228 } 1222 }
1229 1223
(...skipping 1898 matching lines...) Expand 10 before | Expand all | Expand 10 after
3128 memory_getsetlist, /* tp_getset */ 3122 memory_getsetlist, /* tp_getset */
3129 0, /* tp_base */ 3123 0, /* tp_base */
3130 0, /* tp_dict */ 3124 0, /* tp_dict */
3131 0, /* tp_descr_get */ 3125 0, /* tp_descr_get */
3132 0, /* tp_descr_set */ 3126 0, /* tp_descr_set */
3133 0, /* tp_dictoffset */ 3127 0, /* tp_dictoffset */
3134 0, /* tp_init */ 3128 0, /* tp_init */
3135 0, /* tp_alloc */ 3129 0, /* tp_alloc */
3136 memory_new, /* tp_new */ 3130 memory_new, /* tp_new */
3137 }; 3131 };
OLDNEW
« no previous file with comments | « Lib/test/test_memoryview.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+