Skip to content

Commit

Permalink
Fix: make_named_tuple maked ref to temporary alogstring (alibaba#375)
Browse files Browse the repository at this point in the history
Signed-off-by: Coldwings <coldwings@me.com>
  • Loading branch information
Coldwings authored Feb 23, 2024
1 parent 13a4ffd commit 9caa491
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions common/alog.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,24 +528,18 @@ inline NamedValue<T> make_named_value(const char (&name)[N], T&& value)
}

template <ssize_t N, ssize_t M>
inline NamedValue<ALogString> make_named_value(const char (&name)[N],
char (&value)[M]) {
return {ALogStringL(name), alog_forwarding(value)};
inline NamedValue<const char*> make_named_value(const char (&name)[N],
char (&value)[M]) {
return {ALogStringL(name), value};
}

#define VALUE(x) make_named_value(#x, x)

template<typename T>
inline LogBuffer& operator << (LogBuffer& log, const NamedValue<T>& v)
{
template <typename T>
inline LogBuffer& operator<<(LogBuffer& log, const NamedValue<T>& v) {
return log.printf('[', v.name, '=', v.value, ']');
}

inline LogBuffer& operator << (LogBuffer& log, const NamedValue<ALogString>& v)
{
return log.printf('[', v.name, '=', '"', v.value, '"', ']');
}

// output a log message, set errno, then return a value
// keep errno unchaged if new_errno == 0
#define LOG_ERROR_RETURN(new_errno, retv, ...) { \
Expand Down

0 comments on commit 9caa491

Please sign in to comment.