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

Skip to content

Commit d4a3937

Browse files
charriscertik
authored andcommitted
BUG: Replace unprefixed SIZEOF_* macros with prefixed versions.
The sources don't define NPY_NO_PREFIX and consequently none of the unprefixed macros are defined. Using them can lead to some unexpected results.
1 parent 19953ba commit d4a3937

File tree

9 files changed

+25
-26
lines changed

9 files changed

+25
-26
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4088,8 +4088,6 @@ set_typeinfo(PyObject *dict)
40884088
infodict = PyDict_New();
40894089
if (infodict == NULL) return -1;
40904090

4091-
#define BITSOF_INTP CHAR_BIT*SIZEOF_PY_INTPTR_T
4092-
#define BITSOF_BYTE CHAR_BIT
40934091

40944092
/**begin repeat
40954093
*
@@ -4219,7 +4217,7 @@ set_typeinfo(PyObject *dict)
42194217
s = Py_BuildValue("ciiiNNO", NPY_DATETIMELTR,
42204218
#endif
42214219
NPY_DATETIME,
4222-
sizeof(npy_datetime) * CHAR_BIT,
4220+
NPY_BITSOF_DATETIME,
42234221
_ALIGN(npy_datetime),
42244222
MyPyLong_FromInt64(NPY_MAX_DATETIME),
42254223
MyPyLong_FromInt64(NPY_MIN_DATETIME),
@@ -4232,7 +4230,7 @@ set_typeinfo(PyObject *dict)
42324230
s = Py_BuildValue("ciiiNNO",NPY_TIMEDELTALTR,
42334231
#endif
42344232
NPY_TIMEDELTA,
4235-
sizeof(npy_timedelta) * CHAR_BIT,
4233+
NPY_BITSOF_TIMEDELTA,
42364234
_ALIGN(npy_timedelta),
42374235
MyPyLong_FromInt64(NPY_MAX_TIMEDELTA),
42384236
MyPyLong_FromInt64(NPY_MIN_TIMEDELTA),

numpy/core/src/multiarray/conversion_utils.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ PyArray_PyIntAsInt(PyObject *o)
742742
return -1;
743743
}
744744

745-
#if (SIZEOF_LONG > SIZEOF_INT)
745+
#if (NPY_SIZEOF_LONG > NPY_SIZEOF_INT)
746746
if ((long_value < INT_MIN) || (long_value > INT_MAX)) {
747747
PyErr_SetString(PyExc_ValueError, "integer won't fit into a C int");
748748
return -1;
@@ -774,9 +774,9 @@ PyArray_PyIntAsIntp(PyObject *o)
774774
goto finish;
775775
}
776776

777-
#if NPY_SIZEOF_INTP == SIZEOF_LONG
777+
#if NPY_SIZEOF_INTP == NPY_SIZEOF_LONG
778778
descr = &LONG_Descr;
779-
#elif NPY_SIZEOF_INTP == SIZEOF_INT
779+
#elif NPY_SIZEOF_INTP == NPY_SIZEOF_INT
780780
descr = &INT_Descr;
781781
#else
782782
descr = &LONGLONG_Descr;
@@ -869,7 +869,7 @@ PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals)
869869
*/
870870
if ((nd=PySequence_Length(seq)) == -1) {
871871
if (PyErr_Occurred()) PyErr_Clear();
872-
#if SIZEOF_LONG >= NPY_SIZEOF_INTP && !defined(NPY_PY3K)
872+
#if NPY_SIZEOF_LONG >= NPY_SIZEOF_INTP && !defined(NPY_PY3K)
873873
if (!(op = PyNumber_Int(seq))) {
874874
return -1;
875875
}
@@ -879,7 +879,7 @@ PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals)
879879
}
880880
#endif
881881
nd = 1;
882-
#if SIZEOF_LONG >= NPY_SIZEOF_INTP
882+
#if NPY_SIZEOF_LONG >= NPY_SIZEOF_INTP
883883
vals[0] = (npy_intp ) PyInt_AsLong(op);
884884
#else
885885
vals[0] = (npy_intp ) PyLong_AsLongLong(op);
@@ -908,7 +908,7 @@ PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals)
908908
if (op == NULL) {
909909
return -1;
910910
}
911-
#if SIZEOF_LONG >= NPY_SIZEOF_INTP
911+
#if NPY_SIZEOF_LONG >= NPY_SIZEOF_INTP
912912
vals[i]=(npy_intp )PyInt_AsLong(op);
913913
#else
914914
vals[i]=(npy_intp )PyLong_AsLongLong(op);
@@ -1153,7 +1153,7 @@ PyArray_IntTupleFromIntp(int len, npy_intp *vals)
11531153
goto fail;
11541154
}
11551155
for (i = 0; i < len; i++) {
1156-
#if NPY_SIZEOF_INTP <= SIZEOF_LONG
1156+
#if NPY_SIZEOF_INTP <= NPY_SIZEOF_LONG
11571157
PyObject *o = PyInt_FromLong((long) vals[i]);
11581158
#else
11591159
PyObject *o = PyLong_FromLongLong((npy_longlong) vals[i]);

numpy/core/src/multiarray/getset.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ static PyObject *
383383
array_size_get(PyArrayObject *self)
384384
{
385385
npy_intp size=PyArray_SIZE(self);
386-
#if NPY_SIZEOF_INTP <= SIZEOF_LONG
386+
#if NPY_SIZEOF_INTP <= NPY_SIZEOF_LONG
387387
return PyInt_FromLong((long) size);
388388
#else
389389
if (size > NPY_MAX_LONG || size < NPY_MIN_LONG) {
@@ -399,7 +399,7 @@ static PyObject *
399399
array_nbytes_get(PyArrayObject *self)
400400
{
401401
npy_intp nbytes = PyArray_NBYTES(self);
402-
#if NPY_SIZEOF_INTP <= SIZEOF_LONG
402+
#if NPY_SIZEOF_INTP <= NPY_SIZEOF_LONG
403403
return PyInt_FromLong((long) nbytes);
404404
#else
405405
if (nbytes > NPY_MAX_LONG || nbytes < NPY_MIN_LONG) {

numpy/core/src/multiarray/iterators.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ arraymultiter_dealloc(PyArrayMultiIterObject *multi)
16771677
static PyObject *
16781678
arraymultiter_size_get(PyArrayMultiIterObject *self)
16791679
{
1680-
#if NPY_SIZEOF_INTP <= SIZEOF_LONG
1680+
#if NPY_SIZEOF_INTP <= NPY_SIZEOF_LONG
16811681
return PyInt_FromLong((long) self->size);
16821682
#else
16831683
if (self->size < NPY_MAX_LONG) {
@@ -1692,7 +1692,7 @@ arraymultiter_size_get(PyArrayMultiIterObject *self)
16921692
static PyObject *
16931693
arraymultiter_index_get(PyArrayMultiIterObject *self)
16941694
{
1695-
#if NPY_SIZEOF_INTP <= SIZEOF_LONG
1695+
#if NPY_SIZEOF_INTP <= NPY_SIZEOF_LONG
16961696
return PyInt_FromLong((long) self->index);
16971697
#else
16981698
if (self->size < NPY_MAX_LONG) {

numpy/core/src/multiarray/mapping.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ NPY_NO_EXPORT int
2323
array_ass_big_item(PyArrayObject *self, npy_intp i, PyObject *v);
2424

2525
#if PY_VERSION_HEX < 0x02050000
26-
#if SIZEOF_INT == NPY_SIZEOF_INTP
26+
#if NPY_SIZEOF_INT == NPY_SIZEOF_INTP
2727
#define array_ass_item array_ass_big_item
2828
#endif
2929
#else
30+
/* SIZEOF_SIZE_T is nowhere defined, Py_ssize_t perhaps?*/
3031
#if SIZEOF_SIZE_T == NPY_SIZEOF_INTP
3132
#define array_ass_item array_ass_big_item
3233
#endif

numpy/core/src/multiarray/multiarraymodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3784,7 +3784,7 @@ setup_scalartypes(PyObject *NPY_UNUSED(dict))
37843784
SINGLE_INHERIT(Bool, Generic);
37853785
SINGLE_INHERIT(Byte, SignedInteger);
37863786
SINGLE_INHERIT(Short, SignedInteger);
3787-
#if SIZEOF_INT == SIZEOF_LONG && !defined(NPY_PY3K)
3787+
#if NPY_SIZEOF_INT == NPY_SIZEOF_LONG && !defined(NPY_PY3K)
37883788
DUAL_INHERIT(Int, Int, SignedInteger);
37893789
#else
37903790
SINGLE_INHERIT(Int, SignedInteger);
@@ -3794,7 +3794,7 @@ setup_scalartypes(PyObject *NPY_UNUSED(dict))
37943794
#else
37953795
SINGLE_INHERIT(Long, SignedInteger);
37963796
#endif
3797-
#if NPY_SIZEOF_LONGLONG == SIZEOF_LONG && !defined(NPY_PY3K)
3797+
#if NPY_SIZEOF_LONGLONG == NPY_SIZEOF_LONG && !defined(NPY_PY3K)
37983798
DUAL_INHERIT(LongLong, Int, SignedInteger);
37993799
#else
38003800
SINGLE_INHERIT(LongLong, SignedInteger);

numpy/core/src/multiarray/scalartypes.c.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,7 @@ int_arrtype_hash(PyObject *obj)
29392939
* #ext = && (x >= LONG_MIN),#
29402940
*/
29412941
#if NPY_SIZEOF_LONG != NPY_SIZEOF_LONGLONG
2942-
/* we assume SIZEOF_LONGLONG=2*SIZEOF_LONG */
2942+
/* we assume NPY_SIZEOF_LONGLONG=2*NPY_SIZEOF_LONG */
29432943
static long
29442944
@char@longlong_arrtype_hash(PyObject *obj)
29452945
{

numpy/core/src/npymath/_signbit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ _npy_signbit_d(double x)
1212

1313
u.d = x;
1414

15-
#if SIZEOF_INT == 4
15+
#if NPY_SIZEOF_INT == 4
1616

1717
#ifdef WORDS_BIGENDIAN /* defined in pyconfig.h */
1818
return u.i[0] < 0;
1919
#else
2020
return u.i[1] < 0;
2121
#endif
2222

23-
#else /* SIZEOF_INT != 4 */
23+
#else /* NPY_SIZEOF_INT != 4 */
2424

2525
#ifdef WORDS_BIGENDIAN
2626
return u.s[0] < 0;
2727
#else
2828
return u.s[3] < 0;
2929
#endif
3030

31-
#endif /* SIZEOF_INT */
31+
#endif /* NPY_SIZEOF_INT */
3232
}

numpy/core/src/scalarmathmodule.c.src

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* types of the same rank to have the same width.
2525
*/
2626

27-
#if SIZEOF_LONGLONG == 64
27+
#if NPY_SIZEOF_LONGLONG == 64
2828

2929
static int
3030
ulonglong_overflow(npy_ulonglong a, npy_ulonglong b)
@@ -72,7 +72,7 @@ slonglong_overflow(npy_longlong a0, npy_longlong b0)
7272
(((x & mask) + (y & mask) + (w >> 32)) >> 31);
7373
}
7474

75-
#elif SIZEOF_LONGLONG == 128
75+
#elif NPY_SIZEOF_LONGLONG == 128
7676

7777
static int
7878
ulonglong_overflow(npy_ulonglong a, npy_ulonglong b)
@@ -203,8 +203,8 @@ static void
203203
}
204204
/**end repeat**/
205205

206-
#ifndef SIZEOF_BYTE
207-
#define SIZEOF_BYTE 1
206+
#ifndef NPY_SIZEOF_BYTE
207+
#define NPY_SIZEOF_BYTE 1
208208
#endif
209209

210210
/**begin repeat

0 commit comments

Comments
 (0)