18
18
#ifdef HAVE_UNISTD_H
19
19
# include <unistd.h> // lseek()
20
20
#endif
21
- #if defined(HAVE_EXECINFO_H ) && defined(HAVE_DLFCN_H ) && defined(HAVE_LINK_H )
21
+
22
+ #if (defined(HAVE_EXECINFO_H ) && defined(HAVE_DLFCN_H ) && defined(HAVE_LINK_H ))
23
+ #define _PY_HAS_BACKTRACE_HEADERS 1
24
+ #endif
25
+
26
+ #if (defined(__APPLE__ ) && defined(HAVE_EXECINFO_H ) && defined(HAVE_DLFCN_H ))
27
+ #define _PY_HAS_BACKTRACE_HEADERS 1
28
+ #endif
29
+
30
+ #ifdef _PY_HAS_BACKTRACE_HEADERS
22
31
# include <execinfo.h> // backtrace(), backtrace_symbols()
23
32
# include <dlfcn.h> // dladdr1()
24
- # include <link.h> // struct DL_info
25
- # if defined(HAVE_BACKTRACE ) && defined(HAVE_BACKTRACE_SYMBOLS ) && defined(HAVE_DLADDR1 )
33
+ #ifdef HAVE_LINK_H
34
+ # include <link.h> // struct DL_info
35
+ #endif
36
+ #if defined(HAVE_BACKTRACE ) && defined(HAVE_BACKTRACE_SYMBOLS ) && (defined(__APPLE__ ) || defined(HAVE_DLADDR1 ))
26
37
# define CAN_C_BACKTRACE
27
38
# endif
28
39
#endif
@@ -1193,6 +1204,9 @@ _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size)
1193
1204
VLA (int , status , size );
1194
1205
/* Fill in the information we can get from dladdr() */
1195
1206
for (Py_ssize_t i = 0 ; i < size ; ++ i ) {
1207
+ #ifdef __APPLE__
1208
+ status [i ] = dladdr (array [i ], & info [i ]);
1209
+ #else
1196
1210
struct link_map * map ;
1197
1211
status [i ] = dladdr1 (array [i ], & info [i ], (void * * )& map , RTLD_DL_LINKMAP );
1198
1212
if (status [i ] != 0
@@ -1204,6 +1218,7 @@ _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size)
1204
1218
something we want to subtract out */
1205
1219
info [i ].dli_fbase = (void * ) map -> l_addr ;
1206
1220
}
1221
+ #endif
1207
1222
}
1208
1223
for (Py_ssize_t i = 0 ; i < size ; ++ i ) {
1209
1224
if (status [i ] == 0
0 commit comments