Skip to content

Commit

Permalink
Enforce that the numpy-1 only option is given first
Browse files Browse the repository at this point in the history
  • Loading branch information
seberg committed Mar 16, 2024
1 parent 2514af5 commit e0a16e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/pybind11/detail/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@ PYBIND11_WARNING_POP
# define PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
#endif

// Ensure that NumPy 1 only mode is enabled first in each compilation unit
#if defined(PYBIND11_NUMPY_1_ONLY)
# define PYBIND11_INTERNAL_NUMPY_1_ONLY_DETECTED 1
#else
# define PYBIND11_INTERNAL_NUMPY_1_ONLY_DETECTED 0
#endif

// #define PYBIND11_STR_LEGACY_PERMISSIVE
// If DEFINED, pybind11::str can hold PyUnicodeObject or PyBytesObject
// (probably surprising and never documented, but this was the
Expand Down
6 changes: 6 additions & 0 deletions include/pybind11/numpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

#pragma once

// Unless this is the first header PYBIND11_INTERNAL_NUMPY_1_ONLY_DETECTED is defined
#if defined(PYBIND11_NUMPY_1_ONLY) && defined(PYBIND11_INTERNAL_NUMPY_1_ONLY_DETECTED) \
&& PYBIND11_INTERNAL_NUMPY_1_ONLY_DETECTED == 0
# error PYBIND11_NUMPY_1_ONLY must be defined before any pybind11 header is included.
#endif

#include "pybind11.h"
#include "detail/common.h"
#include "complex.h"
Expand Down

0 comments on commit e0a16e6

Please sign in to comment.