Commit e27d9593 authored by Lisandro Dalcin's avatar Lisandro Dalcin

Fix warnings from GCC -Wconversion

parent 48ef0a8b
...@@ -744,7 +744,7 @@ typedef struct { ...@@ -744,7 +744,7 @@ typedef struct {
__Pyx_StructField root; __Pyx_StructField root;
__Pyx_BufFmt_StackElem* head; __Pyx_BufFmt_StackElem* head;
size_t fmt_offset; size_t fmt_offset;
int new_count, enc_count; size_t new_count, enc_count;
int is_complex; int is_complex;
char enc_type; char enc_type;
char new_packmode; char new_packmode;
...@@ -794,8 +794,8 @@ static int __Pyx_BufFmt_ParseNumber(const char** ts) { ...@@ -794,8 +794,8 @@ static int __Pyx_BufFmt_ParseNumber(const char** ts) {
} }
static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) { static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) {
char msg[] = {ch, 0}; PyErr_Format(PyExc_ValueError,
PyErr_Format(PyExc_ValueError, "Unexpected format string character: '%s'", msg); "Unexpected format string character: '%c'", ch);
} }
static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) { static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) {
...@@ -868,7 +868,7 @@ typedef struct { char c; double x; } __Pyx_st_double; ...@@ -868,7 +868,7 @@ typedef struct { char c; double x; } __Pyx_st_double;
typedef struct { char c; long double x; } __Pyx_st_longdouble; typedef struct { char c; long double x; } __Pyx_st_longdouble;
typedef struct { char c; void *x; } __Pyx_st_void_p; typedef struct { char c; void *x; } __Pyx_st_void_p;
#ifdef HAVE_LONG_LONG #ifdef HAVE_LONG_LONG
typedef struct { char c; PY_LONG_LONG x; } __Pyx_s_long_long; typedef struct { char c; PY_LONG_LONG x; } __Pyx_st_longlong;
#endif #endif
static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, int is_complex) { static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, int is_complex) {
...@@ -878,7 +878,7 @@ static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, int is_complex) { ...@@ -878,7 +878,7 @@ static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, int is_complex) {
case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int); case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int);
case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long); case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long);
#ifdef HAVE_LONG_LONG #ifdef HAVE_LONG_LONG
case 'q': case 'Q': return sizeof(__Pyx_s_long_long) - sizeof(PY_LONG_LONG); case 'q': case 'Q': return sizeof(__Pyx_st_longlong) - sizeof(PY_LONG_LONG);
#endif #endif
case 'f': return sizeof(__Pyx_st_float) - sizeof(float); case 'f': return sizeof(__Pyx_st_float) - sizeof(float);
case 'd': return sizeof(__Pyx_st_double) - sizeof(double); case 'd': return sizeof(__Pyx_st_double) - sizeof(double);
...@@ -890,7 +890,7 @@ static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, int is_complex) { ...@@ -890,7 +890,7 @@ static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, int is_complex) {
} }
} }
static size_t __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) { static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) {
switch (ch) { switch (ch) {
case 'c': case 'b': case 'h': case 'i': case 'l': case 'q': return 'I'; case 'c': case 'b': case 'h': case 'i': case 'l': case 'q': return 'I';
case 'B': case 'H': case 'I': case 'L': case 'Q': return 'U'; case 'B': case 'H': case 'I': case 'L': case 'Q': return 'U';
...@@ -944,8 +944,8 @@ static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) { ...@@ -944,8 +944,8 @@ static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) {
size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex); size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex);
} }
if (ctx->enc_packmode == '@') { if (ctx->enc_packmode == '@') {
int align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex); size_t align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex);
int align_mod_offset; size_t align_mod_offset;
if (align_at == 0) return -1; if (align_at == 0) return -1;
align_mod_offset = ctx->fmt_offset % align_at; align_mod_offset = ctx->fmt_offset % align_at;
if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset; if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset;
...@@ -1054,9 +1054,8 @@ static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const cha ...@@ -1054,9 +1054,8 @@ static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const cha
break; break;
case 'T': /* substruct */ case 'T': /* substruct */
{ {
int i;
const char* ts_after_sub; const char* ts_after_sub;
int struct_count = ctx->new_count; size_t i, struct_count = ctx->new_count;
ctx->new_count = 1; ctx->new_count = 1;
++ts; ++ts;
if (*ts != '{') { if (*ts != '{') {
...@@ -1118,15 +1117,14 @@ static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const cha ...@@ -1118,15 +1117,14 @@ static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const cha
break; break;
default: default:
{ {
ctx->new_count = __Pyx_BufFmt_ParseNumber(&ts); int number = __Pyx_BufFmt_ParseNumber(&ts);
if (ctx->new_count == -1) { /* First char was not a digit */ if (number == -1) { /* First char was not a digit */
char msg[2] = { *ts, 0 };
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"Does not understand character buffer dtype format string ('%s')", msg); "Does not understand character buffer dtype format string ('%c')", *ts);
return NULL; return NULL;
} }
ctx->new_count = (size_t)number;
} }
} }
} }
} }
......
...@@ -217,9 +217,9 @@ cdef extern from "numpy/arrayobject.h": ...@@ -217,9 +217,9 @@ cdef extern from "numpy/arrayobject.h":
info.buf = PyArray_DATA(self) info.buf = PyArray_DATA(self)
info.ndim = ndim info.ndim = ndim
if copy_shape: if copy_shape:
# Allocate new buffer for strides and shape info. This is allocated # Allocate new buffer for strides and shape info.
# as one block, strides first. # This is allocated as one block, strides first.
info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * ndim * 2) info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)
info.shape = info.strides + ndim info.shape = info.strides + ndim
for i in range(ndim): for i in range(ndim):
info.strides[i] = PyArray_STRIDES(self)[i] info.strides[i] = PyArray_STRIDES(self)[i]
......
...@@ -1055,7 +1055,8 @@ cdef class MockBuffer: ...@@ -1055,7 +1055,8 @@ cdef class MockBuffer:
stdlib.free(self.buffer) stdlib.free(self.buffer)
cdef void* create_buffer(self, data): cdef void* create_buffer(self, data):
cdef char* buf = <char*>stdlib.malloc(len(data) * self.itemsize) cdef size_t n = <size_t>(len(data) * self.itemsize)
cdef char* buf = <char*>stdlib.malloc(n)
cdef char* it = buf cdef char* it = buf
for value in data: for value in data:
self.write(it, value) self.write(it, value)
...@@ -1063,19 +1064,22 @@ cdef class MockBuffer: ...@@ -1063,19 +1064,22 @@ cdef class MockBuffer:
return buf return buf
cdef void* create_indirect_buffer(self, data, shape): cdef void* create_indirect_buffer(self, data, shape):
cdef size_t n = 0
cdef void** buf cdef void** buf
assert shape[0] == len(data) assert shape[0] == len(data)
if len(shape) == 1: if len(shape) == 1:
return self.create_buffer(data) return self.create_buffer(data)
else: else:
shape = shape[1:] shape = shape[1:]
buf = <void**>stdlib.malloc(len(data) * sizeof(void*)) n = <size_t>len(data) * sizeof(void*)
buf = <void**>stdlib.malloc(n)
for idx, subdata in enumerate(data): for idx, subdata in enumerate(data):
buf[idx] = self.create_indirect_buffer(subdata, shape) buf[idx] = self.create_indirect_buffer(subdata, shape)
return buf return buf
cdef Py_ssize_t* list_to_sizebuf(self, l): cdef Py_ssize_t* list_to_sizebuf(self, l):
cdef Py_ssize_t* buf = <Py_ssize_t*>stdlib.malloc(len(l) * sizeof(Py_ssize_t)) cdef size_t n = <size_t>len(l) * sizeof(Py_ssize_t)
cdef Py_ssize_t* buf = <Py_ssize_t*>stdlib.malloc(n)
for i, x in enumerate(l): for i, x in enumerate(l):
buf[i] = x buf[i] = x
return buf return buf
...@@ -1128,7 +1132,7 @@ cdef class MockBuffer: ...@@ -1128,7 +1132,7 @@ cdef class MockBuffer:
cdef class CharMockBuffer(MockBuffer): cdef class CharMockBuffer(MockBuffer):
cdef int write(self, char* buf, object value) except -1: cdef int write(self, char* buf, object value) except -1:
(<char*>buf)[0] = <int>value (<char*>buf)[0] = <char>value
return 0 return 0
cdef get_itemsize(self): return sizeof(char) cdef get_itemsize(self): return sizeof(char)
cdef get_default_format(self): return b"@b" cdef get_default_format(self): return b"@b"
...@@ -1163,7 +1167,7 @@ cdef class UnsignedShortMockBuffer(MockBuffer): ...@@ -1163,7 +1167,7 @@ cdef class UnsignedShortMockBuffer(MockBuffer):
cdef class FloatMockBuffer(MockBuffer): cdef class FloatMockBuffer(MockBuffer):
cdef int write(self, char* buf, object value) except -1: cdef int write(self, char* buf, object value) except -1:
(<float*>buf)[0] = <float>value (<float*>buf)[0] = <float>(<double>value)
return 0 return 0
cdef get_itemsize(self): return sizeof(float) cdef get_itemsize(self): return sizeof(float)
cdef get_default_format(self): return b"f" cdef get_default_format(self): return b"f"
......
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