Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit402dba2

Browse files
authored
gh-127604: Replace dprintf() with _Py_write_noraise() (#132854)
1 parent99b1377 commit402dba2

File tree

1 file changed

+52
-16
lines changed

1 file changed

+52
-16
lines changed

‎Python/traceback.c

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -842,11 +842,11 @@ _Py_DumpDecimal(int fd, size_t value)
842842

843843
/* Format an integer as hexadecimal with width digits into fd file descriptor.
844844
The function is signal safe. */
845-
void
846-
_Py_DumpHexadecimal(intfd,uintptr_tvalue,Py_ssize_twidth)
845+
staticvoid
846+
dump_hexadecimal(intfd,uintptr_tvalue,Py_ssize_twidth,intstrip_zeros)
847847
{
848848
charbuffer[sizeof(uintptr_t)*2+1],*ptr,*end;
849-
constPy_ssize_tsize=Py_ARRAY_LENGTH(buffer)-1;
849+
Py_ssize_tsize=Py_ARRAY_LENGTH(buffer)-1;
850850

851851
if (width>size)
852852
width=size;
@@ -862,7 +862,35 @@ _Py_DumpHexadecimal(int fd, uintptr_t value, Py_ssize_t width)
862862
value >>=4;
863863
}while ((end-ptr)<width||value);
864864

865-
(void)_Py_write_noraise(fd,ptr,end-ptr);
865+
size=end-ptr;
866+
if (strip_zeros) {
867+
while (*ptr=='0'&&size >=2) {
868+
ptr++;
869+
size--;
870+
}
871+
}
872+
873+
(void)_Py_write_noraise(fd,ptr,size);
874+
}
875+
876+
void
877+
_Py_DumpHexadecimal(intfd,uintptr_tvalue,Py_ssize_twidth)
878+
{
879+
dump_hexadecimal(fd,value,width,0);
880+
}
881+
882+
staticvoid
883+
dump_pointer(intfd,void*ptr)
884+
{
885+
PUTS(fd,"0x");
886+
dump_hexadecimal(fd, (uintptr_t)ptr,sizeof(void*),1);
887+
}
888+
889+
staticvoid
890+
dump_char(intfd,charch)
891+
{
892+
charbuf[1]= {ch};
893+
(void)_Py_write_noraise(fd,buf,1);
866894
}
867895

868896
void
@@ -924,8 +952,7 @@ _Py_DumpASCII(int fd, PyObject *text)
924952
ch=PyUnicode_READ(kind,data,i);
925953
if (' ' <=ch&&ch <=126) {
926954
/* printable ASCII character */
927-
charc= (char)ch;
928-
(void)_Py_write_noraise(fd,&c,1);
955+
dump_char(fd, (char)ch);
929956
}
930957
elseif (ch <=0xff) {
931958
PUTS(fd,"\\x");
@@ -1227,7 +1254,9 @@ _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size)
12271254
||info[i].dli_fname==NULL
12281255
||info[i].dli_fname[0]=='\0'
12291256
) {
1230-
dprintf(fd," Binary file '<unknown>' [%p]\n",array[i]);
1257+
PUTS(fd," Binary file '<unknown>' [");
1258+
dump_pointer(fd,array[i]);
1259+
PUTS(fd,"]\n");
12311260
continue;
12321261
}
12331262

@@ -1237,11 +1266,12 @@ _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size)
12371266
info[i].dli_saddr=info[i].dli_fbase;
12381267
}
12391268

1240-
if (info[i].dli_sname==NULL
1241-
&&info[i].dli_saddr==0) {
1242-
dprintf(fd," Binary file \"%s\" [%p]\n",
1243-
info[i].dli_fname,
1244-
array[i]);
1269+
if (info[i].dli_sname==NULL&&info[i].dli_saddr==0) {
1270+
PUTS(fd," Binary file \"");
1271+
PUTS(fd,info[i].dli_fname);
1272+
PUTS(fd,"\" [");
1273+
dump_pointer(fd,array[i]);
1274+
PUTS(fd,"]\n");
12451275
}
12461276
else {
12471277
charsign;
@@ -1255,10 +1285,16 @@ _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size)
12551285
offset=info[i].dli_saddr-array[i];
12561286
}
12571287
constchar*symbol_name=info[i].dli_sname!=NULL ?info[i].dli_sname :"";
1258-
dprintf(fd," Binary file \"%s\", at %s%c%#tx [%p]\n",
1259-
info[i].dli_fname,
1260-
symbol_name,
1261-
sign,offset,array[i]);
1288+
PUTS(fd," Binary file \"");
1289+
PUTS(fd,info[i].dli_fname);
1290+
PUTS(fd,"\", at ");
1291+
PUTS(fd,symbol_name);
1292+
dump_char(fd,sign);
1293+
PUTS(fd,"0x");
1294+
dump_hexadecimal(fd,offset,sizeof(offset),1);
1295+
PUTS(fd," [");
1296+
dump_pointer(fd,array[i]);
1297+
PUTS(fd,"]\n");
12621298
}
12631299
}
12641300
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp