I'm sorry I missed out on this discussion but the patch below is problematic.
proc_pidinfo is a system function not available on 10.4. When compiling with the 10.5 SDK and deploying to 10.4, a run-time link error will result on 10.4 using the patch. Generally, it is preferable to use MAX_ALLOWED when using compile-time constants (say integers) that may be gracefully handled as a run-time error on the unsupported system, and to use MIN_REQUIRED when invoking functions not present on the older systems. It may seem like a problem that the newer system will not use the new SDK function, but the alternative is for the old system to have a broken binary. The ideal of course is run-time function detection with weak linking; Apple introduced this later in Objective-C and Swift with the @available macro, but AFAIK it's not an option in this context. Thanks for your attention to this. Evan > On Dec 11, 2021, at 11:55, Bruno Haible <br...@clisp.org> wrote: > > Hi Ryan, > > Thank you for the extensive explanations. The MAC_OS_X_VERSION_MAX_ALLOWED / > MAC_OS_X_VERSION_MIN_REQUIRED pair makes perfect sense. > >> In 10.5, Apple introduced a new header Availability.h which they want you to >> use instead of AvailabilityMacros.h > > Huh? The comments in Availability.h say "These macros are for use in OS header > files." So, as I understand it, Availability.h is to be used in OS header > files > and AvailabilityMacros.h in application code. > >> A MacPorts user running Mac OS X 10.4 proposed this fix which just hides the >> #include of <libproc.h> and its uses behind the 10.5 deployment target >> check, without attempting to provide any alternative when deploying for >> earlier versions nor attempting to allow libproc features to be used if >> running on 10.5 or greater when compiled for 10.4. I commented that I did >> not know whether this fix was correct and asked them to bring it up on this >> list, but since I don't think they have, I'm bringing it up for them. >> >> https://github.com/macports/macports-ports/pull/13226/files#diff-8a2ad00cea356fb07a25e323fde8a18232252de4f6421d5e73347aa845d56045 > > That's the major problem of this patch, indeed: "nor attempting to allow > libproc features to be used if running on 10.5 or greater when compiled > for 10.4". > > I'm committing the patch below, which implements optimal behaviour for > any pair of MAC_OS_X_VERSION_MAX_ALLOWED / MAC_OS_X_VERSION_MIN_REQUIRED. > >> (They used __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ instead of >> MAC_OS_X_VERSION_MIN_REQUIRED; the distinction is not clear to me. It might >> be that __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ is defined even if >> AvailabilityMacros.h is not included.) > > I'll prefer to use the macros without __ prefix; it looks safer to use > AvailabilityMacros.h than to bypass it. > >> We may also need to think about what happens when compiling for a non-macOS >> Apple OS (iOS, iPadOS, tvOS, watchOS). I don't think *MAC_OS_X* defines will >> be defined on those other OSes. In MacPorts we don't try to solve the >> problem since we only compile for macOS. > > In Gnulib as well, no one has attempted ports to iOS and its derivatives. > > > 2021-12-11 Bruno Haible <br...@clisp.org> > > get_ppid_of, get_progname_of: Fix compilation error on Mac OS X < 10.5. > Reported by Ryan Schmidt <gnu...@ryandesign.com> in > <https://lists.gnu.org/archive/html/bug-gnulib/2021-12/msg00011.html>. > * lib/get_ppid_of.c: Include AvailabilityMacros.h > (get_ppid_of): Use MAC_OS_X_VERSION_MAX_ALLOWED and > MAC_OS_X_VERSION_MIN_REQUIRED. > * lib/get_progname_of: Include AvailabilityMacros.h > (get_progname_of): Use MAC_OS_X_VERSION_MAX_ALLOWED and > MAC_OS_X_VERSION_MIN_REQUIRED. > > diff --git a/lib/get_ppid_of.c b/lib/get_ppid_of.c > index f153b7539..dd4e38129 100644 > --- a/lib/get_ppid_of.c > +++ b/lib/get_ppid_of.c > @@ -33,7 +33,13 @@ > #endif > > #if defined __APPLE__ && defined __MACH__ /* Mac OS X */ > -# include <libproc.h> > +/* Get MAC_OS_X_VERSION_MIN_REQUIRED, MAC_OS_X_VERSION_MAX_ALLOWED. > + The version at runtime satisfies > + MAC_OS_X_VERSION_MIN_REQUIRED <= version <= MAC_OS_X_VERSION_MAX_ALLOWED. > */ > +# include <AvailabilityMacros.h> > +# if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 > +# include <libproc.h> > +# endif > #endif > > #if defined _AIX /* AIX */ > @@ -226,14 +232,19 @@ get_ppid_of (pid_t pid) > #endif > > #if defined __APPLE__ && defined __MACH__ /* Mac OS X */ > +# if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 > > -# if defined PROC_PIDT_SHORTBSDINFO > + /* Mac OS X >= 10.7 has PROC_PIDT_SHORTBSDINFO. */ > +# if defined PROC_PIDT_SHORTBSDINFO > struct proc_bsdshortinfo info; > > if (proc_pidinfo (pid, PROC_PIDT_SHORTBSDINFO, 0, &info, sizeof (info)) > == sizeof (info)) > return info.pbsi_ppid; > -# else > +# endif > + > +# if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 > + /* For older versions, use PROC_PIDTBSDINFO instead. */ > /* Note: The second part of 'struct proc_bsdinfo' differs in size between > 32-bit and 64-bit environments, and the kernel of Mac OS X 10.5 knows > only about the 32-bit 'struct proc_bsdinfo'. Fortunately all the info > @@ -242,8 +253,9 @@ get_ppid_of (pid_t pid) > > if (proc_pidinfo (pid, PROC_PIDTBSDINFO, 0, &info, 128) == 128) > return info.pbi_ppid; > -# endif > +# endif > > +# endif > #endif > > #if defined _AIX /* AIX */ > diff --git a/lib/get_progname_of.c b/lib/get_progname_of.c > index 46144e742..bdda3c60d 100644 > --- a/lib/get_progname_of.c > +++ b/lib/get_progname_of.c > @@ -41,7 +41,13 @@ > #endif > > #if defined __APPLE__ && defined __MACH__ /* Mac OS X */ > -# include <libproc.h> > +/* Get MAC_OS_X_VERSION_MIN_REQUIRED, MAC_OS_X_VERSION_MAX_ALLOWED. > + The version at runtime satisfies > + MAC_OS_X_VERSION_MIN_REQUIRED <= version <= MAC_OS_X_VERSION_MAX_ALLOWED. > */ > +# include <AvailabilityMacros.h> > +# if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 > +# include <libproc.h> > +# endif > #endif > > #if defined _AIX /* AIX */ > @@ -266,14 +272,19 @@ get_progname_of (pid_t pid) > #endif > > #if defined __APPLE__ && defined __MACH__ /* Mac OS X */ > +# if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 > > -# if defined PROC_PIDT_SHORTBSDINFO > + /* Mac OS X >= 10.7 has PROC_PIDT_SHORTBSDINFO. */ > +# if defined PROC_PIDT_SHORTBSDINFO > struct proc_bsdshortinfo info; > > if (proc_pidinfo (pid, PROC_PIDT_SHORTBSDINFO, 0, &info, sizeof (info)) > == sizeof (info)) > return strdup (info.pbsi_comm); > -# else > +# endif > + > +# if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 > + /* For older versions, use PROC_PIDTBSDINFO instead. */ > /* Note: The second part of 'struct proc_bsdinfo' differs in size between > 32-bit and 64-bit environments, and the kernel of Mac OS X 10.5 knows > only about the 32-bit 'struct proc_bsdinfo'. Fortunately all the info > @@ -282,8 +293,9 @@ get_progname_of (pid_t pid) > > if (proc_pidinfo (pid, PROC_PIDTBSDINFO, 0, &info, 128) == 128) > return strdup (info.pbi_comm); > -# endif > +# endif > > +# endif > #endif > > #if defined _AIX /* AIX */ > > > > >