-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate more interface and definition. Add comments on std::future. Mark noexcept to compat mode-related functions #588
Separate more interface and definition. Add comments on std::future. Mark noexcept to compat mode-related functions #588
Conversation
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
/ok to test |
/ok to test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I only have a minor suggestion
cpp/src/file_handle.cpp
Outdated
{ | ||
if (closed()) { return; } | ||
|
||
if (!is_compat_mode_preferred()) { cuFileAPI::instance().HandleDeregister(_handle); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this refactoring, but might make sense to fix in this PR:
We need an exception catch or make is_compat_mode_preferred()
and compat_mode()
noexcept
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting: defaults::compat_mode()
can't be noexcept
because it calls defaults::instance()
and defaults
's constructor is potentially throwing. One workaround is:
CompatMode defaults::compat_mode() noexcept {
try {
return instance()->_compat_mode;
} catch(...) {}
return CompatMode::ON; // Or we may add an CompatMode::Invalid?
}
But is it worth the hassle to make it noexcept
at all?
@wence- @madsbk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But is it worth the hassle to make it noexcept at all?
Heh, maybe not :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note, we can use noexcept
on functions that might throw exceptions, it just makes them fatal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's UB, rather than just making things fatal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's UB, rather than just making things fatal
It is UB in the sense that calling std::terminate()
is UB (it is implementation-defined whether any stack unwinding).
But std::terminate()
is guaranteed to be called when violating noexcept
: https://en.cppreference.com/w/cpp/error/terminate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, I was wrong, it is not UB, so all good.
{ | ||
try { | ||
cuFileAPI::instance(); | ||
} catch (const std::runtime_error&) { | ||
} catch (...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imho ...
is better since it simplifies the effort to cover all possible exception types that the try block may generate (the exact types can be documented in cuFileAPI::instance()
's @throw
section) while satisfying the noexcept
promise. But I'm ready to revert if there's any other consideration I'm not aware of. @madsbk @vuule @wence-
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, ...
is better!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+2
_fd_direct_on = -1; | ||
_fd_direct_off = -1; | ||
_initialized = false; | ||
} catch (...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cuFileAPI
constructor (hence cuFileAPI::instance()
) is potentially throwing. So to satisfy the noexcept
promise, the try-catch block has to be here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
bool is_running_in_wsl() noexcept | ||
{ | ||
struct utsname buf {}; | ||
int err = ::uname(&buf); | ||
if (err == 0) { | ||
const std::string name(static_cast<char*>(buf.release)); | ||
// 'Microsoft' for WSL1 and 'microsoft' for WSL2 | ||
return name.find("icrosoft") != std::string::npos; | ||
try { | ||
struct utsname buf {}; | ||
int err = ::uname(&buf); | ||
if (err == 0) { | ||
const std::string name(static_cast<char*>(buf.release)); | ||
// 'Microsoft' for WSL1 and 'microsoft' for WSL2 | ||
return name.find("icrosoft") != std::string::npos; | ||
} | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: what might throw here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a bit paranoid about STL function calls. Here the string's constructor basic_string(const charT* s, const Allocator& a = Allocator());
should be potentially throwing, because it does not have a "Throws" section in its specs. According to the specs:
Functions defined in the C++ standard library that do not have a Throws: paragraph but do have a potentially-throwing exception specification may throw implementation-defined exceptions.
In particular, they can report a failure to allocate storage by throwing an exception of type bad_alloc, or a class derived from bad_alloc
I would imagine the rare but not impossible case in practice, where the stack may overflow (when short string optimization is in effect), or the heap may run out of memory.
The string find overload size_type F(const charT* s, size_type pos) const;
is on the same boat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One query about the catch in is_running_in_wsl
, otherwise looks good!
/merge |
This PR performs makes the following three improvements:
file_handle.hpp
that was missed in the previous PR Continue to make KvikIO a shared library by moving code from hpp to cpp #581.pread/pwrite
:noexcept
specifier to compatibility mode-related functions.