feat: add thespian_exit to the C API

This commit is contained in:
CJ van den Berg 2026-03-04 20:19:15 +01:00
parent e9998ce127
commit 703e5d5be1
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 16 additions and 0 deletions

View file

@ -16,6 +16,8 @@ typedef void (*thespian_receiver_dtor)(thespian_behaviour_state);
void thespian_receive(thespian_receiver, thespian_behaviour_state, void thespian_receive(thespian_receiver, thespian_behaviour_state,
thespian_receiver_dtor); thespian_receiver_dtor);
thespian_result thespian_exit(const char *status);
bool thespian_get_trap(); bool thespian_get_trap();
bool thespian_set_trap(bool); bool thespian_set_trap(bool);
void thespian_link(thespian_handle); void thespian_link(thespian_handle);

View file

@ -33,6 +33,20 @@ void thespian_receive(thespian_receiver r, thespian_behaviour_state s,
auto thespian_get_trap() -> bool { return thespian::trap(); } auto thespian_get_trap() -> bool { return thespian::trap(); }
auto thespian_set_trap(bool on) -> bool { return thespian::trap(on); } auto thespian_set_trap(bool on) -> bool { return thespian::trap(on); }
namespace {
thread_local cbor::buffer exit_msg_buf; // NOLINT
thread_local thespian_error exit_error_buf; // NOLINT
} // namespace
auto thespian_exit(const char *status) -> thespian_result {
auto r = thespian::exit(status);
if (r)
return nullptr;
exit_msg_buf = r.error();
exit_error_buf = {exit_msg_buf.data(), exit_msg_buf.size()};
return &exit_error_buf;
}
void thespian_link(thespian_handle h) { void thespian_link(thespian_handle h) {
thespian::handle *h_{ thespian::handle *h_{
reinterpret_cast<thespian::handle *>( // NOLINT(*-reinterpret-cast) reinterpret_cast<thespian::handle *>( // NOLINT(*-reinterpret-cast)