-
Notifications
You must be signed in to change notification settings - Fork 92
Use Base.o_*
instead of raw {#const O_*}
#339
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,25 +223,31 @@ openat_ fdMay str how (OpenFileFlags appendFlag exclusiveFlag nocttyFlag | |
c_fd = maybe (#const AT_FDCWD) (\ (Fd fd) -> fd) fdMay | ||
all_flags = creat .|. flags .|. open_mode | ||
|
||
-- We have to use Base.o_* instead of raw #const O_* | ||
-- due of the fact target platforms at stage1 could have | ||
-- them overridden. | ||
-- For example GHC JS Backend provides its own constants | ||
-- which should be used at the target of cross compilation | ||
-- into Node.JS environment. | ||
flags = | ||
(if appendFlag then (#const O_APPEND) else 0) .|. | ||
(if exclusiveFlag then (#const O_EXCL) else 0) .|. | ||
(if nocttyFlag then (#const O_NOCTTY) else 0) .|. | ||
(if nonBlockFlag then (#const O_NONBLOCK) else 0) .|. | ||
(if truncateFlag then (#const O_TRUNC) else 0) .|. | ||
(if appendFlag then (Base.o_APPEND) else 0) .|. | ||
(if exclusiveFlag then (Base.o_EXCL) else 0) .|. | ||
(if nocttyFlag then (Base.o_NOCTTY) else 0) .|. | ||
(if nonBlockFlag then (Base.o_NONBLOCK) else 0) .|. | ||
(if truncateFlag then (Base.o_TRUNC) else 0) .|. | ||
(if nofollowFlag then (#const O_NOFOLLOW) else 0) .|. | ||
(if cloexecFlag then (#const O_CLOEXEC) else 0) .|. | ||
(if directoryFlag then (#const O_DIRECTORY) else 0) .|. | ||
(if syncFlag then (#const O_SYNC) else 0) | ||
|
||
(creat, mode_w) = case creatFlag of | ||
Nothing -> (0,0) | ||
Just x -> ((#const O_CREAT), x) | ||
Just x -> ((Base.o_CREAT), x) | ||
|
||
open_mode = case how of | ||
ReadOnly -> (#const O_RDONLY) | ||
WriteOnly -> (#const O_WRONLY) | ||
ReadWrite -> (#const O_RDWR) | ||
ReadOnly -> (Base.o_RDONLY) | ||
WriteOnly -> (Base.o_WRONLY) | ||
ReadWrite -> (Base.o_RDWR) | ||
|
||
foreign import capi unsafe "HsUnix.h openat" | ||
c_openat :: CInt -> CString -> CInt -> CMode -> IO CInt | ||
|
@@ -315,8 +321,8 @@ data FdOption = AppendOnWrite -- ^O_APPEND | |
|
||
fdOption2Int :: FdOption -> CInt | ||
fdOption2Int CloseOnExec = (#const FD_CLOEXEC) | ||
fdOption2Int AppendOnWrite = (#const O_APPEND) | ||
fdOption2Int NonBlockingRead = (#const O_NONBLOCK) | ||
fdOption2Int AppendOnWrite = (Base.o_APPEND) | ||
fdOption2Int NonBlockingRead = (Base.o_NONBLOCK) | ||
fdOption2Int SynchronousWrites = (#const O_SYNC) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason for the inconsistency, beyond GHC exporting incomplete set? Could you please raise an issue on GHC side to provide a complete set in future? (We can leave There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
-- | May throw an exception if this is an invalid descriptor. | ||
|
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.
Could you reference a GHC source file which contain overriding logic for JS backend? It would help future readers.
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.
Yes, we have a test which can be referenced for such overridings:
So, files
testsuite/tests/interface-stability/base-exports.stdout*
can be useful to determine which targets have foreigns (exports? 🤔 ).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.
Actual overrides are collected at
./libraries/ghc-internal/src/GHC/Internal/System/Posix/Internals.hs
. For exampleo_CREAT
:JS Backend
Other
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.
Probably need create a
[Note]
there at sources?