Skip to content

Commit

Permalink
BLD: fix missing Python.h includes
Browse files Browse the repository at this point in the history
`Python.h` must be included before including and standard library
headers, if it's pulled in (which happens when you include numpy
headers). Otherwise we see build warnings like:

```
142/244] Compiling C object numpy/core/_multiarray_umath.cpython-311-x86_64-linux-gnu.so.p/src_multiarray_textreading_field_types.c.o
In file included from /opt/hostedtoolcache/Python/3.11.0/x64/include/python3.11/Python.h:86,
                 from ../numpy/core/include/numpy/npy_common.h:5,
                 from ../numpy/core/include/numpy/ndarraytypes.h:4,
                 from ../numpy/core/src/multiarray/textreading/field_types.h:9,
                 from ../numpy/core/src/multiarray/textreading/field_types.c:1:
/opt/hostedtoolcache/Python/3.11.0/x64/include/python3.11/cpython/pytime.h:208:60: warning: ‘struct timespec’ declared inside parameter list will not be visible outside of this definition or declaration
  208 | PyAPI_FUNC(int) _PyTime_FromTimespec(_PyTime_t *tp, struct timespec *ts);
      |                                                            ^~~~~~~~
/opt/hostedtoolcache/Python/3.11.0/x64/include/python3.11/cpython/pytime.h:213:56: warning: ‘struct timespec’ declared inside parameter list will not be visible outside of this definition or declaration
  213 | PyAPI_FUNC(int) _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts);
      |                                                        ^~~~~~~~
/opt/hostedtoolcache/Python/3.11.0/x64/include/python3.11/cpython/pytime.h:217:63: warning: ‘struct timespec’ declared inside parameter list will not be visible outside of this definition or declaration
  217 | PyAPI_FUNC(void) _PyTime_AsTimespec_clamp(_PyTime_t t, struct timespec *ts);
      |                                                               ^~~~~~~~
```
  • Loading branch information
rgommers committed Nov 25, 2022
1 parent 19d982d commit 82fd2b8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions numpy/core/src/multiarray/textreading/field_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#ifndef NUMPY_CORE_SRC_MULTIARRAY_TEXTREADING_FIELD_TYPES_H_
#define NUMPY_CORE_SRC_MULTIARRAY_TEXTREADING_FIELD_TYPES_H_

#define PY_SSIZE_T_CLEAN
#include <Python.h>

#include <stdint.h>
#include <stdbool.h>
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
Expand Down
6 changes: 3 additions & 3 deletions numpy/core/src/multiarray/textreading/readtext.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <stdio.h>
#include <stdbool.h>

#define PY_SSIZE_T_CLEAN
#include <Python.h>

#include <stdio.h>
#include <stdbool.h>

#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
Expand Down
5 changes: 3 additions & 2 deletions numpy/core/src/multiarray/textreading/stream_pyobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* single line of a file.
*/

#define PY_SSIZE_T_CLEAN
#include <Python.h>

#include <stdio.h>
#include <stdlib.h>

#define PY_SSIZE_T_CLEAN
#include <Python.h>
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
Expand Down
4 changes: 4 additions & 0 deletions numpy/linalg/lapack_lite/f2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
it is available, and shipping a static library isn't portable.
*/

#define PY_SSIZE_T_CLEAN
#include <Python.h>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "f2c.h"


Expand Down
3 changes: 3 additions & 0 deletions numpy/linalg/lapack_lite/f2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#ifndef F2C_INCLUDE
#define F2C_INCLUDE

#define PY_SSIZE_T_CLEAN
#include <Python.h>

#include <math.h>
#include "numpy/npy_common.h"
#include "npy_cblas.h"
Expand Down

0 comments on commit 82fd2b8

Please sign in to comment.