δΊ 2013-1-4 22:55, Stefan Hajnoczi ει:
On Mon, Dec 17, 2012 at 02:25:05PM +0800, Wenchao Xia wrote:
This patch has nothing to do with snapshots, so "snapshot: add error set
function" is not a useful commit message. "error: add
error_set_replace()" would be okay. Please use git log <filename> on
the file you are modifying to find good component names (e.g. "block:",
"error:").
@@ -29,6 +29,9 @@ typedef struct Error Error;
*/
void error_set(Error **err, ErrorClass err_class, const char *fmt, ...)
GCC_FMT_ATTR(3, 4);
+void error_set_replace(Error **err, ErrorClass err_class, const char *fmt, ...)
+GCC_FMT_ATTR(3, 4);
+
/**
* Set an indirect pointer to an error given a ErrorClass value and a
* printf-style human message, followed by a strerror() string if
@@ -43,6 +46,12 @@ void error_set_errno(Error **err, int os_error, ErrorClass
err_class, const char
error_set(err, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__)
#define error_setg_errno(err, os_error, fmt, ...) \
error_set_errno(err, os_error, ERROR_CLASS_GENERIC_ERROR, fmt, ##
__VA_ARGS__)
+#define error_setg_replace(err, fmt, ...) do { \
+ if (*err != NULL) { \
+ error_free(*err); \
+ } \
+ error_set(err, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__); \
+} while (/*CONSTCOND*/0)
Why not use error_set_replace() to get rid of the error_free() check?
Stefan
It will be changed to error_set_check() which only set error when
*err is not set, to keep first error not over written.
--
Best Regards
Wenchao Xia