8000 Merge pull request #11181 from charris/backport-11180 · r-devulap/numpy@6c4caa0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c4caa0

Browse files
authored
Merge pull request numpy#11181 from charris/backport-11180
BUG: void dtype setup checked offset not actual pointer for alignment
2 parents 5b3b867 + 35626a2 commit 6c4caa0

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

numpy/core/src/multiarray/arraytypes.c.src

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ npy_strtoull(const char *str, char **endptr, int base)
181181
*****************************************************************************
182182
*/
183183

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+
184193

185194
/**begin repeat
186195
*
@@ -245,8 +254,10 @@ static int
245254
}
246255
return -1;
247256
}
248-
if (ap == NULL || PyArray_ISBEHAVED(ap))
257+
if (ap == NULL || PyArray_ISBEHAVED(ap)) {
258+
assert(npy_is_aligned(ov, _ALIGN(@type@)));
249259
*((@type@ *)ov)=temp;
260+
}
250261
else {
251262
PyArray_DESCR(ap)->f->copyswap(ov, &temp, PyArray_ISBYTESWAPPED(ap),
252263
ap);
@@ -808,7 +819,7 @@ NPY_NO_EXPORT int PyArray_CopyObject(PyArrayObject *, PyObject *);
808819
*/
809820
NPY_NO_EXPORT int
810821
_setup_field(int i, PyArray_Descr *descr, PyArrayObject *arr,
811-
npy_intp *offset_p)
822+
npy_intp *offset_p, char *dstdata)
812823
{
813824
PyObject *key;
814825
PyObject *tup;
@@ -822,7 +833,8 @@ _setup_field(int i, PyArray_Descr *descr, PyArrayObject *arr,
822833
}
823834

824835
((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)) {
826838
PyArray_CLEARFLAGS(arr, NPY_ARRAY_ALIGNED);
827839
}
828840
else {
@@ -850,7 +862,7 @@ _copy_and_return_void_setitem(PyArray_Descr *dstdescr, char *dstdata,
850862
if (PyArray_EquivTypes(srcdescr, dstdescr)) {
851863
for (i = 0; i < names_size; i++) {
852864
/* neither line can ever fail, in principle */
853-
if (_setup_field(i, dstdescr, dummy, &offset)) {
865+
if (_setup_field(i, dstdescr, dummy, &offset, dstdata)) {
854866
return -1;
855867
}
856868
PyArray_DESCR(dummy)->f->copyswap(dstdata + offset,
@@ -920,7 +932,7 @@ VOID_setitem(PyObject *op, void *input, void *vap)
920932
PyObject *item;
921933

922934
/* 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) {
924936
failed = 1;
925937
break;
926938
}
@@ -942,7 +954,7 @@ VOID_setitem(PyObject *op, void *input, void *vap)
942954

943955
for (i = 0; i < names_size; i++) {
944956
/* 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) {
946958
failed = 8000 1;
947959
break;
948960
}
@@ -4240,17 +4252,6 @@ small_correlate(const char * d_, npy_intp dstride,
42404252
*****************************************************************************
42414253
*/
42424254

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-
42544255
/**begin repeat
42554256
*
42564257
* #from = VOID, STRING, UNICODE#

0 commit comments

Comments
 (0)
0