Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 343b19b

Browse files
authored
Merge pull request #24455 from charris/backport-24452
ENH: Add prefix to _ALIGN Macro
2 parents 54a4c28 + a2864da commit 343b19b

File tree

5 files changed

+46
-46
lines changed

5 files changed

+46
-46
lines changed

numpy/core/src/multiarray/_multiarray_tests.c.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,7 @@ get_struct_alignments(PyObject *NPY_UNUSED(self), PyObject *args) {
20262026
/**begin repeat
20272027
* #N = 1,2,3#
20282028
*/
2029-
alignment = PyLong_FromLong(_ALIGN(struct TestStruct@N@));
2029+
alignment = PyLong_FromLong(NPY_ALIGNOF(struct TestStruct@N@));
20302030
size = PyLong_FromLong(sizeof(struct TestStruct@N@));
20312031
val = PyTuple_Pack(2, alignment, size);
20322032
Py_DECREF(alignment);

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ NPY_NO_EXPORT int
392392
return -1;
393393
}
394394
if (ap == NULL || PyArray_ISBEHAVED(ap)) {
395-
assert(npy_is_aligned(ov, _ALIGN(@type@)));
395+
assert(npy_is_aligned(ov, NPY_ALIGNOF(@type@)));
396396
*((@type@ *)ov)=temp;
397397
}
398398
else {
@@ -809,7 +809,7 @@ STRING_setitem(PyObject *op, void *ov, void *vap)
809809

810810
/* OBJECT */
811811

812-
#define __ALIGNED(obj, sz) ((((size_t) obj) % (sz))==0)
812+
#define NPY__ALIGNED(obj, sz) ((((size_t) obj) % (sz))==0)
813813

814814
static PyObject *
815815
OBJECT_getitem(void *ip, void *NPY_UNUSED(ap))
@@ -2426,10 +2426,10 @@ OBJECT_copyswapn(PyObject **dst, npy_intp dstride, PyObject **src,
24262426
{
24272427
npy_intp i;
24282428
if (src != NULL) {
2429-
if (__ALIGNED(dst, sizeof(PyObject **))
2430-
&& __ALIGNED(src, sizeof(PyObject **))
2431-
&& __ALIGNED(dstride, sizeof(PyObject **))
2432-
&& __ALIGNED(sstride, sizeof(PyObject **))) {
2429+
if (NPY__ALIGNED(dst, sizeof(PyObject **))
2430+
&& NPY__ALIGNED(src, sizeof(PyObject **))
2431+
&& NPY__ALIGNED(dstride, sizeof(PyObject **))
2432+
&& NPY__ALIGNED(sstride, sizeof(PyObject **))) {
24332433
dstride /= sizeof(PyObject **);
24342434
sstride /= sizeof(PyObject **);
24352435
for (i = 0; i < n; i++) {
@@ -2466,8 +2466,8 @@ OBJECT_copyswap(PyObject **dst, PyObject **src, int NPY_UNUSED(swap),
24662466
{
24672467

24682468
if (src != NULL) {
2469-
if (__ALIGNED(dst,sizeof(PyObject **)) &&
2470-
__ALIGNED(src,sizeof(PyObject **))) {
2469+
if (NPY__ALIGNED(dst,sizeof(PyObject **)) &&
2470+
NPY__ALIGNED(src,sizeof(PyObject **))) {
24712471
Py_XINCREF(*src);
24722472
Py_XDECREF(*dst);
24732473
*dst = *src;
@@ -2927,7 +2927,7 @@ VOID_nonzero (char *ip, PyArrayObject *ap)
29272927
}
29282928

29292929
dummy_fields.descr = new;
2930-
if ((new->alignment > 1) && !__ALIGNED(ip + offset,
2930+
if ((new->alignment > 1) && !NPY__ALIGNED(ip + offset,
29312931
new->alignment)) {
29322932
PyArray_CLEARFLAGS(dummy_arr, NPY_ARRAY_ALIGNED);
29332933
}
@@ -2952,7 +2952,7 @@ VOID_nonzero (char *ip, PyArrayObject *ap)
29522952
return nonz;
29532953
}
29542954

2955-
#undef __ALIGNED
2955+
#undef NPY__ALIGNED
29562956

29572957

29582958
/*
@@ -4326,7 +4326,7 @@ static PyArray_Descr @from@_Descr = {
43264326
/* elsize */
43274327
0,
43284328
/* alignment */
4329-
_ALIGN(@align@),
4329+
NPY_ALIGNOF(@align@),
43304330
/* subarray */
43314331
NULL,
43324332
/* fields */
@@ -4476,7 +4476,7 @@ NPY_NO_EXPORT PyArray_Descr @from@_Descr = {
44764476
/* elsize */
44774477
sizeof(@fromtype@),
44784478
/* alignment */
4479-
_ALIGN(@fromtype@),
4479+
NPY_ALIGNOF(@fromtype@),
44804480
/* subarray */
44814481
NULL,
44824482
/* fields */
@@ -4815,7 +4815,7 @@ set_typeinfo(PyObject *dict)
48154815
*/
48164816

48174817
s = PyArray_typeinforanged(
4818-
NPY_@name@LTR, NPY_@name@, NPY_BITSOF_@uname@, _ALIGN(@type@),
4818+
NPY_@name@LTR, NPY_@name@, NPY_BITSOF_@uname@, NPY_ALIGNOF(@type@),
48194819
Py_BuildValue("@cx@", @max@),
48204820
Py_BuildValue("@cn@", @min@),
48214821
&Py@Name@ArrType_Type
@@ -4846,7 +4846,7 @@ set_typeinfo(PyObject *dict)
48464846
*/
48474847
s = PyArray_typeinfo(
48484848
NPY_@name@LTR, NPY_@name@, NPY_BITSOF_@name@,
4849-
_ALIGN(@type@), &Py@Name@ArrType_Type
4849+
NPY_ALIGNOF(@type@), &Py@Name@ArrType_Type
48504850
);
48514851
if (s == NULL) {
48524852
Py_DECREF(infodict);
@@ -4863,7 +4863,7 @@ set_typeinfo(PyObject *dict)
48634863

48644864
s = PyArray_typeinfo(
48654865
NPY_OBJECTLTR, NPY_OBJECT, sizeof(PyObject *) * CHAR_BIT,
4866-
_ALIGN(PyObject *),
4866+
NPY_ALIGNOF(PyObject *),
48674867
&PyObjectArrType_Type
48684868
);
48694869
if (s == NULL) {
@@ -4877,7 +4877,7 @@ set_typeinfo(PyObject *dict)
48774877
return -1;
48784878
}
48794879
s = PyArray_typeinfo(
4880-
NPY_STRINGLTR, NPY_STRING, 0, _ALIGN(char),
4880+
NPY_STRINGLTR, NPY_STRING, 0, NPY_ALIGNOF(char),
48814881
&PyStringArrType_Type
48824882
);
48834883
if (s == NULL) {
@@ -4891,7 +4891,7 @@ set_typeinfo(PyObject *dict)
48914891
return -1;
48924892
}
48934893
s = PyArray_typeinfo(
4894-
NPY_UNICODELTR, NPY_UNICODE, 0, _ALIGN(npy_ucs4),
4894+
NPY_UNICODELTR, NPY_UNICODE, 0, NPY_ALIGNOF(npy_ucs4),
48954895
&PyUnicodeArrType_Type
48964896
);
48974897
if (s == NULL) {
@@ -4905,7 +4905,7 @@ set_typeinfo(PyObject *dict)
49054905
return -1;
49064906
}
49074907
s = PyArray_typeinfo(
4908-
NPY_VOIDLTR, NPY_VOID, 0, _ALIGN(char),
4908+
NPY_VOIDLTR, NPY_VOID, 0, NPY_ALIGNOF(char),
49094909
&PyVoidArrType_Type
49104910
);
49114911
if (s == NULL) {
@@ -4920,7 +4920,7 @@ set_typeinfo(PyObject *dict)
49204920
}
49214921
s = PyArray_typeinforanged(
49224922
NPY_DATETIMELTR, NPY_DATETIME, NPY_BITSOF_DATETIME,
4923-
_ALIGN(npy_datetime),
4923+
NPY_ALIGNOF(npy_datetime),
49244924
MyPyLong_FromInt64(NPY_MAX_DATETIME),
49254925
MyPyLong_FromInt64(NPY_MIN_DATETIME),
49264926
&PyDatetimeArrType_Type
@@ -4937,7 +4937,7 @@ set_typeinfo(PyObject *dict)
49374937
}
49384938
s = PyArray_typeinforanged(
49394939
NPY_TIMEDELTALTR, NPY_TIMEDELTA, NPY_BITSOF_TIMEDELTA,
4940-
_ALIGN(npy_timedelta),
4940+
NPY_ALIGNOF(npy_timedelta),
49414941
MyPyLong_FromInt64(NPY_MAX_TIMEDELTA),
49424942
MyPyLong_FromInt64(NPY_MIN_TIMEDELTA),
49434943
&PyTimedeltaArrType_Type

numpy/core/src/multiarray/common.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ check_and_adjust_axis(int *axis, int ndim)
175175
}
176176

177177
/* used for some alignment checks */
178-
/*
178+
/*
179179
* GCC releases before GCC 4.9 had a bug in _Alignof. See GCC bug 52023
180180
* <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>.
181181
* clang versions < 8.0.0 have the same bug.
@@ -184,11 +184,11 @@ check_and_adjust_axis(int *axis, int ndim)
184184
|| (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \
185185
&& !defined __clang__) \
186186
|| (defined __clang__ && __clang_major__ < 8))
187-
# define _ALIGN(type) offsetof(struct {char c; type v;}, v)
187+
# define NPY_ALIGNOF(type) offsetof(struct {char c; type v;}, v)
188188
#else
189-
# define _ALIGN(type) _Alignof(type)
189+
# define NPY_ALIGNOF(type) _Alignof(type)
190190
#endif
191-
#define _UINT_ALIGN(type) npy_uint_alignment(sizeof(type))
191+
#define NPY_ALIGNOF_UINT(type) npy_uint_alignment(sizeof(type))
192192
/*
193193
* Disable harmless compiler warning "4116: unnamed type definition in
194194
* parentheses" which is caused by the _ALIGN macro.
@@ -223,20 +223,20 @@ npy_uint_alignment(int itemsize)
223223
case 1:
224224
return 1;
225225
case 2:
226-
alignment = _ALIGN(npy_uint16);
226+
alignment = NPY_ALIGNOF(npy_uint16);
227227
break;
228228
case 4:
229-
alignment = _ALIGN(npy_uint32);
229+
alignment = NPY_ALIGNOF(npy_uint32);
230230
break;
231231
case 8:
232-
alignment = _ALIGN(npy_uint64);
232+
alignment = NPY_ALIGNOF(npy_uint64);
233233
break;
234234
case 16:
235235
/*
236236
* 16 byte types are copied using 2 uint64 assignments.
237237
* See the strided copy function in lowlevel_strided_loops.c.
238238
*/
239-
alignment = _ALIGN(npy_uint64);
239+
alignment = NPY_ALIGNOF(npy_uint64);
240240
break;
241241
default:
242242
break;

numpy/core/src/multiarray/lowlevel_strided_loops.c.src

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ static int
134134

135135
#if @is_aligned@
136136
/* sanity check */
137-
assert(N == 0 || npy_is_aligned(dst, _UINT_ALIGN(@type@)));
138-
assert(N == 0 || npy_is_aligned(src, _UINT_ALIGN(@type@)));
137+
assert(N == 0 || npy_is_aligned(dst, NPY_ALIGNOF_UINT(@type@)));
138+
assert(N == 0 || npy_is_aligned(src, NPY_ALIGNOF_UINT(@type@)));
139139
#endif
140140
/*printf("fn @prefix@_@oper@_size@elsize@\n");*/
141141
while (N > 0) {
@@ -220,8 +220,8 @@ static NPY_GCC_OPT_3 int
220220
}
221221
#if @is_aligned@ && @elsize@ != 16
222222
/* sanity check */
223-
assert(N == 0 || npy_is_aligned(dst, _UINT_ALIGN(@type@)));
224-
assert(N == 0 || npy_is_aligned(src, _UINT_ALIGN(@type@)));
223+
assert(N == 0 || npy_is_aligned(dst, NPY_ALIGNOF_UINT(@type@)));
224+
assert(N == 0 || npy_is_aligned(src, NPY_ALIGNOF_UINT(@type@)));
225225
#endif
226226
#if @elsize@ == 1 && @dst_contig@
227227
memset(dst, *src, N);
@@ -864,8 +864,8 @@ static NPY_GCC_OPT_3 int
864864

865865
#if @aligned@
866866
/* sanity check */
867-
assert(N == 0 || npy_is_aligned(src, _ALIGN(_TYPE1)));
868-
assert(N == 0 || npy_is_aligned(dst, _ALIGN(_TYPE2)));
867+
assert(N == 0 || npy_is_aligned(src, NPY_ALIGNOF(_TYPE1)));
868+
assert(N == 0 || npy_is_aligned(dst, NPY_ALIGNOF(_TYPE2)));
869869
#endif
870870

871871
/*printf("@prefix@_cast_@name1@_to_@name2@\n");*/
@@ -1515,7 +1515,7 @@ mapiter_trivial_@name@(
15151515
while (itersize--) {
15161516
char * self_ptr;
15171517
npy_intp indval = *((npy_intp*)ind_ptr);
1518-
assert(npy_is_aligned(ind_ptr, _UINT_ALIGN(npy_intp)));
1518+
assert(npy_is_aligned(ind_ptr, NPY_ALIGNOF_UINT(npy_intp)));
15191519
#if @isget@
15201520
if (check_and_adjust_index(&indval, fancy_dim, 0, _save) < 0 ) {
15211521
return -1;
@@ -1529,8 +1529,8 @@ mapiter_trivial_@name@(
15291529

15301530
#if @isget@
15311531
#if @elsize@
1532-
assert(npy_is_aligned(result_ptr, _UINT_ALIGN(@copytype@)));
1533-
assert(npy_is_aligned(self_ptr, _UINT_ALIGN(@copytype@)));
1532+
assert(npy_is_aligned(result_ptr, NPY_ALIGNOF_UINT(@copytype@)));
1533+
assert(npy_is_aligned(self_ptr, NPY_ALIGNOF_UINT(@copytype@)));
15341534
*(@copytype@ *)result_ptr = *(@copytype@ *)self_ptr;
15351535
#else
15361536
char *args[2] = {self_ptr, result_ptr};
@@ -1544,8 +1544,8 @@ mapiter_trivial_@name@(
15441544

15451545
#else /* !@isget@ */
15461546
#if @elsize@
1547-
assert(npy_is_aligned(result_ptr, _UINT_ALIGN(@copytype@)));
1548-
assert(npy_is_aligned(self_ptr, _UINT_ALIGN(@copytype@)));
1547+
assert(npy_is_aligned(result_ptr, NPY_ALIGNOF_UINT(@copytype@)));
1548+
assert(npy_is_aligned(self_ptr, NPY_ALIGNOF_UINT(@copytype@)));
15491549
*(@copytype@ *)self_ptr = *(@copytype@ *)result_ptr;
15501550
#else
15511551
char *args[2] = {result_ptr, self_ptr};
@@ -1672,7 +1672,7 @@ mapiter_@name@(
16721672
for (i=0; i < @numiter@; i++) {
16731673
npy_intp indval = *((npy_intp*)outer_ptrs[i]);
16741674
assert(npy_is_aligned(outer_ptrs[i],
1675-
_UINT_ALIGN(npy_intp)));
1675+
NPY_ALIGNOF_UINT(npy_intp)));
16761676

16771677
#if @isget@ && @one_iter@
16781678
if (check_and_adjust_index(&indval, fancy_dims[i],
@@ -1693,9 +1693,9 @@ mapiter_@name@(
16931693
#if @isget@
16941694
#if @elsize@
16951695
assert(npy_is_aligned(outer_ptrs[i],
1696-
_UINT_ALIGN(@copytype@)));
1696+
NPY_ALIGNOF_UINT(@copytype@)));
16971697
assert(npy_is_aligned(self_ptr,
1698-
_UINT_ALIGN(@copytype@)));
1698+
NPY_ALIGNOF_UINT(@copytype@)));
16991699
*(@copytype@ *)(outer_ptrs[i]) = *(@copytype@ *)self_ptr;
17001700
#else
17011701
char *args[2] = {self_ptr, outer_ptrs[i]};
@@ -1709,9 +1709,9 @@ mapiter_@name@(
17091709
#else /* !@isget@ */
17101710
#if @elsize@
17111711
assert(npy_is_aligned(outer_ptrs[i],
1712-
_UINT_ALIGN(@copytype@)));
1712+
NPY_ALIGNOF_UINT(@copytype@)));
17131713
assert(npy_is_aligned(self_ptr,
1714-
_UINT_ALIGN(@copytype@)));
1714+
NPY_ALIGNOF_UINT(@copytype@)));
17151715
*(@copytype@ *)self_ptr = *(@copytype@ *)(outer_ptrs[i]);
17161716
#else
17171717
char *args[2] = {outer_ptrs[i], self_ptr};

numpy/core/src/umath/_scaled_float_dtype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static PyArray_SFloatDescr SFloatSingleton = {{
149149
.flags = NPY_USE_GETITEM|NPY_USE_SETITEM,
150150
.type_num = -1,
151151
.elsize = sizeof(double),
152-
.alignment = _ALIGN(double),
152+
.alignment = NPY_ALIGNOF(double),
153153
.f = &sfloat_slots.f,
154154
},
155155
.scaling = 1,

0 commit comments

Comments
 (0)