Skip to content
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

Merged
merged 5 commits into from
Apr 3, 2024

Conversation

lihuiba
Copy link
Collaborator

@lihuiba lihuiba commented Apr 2, 2024

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-local errno variable.

@lihuiba lihuiba requested a review from Coldwings April 2, 2024 13:40
@lihuiba lihuiba marked this pull request as ready for review April 2, 2024 14:07
}

template<> inline
LogBuffer& operator << <void> (LogBuffer& log, const photon::retval<void>& v) {
Copy link
Collaborator

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);
Copy link
Collaborator

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.

@lihuiba lihuiba requested a review from Coldwings April 3, 2024 05:34
Copy link
Collaborator

@Coldwings Coldwings left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lihuiba lihuiba merged commit 8ac6741 into alibaba:main Apr 3, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants