1/*
2 pybind11/detail/common.h -- Basic macros
3
4 Copyright (c) 2016 Wenzel Jakob <[email protected]>
5
6 All rights reserved. Use of this source code is governed by a
7 BSD-style license that can be found in the LICENSE file.
8*/
9
10#pragma once
11
12#define PYBIND11_VERSION_MAJOR 2
13#define PYBIND11_VERSION_MINOR 10
14#define PYBIND11_VERSION_PATCH 0
15
16// Similar to Python's convention: https://docs.python.org/3/c-api/apiabiversion.html
17// Additional convention: 0xD = dev
18#define PYBIND11_VERSION_HEX 0x020A0000
19
20#define PYBIND11_NAMESPACE_BEGIN(name) namespace name {
21#define PYBIND11_NAMESPACE_END(name) }
22
23// Robust support for some features and loading modules compiled against different pybind versions
24// requires forcing hidden visibility on pybind code, so we enforce this by setting the attribute
25// on the main `pybind11` namespace.
26#if !defined(PYBIND11_NAMESPACE)
27# ifdef __GNUG__
28# define PYBIND11_NAMESPACE pybind11 __attribute__((visibility("hidden")))
29# else
30# define PYBIND11_NAMESPACE pybind11
31# endif
32#endif
33
34#if !(defined(_MSC_VER) && __cplusplus == 199711L)
35# if __cplusplus >= 201402L
36# define PYBIND11_CPP14
37# if __cplusplus >= 201703L
38# define PYBIND11_CPP17
39# if __cplusplus >= 202002L
40# define PYBIND11_CPP20
41// Please update tests/pybind11_tests.cpp `cpp_std()` when adding a macro here.
42# endif
43# endif
44# endif
45#elif defined(_MSC_VER) && __cplusplus == 199711L
46// MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully
47// implemented). Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3
48// or newer.
49# if _MSVC_LANG >= 201402L
50# define PYBIND11_CPP14
51# if _MSVC_LANG > 201402L
52# define PYBIND11_CPP17
53# if _MSVC_LANG >= 202002L
54# define PYBIND11_CPP20
55# endif
56# endif
57# endif
58#endif
59
60// Compiler version assertions
61#if defined(__INTEL_COMPILER)
62# if __INTEL_COMPILER < 1800
63# error pybind11 requires Intel C++ compiler v18 or newer
64# elif __INTEL_COMPILER < 1900 && defined(PYBIND11_CPP14)
65# error pybind11 supports only C++11 with Intel C++ compiler v18. Use v19 or newer for C++14.
66# endif
67/* The following pragma cannot be pop'ed:
68 https://community.intel.com/t5/Intel-C-Compiler/Inline-and-no-inline-warning/td-p/1216764 */
69# pragma warning disable 2196 // warning #2196: routine is both "inline" and "noinline"
70#elif defined(__clang__) && !defined(__apple_build_version__)
71# if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 3)
72# error pybind11 requires clang 3.3 or newer
73# endif
74#elif defined(__clang__)
75// Apple changes clang version macros to its Xcode version; the first Xcode release based on
76// (upstream) clang 3.3 was Xcode 5:
77# if __clang_major__ < 5
78# error pybind11 requires Xcode/clang 5.0 or newer
79# endif
80#elif defined(__GNUG__)
81# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
82# error pybind11 requires gcc 4.8 or newer
83# endif
84#elif defined(_MSC_VER)
85# if _MSC_VER < 1910
86# error pybind11 2.10+ requires MSVC 2017 or newer
87# endif
88#endif
89
90#if !defined(PYBIND11_EXPORT)
91# if defined(WIN32) || defined(_WIN32)
92# define PYBIND11_EXPORT __declspec(dllexport)
93# else
94# define PYBIND11_EXPORT __attribute__((visibility("default")))
95# endif
96#endif
97
98#if !defined(PYBIND11_EXPORT_EXCEPTION)
99# ifdef __MINGW32__
100// workaround for:
101// error: 'dllexport' implies default visibility, but xxx has already been declared with a
102// different visibility
103# define PYBIND11_EXPORT_EXCEPTION
104# else
105# define PYBIND11_EXPORT_EXCEPTION PYBIND11_EXPORT
106# endif
107#endif
108
109// For CUDA, GCC7, GCC8:
110// PYBIND11_NOINLINE_FORCED is incompatible with `-Wattributes -Werror`.
111// When defining PYBIND11_NOINLINE_FORCED, it is best to also use `-Wno-attributes`.
112// However, the measured shared-library size saving when using noinline are only
113// 1.7% for CUDA, -0.2% for GCC7, and 0.0% for GCC8 (using -DCMAKE_BUILD_TYPE=MinSizeRel,
114// the default under pybind11/tests).
115#if !defined(PYBIND11_NOINLINE_FORCED) \
116 && (defined(__CUDACC__) || (defined(__GNUC__) && (__GNUC__ == 7 || __GNUC__ == 8)))
117# define PYBIND11_NOINLINE_DISABLED
118#endif
119
120// The PYBIND11_NOINLINE macro is for function DEFINITIONS.
121// In contrast, FORWARD DECLARATIONS should never use this macro:
122// https://stackoverflow.com/questions/9317473/forward-declaration-of-inline-functions
123#if defined(PYBIND11_NOINLINE_DISABLED) // Option for maximum portability and experimentation.
124# define PYBIND11_NOINLINE inline
125#elif defined(_MSC_VER)
126# define PYBIND11_NOINLINE __declspec(noinline) inline
127#else
128# define PYBIND11_NOINLINE __attribute__((noinline)) inline
129#endif
130
131#if defined(__MINGW32__)
132// For unknown reasons all PYBIND11_DEPRECATED member trigger a warning when declared
133// whether it is used or not
134# define PYBIND11_DEPRECATED(reason)
135#elif defined(PYBIND11_CPP14)
136# define PYBIND11_DEPRECATED(reason) [[deprecated(reason)]]
137#else
138# define PYBIND11_DEPRECATED(reason) __attribute__((deprecated(reason)))
139#endif
140
141#if defined(PYBIND11_CPP17)
142# define PYBIND11_MAYBE_UNUSED [[maybe_unused]]
143#elif defined(_MSC_VER) && !defined(__clang__)
144# define PYBIND11_MAYBE_UNUSED
145#else
146# define PYBIND11_MAYBE_UNUSED __attribute__((__unused__))
147#endif
148
149/* Don't let Python.h #define (v)snprintf as macro because they are implemented
150 properly in Visual Studio since 2015. */
151#if defined(_MSC_VER)
152# define HAVE_SNPRINTF 1
153#endif
154
155/// Include Python header, disable linking to pythonX_d.lib on Windows in debug mode
156#if defined(_MSC_VER)
157# pragma warning(push)
158// C4505: 'PySlice_GetIndicesEx': unreferenced local function has been removed (PyPy only)
159# pragma warning(disable : 4505)
160# if defined(_DEBUG) && !defined(Py_DEBUG)
161// Workaround for a VS 2022 issue.
162// NOTE: This workaround knowingly violates the Python.h include order requirement:
163// https://docs.python.org/3/c-api/intro.html#include-files
164// See https://github.com/pybind/pybind11/pull/3497 for full context.
165# include <yvals.h>
166# if _MSVC_STL_VERSION >= 143
167# include <crtdefs.h>
168# endif
169# define PYBIND11_DEBUG_MARKER
170# undef _DEBUG
171# endif
172#endif
173
174// https://en.cppreference.com/w/c/chrono/localtime
175#if defined(__STDC_LIB_EXT1__) && !defined(__STDC_WANT_LIB_EXT1__)
176# define __STDC_WANT_LIB_EXT1__
177#endif
178
179#ifdef __has_include
180// std::optional (but including it in c++14 mode isn't allowed)
181# if defined(PYBIND11_CPP17) && __has_include(<optional>)
182# define PYBIND11_HAS_OPTIONAL 1
183# endif
184// std::experimental::optional (but not allowed in c++11 mode)
185# if defined(PYBIND11_CPP14) && (__has_include(<experimental/optional>) && \
186 !__has_include(<optional>))
187# define PYBIND11_HAS_EXP_OPTIONAL 1
188# endif
189// std::variant
190# if defined(PYBIND11_CPP17) && __has_include(<variant>)
191# define PYBIND11_HAS_VARIANT 1
192# endif
193#elif defined(_MSC_VER) && defined(PYBIND11_CPP17)
194# define PYBIND11_HAS_OPTIONAL 1
195# define PYBIND11_HAS_VARIANT 1
196#endif
197
198#if defined(PYBIND11_CPP17)
199# if defined(__has_include)
200# if __has_include(<string_view>)
201# define PYBIND11_HAS_STRING_VIEW
202# endif
203# elif defined(_MSC_VER)
204# define PYBIND11_HAS_STRING_VIEW
205# endif
206#endif
207
208#if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
209# define PYBIND11_HAS_U8STRING
210#endif
211
212#include <Python.h>
213#if PY_VERSION_HEX < 0x03060000
214# error "PYTHON < 3.6 IS UNSUPPORTED. pybind11 v2.9 was the last to support Python 2 and 3.5."
215#endif
216#include <frameobject.h>
217#include <pythread.h>
218
219/* Python #defines overrides on all sorts of core functions, which
220 tends to weak havok in C++ codebases that expect these to work
221 like regular functions (potentially with several overloads) */
222#if defined(isalnum)
223# undef isalnum
224# undef isalpha
225# undef islower
226# undef isspace
227# undef isupper
228# undef tolower
229# undef toupper
230#endif
231
232#if defined(copysign)
233# undef copysign
234#endif
235
236#if defined(_MSC_VER)
237# if defined(PYBIND11_DEBUG_MARKER)
238# define _DEBUG
239# undef PYBIND11_DEBUG_MARKER
240# endif
241# pragma warning(pop)
242#endif
243
244#include <cstddef>
245#include <cstring>
246#include <exception>
247#include <forward_list>
248#include <memory>
249#include <stdexcept>
250#include <string>
251#include <type_traits>
252#include <typeindex>
253#include <unordered_map>
254#include <unordered_set>
255#include <vector>
256#if defined(__has_include)
257# if __has_include(<version>)
258# include <version>
259# endif
260#endif
261
262// #define PYBIND11_STR_LEGACY_PERMISSIVE
263// If DEFINED, pybind11::str can hold PyUnicodeObject or PyBytesObject
264// (probably surprising and never documented, but this was the
265// legacy behavior until and including v2.6.x). As a side-effect,
266// pybind11::isinstance<str>() is true for both pybind11::str and
267// pybind11::bytes.
268// If UNDEFINED, pybind11::str can only hold PyUnicodeObject, and
269// pybind11::isinstance<str>() is true only for pybind11::str.
270// However, for Python 2 only (!), the pybind11::str caster
271// implicitly decoded bytes to PyUnicodeObject. This was to ease
272// the transition from the legacy behavior to the non-permissive
273// behavior.
274
275/// Compatibility macros for Python 2 / Python 3 versions TODO: remove
276#define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyInstanceMethod_New(ptr)
277#define PYBIND11_INSTANCE_METHOD_CHECK PyInstanceMethod_Check
278#define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyInstanceMethod_GET_FUNCTION
279#define PYBIND11_BYTES_CHECK PyBytes_Check
280#define PYBIND11_BYTES_FROM_STRING PyBytes_FromString
281#define PYBIND11_BYTES_FROM_STRING_AND_SIZE PyBytes_FromStringAndSize
282#define PYBIND11_BYTES_AS_STRING_AND_SIZE PyBytes_AsStringAndSize
283#define PYBIND11_BYTES_AS_STRING PyBytes_AsString
284#define PYBIND11_BYTES_SIZE PyBytes_Size
285#define PYBIND11_LONG_CHECK(o) PyLong_Check(o)
286#define PYBIND11_LONG_AS_LONGLONG(o) PyLong_AsLongLong(o)
287#define PYBIND11_LONG_FROM_SIGNED(o) PyLong_FromSsize_t((ssize_t) (o))
288#define PYBIND11_LONG_FROM_UNSIGNED(o) PyLong_FromSize_t((size_t) (o))
289#define PYBIND11_BYTES_NAME "bytes"
290#define PYBIND11_STRING_NAME "str"
291#define PYBIND11_SLICE_OBJECT PyObject
292#define PYBIND11_FROM_STRING PyUnicode_FromString
293#define PYBIND11_STR_TYPE ::pybind11::str
294#define PYBIND11_BOOL_ATTR "__bool__"
295#define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_bool)
296#define PYBIND11_BUILTINS_MODULE "builtins"
297// Providing a separate declaration to make Clang's -Wmissing-prototypes happy.
298// See comment for PYBIND11_MODULE below for why this is marked "maybe unused".
299#define PYBIND11_PLUGIN_IMPL(name) \
300 extern "C" PYBIND11_MAYBE_UNUSED PYBIND11_EXPORT PyObject *PyInit_##name(); \
301 extern "C" PYBIND11_EXPORT PyObject *PyInit_##name()
302
303#define PYBIND11_TRY_NEXT_OVERLOAD ((PyObject *) 1) // special failure return code
304#define PYBIND11_STRINGIFY(x) #x
305#define PYBIND11_TOSTRING(x) PYBIND11_STRINGIFY(x)
306#define PYBIND11_CONCAT(first, second) first##second
307#define PYBIND11_ENSURE_INTERNALS_READY pybind11::detail::get_internals();
308
309#define PYBIND11_CHECK_PYTHON_VERSION \
310 { \
311 const char *compiled_ver \
312 = PYBIND11_TOSTRING(PY_MAJOR_VERSION) "." PYBIND11_TOSTRING(PY_MINOR_VERSION); \
313 const char *runtime_ver = Py_GetVersion(); \
314 size_t len = std::strlen(compiled_ver); \
315 if (std::strncmp(runtime_ver, compiled_ver, len) != 0 \
316 || (runtime_ver[len] >= '0' && runtime_ver[len] <= '9')) { \
317 PyErr_Format(PyExc_ImportError, \
318 "Python version mismatch: module was compiled for Python %s, " \
319 "but the interpreter version is incompatible: %s.", \
320 compiled_ver, \
321 runtime_ver); \
322 return nullptr; \
323 } \
324 }
325
326#define PYBIND11_CATCH_INIT_EXCEPTIONS \
327 catch (pybind11::error_already_set & e) { \
328 pybind11::raise_from(e, PyExc_ImportError, "initialization failed"); \
329 return nullptr; \
330 } \
331 catch (const std::exception &e) { \
332 PyErr_SetString(PyExc_ImportError, e.what()); \
333 return nullptr; \
334 }
335
336/** \rst
337 ***Deprecated in favor of PYBIND11_MODULE***
338
339 This macro creates the entry point that will be invoked when the Python interpreter
340 imports a plugin library. Please create a `module_` in the function body and return
341 the pointer to its underlying Python object at the end.
342
343 .. code-block:: cpp
344
345 PYBIND11_PLUGIN(example) {
346 pybind11::module_ m("example", "pybind11 example plugin");
347 /// Set up bindings here
348 return m.ptr();
349 }
350\endrst */
351#define PYBIND11_PLUGIN(name) \
352 PYBIND11_DEPRECATED("PYBIND11_PLUGIN is deprecated, use PYBIND11_MODULE") \
353 static PyObject *pybind11_init(); \
354 PYBIND11_PLUGIN_IMPL(name) { \
355 PYBIND11_CHECK_PYTHON_VERSION \
356 PYBIND11_ENSURE_INTERNALS_READY \
357 try { \
358 return pybind11_init(); \
359 } \
360 PYBIND11_CATCH_INIT_EXCEPTIONS \
361 } \
362 PyObject *pybind11_init()
363
364/** \rst
365 This macro creates the entry point that will be invoked when the Python interpreter
366 imports an extension module. The module name is given as the fist argument and it
367 should not be in quotes. The second macro argument defines a variable of type
368 `py::module_` which can be used to initialize the module.
369
370 The entry point is marked as "maybe unused" to aid dead-code detection analysis:
371 since the entry point is typically only looked up at runtime and not referenced
372 during translation, it would otherwise appear as unused ("dead") code.
373
374 .. code-block:: cpp
375
376 PYBIND11_MODULE(example, m) {
377 m.doc() = "pybind11 example module";
378
379 // Add bindings here
380 m.def("foo", []() {
381 return "Hello, World!";
382 });
383 }
384\endrst */
385#define PYBIND11_MODULE(name, variable) \
386 static ::pybind11::module_::module_def PYBIND11_CONCAT(pybind11_module_def_, name) \
387 PYBIND11_MAYBE_UNUSED; \
388 PYBIND11_MAYBE_UNUSED \
389 static void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ &); \
390 PYBIND11_PLUGIN_IMPL(name) { \
391 PYBIND11_CHECK_PYTHON_VERSION \
392 PYBIND11_ENSURE_INTERNALS_READY \
393 auto m = ::pybind11::module_::create_extension_module( \
394 PYBIND11_TOSTRING(name), nullptr, &PYBIND11_CONCAT(pybind11_module_def_, name)); \
395 try { \
396 PYBIND11_CONCAT(pybind11_init_, name)(m); \
397 return m.ptr(); \
398 } \
399 PYBIND11_CATCH_INIT_EXCEPTIONS \
400 } \
401 void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ & (variable))
402
403PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
404
405using ssize_t = Py_ssize_t;
406using size_t = std::size_t;
407
408template <typename IntType>
409inline ssize_t ssize_t_cast(const IntType &val) {
410 static_assert(sizeof(IntType) <= sizeof(ssize_t), "Implicit narrowing is not permitted.");
411 return static_cast<ssize_t>(val);
412}
413
414/// Approach used to cast a previously unknown C++ instance into a Python object
415enum class return_value_policy : uint8_t {
416 /** This is the default return value policy, which falls back to the policy
417 return_value_policy::take_ownership when the return value is a pointer.
418 Otherwise, it uses return_value::move or return_value::copy for rvalue
419 and lvalue references, respectively. See below for a description of what
420 all of these different policies do. */
421 automatic = 0,
422
423 /** As above, but use policy return_value_policy::reference when the return
424 value is a pointer. This is the default conversion policy for function
425 arguments when calling Python functions manually from C++ code (i.e. via
426 handle::operator()). You probably won't need to use this. */
427 automatic_reference,
428
429 /** Reference an existing object (i.e. do not create a new copy) and take
430 ownership. Python will call the destructor and delete operator when the
431 object's reference count reaches zero. Undefined behavior ensues when
432 the C++ side does the same.. */
433 take_ownership,
434
435 /** Create a new copy of the returned object, which will be owned by
436 Python. This policy is comparably safe because the lifetimes of the two
437 instances are decoupled. */
438 copy,
439
440 /** Use std::move to move the return value contents into a new instance
441 that will be owned by Python. This policy is comparably safe because the
442 lifetimes of the two instances (move source and destination) are
443 decoupled. */
444 move,
445
446 /** Reference an existing object, but do not take ownership. The C++ side
447 is responsible for managing the object's lifetime and deallocating it
448 when it is no longer used. Warning: undefined behavior will ensue when
449 the C++ side deletes an object that is still referenced and used by
450 Python. */
451 reference,
452
453 /** This policy only applies to methods and properties. It references the
454 object without taking ownership similar to the above
455 return_value_policy::reference policy. In contrast to that policy, the
456 function or property's implicit this argument (called the parent) is
457 considered to be the the owner of the return value (the child).
458 pybind11 then couples the lifetime of the parent to the child via a
459 reference relationship that ensures that the parent cannot be garbage
460 collected while Python is still using the child. More advanced
461 variations of this scheme are also possible using combinations of
462 return_value_policy::reference and the keep_alive call policy */
463 reference_internal
464};
465
466PYBIND11_NAMESPACE_BEGIN(detail)
467
468inline static constexpr int log2(size_t n, int k = 0) {
469 return (n <= 1) ? k : log2(n >> 1, k + 1);
470}
471
472// Returns the size as a multiple of sizeof(void *), rounded up.
473inline static constexpr size_t size_in_ptrs(size_t s) {
474 return 1 + ((s - 1) >> log2(sizeof(void *)));
475}
476
477/**
478 * The space to allocate for simple layout instance holders (see below) in multiple of the size of
479 * a pointer (e.g. 2 means 16 bytes on 64-bit architectures). The default is the minimum required
480 * to holder either a std::unique_ptr or std::shared_ptr (which is almost always
481 * sizeof(std::shared_ptr<T>)).
482 */
483constexpr size_t instance_simple_holder_in_ptrs() {
484 static_assert(sizeof(std::shared_ptr<int>) >= sizeof(std::unique_ptr<int>),
485 "pybind assumes std::shared_ptrs are at least as big as std::unique_ptrs");
486 return size_in_ptrs(sizeof(std::shared_ptr<int>));
487}
488
489// Forward declarations
490struct type_info;
491struct value_and_holder;
492
493struct nonsimple_values_and_holders {
494 void **values_and_holders;
495 uint8_t *status;
496};
497
498/// The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
499struct instance {
500 PyObject_HEAD
501 /// Storage for pointers and holder; see simple_layout, below, for a description
502 union {
503 void *simple_value_holder[1 + instance_simple_holder_in_ptrs()];
504 nonsimple_values_and_holders nonsimple;
505 };
506 /// Weak references
507 PyObject *weakrefs;
508 /// If true, the pointer is owned which means we're free to manage it with a holder.
509 bool owned : 1;
510 /**
511 * An instance has two possible value/holder layouts.
512 *
513 * Simple layout (when this flag is true), means the `simple_value_holder` is set with a
514 * pointer and the holder object governing that pointer, i.e. [val1*][holder]. This layout is
515 * applied whenever there is no python-side multiple inheritance of bound C++ types *and* the
516 * type's holder will fit in the default space (which is large enough to hold either a
517 * std::unique_ptr or std::shared_ptr).
518 *
519 * Non-simple layout applies when using custom holders that require more space than
520 * `shared_ptr` (which is typically the size of two pointers), or when multiple inheritance is
521 * used on the python side. Non-simple layout allocates the required amount of memory to have
522 * multiple bound C++ classes as parents. Under this layout, `nonsimple.values_and_holders` is
523 * set to a pointer to allocated space of the required space to hold a sequence of value
524 * pointers and holders followed `status`, a set of bit flags (1 byte each), i.e.
525 * [val1*][holder1][val2*][holder2]...[bb...] where each [block] is rounded up to a multiple
526 * of `sizeof(void *)`. `nonsimple.status` is, for convenience, a pointer to the beginning of
527 * the [bb...] block (but not independently allocated).
528 *
529 * Status bits indicate whether the associated holder is constructed (&
530 * status_holder_constructed) and whether the value pointer is registered (&
531 * status_instance_registered) in `registered_instances`.
532 */
533 bool simple_layout : 1;
534 /// For simple layout, tracks whether the holder has been constructed
535 bool simple_holder_constructed : 1;
536 /// For simple layout, tracks whether the instance is registered in `registered_instances`
537 bool simple_instance_registered : 1;
538 /// If true, get_internals().patients has an entry for this object
539 bool has_patients : 1;
540
541 /// Initializes all of the above type/values/holders data (but not the instance values
542 /// themselves)
543 void allocate_layout();
544
545 /// Destroys/deallocates all of the above
546 void deallocate_layout();
547
548 /// Returns the value_and_holder wrapper for the given type (or the first, if `find_type`
549 /// omitted). Returns a default-constructed (with `.inst = nullptr`) object on failure if
550 /// `throw_if_missing` is false.
551 value_and_holder get_value_and_holder(const type_info *find_type = nullptr,
552 bool throw_if_missing = true);
553
554 /// Bit values for the non-simple status flags
555 static constexpr uint8_t status_holder_constructed = 1;
556 static constexpr uint8_t status_instance_registered = 2;
557};
558
559static_assert(std::is_standard_layout<instance>::value,
560 "Internal error: `pybind11::detail::instance` is not standard layout!");
561
562/// from __cpp_future__ import (convenient aliases from C++14/17)
563#if defined(PYBIND11_CPP14)
564using std::conditional_t;
565using std::enable_if_t;
566using std::remove_cv_t;
567using std::remove_reference_t;
568#else
569template <bool B, typename T = void>
570using enable_if_t = typename std::enable_if<B, T>::type;
571template <bool B, typename T, typename F>
572using conditional_t = typename std::conditional<B, T, F>::type;
573template <typename T>
574using remove_cv_t = typename std::remove_cv<T>::type;
575template <typename T>
576using remove_reference_t = typename std::remove_reference<T>::type;
577#endif
578
579#if defined(PYBIND11_CPP20)
580using std::remove_cvref;
581using std::remove_cvref_t;
582#else
583template <class T>
584struct remove_cvref {
585 using type = remove_cv_t<remove_reference_t<T>>;
586};
587template <class T>
588using remove_cvref_t = typename remove_cvref<T>::type;
589#endif
590
591/// Index sequences
592#if defined(PYBIND11_CPP14)
593using std::index_sequence;
594using std::make_index_sequence;
595#else
596template <size_t...>
597struct index_sequence {};
598template <size_t N, size_t... S>
599struct make_index_sequence_impl : make_index_sequence_impl<N - 1, N - 1, S...> {};
600template <size_t... S>
601struct make_index_sequence_impl<0, S...> {
602 using type = index_sequence<S...>;
603};
604template <size_t N>
605using make_index_sequence = typename make_index_sequence_impl<N>::type;
606#endif
607
608/// Make an index sequence of the indices of true arguments
609template <typename ISeq, size_t, bool...>
610struct select_indices_impl {
611 using type = ISeq;
612};
613template <size_t... IPrev, size_t I, bool B, bool... Bs>
614struct select_indices_impl<index_sequence<IPrev...>, I, B, Bs...>
615 : select_indices_impl<conditional_t<B, index_sequence<IPrev..., I>, index_sequence<IPrev...>>,
616 I + 1,
617 Bs...> {};
618template <bool... Bs>
619using select_indices = typename select_indices_impl<index_sequence<>, 0, Bs...>::type;
620
621/// Backports of std::bool_constant and std::negation to accommodate older compilers
622template <bool B>
623using bool_constant = std::integral_constant<bool, B>;
624template <typename T>
625struct negation : bool_constant<!T::value> {};
626
627// PGI/Intel cannot detect operator delete with the "compatible" void_t impl, so
628// using the new one (C++14 defect, so generally works on newer compilers, even
629// if not in C++17 mode)
630#if defined(__PGIC__) || defined(__INTEL_COMPILER)
631template <typename...>
632using void_t = void;
633#else
634template <typename...>
635struct void_t_impl {
636 using type = void;
637};
638template <typename... Ts>
639using void_t = typename void_t_impl<Ts...>::type;
640#endif
641
642/// Compile-time all/any/none of that check the boolean value of all template types
643#if defined(__cpp_fold_expressions) && !(defined(_MSC_VER) && (_MSC_VER < 1916))
644template <class... Ts>
645using all_of = bool_constant<(Ts::value && ...)>;
646template <class... Ts>
647using any_of = bool_constant<(Ts::value || ...)>;
648#elif !defined(_MSC_VER)
649template <bool...>
650struct bools {};
651template <class... Ts>
652using all_of = std::is_same<bools<Ts::value..., true>, bools<true, Ts::value...>>;
653template <class... Ts>
654using any_of = negation<all_of<negation<Ts>...>>;
655#else
656// MSVC has trouble with the above, but supports std::conjunction, which we can use instead (albeit
657// at a slight loss of compilation efficiency).
658template <class... Ts>
659using all_of = std::conjunction<Ts...>;
660template <class... Ts>
661using any_of = std::disjunction<Ts...>;
662#endif
663template <class... Ts>
664using none_of = negation<any_of<Ts...>>;
665
666template <class T, template <class> class... Predicates>
667using satisfies_all_of = all_of<Predicates<T>...>;
668template <class T, template <class> class... Predicates>
669using satisfies_any_of = any_of<Predicates<T>...>;
670template <class T, template <class> class... Predicates>
671using satisfies_none_of = none_of<Predicates<T>...>;
672
673/// Strip the class from a method type
674template <typename T>
675struct remove_class {};
676template <typename C, typename R, typename... A>
677struct remove_class<R (C::*)(A...)> {
678 using type = R(A...);
679};
680template <typename C, typename R, typename... A>
681struct remove_class<R (C::*)(A...) const> {
682 using type = R(A...);
683};
684
685/// Helper template to strip away type modifiers
686template <typename T>
687struct intrinsic_type {
688 using type = T;
689};
690template <typename T>
691struct intrinsic_type<const T> {
692 using type = typename intrinsic_type<T>::type;
693};
694template <typename T>
695struct intrinsic_type<T *> {
696 using type = typename intrinsic_type<T>::type;
697};
698template <typename T>
699struct intrinsic_type<T &> {
700 using type = typename intrinsic_type<T>::type;
701};
702template <typename T>
703struct intrinsic_type<T &&> {
704 using type = typename intrinsic_type<T>::type;
705};
706template <typename T, size_t N>
707struct intrinsic_type<const T[N]> {
708 using type = typename intrinsic_type<T>::type;
709};
710template <typename T, size_t N>
711struct intrinsic_type<T[N]> {
712 using type = typename intrinsic_type<T>::type;
713};
714template <typename T>
715using intrinsic_t = typename intrinsic_type<T>::type;
716
717/// Helper type to replace 'void' in some expressions
718struct void_type {};
719
720/// Helper template which holds a list of types
721template <typename...>
722struct type_list {};
723
724/// Compile-time integer sum
725#ifdef __cpp_fold_expressions
726template <typename... Ts>
727constexpr size_t constexpr_sum(Ts... ns) {
728 return (0 + ... + size_t{ns});
729}
730#else
731constexpr size_t constexpr_sum() { return 0; }
732template <typename T, typename... Ts>
733constexpr size_t constexpr_sum(T n, Ts... ns) {
734 return size_t{n} + constexpr_sum(ns...);
735}
736#endif
737
738PYBIND11_NAMESPACE_BEGIN(constexpr_impl)
739/// Implementation details for constexpr functions
740constexpr int first(int i) { return i; }
741template <typename T, typename... Ts>
742constexpr int first(int i, T v, Ts... vs) {
743 return v ? i : first(i + 1, vs...);
744}
745
746constexpr int last(int /*i*/, int result) { return result; }
747template <typename T, typename... Ts>
748constexpr int last(int i, int result, T v, Ts... vs) {
749 return last(i + 1, v ? i : result, vs...);
750}
751PYBIND11_NAMESPACE_END(constexpr_impl)
752
753/// Return the index of the first type in Ts which satisfies Predicate<T>.
754/// Returns sizeof...(Ts) if none match.
755template <template <typename> class Predicate, typename... Ts>
756constexpr int constexpr_first() {
757 return constexpr_impl::first(0, Predicate<Ts>::value...);
758}
759
760/// Return the index of the last type in Ts which satisfies Predicate<T>, or -1 if none match.
761template <template <typename> class Predicate, typename... Ts>
762constexpr int constexpr_last() {
763 return constexpr_impl::last(0, -1, Predicate<Ts>::value...);
764}
765
766/// Return the Nth element from the parameter pack
767template <size_t N, typename T, typename... Ts>
768struct pack_element {
769 using type = typename pack_element<N - 1, Ts...>::type;
770};
771template <typename T, typename... Ts>
772struct pack_element<0, T, Ts...> {
773 using type = T;
774};
775
776/// Return the one and only type which matches the predicate, or Default if none match.
777/// If more than one type matches the predicate, fail at compile-time.
778template <template <typename> class Predicate, typename Default, typename... Ts>
779struct exactly_one {
780 static constexpr auto found = constexpr_sum(Predicate<Ts>::value...);
781 static_assert(found <= 1, "Found more than one type matching the predicate");
782
783 static constexpr auto index = found ? constexpr_first<Predicate, Ts...>() : 0;
784 using type = conditional_t<found, typename pack_element<index, Ts...>::type, Default>;
785};
786template <template <typename> class P, typename Default>
787struct exactly_one<P, Default> {
788 using type = Default;
789};
790
791template <template <typename> class Predicate, typename Default, typename... Ts>
792using exactly_one_t = typename exactly_one<Predicate, Default, Ts...>::type;
793
794/// Defer the evaluation of type T until types Us are instantiated
795template <typename T, typename... /*Us*/>
796struct deferred_type {
797 using type = T;
798};
799template <typename T, typename... Us>
800using deferred_t = typename deferred_type<T, Us...>::type;
801
802/// Like is_base_of, but requires a strict base (i.e. `is_strict_base_of<T, T>::value == false`,
803/// unlike `std::is_base_of`)
804template <typename Base, typename Derived>
805using is_strict_base_of
806 = bool_constant<std::is_base_of<Base, Derived>::value && !std::is_same<Base, Derived>::value>;
807
808/// Like is_base_of, but also requires that the base type is accessible (i.e. that a Derived
809/// pointer can be converted to a Base pointer) For unions, `is_base_of<T, T>::value` is False, so
810/// we need to check `is_same` as well.
811template <typename Base, typename Derived>
812using is_accessible_base_of
813 = bool_constant<(std::is_same<Base, Derived>::value || std::is_base_of<Base, Derived>::value)
814 && std::is_convertible<Derived *, Base *>::value>;
815
816template <template <typename...> class Base>
817struct is_template_base_of_impl {
818 template <typename... Us>
819 static std::true_type check(Base<Us...> *);
820 static std::false_type check(...);
821};
822
823/// Check if a template is the base of a type. For example:
824/// `is_template_base_of<Base, T>` is true if `struct T : Base<U> {}` where U can be anything
825template <template <typename...> class Base, typename T>
826// Sadly, all MSVC versions incl. 2022 need the workaround, even in C++20 mode.
827// See also: https://github.com/pybind/pybind11/pull/3741
828#if !defined(_MSC_VER)
829using is_template_base_of
830 = decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T> *) nullptr));
831#else
832struct is_template_base_of
833 : decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T> *) nullptr)) {
834};
835#endif
836
837/// Check if T is an instantiation of the template `Class`. For example:
838/// `is_instantiation<shared_ptr, T>` is true if `T == shared_ptr<U>` where U can be anything.
839template <template <typename...> class Class, typename T>
840struct is_instantiation : std::false_type {};
841template <template <typename...> class Class, typename... Us>
842struct is_instantiation<Class, Class<Us...>> : std::true_type {};
843
844/// Check if T is std::shared_ptr<U> where U can be anything
845template <typename T>
846using is_shared_ptr = is_instantiation<std::shared_ptr, T>;
847
848/// Check if T looks like an input iterator
849template <typename T, typename = void>
850struct is_input_iterator : std::false_type {};
851template <typename T>
852struct is_input_iterator<T,
853 void_t<decltype(*std::declval<T &>()), decltype(++std::declval<T &>())>>
854 : std::true_type {};
855
856template <typename T>
857using is_function_pointer
858 = bool_constant<std::is_pointer<T>::value
859 && std::is_function<typename std::remove_pointer<T>::type>::value>;
860
861template <typename F>
862struct strip_function_object {
863 // If you are encountering an
864 // 'error: name followed by "::" must be a class or namespace name'
865 // with the Intel compiler and a noexcept function here,
866 // try to use noexcept(true) instead of plain noexcept.
867 using type = typename remove_class<decltype(&F::operator())>::type;
868};
869
870// Extracts the function signature from a function, function pointer or lambda.
871template <typename Function, typename F = remove_reference_t<Function>>
872using function_signature_t = conditional_t<
873 std::is_function<F>::value,
874 F,
875 typename conditional_t<std::is_pointer<F>::value || std::is_member_pointer<F>::value,
876 std::remove_pointer<F>,
877 strip_function_object<F>>::type>;
878
879/// Returns true if the type looks like a lambda: that is, isn't a function, pointer or member
880/// pointer. Note that this can catch all sorts of other things, too; this is intended to be used
881/// in a place where passing a lambda makes sense.
882template <typename T>
883using is_lambda = satisfies_none_of<remove_reference_t<T>,
884 std::is_function,
885 std::is_pointer,
886 std::is_member_pointer>;
887
888// [workaround(intel)] Internal error on fold expression
889/// Apply a function over each element of a parameter pack
890#if defined(__cpp_fold_expressions) && !defined(__INTEL_COMPILER)
891// Intel compiler produces an internal error on this fold expression (tested with ICC 19.0.2)
892# define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) (((PATTERN), void()), ...)
893#else
894using expand_side_effects = bool[];
895# define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) \
896 (void) pybind11::detail::expand_side_effects { ((PATTERN), void(), false)..., false }
897#endif
898
899PYBIND11_NAMESPACE_END(detail)
900
901#if defined(_MSC_VER)
902# pragma warning(push)
903# pragma warning(disable : 4275)
904// warning C4275: An exported class was derived from a class that wasn't exported.
905// Can be ignored when derived from a STL class.
906#endif
907/// C++ bindings of builtin Python exceptions
908class PYBIND11_EXPORT_EXCEPTION builtin_exception : public std::runtime_error {
909public:
910 using std::runtime_error::runtime_error;
911 /// Set the error using the Python C API
912 virtual void set_error() const = 0;
913};
914#if defined(_MSC_VER)
915# pragma warning(pop)
916#endif
917
918#define PYBIND11_RUNTIME_EXCEPTION(name, type) \
919 class PYBIND11_EXPORT_EXCEPTION name : public builtin_exception { \
920 public: \
921 using builtin_exception::builtin_exception; \
922 name() : name("") {} \
923 void set_error() const override { PyErr_SetString(type, what()); } \
924 };
925
926PYBIND11_RUNTIME_EXCEPTION(stop_iteration, PyExc_StopIteration)
927PYBIND11_RUNTIME_EXCEPTION(index_error, PyExc_IndexError)
928PYBIND11_RUNTIME_EXCEPTION(key_error, PyExc_KeyError)
929PYBIND11_RUNTIME_EXCEPTION(value_error, PyExc_ValueError)
930PYBIND11_RUNTIME_EXCEPTION(type_error, PyExc_TypeError)
931PYBIND11_RUNTIME_EXCEPTION(buffer_error, PyExc_BufferError)
932PYBIND11_RUNTIME_EXCEPTION(import_error, PyExc_ImportError)
933PYBIND11_RUNTIME_EXCEPTION(attribute_error, PyExc_AttributeError)
934PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError) /// Thrown when pybind11::cast or
935 /// handle::call fail due to a type
936 /// casting error
937PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used internally
938
939[[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const char *reason) {
940 assert(!PyErr_Occurred());
941 throw std::runtime_error(reason);
942}
943[[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const std::string &reason) {
944 assert(!PyErr_Occurred());
945 throw std::runtime_error(reason);
946}
947
948template <typename T, typename SFINAE = void>
949struct format_descriptor {};
950
951PYBIND11_NAMESPACE_BEGIN(detail)
952// Returns the index of the given type in the type char array below, and in the list in numpy.h
953// The order here is: bool; 8 ints ((signed,unsigned)x(8,16,32,64)bits); float,double,long double;
954// complex float,double,long double. Note that the long double types only participate when long
955// double is actually longer than double (it isn't under MSVC).
956// NB: not only the string below but also complex.h and numpy.h rely on this order.
957template <typename T, typename SFINAE = void>
958struct is_fmt_numeric {
959 static constexpr bool value = false;
960};
961template <typename T>
962struct is_fmt_numeric<T, enable_if_t<std::is_arithmetic<T>::value>> {
963 static constexpr bool value = true;
964 static constexpr int index
965 = std::is_same<T, bool>::value
966 ? 0
967 : 1
968 + (std::is_integral<T>::value
969 ? detail::log2(sizeof(T)) * 2 + std::is_unsigned<T>::value
970 : 8
971 + (std::is_same<T, double>::value ? 1
972 : std::is_same<T, long double>::value ? 2
973 : 0));
974};
975PYBIND11_NAMESPACE_END(detail)
976
977template <typename T>
978struct format_descriptor<T, detail::enable_if_t<std::is_arithmetic<T>::value>> {
979 static constexpr const char c = "?bBhHiIqQfdg"[detail::is_fmt_numeric<T>::index];
980 static constexpr const char value[2] = {c, '\0'};
981 static std::string format() { return std::string(1, c); }
982};
983
984#if !defined(PYBIND11_CPP17)
985
986template <typename T>
987constexpr const char
988 format_descriptor<T, detail::enable_if_t<std::is_arithmetic<T>::value>>::value[2];
989
990#endif
991
992/// RAII wrapper that temporarily clears any Python error state
993struct error_scope {
994 PyObject *type, *value, *trace;
995 error_scope() { PyErr_Fetch(&type, &value, &trace); }
996 error_scope(const error_scope &) = delete;
997 error_scope &operator=(const error_scope &) = delete;
998 ~error_scope() { PyErr_Restore(type, value, trace); }
999};
1000
1001/// Dummy destructor wrapper that can be used to expose classes with a private destructor
1002struct nodelete {
1003 template <typename T>
1004 void operator()(T *) {}
1005};
1006
1007PYBIND11_NAMESPACE_BEGIN(detail)
1008template <typename... Args>
1009struct overload_cast_impl {
1010 template <typename Return>
1011 constexpr auto operator()(Return (*pf)(Args...)) const noexcept -> decltype(pf) {
1012 return pf;
1013 }
1014
1015 template <typename Return, typename Class>
1016 constexpr auto operator()(Return (Class::*pmf)(Args...), std::false_type = {}) const noexcept
1017 -> decltype(pmf) {
1018 return pmf;
1019 }
1020
1021 template <typename Return, typename Class>
1022 constexpr auto operator()(Return (Class::*pmf)(Args...) const, std::true_type) const noexcept
1023 -> decltype(pmf) {
1024 return pmf;
1025 }
1026};
1027PYBIND11_NAMESPACE_END(detail)
1028
1029// overload_cast requires variable templates: C++14
1030#if defined(PYBIND11_CPP14)
1031# define PYBIND11_OVERLOAD_CAST 1
1032/// Syntax sugar for resolving overloaded function pointers:
1033/// - regular: static_cast<Return (Class::*)(Arg0, Arg1, Arg2)>(&Class::func)
1034/// - sweet: overload_cast<Arg0, Arg1, Arg2>(&Class::func)
1035template <typename... Args>
1036# if (defined(_MSC_VER) && _MSC_VER < 1920) /* MSVC 2017 */ \
1037 || (defined(__clang__) && __clang_major__ == 5)
1038static constexpr detail::overload_cast_impl<Args...> overload_cast = {};
1039# else
1040static constexpr detail::overload_cast_impl<Args...> overload_cast;
1041# endif
1042#endif
1043
1044/// Const member function selector for overload_cast
1045/// - regular: static_cast<Return (Class::*)(Arg) const>(&Class::func)
1046/// - sweet: overload_cast<Arg>(&Class::func, const_)
1047static constexpr auto const_ = std::true_type{};
1048
1049#if !defined(PYBIND11_CPP14) // no overload_cast: providing something that static_assert-fails:
1050template <typename... Args>
1051struct overload_cast {
1052 static_assert(detail::deferred_t<std::false_type, Args...>::value,
1053 "pybind11::overload_cast<...> requires compiling in C++14 mode");
1054};
1055#endif // overload_cast
1056
1057PYBIND11_NAMESPACE_BEGIN(detail)
1058
1059// Adaptor for converting arbitrary container arguments into a vector; implicitly convertible from
1060// any standard container (or C-style array) supporting std::begin/std::end, any singleton
1061// arithmetic type (if T is arithmetic), or explicitly constructible from an iterator pair.
1062template <typename T>
1063class any_container {
1064 std::vector<T> v;
1065
1066public:
1067 any_container() = default;
1068
1069 // Can construct from a pair of iterators
1070 template <typename It, typename = enable_if_t<is_input_iterator<It>::value>>
1071 any_container(It first, It last) : v(first, last) {}
1072
1073 // Implicit conversion constructor from any arbitrary container type
1074 // with values convertible to T
1075 template <typename Container,
1076 typename = enable_if_t<
1077 std::is_convertible<decltype(*std::begin(std::declval<const Container &>())),
1078 T>::value>>
1079 // NOLINTNEXTLINE(google-explicit-constructor)
1080 any_container(const Container &c) : any_container(std::begin(c), std::end(c)) {}
1081
1082 // initializer_list's aren't deducible, so don't get matched by the above template;
1083 // we need this to explicitly allow implicit conversion from one:
1084 template <typename TIn, typename = enable_if_t<std::is_convertible<TIn, T>::value>>
1085 any_container(const std::initializer_list<TIn> &c) : any_container(c.begin(), c.end()) {}
1086
1087 // Avoid copying if given an rvalue vector of the correct type.
1088 // NOLINTNEXTLINE(google-explicit-constructor)
1089 any_container(std::vector<T> &&v) : v(std::move(v)) {}
1090
1091 // Moves the vector out of an rvalue any_container
1092 // NOLINTNEXTLINE(google-explicit-constructor)
1093 operator std::vector<T> &&() && { return std::move(v); }
1094
1095 // Dereferencing obtains a reference to the underlying vector
1096 std::vector<T> &operator*() { return v; }
1097 const std::vector<T> &operator*() const { return v; }
1098
1099 // -> lets you call methods on the underlying vector
1100 std::vector<T> *operator->() { return &v; }
1101 const std::vector<T> *operator->() const { return &v; }
1102};
1103
1104// Forward-declaration; see detail/class.h
1105std::string get_fully_qualified_tp_name(PyTypeObject *);
1106
1107template <typename T>
1108inline static std::shared_ptr<T>
1109try_get_shared_from_this(std::enable_shared_from_this<T> *holder_value_ptr) {
1110// Pre C++17, this code path exploits undefined behavior, but is known to work on many platforms.
1111// Use at your own risk!
1112// See also https://en.cppreference.com/w/cpp/memory/enable_shared_from_this, and in particular
1113// the `std::shared_ptr<Good> gp1 = not_so_good.getptr();` and `try`-`catch` parts of the example.
1114#if defined(__cpp_lib_enable_shared_from_this) && (!defined(_MSC_VER) || _MSC_VER >= 1912)
1115 return holder_value_ptr->weak_from_this().lock();
1116#else
1117 try {
1118 return holder_value_ptr->shared_from_this();
1119 } catch (const std::bad_weak_ptr &) {
1120 return nullptr;
1121 }
1122#endif
1123}
1124
1125// For silencing "unused" compiler warnings in special situations.
1126template <typename... Args>
1127#if defined(_MSC_VER) && _MSC_VER < 1920 // MSVC 2017
1128constexpr
1129#endif
1130 inline void
1131 silence_unused_warnings(Args &&...) {
1132}
1133
1134// MSVC warning C4100: Unreferenced formal parameter
1135#if defined(_MSC_VER) && _MSC_VER <= 1916
1136# define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...) \
1137 detail::silence_unused_warnings(__VA_ARGS__)
1138#else
1139# define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...)
1140#endif
1141
1142// GCC -Wunused-but-set-parameter All GCC versions (as of July 2021).
1143#if defined(__GNUG__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
1144# define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...) \
1145 detail::silence_unused_warnings(__VA_ARGS__)
1146#else
1147# define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...)
1148#endif
1149
1150#if defined(_MSC_VER) // All versions (as of July 2021).
1151
1152// warning C4127: Conditional expression is constant
1153constexpr inline bool silence_msvc_c4127(bool cond) { return cond; }
1154
1155# define PYBIND11_SILENCE_MSVC_C4127(...) ::pybind11::detail::silence_msvc_c4127(__VA_ARGS__)
1156
1157#else
1158# define PYBIND11_SILENCE_MSVC_C4127(...) __VA_ARGS__
1159#endif
1160
1161// Pybind offers detailed error messages by default for all builts that are debug (through the
1162// negation of ndebug). This can also be manually enabled by users, for any builds, through
1163// defining PYBIND11_DETAILED_ERROR_MESSAGES.
1164#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) && !defined(NDEBUG)
1165# define PYBIND11_DETAILED_ERROR_MESSAGES
1166#endif
1167
1168PYBIND11_NAMESPACE_END(detail)
1169PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
1170