-
Notifications
You must be signed in to change notification settings - Fork 92
Add accessors for st_blocks and st_blksize #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fyi, I need to think about the conditional API part; we're trying hard to avoid conditional exports going forward with |
2403c59
to
b2a4c24
Compare
How about this then? |
@DanielG better... otoh, if you know it's conditional, you can also make it into a |
System/Posix/Files/Common.hsc
Outdated
unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_blksize) | ||
#else | ||
{-# WARNING fileBlockSize "fileBlockSize: not available on this platform" #-} | ||
fileBlockSize = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, this CPP branch is missing its typesig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fine now.
@hvr what's the status on this? Any reason this never got merged? |
it's not. |
Indeed both st_blocks and st_blksize are XSI options. Thanks @llelf |
f2f5c65
to
8142f27
Compare
This is blocked until a) either we drop support of older GHCs, b) or agree our stance on conditional APIs, c) fix backward compatibility in other way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks largely fine, but unless I'm missing something about who sees the #WARNING
s about missing optional structure members, those warnings should go.
@@ -250,6 +251,10 @@ specialDeviceID :: FileStatus -> DeviceID | |||
-- | Size of the file in bytes. If this file is a symbolic link the size is | |||
-- the length of the pathname it contains. | |||
fileSize :: FileStatus -> FileOffset | |||
-- | Number of block blocks allocated for this file, in units of 512-byte. | |||
fileBlocks :: FileStatus -> Maybe CBlkCnt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The types CBlkCnt
and CBlkSize
below don't appear to be defined with GHC <= 8.0
breaking CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed these were introduced conditionally in GHC 8.2 and this PR can probably use the corresponding macros to detect their presence. The new feature can then only be offered if the stat
structure has the requisite fields (already done) AND the types are available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right. Not sure how we missed that before. I'll add some more GLASGOW_HASKELL version checking then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This CPP guard is not sufficient. GHC 8.2 conditionally defines these types. So you need to:
#include "HsBaseConfig.h"
and use the same feature macros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which means that the types might in fact be unsupported on some platforms even with GHC >= 8.2. However, when that's the case we could define them to be new types for Void
in that case, and then the functions can return Maybe X -- X ~ Void
, which can only be instantiated as Nothing
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that, but that doesn't work because HsBaseConfig.h
defines a bunch of conflicting defines like PACKAGE_NAME etc. which we also have in HsUnix.h
.
I'm pretty sure that if the st_
fields exist the corresponding types must also be defined in the system headers so there shouldn't be any need to check for the types and struct fields separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then the functions can return Maybe X -- X ~ Void
I thought about that too, but then the API is conditional depending on platform factors again :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure that if the st_ fields exist the corresponding types must also be defined
Looks like these didn't always exist, at least according to https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html
Issue 5
[...]
The type of st_blksize is changed from long to blksize_t; the type of st_blocks is changed from long to blkcnt_t.
I am not sure why "older GHCs" come into play here. Sure we need at least GHC 8.2 for the types, but since in any case the member fields of "stat" are not universally present, and the PR now returns In other words, given GHC >= 8.2, and a platform that has these fields in |
11b3a8a
to
ef0cc33
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can (and should) also return Nothing with older GHCs
No it can't because we can't mention the new types since they don't exist on old GHCs yet.
I think there is simply no (good) way to avoid having a conditional API depending on the GHC version. We can however still offer the same API regardless of the availability of the two struct fields. I think that's acceptable.
@@ -250,6 +251,10 @@ specialDeviceID :: FileStatus -> DeviceID | |||
-- | Size of the file in bytes. If this file is a symbolic link the size is | |||
-- the length of the pathname it contains. | |||
fileSize :: FileStatus -> FileOffset | |||
-- | Number of block blocks allocated for this file, in units of 512-byte. | |||
fileBlocks :: FileStatus -> Maybe CBlkCnt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right. Not sure how we missed that before. I'll add some more GLASGOW_HASKELL version checking then.
ef0cc33
to
2e59464
Compare
Changes:
|
2e59464
to
d7ea7ed
Compare
Changes:
|
Any interest in rebasing this on master, which now has a more comprehensive CI? |
Please rebase, now that #175 is merged. |
d7ea7ed
to
d60d7bc
Compare
Sure, thanks for the ping :) |
d60d7bc
to
edd6b33
Compare
Changes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ready overall, just curious what others make of my strictness question?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With FreeBSD passing CI after initially timing out in some sort of odd virtualbox error, this appears to be ready. I'm satisfied with the Just/unsafePerformIO
order rationale by @Bodigrim, so this is ready to go. So I'm approving and merging this PR.
🎉 This has to be my longest running PR by far, hehe, only took a measly 4.25 years to get merged, thanks everyone :D |
Congratulations! Now that we've sorted out the CI, and dropped support for old GHC versions that can make it difficult to adopt new features, it should be possible to address the backlog without similar delays. |
AFAIU st_blocks is mandatory in POSIX but st_blksize is part of the XSI option (whatever that means) so it's definition is protected by a feature test macro.
This depends on https://ghc.haskell.org/trac/ghc/ticket/12795.