Skip to content

Commit 2087232

Browse files
committed
Size debug_cycle lines from tp_name instead of measuring with snprintf
1 parent 93e1bd1 commit 2087232

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

‎Python/gc.c‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -996,22 +996,19 @@ clear_weakrefs(PyGC_Head *unreachable)
996996
}
997997
}
998998

999+
/* "gc: " + msg (at most "uncollectable") + " <" + " " + %p + ">\n" + NUL */
1000+
#define DEBUG_LINE_FIXED_LEN 64
1001+
9991002
static char *
10001003
debug_cycle(const char *msg, PyObject *op)
10011004
{
1002-
const char fmt[] = "gc: %s <%s %p>\n";
10031005
const char *name = Py_TYPE(op)->tp_name;
1004-
int len = PyOS_snprintf(NULL, 0, fmt,
1005-
msg, name, (void *)op);
1006-
if (len < 0) {
1007-
return NULL;
1008-
}
1009-
char *line = PyMem_RawMalloc((size_t)len + 1);
1006+
size_t size = strlen(name) + DEBUG_LINE_FIXED_LEN;
1007+
char *line = PyMem_RawMalloc(size);
10101008
if (line == NULL) {
10111009
return NULL;
10121010
}
1013-
PyOS_snprintf(line, (size_t)len + 1, fmt,
1014-
msg, name, (void *)op);
1011+
PyOS_snprintf(line, size, "gc: %s <%s %p>\n", msg, name, (void *)op);
10151012
return line;
10161013
}
10171014

0 commit comments

Comments
 (0)