Re: [commit: packages/unix] master: Fix assumption that RLIM_INFINITY is a simple number (b092e35)

Hello Bryan, Thanks for catching this! (see also comment below) [...]
commit b092e35f4c99bfab12247e93c7fa478de638276a Author: Bryan O'Sullivan
Date: Sat Oct 12 16:45:50 2013 -0700 Fix assumption that RLIM_INFINITY is a simple number
On MacOS X, it is defined as "(((__uint64_t)1 << 63) - 1)", and hence cannot be used inside C preprocessor logic.
---------------------------------------------------------------
b092e35f4c99bfab12247e93c7fa478de638276a System/Posix/Resource.hsc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/System/Posix/Resource.hsc b/System/Posix/Resource.hsc index a0d0d35..58cff6f 100644 --- a/System/Posix/Resource.hsc +++ b/System/Posix/Resource.hsc @@ -95,13 +95,16 @@ packResource ResourceTotalMemory = (#const RLIMIT_AS)
unpackRLimit :: CRLim -> ResourceLimit unpackRLimit (#const RLIM_INFINITY) = ResourceLimitInfinity
[...] I wonder though, how could that even have compiled in the past on OSX if the expanded RLIM_INFINITY macro #define in the LHS pattern wouldn't result in a simple number? Cheers, hvr

On Sun, Oct 13, 2013 at 12:20 AM, Herbert Valerio Riedel
unpackRLimit :: CRLim -> ResourceLimit unpackRLimit (#const RLIM_INFINITY) = ResourceLimitInfinity
[...]
I wonder though, how could that even have compiled in the past on OSX if the expanded RLIM_INFINITY macro #define in the LHS pattern wouldn't result in a simple number?
You'll want to take a look at what hsc2hs actually does here to really understand :-) In short, a constant C-level expression is fine if used in a #const construct, regardless of it containing embedded casts and whatnot.

On 2013-10-14 at 06:07:01 +0200, Bryan O'Sullivan wrote: [...]
You'll want to take a look at what hsc2hs actually does here to really understand :-)
In short, a constant C-level expression is fine if used in a #const construct, regardless of it containing embedded casts and whatnot.
thx, now I see! :-) Otoh, does that mean one could have rewritten that to something like ##if defined(RLIM_SAVED_MAX) && (#{const RLIM_SAVED_MAX} != #{const RLIM_INFINITY}) unpackRLimit (#const RLIM_SAVED_MAX) = ResourceLimitUnknown ##endif instead and exploit the fact that CPP can be run a second time when compiling the resulting .hs file, which would then take care of the #ifdef with the '#const' terms already evaluated? Cheers, hvr
participants (2)
-
Bryan O'Sullivan
-
Herbert Valerio Riedel