🌐 AI搜索 & 代理 主页
Skip to content

Commit 22cd369

Browse files
authored
BUG: Include python-including headers first (#29281)
Makes sure that Python headers always come first (if implicitly) Also adds a script to check this and a CI run to ensure this. NOTE(seberg): If that script/CI run becomes problematic and not super easy to fix maybe we shouldn't worry too much about even deleting it again. It's wortwhile for sure, but I am not sure it is worthwhile to spend too many cycles making pretty.
1 parent 24af754 commit 22cd369

File tree

12 files changed

+304
-12
lines changed

12 files changed

+304
-12
lines changed

azure-pipelines.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ stages:
5656
python tools/linter.py
5757
displayName: 'Run Lint Checks'
5858
failOnStderr: true
59+
- script: |
60+
python tools/check_python_h_first.py
61+
displayName: 'Check Python.h is first file included'
5962
6063
- job: Linux_Python_311_32bit_full_with_asserts
6164
pool:

numpy/_core/src/common/binop_override.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef NUMPY_CORE_SRC_COMMON_BINOP_OVERRIDE_H_
22
#define NUMPY_CORE_SRC_COMMON_BINOP_OVERRIDE_H_
33

4-
#include <string.h>
54
#include <Python.h>
5+
#include <string.h>
66
#include "numpy/arrayobject.h"
77

88
#include "get_attr_string.h"

numpy/_core/src/common/blas_utils.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#include "numpy/npy_math.h" // npy_get_floatstatus_barrier
2+
#include "numpy/numpyconfig.h" // NPY_VISIBILITY_HIDDEN
3+
#include "blas_utils.h"
4+
15
#include <stdbool.h>
26
#include <stdio.h>
37
#include <stdlib.h>
@@ -6,10 +10,6 @@
610
#include <sys/sysctl.h>
711
#endif
812

9-
#include "numpy/numpyconfig.h" // NPY_VISIBILITY_HIDDEN
10-
#include "numpy/npy_math.h" // npy_get_floatstatus_barrier
11-
#include "blas_utils.h"
12-
1313
#if NPY_BLAS_CHECK_FPE_SUPPORT
1414

1515
/* Return whether we're running on macOS 15.4 or later

numpy/_core/src/common/blas_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include <stdbool.h>
2-
31
#include "numpy/numpyconfig.h" // for NPY_VISIBILITY_HIDDEN
42

3+
#include <stdbool.h>
4+
55
/* NPY_BLAS_CHECK_FPE_SUPPORT controls whether we need a runtime check
66
* for floating-point error (FPE) support in BLAS.
77
*/

numpy/_core/src/multiarray/array_method.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#define _UMATHMODULE
3131
#define _MULTIARRAYMODULE
3232

33-
#include <npy_pycompat.h>
3433
#include <numpy/ndarrayobject.h>
34+
#include <npy_pycompat.h>
3535
#include "arrayobject.h"
3636
#include "array_coercion.h"
3737
#include "array_method.h"

numpy/_core/src/multiarray/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef NUMPY_CORE_SRC_MULTIARRAY_COMMON_H_
22
#define NUMPY_CORE_SRC_MULTIARRAY_COMMON_H_
33

4+
#include <Python.h>
5+
46
#include <structmember.h>
57
#include "numpy/npy_common.h"
68
#include "numpy/ndarraytypes.h"

numpy/_core/src/multiarray/textreading/conversions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#ifndef NUMPY_CORE_SRC_MULTIARRAY_TEXTREADING_CONVERSIONS_H_
22
#define NUMPY_CORE_SRC_MULTIARRAY_TEXTREADING_CONVERSIONS_H_
33

4-
#include <stdbool.h>
5-
64
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
75
#define _MULTIARRAYMODULE
86
#include "numpy/arrayobject.h"
97

8+
#include <stdbool.h>
9+
1010
#include "textreading/parser_config.h"
1111

1212
NPY_NO_EXPORT int

numpy/_core/src/npysort/npysort_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef __NPY_SORT_COMMON_H__
22
#define __NPY_SORT_COMMON_H__
33

4-
#include <stdlib.h>
54
#include <numpy/ndarraytypes.h>
5+
#include <stdlib.h>
66
#include <numpy/npy_math.h>
77
#include "dtypemeta.h"
88

numpy/_core/src/umath/clip.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* This module provides the inner loops for the clip ufunc
33
*/
4-
#include <type_traits>
54

65
#define _UMATHMODULE
76
#define _MULTIARRAYMODULE
@@ -10,6 +9,7 @@
109
#define PY_SSIZE_T_CLEAN
1110
#include <Python.h>
1211

12+
#include <type_traits>
1313
#include "numpy/halffloat.h"
1414
#include "numpy/ndarraytypes.h"
1515
#include "numpy/npy_common.h"

numpy/random/src/mt19937/randomkit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6363
*/
6464

65+
#include <Python.h>
66+
6567
/* static char const rcsid[] =
6668
"@(#) $Jeannot: randomkit.c,v 1.28 2005/07/21 22:14:09 js Exp $"; */
6769

0 commit comments

Comments
 (0)