@@ -181,6 +181,15 @@ npy_strtoull(const char *str, char **endptr, int base)
181
181
*****************************************************************************
182
182
*/
183
183
184
+ #define _ALIGN (type ) offsetof(struct {char c; type v;}, v)
185
+ /*
186
+ * Disable harmless compiler warning "4116: unnamed type definition in
187
+ * parentheses" which is caused by the _ALIGN macro.
188
+ */
189
+ #if defined(_MSC_VER )
190
+ #pragma warning(disable:4116)
191
+ #endif
192
+
184
193
185
194
/**begin repeat
186
195
*
@@ -245,8 +254,10 @@ static int
245
254
}
246
255
return -1 ;
247
256
}
248
- if (ap == NULL || PyArray_ISBEHAVED (ap ))
257
+ if (ap == NULL || PyArray_ISBEHAVED (ap )) {
258
+ assert (npy_is_aligned (ov , _ALIGN (@type @)));
249
259
* ((@type @ * )ov )= temp ;
260
+ }
250
261
else {
251
262
PyArray_DESCR (ap )-> f -> copyswap (ov , & temp , PyArray_ISBYTESWAPPED (ap ),
252
263
ap );
@@ -808,7 +819,7 @@ NPY_NO_EXPORT int PyArray_CopyObject(PyArrayObject *, PyObject *);
808
819
*/
809
820
NPY_NO_EXPORT int
810
821
_setup_field (int i , PyArray_Descr * descr , PyArrayObject * arr ,
811
- npy_intp * offset_p )
822
+ npy_intp * offset_p , char * dstdata )
812
823
{
813
824
PyObject * key ;
814
825
PyObject * tup ;
@@ -822,7 +833,8 @@ _setup_field(int i, PyArray_Descr *descr, PyArrayObject *arr,
822
833
}
823
834
824
835
((PyArrayObject_fields * )(arr ))-> descr = new ;
825
- if ((new -> alignment > 1 ) && ((offset % new -> alignment ) != 0 )) {
836
+ if ((new -> alignment > 1 ) &&
837
+ ((((uintptr_t )dstdata + offset ) % new -> alignment ) != 0 )) {
826
838
PyArray_CLEARFLAGS (arr , NPY_ARRAY_ALIGNED );
827
839
}
828
840
else {
@@ -850,7 +862,7 @@ _copy_and_return_void_setitem(PyArray_Descr *dstdescr, char *dstdata,
850
862
if (PyArray_EquivTypes (srcdescr , dstdescr )) {
851
863
for (i = 0 ; i < names_size ; i ++ ) {
852
864
/* neither line can ever fail, in principle */
853
- if (_setup_field (i , dstdescr , dummy , & offset )) {
865
+ if (_setup_field (i , dstdescr , dummy , & offset , dstdata )) {
854
866
return -1 ;
855
867
}
856
868
PyArray_DESCR (dummy )-> f -> copyswap (dstdata + offset ,
@@ -920,7 +932,7 @@ VOID_setitem(PyObject *op, void *input, void *vap)
920
932
PyObject * item ;
921
933
922
934
/* temporarily make ap have only this field */
923
- if (_setup_field (i , descr , ap , & offset ) == -1 ) {
935
+ if (_setup_field (i , descr , ap , & offset , ip ) == -1 ) {
924
936
failed = 1 ;
925
937
break ;
926
938
}
@@ -942,7 +954,7 @@ VOID_setitem(PyObject *op, void *input, void *vap)
942
954
943
955
for (i = 0 ; i < names_size ; i ++ ) {
944
956
/* temporarily make ap have only this field */
945
- if (_setup_field (i , descr , ap , & offset ) == -1 ) {
957
+ if (_setup_field (i , descr , ap , & offset , ip ) == -1 ) {
946
958
failed =
8000
1 ;
947
959
break ;
948
960
}
@@ -4240,17 +4252,6 @@ small_correlate(const char * d_, npy_intp dstride,
4240
4252
*****************************************************************************
4241
4253
*/
4242
4254
4243
-
4244
- #define _ALIGN (type ) offsetof(struct {char c; type v;}, v)
4245
- /*
4246
- * Disable harmless compiler warning "4116: unnamed type definition in
4247
- * parentheses" which is caused by the _ALIGN macro.
4248
- */
4249
- #if defined(_MSC_VER )
4250
- #pragma warning(disable:4116)
4251
- #endif
4252
-
4253
-
4254
4255
/**begin repeat
4255
4256
*
4256
4257
* #from = VOID, STRING, UNICODE#
0 commit comments