[Tarantool-patches] [PATCH 05/13] diag: introduce diag_set_detailed()

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Sat Jun 12 00:56:13 MSK 2021


diag_set() uses the current file and line as built-in macros.
In the future patches there are going to appear a couple of new
diag_set-like helpers which also would want to preserve the
original file and line.

For that they must be macros at least partially, like diag_set(),
and pass their own file and line. Because they are going not to be
very trivial and won't be implemented in the header.

The patch introduces diag_set_detailed() which allows to pass
custom file and line.

Needed for #6027
---
 src/lib/core/diag.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/lib/core/diag.h b/src/lib/core/diag.h
index b07eea838..fa85326ad 100644
--- a/src/lib/core/diag.h
+++ b/src/lib/core/diag.h
@@ -347,17 +347,20 @@ struct error *
 BuildSocketError(const char *file, unsigned line, const char *socketname,
 		 const char *format, ...);
 
-#define diag_set(class, ...) do {					\
+#define diag_set_detailed(file, line, class, ...) do {			\
 	/* Preserve the original errno. */                              \
 	int save_errno = errno;                                         \
-	say_debug("%s at %s:%i", #class, __FILE__, __LINE__);		\
+	say_debug("%s at %s:%i", #class, file, line);			\
 	struct error *e;						\
-	e = Build##class(__FILE__, __LINE__, ##__VA_ARGS__);		\
+	e = Build##class(file, line, ##__VA_ARGS__);			\
 	diag_set_error(diag_get(), e);					\
 	/* Restore the errno which might have been reset.  */           \
 	errno = save_errno;                                             \
 } while (0)
 
+#define diag_set(...)							\
+	diag_set_detailed(__FILE__, __LINE__, __VA_ARGS__)
+
 #define diag_add(class, ...) do {					\
 	int save_errno = errno;						\
 	say_debug("%s at %s:%i", #class, __FILE__, __LINE__);		\
-- 
2.24.3 (Apple Git-128)



More information about the Tarantool-patches mailing list