From 8350b48cfa7d344d9e2dc9748c26607c1b89d7df Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 26 Sep 2024 10:32:30 +0900 Subject: [PATCH] Import patches for old macOS from MacPorts --- .gdbinit | 5 +++-- file.c | 14 +++++++++++++- io.c | 10 ++++++++++ signal.c | 3 ++- vm_dump.c | 6 ++++-- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/.gdbinit b/.gdbinit index 1b5b6cb562..911624d8c9 100644 --- a/.gdbinit +++ b/.gdbinit @@ -1,5 +1,3 @@ -set startup-with-shell off - define hook-run set $color_type = 0 set $color_highlite = 0 @@ -1345,3 +1343,6 @@ define print_flags end source -s misc/gdb.py + +# Moved from beginning, since it fails on older gdbs +set startup-with-shell off diff --git a/file.c b/file.c index 9b89f36fbe..64fc470c1c 100644 --- a/file.c +++ b/file.c @@ -4533,6 +4533,11 @@ rb_check_realpath_emulate_rescue(VALUE arg, VALUE exc) { return Qnil; } +#elif !defined(NEEDS_REALPATH_BUFFER) && defined(__APPLE__) && \ + (!defined(MAC_OS_X_VERSION_10_6) || (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)) +/* realpath() on OSX < 10.6 doesn't implement automatic allocation */ +# include +# define NEEDS_REALPATH_BUFFER 1 #endif /* HAVE_REALPATH */ static VALUE @@ -4542,6 +4547,11 @@ rb_check_realpath_internal(VALUE basedir, VALUE path, rb_encoding *origenc, enum VALUE unresolved_path; char *resolved_ptr = NULL; VALUE resolved; +# if defined(NEEDS_REALPATH_BUFFER) && NEEDS_REALPATH_BUFFER + char resolved_buffer[PATH_MAX]; +# else + char *const resolved_buffer = NULL; +# endif if (mode == RB_REALPATH_DIR) { return rb_check_realpath_emulate(basedir, path, origenc, mode); @@ -4553,7 +4563,7 @@ rb_check_realpath_internal(VALUE basedir, VALUE path, rb_encoding *origenc, enum } if (origenc) unresolved_path = TO_OSPATH(unresolved_path); - if ((resolved_ptr = realpath(RSTRING_PTR(unresolved_path), NULL)) == NULL) { + if ((resolved_ptr = realpath(RSTRING_PTR(unresolved_path), resolved_buffer)) == NULL) { /* glibc realpath(3) does not allow /path/to/file.rb/../other_file.rb, returning ENOTDIR in that case. glibc realpath(3) can also return ENOENT for paths that exist, @@ -4570,7 +4580,9 @@ rb_check_realpath_internal(VALUE basedir, VALUE path, rb_encoding *origenc, enum rb_sys_fail_path(unresolved_path); } resolved = ospath_new(resolved_ptr, strlen(resolved_ptr), rb_filesystem_encoding()); +# if defined(NEEDS_REALPATH_BUFFER) && NEEDS_REALPATH_BUFFER free(resolved_ptr); +# endif # if !defined(__LINUX__) && !defined(__APPLE__) /* As `resolved` is a String in the filesystem encoding, no diff --git a/io.c b/io.c index 590e8d11d7..3c99043916 100644 --- a/io.c +++ b/io.c @@ -104,6 +104,16 @@ #ifdef HAVE_COPYFILE_H # include + +# ifndef COPYFILE_STATE_COPIED +/* + * Some OSes (e.g., OSX < 10.6) implement fcopyfile() but not + * COPYFILE_STATE_COPIED. Since the only use of the former here + * requires the latter, we disable the former when the latter is undefined. + */ +# undef HAVE_FCOPYFILE +# endif + #endif #include "ruby/internal/stdbool.h" diff --git a/signal.c b/signal.c index 1c8f8c112b..2f7796c127 100644 --- a/signal.c +++ b/signal.c @@ -803,7 +803,8 @@ check_stack_overflow(int sig, const uintptr_t addr, const ucontext_t *ctx) const greg_t bp = mctx->gregs[REG_EBP]; # endif # elif defined __APPLE__ -# if __DARWIN_UNIX03 +# include +# if defined(MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 # define MCTX_SS_REG(reg) __ss.__##reg # else # define MCTX_SS_REG(reg) ss.reg diff --git a/vm_dump.c b/vm_dump.c index 444be4a4f3..dcf0ec4c6e 100644 --- a/vm_dump.c +++ b/vm_dump.c @@ -490,7 +490,8 @@ rb_vmdebug_thread_dump_state(FILE *errout, VALUE self) } #if defined __APPLE__ -# if __DARWIN_UNIX03 +# include +# if defined(MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 # define MCTX_SS_REG(reg) __ss.__##reg # else # define MCTX_SS_REG(reg) ss.reg @@ -502,7 +503,8 @@ rb_vmdebug_thread_dump_state(FILE *errout, VALUE self) # ifdef HAVE_LIBUNWIND # undef backtrace # define backtrace unw_backtrace -# elif defined(__APPLE__) && defined(HAVE_LIBUNWIND_H) +# elif defined(__APPLE__) && defined(HAVE_LIBUNWIND_H) \ + && defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 # define UNW_LOCAL_ONLY # include # include