Mercurial > cpython-lru_cache-weakref
comparison Python/getargs.c @ 63259:ac7eb6eaef68
Issue #8991: convertbuffer() rejects discontigious buffers
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Wed, 28 Jul 2010 00:40:58 +0000 |
| parents | bcc0e825faa0 |
| children | 9108e7dcd7d8 |
comparison
equal
deleted
inserted
replaced
| 63258:5edce14b6287 | 63259:ac7eb6eaef68 |
|---|---|
| 1244 supports it directly. */ | 1244 supports it directly. */ |
| 1245 if (PyObject_GetBuffer(arg, (Py_buffer*)p, PyBUF_WRITABLE) < 0) { | 1245 if (PyObject_GetBuffer(arg, (Py_buffer*)p, PyBUF_WRITABLE) < 0) { |
| 1246 PyErr_Clear(); | 1246 PyErr_Clear(); |
| 1247 return converterr("read-write buffer", arg, msgbuf, bufsize); | 1247 return converterr("read-write buffer", arg, msgbuf, bufsize); |
| 1248 } | 1248 } |
| 1249 if (!PyBuffer_IsContiguous((Py_buffer*)p, 'C')) { | |
| 1250 PyBuffer_Release((Py_buffer*)p); | |
| 1251 return converterr("contiguous buffer", arg, msgbuf, bufsize); | |
| 1252 } | |
| 1249 if (addcleanup(p, freelist, cleanup_buffer)) { | 1253 if (addcleanup(p, freelist, cleanup_buffer)) { |
| 1250 return converterr( | 1254 return converterr( |
| 1251 "(cleanup problem)", | 1255 "(cleanup problem)", |
| 1252 arg, msgbuf, bufsize); | 1256 arg, msgbuf, bufsize); |
| 1253 } | 1257 } |
| 1254 if (!PyBuffer_IsContiguous((Py_buffer*)p, 'C')) | |
| 1255 return converterr("contiguous buffer", arg, msgbuf, bufsize); | |
| 1256 break; | 1258 break; |
| 1257 } | 1259 } |
| 1258 | 1260 |
| 1259 default: | 1261 default: |
| 1260 return converterr("impossible<bad format char>", arg, msgbuf, bufsize); | 1262 return converterr("impossible<bad format char>", arg, msgbuf, bufsize); |
| 1272 Py_ssize_t count; | 1274 Py_ssize_t count; |
| 1273 Py_buffer view; | 1275 Py_buffer view; |
| 1274 | 1276 |
| 1275 *errmsg = NULL; | 1277 *errmsg = NULL; |
| 1276 *p = NULL; | 1278 *p = NULL; |
| 1277 if (pb == NULL || | 1279 if (pb != NULL && pb->bf_releasebuffer != NULL) { |
| 1278 pb->bf_getbuffer == NULL || | 1280 *errmsg = "read-only pinned buffer"; |
| 1279 pb->bf_releasebuffer != NULL) { | |
| 1280 *errmsg = "bytes or read-only buffer"; | |
| 1281 return -1; | 1281 return -1; |
| 1282 } | 1282 } |
| 1283 | 1283 |
| 1284 if (PyObject_GetBuffer(arg, &view, PyBUF_SIMPLE) != 0) { | 1284 if (getbuffer(arg, &view, errmsg) < 0) |
| 1285 *errmsg = "bytes or single-segment read-only buffer"; | |
| 1286 return -1; | 1285 return -1; |
| 1287 } | |
| 1288 count = view.len; | 1286 count = view.len; |
| 1289 *p = view.buf; | 1287 *p = view.buf; |
| 1290 PyBuffer_Release(&view); | 1288 PyBuffer_Release(&view); |
| 1291 return count; | 1289 return count; |
| 1292 } | 1290 } |
| 1293 | 1291 |
| 1294 /* XXX for 3.x, getbuffer and convertbuffer can probably | |
| 1295 be merged again. */ | |
| 1296 static int | 1292 static int |
| 1297 getbuffer(PyObject *arg, Py_buffer *view, char **errmsg) | 1293 getbuffer(PyObject *arg, Py_buffer *view, char **errmsg) |
| 1298 { | 1294 { |
| 1299 PyBufferProcs *pb = Py_TYPE(arg)->tp_as_buffer; | 1295 if (PyObject_GetBuffer(arg, view, PyBUF_SIMPLE) != 0) { |
| 1300 if (pb == NULL) { | |
| 1301 *errmsg = "bytes or buffer"; | 1296 *errmsg = "bytes or buffer"; |
| 1302 return -1; | |
| 1303 } | |
| 1304 if (pb->bf_getbuffer == NULL) { | |
| 1305 *errmsg = "convertible to a buffer"; | |
| 1306 return -1; | |
| 1307 } | |
| 1308 if (PyObject_GetBuffer(arg, view, 0) < 0) { | |
| 1309 *errmsg = "convertible to a buffer"; | |
| 1310 return -1; | 1297 return -1; |
| 1311 } | 1298 } |
| 1312 if (!PyBuffer_IsContiguous(view, 'C')) { | 1299 if (!PyBuffer_IsContiguous(view, 'C')) { |
| 1313 PyBuffer_Release(view); | 1300 PyBuffer_Release(view); |
| 1314 *errmsg = "contiguous buffer"; | 1301 *errmsg = "contiguous buffer"; |
