bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gnulib fails for build on Mac OS X 10.4: get_ppid_of.c:36:22: error:


From: Bruno Haible
Subject: Re: gnulib fails for build on Mac OS X 10.4: get_ppid_of.c:36:22: error: libproc.h: No such file or directory
Date: Sat, 11 Dec 2021 17:55:51 +0100

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  <bruno@clisp.org>

        get_ppid_of, get_progname_of: Fix compilation error on Mac OS X < 10.5.
        Reported by Ryan Schmidt <gnulib@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 */






reply via email to

[Prev in Thread] Current Thread [Next in Thread]