|
25 | 25 | # define CAN_C_BACKTRACE |
26 | 26 | #endif |
27 | 27 |
|
| 28 | +#if defined(__STDC_NO_VLA__) && (__STDC_NO_VLA__ == 1) |
| 29 | +/* Use alloca() for VLAs. */ |
| 30 | +# define VLA(type, name, size) type *name = alloca(size) |
| 31 | +#elif !defined(__STDC_NO_VLA__) || (__STDC_NO_VLA__ == 0) |
| 32 | +/* Use actual C VLAs.*/ |
| 33 | +# define VLA(type, name, size) type name[size] |
| 34 | +#elif defined(CAN_C_BACKTRACE) |
| 35 | +/* VLAs are not possible. Disable C stack trace functions. */ |
| 36 | +# undef CAN_C_BACKTRACE |
| 37 | +#endif |
| 38 | + |
28 | 39 | #define OFF(x) offsetof(PyTracebackObject, x) |
29 | 40 | #define PUTS(fd, str) (void)_Py_write_noraise(fd, str, strlen(str)) |
30 | 41 |
|
@@ -1176,13 +1187,12 @@ _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp, |
1176 | 1187 | void |
1177 | 1188 | _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size) |
1178 | 1189 | { |
1179 | | - Dl_info info[size] = {}; |
1180 | | - int status[size] = {}; |
| 1190 | + VLA(Dl_info, info, size); |
| 1191 | + VLA(int, status, size); |
1181 | 1192 | /* Fill in the information we can get from dladdr() */ |
1182 | 1193 | for (Py_ssize_t i = 0; i < size; ++i) |
1183 | 1194 | { |
1184 | 1195 | struct link_map *map; |
1185 | | - assert(array[i] != NULL); |
1186 | 1196 | status[i] = dladdr1(array[i], &info[i], (void **)&map, RTLD_DL_LINKMAP); |
1187 | 1197 | if (status[i] != 0 |
1188 | 1198 | && info[i].dli_fname != NULL |
@@ -1240,7 +1250,7 @@ _Py_DumpStack(int fd) |
1240 | 1250 | { |
1241 | 1251 | #define BACKTRACE_SIZE 32 |
1242 | 1252 | PUTS(fd, "Current thread's C stack trace (most recent call first):\n"); |
1243 | | - void *callstack[BACKTRACE_SIZE] = {}; |
| 1253 | + VLA(void *, callstack, BACKTRACE_SIZE); |
1244 | 1254 | int frames = backtrace(callstack, BACKTRACE_SIZE); |
1245 | 1255 | if (frames == 0) { |
1246 | 1256 | // Some systems won't return anything for the stack trace |
|
0 commit comments