From 96d019622c8664693f6966a219cfdfd9c81ac025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Wed, 12 Feb 2020 20:18:40 +0000 Subject: Revert "pp_(get|set)priority: remove ancient glibc C++ workaround" 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 | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'pp_sys.c') diff --git a/pp_sys.c b/pp_sys.c index 8cd953e2dc..9bae03dc08 100644 --- 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) -- cgit v1.2.1