mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
build: fix VIR_DEBUG on mingw
We don't use the gnulib vsnprintf replacement, which means that on mingw, vsnprintf doesn't support %zn or %lln. And as it turns out, VIR_GET_VAR_STR was a rather inefficient reimplementation of virVasprintf logic. * src/util/logging.c (VIR_GET_VAR_STR): Drop. (virLogMessage): Inline a simpler version here. * src/util/virterror.c (VIR_GET_VAR_STR, virRaiseErrorFull): Likewise. Reported by Matthias Bolte.
This commit is contained in:
parent
764c282cdf
commit
4486f3a209
@ -46,43 +46,6 @@
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||
|
||||
/*
|
||||
* Macro used to format the message as a string in virLogMessage
|
||||
* and borrowed from libxml2 (also used in virRaiseError)
|
||||
*/
|
||||
#define VIR_GET_VAR_STR(msg, str) { \
|
||||
int size, prev_size = -1; \
|
||||
int chars; \
|
||||
char *larger; \
|
||||
va_list ap; \
|
||||
\
|
||||
str = (char *) malloc(150); \
|
||||
if (str != NULL) { \
|
||||
\
|
||||
size = 150; \
|
||||
\
|
||||
while (1) { \
|
||||
va_start(ap, msg); \
|
||||
chars = vsnprintf(str, size, msg, ap); \
|
||||
va_end(ap); \
|
||||
if ((chars > -1) && (chars < size)) { \
|
||||
if (prev_size == chars) { \
|
||||
break; \
|
||||
} else { \
|
||||
prev_size = chars; \
|
||||
} \
|
||||
} \
|
||||
if (chars > -1) \
|
||||
size += chars + 1; \
|
||||
else \
|
||||
size += 100; \
|
||||
if ((larger = (char *) realloc(str, size)) == NULL) { \
|
||||
break; \
|
||||
} \
|
||||
str = larger; \
|
||||
}} \
|
||||
}
|
||||
|
||||
/*
|
||||
* A logging buffer to keep some history over logs
|
||||
*/
|
||||
@ -729,6 +692,7 @@ void virLogMessage(const char *category, int priority, const char *funcname,
|
||||
int len, fprio, i, ret;
|
||||
int saved_errno = errno;
|
||||
int emit = 1;
|
||||
va_list ap;
|
||||
|
||||
if (!virLogInitialized)
|
||||
virLogStartup();
|
||||
@ -753,9 +717,12 @@ void virLogMessage(const char *category, int priority, const char *funcname,
|
||||
/*
|
||||
* serialize the error message, add level and timestamp
|
||||
*/
|
||||
VIR_GET_VAR_STR(fmt, str);
|
||||
if (str == NULL)
|
||||
va_start(ap, fmt);
|
||||
if (virVasprintf(&str, fmt, ap) < 0) {
|
||||
va_end(ap);
|
||||
goto cleanup;
|
||||
}
|
||||
va_end(ap);
|
||||
gettimeofday(&cur_time, NULL);
|
||||
localtime_r(&cur_time.tv_sec, &time_info);
|
||||
|
||||
|
@ -28,43 +28,6 @@ virErrorFunc virErrorHandler = NULL; /* global error handler */
|
||||
void *virUserData = NULL; /* associated data */
|
||||
virErrorLogPriorityFunc virErrorLogPriorityFilter = NULL;
|
||||
|
||||
/*
|
||||
* Macro used to format the message as a string in virRaiseError
|
||||
* and borrowed from libxml2.
|
||||
*/
|
||||
#define VIR_GET_VAR_STR(msg, str) { \
|
||||
int size, prev_size = -1; \
|
||||
int chars; \
|
||||
char *larger; \
|
||||
va_list ap; \
|
||||
\
|
||||
str = (char *) malloc(150); \
|
||||
if (str != NULL) { \
|
||||
\
|
||||
size = 150; \
|
||||
\
|
||||
while (1) { \
|
||||
va_start(ap, msg); \
|
||||
chars = vsnprintf(str, size, msg, ap); \
|
||||
va_end(ap); \
|
||||
if ((chars > -1) && (chars < size)) { \
|
||||
if (prev_size == chars) { \
|
||||
break; \
|
||||
} else { \
|
||||
prev_size = chars; \
|
||||
} \
|
||||
} \
|
||||
if (chars > -1) \
|
||||
size += chars + 1; \
|
||||
else \
|
||||
size += 100; \
|
||||
if ((larger = (char *) realloc(str, size)) == NULL) { \
|
||||
break; \
|
||||
} \
|
||||
str = larger; \
|
||||
}} \
|
||||
}
|
||||
|
||||
static virLogPriority virErrorLevelPriority(virErrorLevel level) {
|
||||
switch (level) {
|
||||
case VIR_ERR_NONE:
|
||||
@ -718,12 +681,15 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED,
|
||||
}
|
||||
|
||||
/*
|
||||
* formats the message
|
||||
* formats the message; drop message on OOM situations
|
||||
*/
|
||||
if (fmt == NULL) {
|
||||
str = strdup(_("No error message provided"));
|
||||
} else {
|
||||
VIR_GET_VAR_STR(fmt, str);
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
virVasprintf(&str, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user