GitHub CopilotWrite better code with AI | MCP RegistryIntegrate external tools | ActionsAutomate any workflow | CodespacesInstant dev environments | IssuesPlan and track work | Code ReviewManage code changes | Code QualityEnforce quality at merge | Why GitHub | Marketplace | View all features | Enterprises | Small and medium teams | Startups | View all use cases | View all industries | View all solutions | AI | Software Development | DevOps | Security | View all topics | Customer stories | Events & webinars | Ebooks & reports | Business insights | Trust center | Partners | View all resources
Original file line numberDiff line numberDiff line change@@ -18,11 +18,24 @@
1818#ifdefHAVE_UNISTD_H
1919# include<unistd.h>// lseek()
2020#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
2231# include<execinfo.h>// backtrace(), backtrace_symbols()
2332# include<dlfcn.h>// dladdr1()
24-# include<link.h>// struct DL_info
25-# if defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS) && defined(HAVE_DLADDR1)
33+#ifdefHAVE_LINK_H
34+# include<link.h>// struct DL_info
35+#endif
36+# if defined(__APPLE__) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS) && defined(HAVE_DLADDR)
37+# defineCAN_C_BACKTRACE
38+# elif defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS) && defined(HAVE_DLADDR1)
2639# defineCAN_C_BACKTRACE
2740# endif
2841#endif
@@ -1193,6 +1206,9 @@ _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size)
11931206VLA(int, status, size);
11941207/* Fill in the information we can get from dladdr() */
11951208for (Py_ssize_ti=0; i<size; ++i) {
1209+#ifdef__APPLE__
1210+status[i] =dladdr(array[i], &info[i]);
1211+#else
11961212structlink_map*map;
11971213status[i] =dladdr1(array[i], &info[i], (void**)&map, RTLD_DL_LINKMAP);
11981214if (status[i] !=0
@@ -1204,6 +1220,7 @@ _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size)
12041220 something we want to subtract out */
12051221info[i].dli_fbase= (void*) map->l_addr;
12061222 }
1223+#endif
12071224 }
12081225for (Py_ssize_ti=0; i<size; ++i) {
12091226if (status[i] ==0