mirror of
https://github.com/python/cpython.git
synced 2025-08-24 10:45:53 +00:00
gh-127604: Replace dprintf() with _Py_write_noraise() (#132854)
This commit is contained in:
parent
99b13775da
commit
402dba2928
1 changed files with 52 additions and 16 deletions
|
@ -842,11 +842,11 @@ _Py_DumpDecimal(int fd, size_t value)
|
||||||
|
|
||||||
/* Format an integer as hexadecimal with width digits into fd file descriptor.
|
/* Format an integer as hexadecimal with width digits into fd file descriptor.
|
||||||
The function is signal safe. */
|
The function is signal safe. */
|
||||||
void
|
static void
|
||||||
_Py_DumpHexadecimal(int fd, uintptr_t value, Py_ssize_t width)
|
dump_hexadecimal(int fd, uintptr_t value, Py_ssize_t width, int strip_zeros)
|
||||||
{
|
{
|
||||||
char buffer[sizeof(uintptr_t) * 2 + 1], *ptr, *end;
|
char buffer[sizeof(uintptr_t) * 2 + 1], *ptr, *end;
|
||||||
const Py_ssize_t size = Py_ARRAY_LENGTH(buffer) - 1;
|
Py_ssize_t size = Py_ARRAY_LENGTH(buffer) - 1;
|
||||||
|
|
||||||
if (width > size)
|
if (width > size)
|
||||||
width = size;
|
width = size;
|
||||||
|
@ -862,7 +862,35 @@ _Py_DumpHexadecimal(int fd, uintptr_t value, Py_ssize_t width)
|
||||||
value >>= 4;
|
value >>= 4;
|
||||||
} while ((end - ptr) < width || value);
|
} while ((end - ptr) < width || value);
|
||||||
|
|
||||||
(void)_Py_write_noraise(fd, ptr, end - ptr);
|
size = end - ptr;
|
||||||
|
if (strip_zeros) {
|
||||||
|
while (*ptr == '0' && size >= 2) {
|
||||||
|
ptr++;
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)_Py_write_noraise(fd, ptr, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_Py_DumpHexadecimal(int fd, uintptr_t value, Py_ssize_t width)
|
||||||
|
{
|
||||||
|
dump_hexadecimal(fd, value, width, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dump_pointer(int fd, void *ptr)
|
||||||
|
{
|
||||||
|
PUTS(fd, "0x");
|
||||||
|
dump_hexadecimal(fd, (uintptr_t)ptr, sizeof(void*), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dump_char(int fd, char ch)
|
||||||
|
{
|
||||||
|
char buf[1] = {ch};
|
||||||
|
(void)_Py_write_noraise(fd, buf, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -924,8 +952,7 @@ _Py_DumpASCII(int fd, PyObject *text)
|
||||||
ch = PyUnicode_READ(kind, data, i);
|
ch = PyUnicode_READ(kind, data, i);
|
||||||
if (' ' <= ch && ch <= 126) {
|
if (' ' <= ch && ch <= 126) {
|
||||||
/* printable ASCII character */
|
/* printable ASCII character */
|
||||||
char c = (char)ch;
|
dump_char(fd, (char)ch);
|
||||||
(void)_Py_write_noraise(fd, &c, 1);
|
|
||||||
}
|
}
|
||||||
else if (ch <= 0xff) {
|
else if (ch <= 0xff) {
|
||||||
PUTS(fd, "\\x");
|
PUTS(fd, "\\x");
|
||||||
|
@ -1227,7 +1254,9 @@ _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size)
|
||||||
|| info[i].dli_fname == NULL
|
|| info[i].dli_fname == NULL
|
||||||
|| info[i].dli_fname[0] == '\0'
|
|| info[i].dli_fname[0] == '\0'
|
||||||
) {
|
) {
|
||||||
dprintf(fd, " Binary file '<unknown>' [%p]\n", array[i]);
|
PUTS(fd, " Binary file '<unknown>' [");
|
||||||
|
dump_pointer(fd, array[i]);
|
||||||
|
PUTS(fd, "]\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1237,11 +1266,12 @@ _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size)
|
||||||
info[i].dli_saddr = info[i].dli_fbase;
|
info[i].dli_saddr = info[i].dli_fbase;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info[i].dli_sname == NULL
|
if (info[i].dli_sname == NULL && info[i].dli_saddr == 0) {
|
||||||
&& info[i].dli_saddr == 0) {
|
PUTS(fd, " Binary file \"");
|
||||||
dprintf(fd, " Binary file \"%s\" [%p]\n",
|
PUTS(fd, info[i].dli_fname);
|
||||||
info[i].dli_fname,
|
PUTS(fd, "\" [");
|
||||||
array[i]);
|
dump_pointer(fd, array[i]);
|
||||||
|
PUTS(fd, "]\n");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char sign;
|
char sign;
|
||||||
|
@ -1255,10 +1285,16 @@ _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size)
|
||||||
offset = info[i].dli_saddr - array[i];
|
offset = info[i].dli_saddr - array[i];
|
||||||
}
|
}
|
||||||
const char *symbol_name = info[i].dli_sname != NULL ? info[i].dli_sname : "";
|
const char *symbol_name = info[i].dli_sname != NULL ? info[i].dli_sname : "";
|
||||||
dprintf(fd, " Binary file \"%s\", at %s%c%#tx [%p]\n",
|
PUTS(fd, " Binary file \"");
|
||||||
info[i].dli_fname,
|
PUTS(fd, info[i].dli_fname);
|
||||||
symbol_name,
|
PUTS(fd, "\", at ");
|
||||||
sign, offset, array[i]);
|
PUTS(fd, symbol_name);
|
||||||
|
dump_char(fd, sign);
|
||||||
|
PUTS(fd, "0x");
|
||||||
|
dump_hexadecimal(fd, offset, sizeof(offset), 1);
|
||||||
|
PUTS(fd, " [");
|
||||||
|
dump_pointer(fd, array[i]);
|
||||||
|
PUTS(fd, "]\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue