-
Notifications
You must be signed in to change notification settings - Fork 118
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
retval<T> to return a value and an error number at the same time #439
Conversation
} | ||
|
||
template<> inline | ||
LogBuffer& operator << <void> (LogBuffer& log, const photon::retval<void>& v) { |
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.
Log on A successful retval breaks assertion in LogBuffer::operator<<(retval_base)
common/alog.h
Outdated
@@ -508,6 +510,22 @@ struct ERRNO | |||
|
|||
LogBuffer& operator << (LogBuffer& log, ERRNO e); | |||
|
|||
inline LogBuffer& operator << (LogBuffer& log, const photon::retval_base& rvb) { | |||
auto x = rvb._errno; | |||
assert(0<x && x<INT_MAX); |
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.
assertion rejects x ==0 situation.
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.
LGTM
so as to avoid some bugs:
unintentionally change the global errno by some function calls (e.g. printf or LOG_XXXX) in the error handling path, causing misunderstanding about the error
return an error but forget to set errno, causing incorrect handling of the error
In addition,
retval<T>
makes the error number returned in register, more efficient than the global thread-localerrno
variable.