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

Refactor and simplify code by useful macros #875

Closed
acelyc111 opened this issue Jan 10, 2022 · 0 comments
Closed

Refactor and simplify code by useful macros #875

acelyc111 opened this issue Jan 10, 2022 · 0 comments
Labels
type/enhancement Indicates new feature requests

Comments

@acelyc111
Copy link
Member

Feature Request

Is your feature request related to a problem? Please describe:
There are some duplicate code in rdsn and pegasus project, we can simplify them by some useful macros.

Describe the feature you'd like:
We can add some macros like:

// Return the given status if it is not ERR_OK.
#define ERR_LOG_AND_RETURN_NOT_OK(s, ...)                                                          \
    do {                                                                                           \
        error_code _err = (s);                                                                     \
        if (dsn_unlikely(_err != ERR_OK)) {                                                        \
            derror_f("{}: {}", _err, fmt::format(__VA_ARGS__));                                    \
            return _err;                                                                           \
        }                                                                                          \
    } while (0)

// Return the given status if condition is not true.
#define ERR_LOG_AND_RETURN_NOT_TRUE(s, err, ...)                                                   \
    do {                                                                                           \
        if (dsn_unlikely(!(s))) {                                                                  \
            derror_f("{}: {}", err, fmt::format(__VA_ARGS__));                                     \
            return err;                                                                            \
        }                                                                                          \
    } while (0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Indicates new feature requests
Projects
None yet
Development

No branches or pull requests

1 participant