[casacore] r21589 committed - Remove type-punned compiler warnings

0 views
Skip to first unread message

casa...@googlecode.com

unread,
Mar 26, 2015, 12:26:43 PM3/26/15
to casacor...@googlegroups.com
Revision: 21589
Author: gervandiepen
Date: Thu Mar 26 16:26:26 2015 UTC
Log: Remove type-punned compiler warnings
https://code.google.com/p/casacore/source/detail?r=21589

Modified:
/branches/nov14/python/Converters/PycArrayComCC.h
/branches/nov14/python/Converters/PycArrayNP.cc
/branches/nov14/python/Converters/test/tConvert.out

=======================================
--- /branches/nov14/python/Converters/PycArrayComCC.h Tue Mar 24 09:48:34
2015 UTC
+++ /branches/nov14/python/Converters/PycArrayComCC.h Thu Mar 26 16:26:26
2015 UTC
@@ -345,7 +345,9 @@
// Copy using Char, because uChar is mapped to Short in the Traits.
Array<Char> arr = ArrayCopy<Char>::toArray(shp, po->data, False);
Array<Short> res(arr.shape());
- convertArray (res, (const Array<uChar>&)arr);
+ void* varr = &arr;
+ Array<uChar>* uarr = static_cast<Array<uChar>*>(varr);
+ convertArray (res, *uarr);
return ValueHolder(res);
} else if (po->descr->type_num == NPY_STRING) {
int slen = 0;
=======================================
--- /branches/nov14/python/Converters/PycArrayNP.cc Wed Dec 17 15:21:43
2014 UTC
+++ /branches/nov14/python/Converters/PycArrayNP.cc Thu Mar 26 16:26:26
2015 UTC
@@ -182,31 +182,70 @@
PyArray_ScalarAsCtype(obj_ptr, buffer);
switch (type) {
case NPY_BOOL:
- return ValueHolder(*(::npy_bool*)buffer != 0);
+ {
+ ::npy_bool* ptr = (::npy_bool* )buffer;
+ return ValueHolder(*ptr != 0);
+ }
case NPY_INT8:
- return ValueHolder(int(*(::npy_int8*)buffer));
+ {
+ ::npy_int8* ptr = (::npy_int8*)buffer;
+ return ValueHolder(Short(*ptr));
+ }
case NPY_UINT8:
- return ValueHolder(uint(*(::npy_uint8*)buffer));
+ {
+ ::npy_uint8* ptr = (::npy_uint8*)buffer;
+ return ValueHolder(uShort(*ptr));
+ }
case NPY_INT16:
- return ValueHolder(int(*(::npy_int16*)buffer));
+ {
+ ::npy_int16* ptr = (::npy_int16*)buffer;
+ return ValueHolder(Short(*ptr));
+ }
case NPY_UINT16:
- return ValueHolder(uint(*(::npy_uint16*)buffer));
+ {
+ ::npy_uint16* ptr = (::npy_uint16*)buffer;
+ return ValueHolder(uShort(*ptr));
+ }
case NPY_INT32:
- return ValueHolder(int(*(::npy_int32*)buffer));
+ {
+ ::npy_int32* ptr = (::npy_int32*)buffer;
+ return ValueHolder(Int(*ptr));
+ }
case NPY_UINT32:
- return ValueHolder(uint(*(::npy_uint32*)buffer));
+ {
+ ::npy_uint32* ptr = (::npy_uint32*)buffer;
+ return ValueHolder(uInt(*ptr));
+ }
case NPY_INT64:
- return ValueHolder(Int64(*(::npy_int64*)buffer));
+ {
+ ::npy_int64* ptr = (::npy_int64*)buffer;
+ return ValueHolder(Int64(*ptr));
+ }
case NPY_UINT64:
- return ValueHolder(Int64(*(::npy_uint64*)buffer));
+ {
+ ::npy_uint64* ptr = (::npy_uint64*)buffer;
+ return ValueHolder(Int64(*ptr));
+ }
case NPY_FLOAT32:
- return ValueHolder(float(*(::npy_float32*)buffer));
+ {
+ ::npy_float32* ptr = (::npy_float32*)buffer;
+ return ValueHolder(float(*ptr));
+ }
case NPY_FLOAT64:
- return ValueHolder(double(*(::npy_float64*)buffer));
+ {
+ ::npy_float64* ptr = (::npy_float64*)buffer;
+ return ValueHolder(double(*ptr));
+ }
case NPY_COMPLEX64:
- return ValueHolder(*(Complex*)buffer);
+ {
+ Complex* ptr = (Complex*)buffer;
+ return ValueHolder(*ptr);
+ }
case NPY_COMPLEX128:
- return ValueHolder(*(DComplex*)buffer);
+ {
+ DComplex* ptr = (DComplex*)buffer;
+ return ValueHolder(*ptr);
+ }
default:
break;
}
@@ -258,11 +297,12 @@
}
}
// Create the array from the shape.
+ // This gives a warning because a function pointer is converted
+ // to a data pointer.
+ // A union could be used as in e.g. DynLib.cc, but numpy
+ // declarations are too complicated for it.
PyArrayObject* po = (PyArrayObject*)
(PyArray_SimpleNew(nd, &(newshp[0]), TypeConvTraits<T>::pyType()));
- if (po == 0) {
- throw AipsError ("PycArray: failed to allocate python array-object");
- }
// Copy the data to numarray.
if (arr.size() > 0) {
casacore::Bool deleteIt;
=======================================
--- /branches/nov14/python/Converters/test/tConvert.out Mon Mar 2 10:51:35
2015 UTC
+++ /branches/nov14/python/Converters/test/tConvert.out Thu Mar 26 16:26:26
2015 UTC
@@ -23,7 +23,7 @@
testarrvh
VH Array<Short>
[-6 -7]
-VH Int
+VH Short
-6
VH Array<Int>
[-6]
@@ -42,7 +42,7 @@
testarrvh
VH Array<Short>
[5 6]
-VH uInt
+VH uShort
5
VH Array<Int>
[5]
@@ -61,7 +61,7 @@
testarrvh
VH Array<Short>
[-16 -17]
-VH Int
+VH Short
-16
VH Array<Int>
[-16]
@@ -80,7 +80,7 @@
testarrvh
VH Array<Int>
[15 16]
-VH uInt
+VH uShort
15
VH Array<Int>
[15]
Reply all
Reply to author
Forward
0 new messages