1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-12-04 14:46:31 -05:00

Feature: Report instance in object stringify. Plus support %P for objects in igloo_private__snprintf()

This commit is contained in:
Philipp Schafft 2019-09-15 08:39:23 +00:00
parent 64e0ab7c3a
commit 4b9211e0cf
2 changed files with 34 additions and 17 deletions

View File

@ -62,7 +62,8 @@ void igloo_private__vsnprintf(char *str, size_t size, const char *format, va_lis
int block_alt = 0;
const char * arg;
const void * argp;
char buf[80];
igloo_ro_t argro;
char buf[128];
for (; *format && size; format++)
{
@ -126,6 +127,21 @@ void igloo_private__vsnprintf(char *str, size_t size, const char *format, va_lis
snprintf(buf, sizeof(buf), "%p", argp);
arg = buf;
}
case 'P':
if (!arg)
{
igloo_ro_base_t *base;
argro = va_arg(ap, igloo_ro_t);
base = igloo_RO__GETBASE(argro);
if (base) {
snprintf(buf, sizeof(buf), "{%s@%p}", base->type->type_name, base);
arg = buf;
} else if (block_alt) {
arg = "-";
} else {
arg = "{igloo_RO_NULL}";
}
}
case 'd':
case 'i':
case 'u':

View File

@ -482,6 +482,16 @@ igloo_ro_t igloo_ro_get_interface_ext(igloo_ro_t self, const igloo_ro_type_t *ty
return ret;
}
static size_t igloo_ro_stringify__calc_object_strlen_short(igloo_ro_t self)
{
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
if (!base)
return 2;
return strlen(base->type->type_name) + 2+(64/4) /* pointer rendering */ + 4 /* "{@}\0" */;
}
char * igloo_ro_stringify(igloo_ro_t self, igloo_ro_sy_t flags)
{
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
@ -524,23 +534,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) {
if (igloo_RO_IS_NULL(base->associated)) {
static const char *format = "{%s@%p, strong, name=%# H, associated=-}";
size_t len = strlen(base->type->type_name) + 1*(2+64/4) + strlen(format) + igloo_private__vsnprintf_Hstrlen(base->name, 1, 1) + 1;
static const char *format = "{%s@%p, strong, name=%# H, associated=%#P, instance=%#P}";
size_t len = strlen(base->type->type_name) + 1*(2+64/4) + strlen(format) + igloo_private__vsnprintf_Hstrlen(base->name, 1, 1) + 1 +
igloo_ro_stringify__calc_object_strlen_short(base->associated) +
igloo_ro_stringify__calc_object_strlen_short(base->instance);
ret = calloc(1, len);
if (ret) {
igloo_private__snprintf(ret, len + 1, format, base->type->type_name, base, base->name);
}
} else {
static const char *format = "{%s@%p, strong, name=%# H, associated={%s@%p}}";
igloo_ro_base_t *associated = igloo_RO__GETBASE(base->associated);
size_t len = strlen(base->type->type_name) + strlen(associated->type->type_name) + 2*(2+64/4) + strlen(format) + igloo_private__vsnprintf_Hstrlen(base->name, 1, 1) + 1;
ret = calloc(1, len);
if (ret) {
igloo_private__snprintf(ret, len + 1, format, base->type->type_name, base, base->name, associated->type->type_name, associated);
}
ret = calloc(1, len);
if (ret) {
igloo_private__snprintf(ret, len + 1, format, base->type->type_name, base, base->name, base->associated, base->instance);
}
}
}