Skip to content

Commit c3ac755

Browse files
committed
--modify ESP_CHECK to exit not abort.
1 parent 537cdaa commit c3ac755

File tree

3 files changed

+33
-36
lines changed

3 files changed

+33
-36
lines changed

src/esp/bindings/Bindings.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ PYBIND11_MODULE(habitat_sim_bindings, m) {
4848
#endif
4949
m.attr("stage_id") = esp::RIGID_STAGE_ID;
5050

51-
/* This function pointer is used by ESP_CHECK(). If it's null, it
52-
std::abort()s, if not, it calls it to cause a Python AssertionError */
53-
esp::core::throwInPython = [](const char* const message) {
54-
PyErr_SetString(PyExc_AssertionError, message);
51+
/**
52+
* This function pointer is used by ESP_CHECK(). If this is null, the macro
53+
* std::exit(1)s, if not, the macro calls this to throw a Python RuntimeError
54+
*/
55+
esp::core::throwRuntimeInPython = [](const char* const message) {
56+
PyErr_SetString(PyExc_RuntimeError, message);
5557
throw pybind11::error_already_set{};
5658
};
5759

src/esp/core/Check.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@
99
namespace esp {
1010
namespace core {
1111

12-
void (*throwInPython)(const char*) = nullptr;
12+
void (*throwRuntimeInPython)(const char*) = nullptr;
1313

1414
/* [[noreturn]] will help the compiler optimize -- it basically tells it that
1515
the condition passed to HABITAT_EXCEPTION() can be assumed to be always true
1616
in the following code, because if not then the execution ends in this
1717
function. */
18-
[[noreturn]] void throwIfInPythonOtherwiseAbort(const char* message) {
19-
/* The throwInPython function pointer gets filled during Python bindings
20-
startup. If it's nullptr, we're in plain C++ code. */
21-
if (throwInPython) {
22-
throwInPython(message);
23-
/* I failed to apply the NORETURN attribute to the throwInPython function
24-
pointer so at least this */
25-
CORRADE_INTERNAL_ASSERT_UNREACHABLE();
18+
19+
[[noreturn]] void throwIfInPythonOtherwiseExit(const char* message) {
20+
/* The throwRuntimeInPython function pointer gets filled during Python
21+
bindings startup. If it's nullptr, we're in plain C++ code. */
22+
if (throwRuntimeInPython) {
23+
throwRuntimeInPython(message);
24+
25+
std::exit(1);
2626
}
2727

28-
/* If it isn't defined, do an abort the same way as CORRADE_ASSERT(). This
29-
could be in an `else` block but I like to play with fire, so it's not --
30-
the NORETURN above should tell that to the compiler and the function
31-
should throw. */
32-
Corrade::Utility::Error{Corrade::Utility::Error::defaultOutput()} << message;
33-
std::abort();
28+
/*
29+
* If it isn't defined, display a Fatal message, which will terminate with
30+
* std::exit(1).
31+
*/
32+
Corrade::Utility::Fatal{Corrade::Utility::Fatal::defaultOutput(), 1}
33+
<< message;
3434
}
3535

3636
} // namespace core

src/esp/core/Check.h

+12-17
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
/** @file
1313
@brief ESP_CHECK macro, for use with fatal runtime errors.
1414
15-
Below is an overview of asserts, ESP_CHECK, exception-throwing, and warnings
16-
in Habitat-sim. These are new guidelines as of Feb 2021; not all Habitat code
17-
follows these guidelines yet.
15+
Below is an overview of asserts, ESP_CHECK vs. ESP_FATAL, exception-throwing,
16+
and warnings in Habitat-sim. These are new guidelines as of Feb 2021, and
17+
updated June 2023; not all Habitat code follows these guidelines yet.
1818
1919
assert
2020
- see CORRADE_ASSERT and CORRADE_ASSERT_INTERNAL.
@@ -51,32 +51,27 @@
5151
namespace esp {
5252
namespace core {
5353

54-
/**
55-
* @brief The throwInPython function pointer gets filled during Python bindings
56-
* startup. If it's nullptr, we're in plain C++ code.
57-
*/
58-
extern void (*throwInPython)(const char*);
54+
/* The throwRuntimeInPython function pointer gets filled during Python bindings
55+
startup. If it's nullptr, we're in plain C++ code. */
56+
extern void (*throwRuntimeInPython)(const char*);
5957

60-
/**
61-
* @brief For use in ESP_CHECK
62-
*/
63-
[[noreturn]] void throwIfInPythonOtherwiseAbort(const char* message);
58+
// For use in ESP_CHECK
59+
[[noreturn]] void throwIfInPythonOtherwiseExit(const char* message);
6460

6561
} // namespace core
6662
} // namespace esp
6763

68-
/**
69-
* @brief A runtime check that must pass, otherwise we consider this a fatal
70-
* runtime error. The program terminates with the supplied error message.
71-
*/
64+
/* A runtime check that must pass, otherwise we consider this a fatal
65+
* user-caused error (bad data). The program exist with the supplied error
66+
* message but no core dump. */
7267
#define ESP_CHECK(condition, ...) \
7368
do { \
7469
if (!(condition)) { \
7570
std::ostringstream out; \
7671
Corrade::Utility::Debug{ \
7772
&out, Corrade::Utility::Debug::Flag::NoNewlineAtTheEnd} \
7873
<< "ESP_CHECK failed:" << __VA_ARGS__; \
79-
esp::core::throwIfInPythonOtherwiseAbort(out.str().data()); \
74+
esp::core::throwIfInPythonOtherwiseExit(out.str().data()); \
8075
} \
8176
} while (false)
8277

0 commit comments

Comments
 (0)