8000 Merge pull request #25072 from rgommers/fix-build-warnings · numpy/numpy@a7b7e55 · GitHub
[go: up one dir, main page]

Skip to content

Commit a7b7e55

Browse files
authored
Merge pull request #25072 from rgommers/fix-build-warnings
MAINT: default to C11 rather than C99, fix most build warnings with Clang 14
2 parents 3ffad97 + 0ee0b6f commit a7b7e55

11 files changed

+18
-93
lines changed

build_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
meson-python>=0.13.1
2-
Cython>=3.0
2+
Cython>=3.0.6
33
ninja
44
spin==0.8
55
build

doc/source/dev/development_environment.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Recommended development setup
1111
Since NumPy contains parts written in C and Cython that need to be
1212
compiled before use, make sure you have the necessary compilers and Python
1313
development headers installed - see :ref:`building-from-source`. Building
14-
NumPy as of version ``1.17`` requires a C99 compliant compiler.
14+
NumPy as of version ``2.0`` requires C11 and C++17 compliant compilers.
1515

1616
Having compiled code also means that importing NumPy from the development
1717
sources needs some additional steps, which are explained below. For the rest

meson.build

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ project(
1010
default_options: [
1111
'buildtype=debugoptimized',
1212
'b_ndebug=if-release',
13-
'c_std=c99',
13+
'c_std=c11',
1414
'cpp_std=c++17',
1515
'pkgconfig.relocatable=true',
1616
],
@@ -33,8 +33,8 @@ elif cc.get_id() == 'msvc'
3333
'when building with MSVC')
3434
endif
3535
endif
36-
if not cy.version().version_compare('>=0.29.34')
37-
error('NumPy requires Cython >= 0.29.34')
36+
if not cy.version().version_compare('>=3.0.6')
37+
error('NumPy requires Cython >= 3.0.6')
3838
endif
3939

4040
py = import('python').find_installation(pure: false)

numpy/_core/src/multiarray/einsum.c.src

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,6 @@ get_combined_dims_view(PyArrayObject *op, int iop, char *labels)
402402
}
403403
/* A repeated label, find the original one and merge them. */
404404
else {
405-
#ifdef __GNUC__
406-
#pragma GCC diagnostic push
407-
#pragma GCC diagnostic ignored "-Wuninitialized"
408-
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
409-
#endif
410405
int i = icombinemap[idim + label];
411406

412407
icombinemap[idim] = -1;
@@ -419,9 +414,6 @@ get_combined_dims_view(PyArrayObject *op, int iop, char *labels)
419414
return NULL;
420415
}
421416
new_strides[i] += stride;
422-
#ifdef __GNUC__
423-
#pragma GCC diagnostic pop
424-
#endif
425417
}
426418
}
427419

numpy/_core/src/multiarray/item_selection.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,6 +2367,7 @@ PyArray_Compress(PyArrayObject *self, PyObject *condition, int axis,
23672367
* even though it uses 64 bit types its faster than the bytewise sum on 32 bit
23682368
* but a 32 bit type version would make it even faster on these platforms
23692369
*/
2370+
#if !NPY_SIMD
23702371
static inline npy_intp
23712372
count_nonzero_bytes_384(const npy_uint64 * w)
23722373
{
@@ -2407,6 +2408,7 @@ count_nonzero_bytes_384(const npy_uint64 * w)
24072408

24082409
return r;
24092410
}
2411+
#endif
24102412

24112413
#if NPY_SIMD
24122414
/* Count the zero bytes between `*d` and `end`, updating `*d` to point to where to keep counting from. */

numpy/_core/src/npysort/selection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ _get_partition_func(int type, NPY_SELECTKIND which)
518518
npy_intp i;
519519
npy_intp ntypes = partition_t::map.size();
520520

521-
if (which >= NPY_NSELECTS) {
521+
if ((int)which < 0 || (int)which >= NPY_NSELECTS) {
522522
return NULL;
523523
}
524524
for (i = 0; i < ntypes; i++) {

numpy/_core/src/umath/loops_arithm_fp.dispatch.c.src

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ NPY_NO_EXPORT int NPY_CPU_DISPATCH_CURFX(@TYPE@_@kind@_indexed)
215215
//###############################################################################
216216

217217
/********************************************************************************
218-
** op intrinics
218+
** op intrinsics
219219
********************************************************************************/
220220

221221
#if NPY_SIMD_F32
@@ -296,61 +296,6 @@ simd_csquare_f64(npyv_f64 x)
296296
{ return simd_cmul_f64(x, x); }
297297
#endif
298298

299-
/**begin repeat
300-
* #type = npy_float, npy_double#
301-
* #sfx = f32, f64#
302-
* #bsfx = b32, b64#
303-
* #usfx = b32, u64#
304-
* #VECTOR = NPY_SIMD_F32, NPY_SIMD_F64#
305-
* #is_double = 0, 1#
306-
* #c = f, #
307-
* #INF = NPY_INFINITYF, NPY_INFINITY#
308-
* #NAN = NPY_NANF, NPY_NAN#
309-
*/
310-
#if @VECTOR@
311-
NPY_FINLINE npyv_@sfx@
312-
simd_cabsolute_@sfx@(npyv_@sfx@ re, npyv_@sfx@ im)
313-
{
314-
const npyv_@sfx@ inf = npyv_setall_@sfx@(@INF@);
315-
const npyv_@sfx@ nan = npyv_setall_@sfx@(@NAN@);
316-
317-
re = npyv_abs_@sfx@(re);
318-
im = npyv_abs_@sfx@(im);
319-
/*
320-
* If real or imag = INF, then convert it to inf + j*inf
321-
* Handles: inf + j*nan, nan + j*inf
322-
*/
323-
npyv_@bsfx@ re_infmask = npyv_cmpeq_@sfx@(re, inf);
324-
npyv_@bsfx@ im_infmask = npyv_cmpeq_@sfx@(im, inf);
325-
im = npyv_select_@sfx@(re_infmask, inf, im);
326-
re = npyv_select_@sfx@(im_infmask, inf, re);
327-
/*
328-
* If real or imag = NAN, then convert it to nan + j*nan
329-
* Handles: x + j*nan, nan + j*x
330-
*/
331-
npyv_@bsfx@ re_nnanmask = npyv_notnan_@sfx@(re);
332-
npyv_@bsfx@ im_nnanmask = npyv_notnan_@sfx@(im);
333-
im = npyv_select_@sfx@(re_nnanmask, im, nan);
334-
re = npyv_select_@sfx@(im_nnanmask, re, nan);
335-
336-
npyv_@sfx@ larger = npyv_max_@sfx@(re, im);
337-
npyv_@sfx@ smaller = npyv_min_@sfx@(im, re);
338-
/*
339-
* Calculate div_mask to prevent 0./0. and inf/inf operations in div
340-
*/
341-
npyv_@bsfx@ zeromask = npyv_cmpeq_@sfx@(larger, npyv_zero_@sfx@());
342-
npyv_@bsfx@ infmask = npyv_cmpeq_@sfx@(smaller, inf);
343-
npyv_@bsfx@ div_mask = npyv_not_@bsfx@(npyv_or_@bsfx@(zeromask, infmask));
344-
345-
npyv_@sfx@ ratio = npyv_ifdivz_@sfx@(div_mask, smaller, larger);
346-
npyv_@sfx@ hypot = npyv_sqrt_@sfx@(
347-
npyv_muladd_@sfx@(ratio, ratio, npyv_setall_@sfx@(1.0@c@)
348-
));
349-
return npyv_mul_@sfx@(hypot, larger);
350-
}
351-
#endif // VECTOR
352-
/**end repeat**/
353-
354299
/********************************************************************************
355300
** Defining ufunc inner functions
356301
********************************************************************************/

numpy/_core/src/umath/scalarmath.c.src

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,12 +1804,6 @@ static PyObject *
18041804
}
18051805
/**end repeat**/
18061806

1807-
#if __GNUC__ < 10
1808-
/* At least GCC 9.2 issues spurious warnings for arg2 below. */
1809-
#pragma GCC diagnostic push /* matching pop after function and repeat */
1810-
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
1811-
#endif
1812-
18131807
/**begin repeat
18141808
* #oper = le, ge, lt, gt, eq, ne#
18151809
* #op = <=, >=, <, >, ==, !=#
@@ -1941,10 +1935,6 @@ static PyObject*
19411935
#undef IS_@name@
19421936
/**end repeat**/
19431937

1944-
#if __GNUC__ < 10
1945-
#pragma GCC diagnostic pop
1946-
#endif
1947-
19481938

19491939
/**begin repeat
19501940
* #name = byte, ubyte, short, ushort, int, uint,

numpy/_core/src/umath/special_integer_comparisons.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ get_min_max(int typenum, long long *min, unsigned long long *max)
9999
*max = NPY_MAX_ULONGLONG;
100100
break;
101101
default:
102+
*max = 0;
102103
assert(0);
103104
}
104105
}

numpy/linalg/umath_linalg.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ static const char* umath_linalg_version_string = "0.1.5";
3434
* Debugging support *
3535
****************************************************************************
3636
*/
37+
#define _UMATH_LINALG_DEBUG 0
38+
3739
#define TRACE_TXT(...) do { fprintf (stderr, __VA_ARGS__); } while (0)
3840
#define STACK_TRACE do {} while (0)
3941
#define TRACE\
@@ -46,7 +48,7 @@ static const char* umath_linalg_version_string = "0.1.5";
4648
STACK_TRACE; \
4749
} while (0)
4850

49-
#if 0
51+
#if _UMATH_LINALG_DEBUG
5052
#if defined HAVE_EXECINFO_H
5153
#include <execinfo.h>
5254
#elif defined HAVE_LIBUNWIND_H
@@ -574,6 +576,7 @@ init_linearize_data(LINEARIZE_DATA_t *lin_data,
574576
lin_data, rows, columns, row_strides, column_strides, columns);
575577
}
576578

579+
#if _UMATH_LINALG_DEBUG
577580
static inline void
578581
dump_ufunc_object(PyUFuncObject* ufunc)
579582
{
@@ -651,7 +654,7 @@ dump_matrix(const char* name,
651654
TRACE_TXT(" |\n");
652655
}
653656
}
654-
657+
#endif
655658

656659
/*
657660
*****************************************************************************
@@ -761,12 +764,6 @@ update_pointers(npy_uint8** bases, ptrdiff_t* offsets, size_t count)
761764
}
762765

763766

764-
/* disable -Wmaybe-uninitialized as there is some code that generate false
765-
positives with this warning
766-
*/
767-
#pragma GCC diagnostic push
768-
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
769-
770767
/*
771768
*****************************************************************************
772769
** DISPATCHER FUNCS **
@@ -2926,7 +2923,7 @@ using basetyp = basetype_t<typ>;
29262923
(fortran_int)dimensions[0],
29272924
(fortran_int)dimensions[1],
29282925
dispatch_scalar<typ>())) {
2929-
LINEARIZE_DATA_t a_in, u_out, s_out, v_out;
2926+
LINEARIZE_DATA_t a_in, u_out = {}, s_out = {}, v_out = {};
29302927
fortran_int min_m_n = params.M < params.N ? params.M : params.N;
29312928

29322929
init_linearize_data(&a_in, params.N, params.M, steps[1], steps[0]);
@@ -4081,8 +4078,6 @@ dispatch_scalar<typ>{});
40814078
set_fp_invalid_or_clear(error_occurred);
40824079
}
40834080

4084-
#pragma GCC diagnostic pop
4085-
40864081
/* -------------------------------------------------------------------------- */
40874082
/* gufunc registration */
40884083

@@ -4548,7 +4543,7 @@ addUfuncs(PyObject *dictionary) {
45484543
if (f == NULL) {
45494544
return -1;
45504545
}
4551-
#if 0
4546+
#if _UMATH_LINALG_DEBUG
45524547
dump_ufunc_object((PyUFuncObject*) f);
45534548
#endif
45544549
int ret = PyDict_SetItemString(dictionary, d->name, f);

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
build-backend = "mesonpy"
33
requires = [
44
"meson-python>=0.15.0",
5-
"Cython>=3.0",
5+
"Cython>=3.0.6", # keep in sync with version check in meson.build
66
]
77

88
[project]

0 commit comments

Comments
 (0)
0