summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2011-04-03 00:35:00 +0200
committerPauli Virtanen <pav@iki.fi>2011-04-03 00:36:06 +0200
commit49320e87e06c0c8ef4462f7adab020348896e1c9 (patch)
tree6361fbd5b44acb15885ee0349e23872d7c986fa3 /numpy
parent7b39b9e5ef6d21a199ec95a27ed19b8b1a34bce1 (diff)
downloadnumpy-49320e87e06c0c8ef4462f7adab020348896e1c9.tar.gz
STY: core/buffer: handle also cases where descr->subarray->shape is not a tuple
Currently, Numpy does not create such dtypes, but this is a sanity check for 3rd party code that might.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/buffer.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/numpy/core/src/multiarray/buffer.c b/numpy/core/src/multiarray/buffer.c
index 9bc45a76f..c88174ffc 100644
--- a/numpy/core/src/multiarray/buffer.c
+++ b/numpy/core/src/multiarray/buffer.c
@@ -193,19 +193,27 @@ _buffer_format_string(PyArray_Descr *descr, _tmp_string_t *str,
}
if (descr->subarray) {
- PyObject *item;
+ PyObject *item, *subarray_tuple;
Py_ssize_t total_count = 1;
Py_ssize_t dim_size;
char buf[128];
int old_offset;
int ret;
+ if (PyTuple_Check(descr->subarray->shape)) {
+ subarray_tuple = descr->subarray->shape;
+ Py_INCREF(subarray_tuple);
+ }
+ else {
+ subarray_tuple = Py_BuildValue("(O)", descr->subarray->shape);
+ }
+
_append_char(str, '(');
- for (k = 0; k < PyTuple_GET_SIZE(descr->subarray->shape); ++k) {
+ for (k = 0; k < PyTuple_GET_SIZE(subarray_tuple); ++k) {
if (k > 0) {
_append_char(str, ',');
}
- item = PyTuple_GET_ITEM(descr->subarray->shape, k);
+ item = PyTuple_GET_ITEM(subarray_tuple, k);
dim_size = PyNumber_AsSsize_t(item, NULL);
PyOS_snprintf(buf, sizeof(buf), "%ld", (long)dim_size);
@@ -213,6 +221,9 @@ _buffer_format_string(PyArray_Descr *descr, _tmp_string_t *str,
total_count *= dim_size;
}
_append_char(str, ')');
+
+ Py_DECREF(subarray_tuple);
+
old_offset = *offset;
ret = _buffer_format_string(descr->subarray->base, str, arr, offset,
active_byteorder);