add some noexcept#51
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds noexcept specifiers to numerous functions across the runtime and ring classes, fundamentally changing the error handling strategy from exceptions to assertions. The changes affect core runtime operations, io_uring wrapper functions, and synchronization helpers.
Changes:
- Added
noexceptto ~30 functions inruntime.hpp,ring.hpp, and helper functions - Converted exception-throwing error handling to assertions in critical paths
- Removed test case that verified exception behavior for deprecated fd_accepter feature
- Removed try-catch block from
sync_waitthat handled runtime.run() exceptions
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_fd_table.cpp | Removed test case that verified std::logic_error throwing behavior for deprecated fd_accepter feature |
| include/condy/sync_wait.hpp | Removed try-catch block around runtime.run() call, consistent with run() becoming noexcept |
| include/condy/runtime.hpp | Added noexcept to run(), schedule(), and other runtime methods; replaced exceptions with assertions and fprintf |
| include/condy/ring.hpp | Added noexcept to Ring, FdTable, BufferTable, and RingSettings methods; replaced throw with assertion in reap_completions_wait() |
Comments suppressed due to low confidence (2)
include/condy/runtime.hpp:369
- The process_cqe_ function is now marked noexcept, but it calls handle->handle_cqe(cqe) on line 368, which can indirectly call user-provided callbacks (e.g., in MultiShotMixin::func_ and ZeroCopyMixin::free_func_) that may throw exceptions. If any of these user callbacks throw an exception, std::terminate will be called. This is a breaking change in behavior and should be carefully considered, especially since the MultiShotMixin pattern allows arbitrary user code to be executed during CQE processing.
void process_cqe_(io_uring_cqe *cqe) noexcept {
auto *data_raw = io_uring_cqe_get_data(cqe);
auto [data, type] = decode_work(data_raw);
if (type == WorkType::Ignore) {
// No-op
assert(cqe->res != -EINVAL); // If EINVAL, something is wrong
} else if (type == WorkType::SendFd) {
auto &fd_table = ring_.fd_table();
if (fd_table.fd_accepter_ == nullptr) [[unlikely]] {
std::fprintf(stderr, "[Deprecated Warning] Received a file "
"descriptor but no accepter is set.");
}
uint64_t payload = reinterpret_cast<uint64_t>(data) >> 3;
if (payload == 0) { // Auto-allocate
fd_table.fd_accepter_(cqe->res);
} else {
int target_fd = static_cast<int>(payload - 1);
fd_table.fd_accepter_(target_fd);
}
} else if (type == WorkType::Schedule) {
if (data == nullptr) {
assert(cqe->res == 0);
pending_works_--;
} else {
auto *work = static_cast<WorkInvoker *>(data);
tsan_acquire(data);
local_queue_.push_back(work);
}
} else if (type == WorkType::Common) {
auto *handle = static_cast<OpFinishHandleBase *>(data);
auto action = handle->handle_cqe(cqe);
if (action.op_finish) {
include/condy/runtime.hpp:356
- The warning message is printed when fd_accepter_ is nullptr, but then the code continues to call fd_accepter_ unconditionally on lines 352 and 355, which will cause a null pointer dereference. This check should either return early after printing the warning, or the subsequent calls to fd_accepter_ should be guarded with another nullptr check.
if (fd_table.fd_accepter_ == nullptr) [[unlikely]] {
std::fprintf(stderr, "[Deprecated Warning] Received a file "
"descriptor but no accepter is set.");
}
uint64_t payload = reinterpret_cast<uint64_t>(data) >> 3;
if (payload == 0) { // Auto-allocate
fd_table.fd_accepter_(cqe->res);
} else {
int target_fd = static_cast<int>(payload - 1);
fd_table.fd_accepter_(target_fd);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.