Skip to content

Commit 6541fe4

Browse files
authored
Ignore _Py_write_noraise() result: cast to (void) (#108291)
Code using _Py_write_noraise() usually cannot report. Ignore errors is the least surprising behavior for users.
1 parent a541e01 commit 6541fe4

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

Modules/faulthandler.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/* Allocate at maximum 100 MiB of the stack to raise the stack overflow */
2727
#define STACK_OVERFLOW_MAX_SIZE (100 * 1024 * 1024)
2828

29-
#define PUTS(fd, str) _Py_write_noraise(fd, str, strlen(str))
29+
#define PUTS(fd, str) (void)_Py_write_noraise(fd, str, strlen(str))
3030

3131

3232
// clang uses __attribute__((no_sanitize("undefined")))
@@ -576,7 +576,7 @@ faulthandler_thread(void *unused)
576576
/* Timeout => dump traceback */
577577
assert(st == PY_LOCK_FAILURE);
578578

579-
_Py_write_noraise(thread.fd, thread.header, (int)thread.header_len);
579+
(void)_Py_write_noraise(thread.fd, thread.header, (int)thread.header_len);
580580

581581
errmsg = _Py_DumpTracebackThreads(thread.fd, thread.interp, NULL);
582582
ok = (errmsg == NULL);

Python/pylifecycle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
# undef BYTE
5858
#endif
5959

60-
#define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str))
60+
#define PUTS(fd, str) (void)_Py_write_noraise(fd, str, (int)strlen(str))
6161

6262

6363
#ifdef __cplusplus

Python/traceback.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#define OFF(x) offsetof(PyTracebackObject, x)
2727

28-
#define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str))
28+
#define PUTS(fd, str) (void)_Py_write_noraise(fd, str, (int)strlen(str))
2929
#define MAX_STRING_LENGTH 500
3030
#define MAX_FRAME_DEPTH 100
3131
#define MAX_NTHREADS 100
@@ -1047,7 +1047,7 @@ _Py_DumpDecimal(int fd, size_t value)
10471047
value /= 10;
10481048
} while (value);
10491049

1050-
_Py_write_noraise(fd, ptr, end - ptr);
1050+
(void)_Py_write_noraise(fd, ptr, end - ptr);
10511051
}
10521052

10531053
/* Format an integer as hexadecimal with width digits into fd file descriptor.
@@ -1072,7 +1072,7 @@ _Py_DumpHexadecimal(int fd, uintptr_t value, Py_ssize_t width)
10721072
value >>= 4;
10731073
} while ((end - ptr) < width || value);
10741074

1075-
_Py_write_noraise(fd, ptr, end - ptr);
1075+
(void)_Py_write_noraise(fd, ptr, end - ptr);
10761076
}
10771077

10781078
void
@@ -1125,7 +1125,7 @@ _Py_DumpASCII(int fd, PyObject *text)
11251125
}
11261126
if (!need_escape) {
11271127
// The string can be written with a single write() syscall
1128-
_Py_write_noraise(fd, str, size);
1128+
(void)_Py_write_noraise(fd, str, size);
11291129
goto done;
11301130
}
11311131
}
@@ -1135,7 +1135,7 @@ _Py_DumpASCII(int fd, PyObject *text)
11351135
if (' ' <= ch && ch <= 126) {
11361136
/* printable ASCII character */
11371137
char c = (char)ch;
1138-
_Py_write_noraise(fd, &c, 1);
1138+
(void)_Py_write_noraise(fd, &c, 1);
11391139
}
11401140
else if (ch <= 0xff) {
11411141
PUTS(fd, "\\x");

Python/tracemalloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ tracemalloc_get_traceback(unsigned int domain, uintptr_t ptr)
12471247
}
12481248

12491249

1250-
#define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str))
1250+
#define PUTS(fd, str) (void)_Py_write_noraise(fd, str, (int)strlen(str))
12511251

12521252
static void
12531253
_PyMem_DumpFrame(int fd, frame_t * frame)

0 commit comments

Comments
 (0)