@@ -777,8 +777,9 @@ struct copyable_holder_caster : public type_caster_base<type> {
777777 return true ;
778778 }
779779 throw cast_error (" Unable to cast from non-held to held instance (T& to Holder<T>) "
780- #if defined(NDEBUG)
781- " (compile in debug mode for type information)" );
780+ #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
781+ " (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for "
782+ " type information)" );
782783#else
783784 " of type '"
784785 + type_id<holder_type>() + " ''" );
@@ -1001,9 +1002,9 @@ struct return_value_policy_override<
10011002template <typename T, typename SFINAE>
10021003type_caster<T, SFINAE> &load_type (type_caster<T, SFINAE> &conv, const handle &handle) {
10031004 if (!conv.load (handle, true )) {
1004- #if defined(NDEBUG )
1005- throw cast_error (
1006- " Unable to cast Python instance to C++ type ( compile in debug mode for details)" );
1005+ #if ! defined(PYBIND11_DETAILED_ERROR_MESSAGES )
1006+ throw cast_error (" Unable to cast Python instance to C++ type (#define "
1007+ " PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)" );
10071008#else
10081009 throw cast_error (" Unable to cast Python instance of type "
10091010 + (std::string) str (type::handle_of (handle)) + " to C++ type '"
@@ -1068,10 +1069,10 @@ inline void handle::cast() const {
10681069template <typename T>
10691070detail::enable_if_t <!detail::move_never<T>::value, T> move (object &&obj) {
10701071 if (obj.ref_count () > 1 ) {
1071- #if defined(NDEBUG )
1072+ #if ! defined(PYBIND11_DETAILED_ERROR_MESSAGES )
10721073 throw cast_error (
10731074 " Unable to cast Python instance to C++ rvalue: instance has multiple references"
1074- " (compile in debug mode for details)" );
1075+ " (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)" );
10751076#else
10761077 throw cast_error (" Unable to move from Python " + (std::string) str (type::handle_of (obj))
10771078 + " instance to C++ " + type_id<T>()
@@ -1172,10 +1173,10 @@ PYBIND11_NAMESPACE_END(detail)
11721173
11731174// The overloads could coexist, i.e. the #if is not strictly speaking needed,
11741175// but it is an easy minor optimization.
1175- #if defined(NDEBUG )
1176+ #if ! defined(PYBIND11_DETAILED_ERROR_MESSAGES )
11761177inline cast_error cast_error_unable_to_convert_call_arg () {
1177- return cast_error (
1178- " Unable to convert call argument to Python object ( compile in debug mode for details)" );
1178+ return cast_error (" Unable to convert call argument to Python object (#define "
1179+ " PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)" );
11791180}
11801181#else
11811182inline cast_error cast_error_unable_to_convert_call_arg (const std::string &name,
@@ -1197,7 +1198,7 @@ tuple make_tuple(Args &&...args_) {
11971198 detail::make_caster<Args>::cast (std::forward<Args>(args_), policy, nullptr ))...}};
11981199 for (size_t i = 0 ; i < args.size (); i++) {
11991200 if (!args[i]) {
1200- #if defined(NDEBUG )
1201+ #if ! defined(PYBIND11_DETAILED_ERROR_MESSAGES )
12011202 throw cast_error_unable_to_convert_call_arg ();
12021203#else
12031204 std::array<std::string, size> argtypes{{type_id<Args>()...}};
@@ -1249,7 +1250,7 @@ struct arg_v : arg {
12491250 : arg(base), value(reinterpret_steal<object>(detail::make_caster<T>::cast(
12501251 std::forward<T>(x), return_value_policy::automatic, {}))),
12511252 descr (descr)
1252- #if ! defined(NDEBUG )
1253+ #if defined(PYBIND11_DETAILED_ERROR_MESSAGES )
12531254 ,
12541255 type (type_id<T>())
12551256#endif
@@ -1289,7 +1290,7 @@ struct arg_v : arg {
12891290 object value;
12901291 // / The (optional) description of the default value
12911292 const char *descr;
1292- #if ! defined(NDEBUG )
1293+ #if defined(PYBIND11_DETAILED_ERROR_MESSAGES )
12931294 // / The C++ type name of the default value (only available when compiled in debug mode)
12941295 std::string type;
12951296#endif
@@ -1487,7 +1488,7 @@ class unpacking_collector {
14871488 auto o = reinterpret_steal<object>(
14881489 detail::make_caster<T>::cast (std::forward<T>(x), policy, {}));
14891490 if (!o) {
1490- #if defined(NDEBUG )
1491+ #if ! defined(PYBIND11_DETAILED_ERROR_MESSAGES )
14911492 throw cast_error_unable_to_convert_call_arg ();
14921493#else
14931494 throw cast_error_unable_to_convert_call_arg (std::to_string (args_list.size ()),
@@ -1505,21 +1506,21 @@ class unpacking_collector {
15051506
15061507 void process (list & /* args_list*/ , arg_v a) {
15071508 if (!a.name ) {
1508- #if defined(NDEBUG )
1509+ #if ! defined(PYBIND11_DETAILED_ERROR_MESSAGES )
15091510 nameless_argument_error ();
15101511#else
15111512 nameless_argument_error (a.type );
15121513#endif
15131514 }
15141515 if (m_kwargs.contains (a.name )) {
1515- #if defined(NDEBUG )
1516+ #if ! defined(PYBIND11_DETAILED_ERROR_MESSAGES )
15161517 multiple_values_error ();
15171518#else
15181519 multiple_values_error (a.name );
15191520#endif
15201521 }
15211522 if (!a.value ) {
1522- #if defined(NDEBUG )
1523+ #if ! defined(PYBIND11_DETAILED_ERROR_MESSAGES )
15231524 throw cast_error_unable_to_convert_call_arg ();
15241525#else
15251526 throw cast_error_unable_to_convert_call_arg (a.name , a.type );
@@ -1534,7 +1535,7 @@ class unpacking_collector {
15341535 }
15351536 for (auto k : reinterpret_borrow<dict>(kp)) {
15361537 if (m_kwargs.contains (k.first )) {
1537- #if defined(NDEBUG )
1538+ #if ! defined(PYBIND11_DETAILED_ERROR_MESSAGES )
15381539 multiple_values_error ();
15391540#else
15401541 multiple_values_error (str (k.first ));
@@ -1545,18 +1546,20 @@ class unpacking_collector {
15451546 }
15461547
15471548 [[noreturn]] static void nameless_argument_error () {
1548- throw type_error (" Got kwargs without a name; only named arguments "
1549- " may be passed via py::arg() to a python function call. "
1550- " (compile in debug mode for details)" );
1549+ throw type_error (
1550+ " Got kwargs without a name; only named arguments "
1551+ " may be passed via py::arg() to a python function call. "
1552+ " (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)" );
15511553 }
15521554 [[noreturn]] static void nameless_argument_error (const std::string &type) {
15531555 throw type_error (" Got kwargs without a name of type '" + type
15541556 + " '; only named "
15551557 " arguments may be passed via py::arg() to a python function call. " );
15561558 }
15571559 [[noreturn]] static void multiple_values_error () {
1558- throw type_error (" Got multiple values for keyword argument "
1559- " (compile in debug mode for details)" );
1560+ throw type_error (
1561+ " Got multiple values for keyword argument "
1562+ " (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)" );
15601563 }
15611564
15621565 [[noreturn]] static void multiple_values_error (const std::string &name) {
@@ -1603,7 +1606,7 @@ unpacking_collector<policy> collect_arguments(Args &&...args) {
16031606template <typename Derived>
16041607template <return_value_policy policy, typename ... Args>
16051608object object_api<Derived>::operator ()(Args &&...args) const {
1606- #ifndef NDEBUG
1609+ #if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
16071610 if (!PyGILState_Check ()) {
16081611 pybind11_fail (" pybind11::object_api<>::operator() PyGILState_Check() failure." );
16091612 }
0 commit comments