Commit 111a3678 authored by Michael Wimmer's avatar Michael Wimmer Committed by Christoph Groth
Browse files

correct some integer length issues

parent a04eb82c
......@@ -368,12 +368,12 @@ Py_ssize_t len(Array_base *self)
Py_ssize_t index_from_key(int ndim, const size_t *shape, PyObject *key)
{
long indices[max_ndim];
Py_ssize_t res = load_index_seq_as_long(key, indices, max_ndim);
int res = load_index_seq_as_long(key, indices, max_ndim);
if (res == -1) {
PyErr_SetString(PyExc_IndexError, "Invalid index.");
return -1;
}
if (int(res) != ndim) {
if (res != ndim) {
PyErr_SetString(PyExc_IndexError, "Number of indices "
"must be equal to number of dimensions.");
return -1;
......@@ -879,19 +879,20 @@ void inittinyarray()
if (complex_str == 0) return;
}
Py_ssize_t load_index_seq_as_long(PyObject *obj, long *out, Py_ssize_t maxlen)
int load_index_seq_as_long(PyObject *obj, long *out, int maxlen)
{
assert(maxlen >= 1);
Py_ssize_t len;
int len;
if (PySequence_Check(obj)) {
obj = PySequence_Fast(obj, "Bug in tinyarray, load_index_seq_as_long");
if (!obj) return -1;
len = PySequence_Fast_GET_SIZE(obj);
if (len > maxlen) {
Py_ssize_t long_len = PySequence_Fast_GET_SIZE(obj);
if (long_len > maxlen) {
PyErr_Format(PyExc_ValueError, "Sequence too long."
" Maximum length is %ld.", maxlen);
" Maximum length is %d.", maxlen);
goto fail;
}
len = static_cast<int>(long_len);
for (PyObject **p = PySequence_Fast_ITEMS(obj), **e = p + len; p < e;
++p, ++out) {
PyObject *index = PyNumber_Index(*p);
......@@ -912,13 +913,13 @@ fail:
return -1;
}
Py_ssize_t load_index_seq_as_ulong(PyObject *obj, unsigned long *uout,
Py_ssize_t maxlen, const char *errmsg)
int load_index_seq_as_ulong(PyObject *obj, unsigned long *uout,
int maxlen, const char *errmsg)
{
long *out = reinterpret_cast<long*>(uout);
Py_ssize_t len = load_index_seq_as_long(obj, out, maxlen);
int len = load_index_seq_as_long(obj, out, maxlen);
if (len == -1) return -1;
for (Py_ssize_t i = 0; i < len; ++i)
for (int i = 0; i < len; ++i)
if (out[i] < 0) {
if (errmsg == 0)
errmsg = "Sequence may not contain negative values.";
......
......@@ -24,7 +24,7 @@ public:
if (ndim) *ndim = 1;
if (shape) *shape = (size_t*)&ob_base.ob_size;
} else if (ob_size < -1) {
if (ndim) *ndim = -ob_size;
if (ndim) *ndim = static_cast<int>(-ob_size);
if (shape) *shape = (size_t*)((char*)this + sizeof(Array_base));
} else {
if (ndim) *ndim = 0;
......@@ -74,9 +74,9 @@ private:
friend void inittinyarray();
};
Py_ssize_t load_index_seq_as_long(PyObject *obj, long *out, Py_ssize_t maxlen);
Py_ssize_t load_index_seq_as_ulong(PyObject *obj, unsigned long *uout,
Py_ssize_t maxlen, const char *errmsg = 0);
int load_index_seq_as_long(PyObject *obj, long *out, int maxlen);
int load_index_seq_as_ulong(PyObject *obj, unsigned long *uout,
int maxlen, const char *errmsg = 0);
inline size_t calc_size(int ndim, const size_t *shape)
{
......
......@@ -24,7 +24,7 @@ int dtype_converter(const PyObject *ob, Dtype *dtype)
}
template <typename T>
PyObject *filled(size_t ndim, const size_t *shape, int value)
PyObject *filled(int ndim, const size_t *shape, int value)
{
size_t size;
Array<T> *result = Array<T>::make(ndim, shape, &size);
......@@ -34,7 +34,7 @@ PyObject *filled(size_t ndim, const size_t *shape, int value)
return (PyObject*)result;
}
PyObject *(*filled_dtable[])(size_t, const size_t*, int) =
PyObject *(*filled_dtable[])(int, const size_t*, int) =
DTYPE_DISPATCH(filled);
PyObject *filled_pyargs(PyObject *args, int value)
......@@ -45,7 +45,7 @@ PyObject *filled_pyargs(PyObject *args, int value)
return 0;
size_t shape[max_ndim];
Py_ssize_t ndim = load_index_seq_as_ulong(
int ndim = load_index_seq_as_ulong(
pyshape, shape, max_ndim, "Negative dimensions are not allowed.");
if (ndim == -1) return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment