1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-11-03 04:17:20 -05:00

Feature: use %H and alt form for printing base object content

This commit is contained in:
Philipp Schafft 2019-08-03 14:08:28 +00:00
parent ecdfa060d7
commit 08e849de9a
3 changed files with 25 additions and 11 deletions

View File

@ -25,7 +25,7 @@ static inline int __vsnprintf__is_print(int c, int allow_space)
}
}
static inline size_t __vsnprintf__strlen(const char *str, int is_alt, int allow_space)
size_t igloo_private__vsnprintf_Hstrlen(const char *str, int is_alt, int allow_space)
{
size_t ret = 0;
@ -61,6 +61,7 @@ void igloo_private__vsnprintf(char *str, size_t size, const char *format, va_lis
int block_space = 0;
int block_alt = 0;
const char * arg;
const void * argp;
char buf[80];
for (; *format && size; format++)
@ -118,8 +119,13 @@ void igloo_private__vsnprintf(char *str, size_t size, const char *format, va_lis
format--;
break;
case 'p':
snprintf(buf, sizeof(buf), "%p", (void*)va_arg(ap, void *));
arg = buf;
argp = va_arg(ap, void *);
if (!argp && block_alt) {
arg = "-";
} else {
snprintf(buf, sizeof(buf), "%p", argp);
arg = buf;
}
case 'd':
case 'i':
case 'u':
@ -169,7 +175,7 @@ void igloo_private__vsnprintf(char *str, size_t size, const char *format, va_lis
if (!arg && !block_alt)
arg = "(null)";
if (!block_len) {
block_len = __vsnprintf__strlen(arg, block_alt, block_space);
block_len = igloo_private__vsnprintf_Hstrlen(arg, block_alt, block_space);
}
// the if() is the outer structure so the inner for()
@ -231,3 +237,10 @@ void igloo_private__vsnprintf(char *str, size_t size, const char *format, va_lis
*str = 0;
}
void igloo_private__snprintf(char *str, size_t size, const char *format, ...)
{
va_list ap;
va_start(ap, format);
igloo_private__vsnprintf(str, size, format, ap);
va_end(ap);
}

View File

@ -59,6 +59,8 @@ void igloo_interface_base_free(igloo_ro_t self);
igloo_ro_t igloo_interface_base_new_real(const igloo_ro_type_t *type, size_t description_length, const igloo_interface_base_ifdesc_t *ifdesc, igloo_ro_t backend_object, void *backend_userdata, const char *name, igloo_ro_t associated);
#define igloo_interface_base_new(type, ifdesc, backend_object, backend_userdata, name, associated) igloo_RO_TO_TYPE(igloo_interface_base_new_real(igloo_ro__type__ ## type, sizeof(*(ifdesc)), (const igloo_interface_base_ifdesc_t*)(ifdesc), (backend_object), (backend_userdata), (name), (associated)), type)
size_t igloo_private__vsnprintf_Hstrlen(const char *str, int is_alt, int allow_space);
void igloo_private__vsnprintf(char *str, size_t size, const char *format, va_list ap);
void igloo_private__snprintf(char *str, size_t size, const char *format, ...);
#endif

View File

@ -26,6 +26,7 @@
#include <string.h>
#include <igloo/ro.h>
#include "private.h"
/* This is not static as it is used by igloo_RO_TYPEDECL_NEW_NOOP() */
int igloo_ro_new__return_zero(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap)
@ -434,16 +435,14 @@ char * igloo_ro_stringify(igloo_ro_t self, igloo_ro_sy_t flags)
ret = base->type->type_stringifycb(self, flags);
} else {
if (flags & igloo_RO_SY_OBJECT) {
int len;
char buf;
#define STRINGIFY_FORMAT_FULL_FORMAT "{%s@%p, strong, name=%# H, associated=%#p}"
#define STRINGIFY_FORMAT_FULL STRINGIFY_FORMAT_FULL_FORMAT, base->type->type_name, base, base->name, igloo_RO__GETBASE(base->associated)
int len = strlen(base->type->type_name) + 2*(2+64/4) + strlen(STRINGIFY_FORMAT_FULL_FORMAT) + igloo_private__vsnprintf_Hstrlen(base->name, 1, 1) + 1;
#define STRINGIFY_FORMAT_FULL "{%s@%p, strong, name=\"%s\", associated=%p}", base->type->type_name, base, base->name, igloo_RO__GETBASE(base->associated)
len = snprintf(&buf, 1, STRINGIFY_FORMAT_FULL);
if (len > 2) {
/* We add 2 bytes just to make sure no buggy interpretation of \0 inclusion could bite us. */
ret = calloc(1, len + 2);
ret = calloc(1, len);
if (ret) {
snprintf(ret, len + 1, STRINGIFY_FORMAT_FULL);
igloo_private__snprintf(ret, len + 1, STRINGIFY_FORMAT_FULL);
}
}
}