This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Revert "pp_(get|set)priority: remove ancient glibc C++ workaround"
authorDagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Wed, 12 Feb 2020 20:18:40 +0000 (20:18 +0000)
committerDagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Wed, 12 Feb 2020 20:26:11 +0000 (20:26 +0000)
It turns out that even though the headers correctly define the argument
as `int` under C++, -Wc++-compat doesn't know this.

Add a comment to stop others from falling into the same trap I did.

This reverts commit 34d254cefc451e5ab438acf22a51d7b557c05a0e.

pp_sys.c

index 8cd953e..9bae03d 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -4619,13 +4619,24 @@ PP(pp_setpgrp)
 #endif
 }
 
+/*
+ * The glibc headers typedef __priority_which_t to an enum under C, but
+ * under C++, it keeps it as int. -Wc++-compat doesn't know this, so we
+ * need to explicitly cast it to shut up the warning.
+ */
+#if defined(__GLIBC__) && ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) || (__GLIBC__ > 2))
+#  define PRIORITY_WHICH_T(which) (__priority_which_t)which
+#else
+#  define PRIORITY_WHICH_T(which) which
+#endif
+
 PP(pp_getpriority)
 {
 #ifdef HAS_GETPRIORITY
     dSP; dTARGET;
     const int who = POPi;
     const int which = TOPi;
-    SETi( getpriority(which, who) );
+    SETi( getpriority(PRIORITY_WHICH_T(which), who) );
     RETURN;
 #else
     DIE(aTHX_ PL_no_func, "getpriority");
@@ -4640,13 +4651,15 @@ PP(pp_setpriority)
     const int who = POPi;
     const int which = TOPi;
     TAINT_PROPER("setpriority");
-    SETi( setpriority(which, who, niceval) >= 0 );
+    SETi( setpriority(PRIORITY_WHICH_T(which), who, niceval) >= 0 );
     RETURN;
 #else
     DIE(aTHX_ PL_no_func, "setpriority");
 #endif
 }
 
+#undef PRIORITY_WHICH_T
+
 /* Time calls. */
 
 PP(pp_time)