summaryrefslogtreecommitdiff
path: root/libraries/base/GHC/IO/Handle
Commit message (Collapse)AuthorAgeFilesLines
...
* base: Implement file locking in terms of POSIX locksBen Gamari2017-10-291-2/+72
| | | | | | | | | | | | | | | Hopefully these are more robust to NFS malfunction than BSD flock-style locks. See #13945. Test Plan: Validate via @simonpj Reviewers: austin, hvr Subscribers: rwbarton, thomie, erikd, simonpj GHC Trac Issues: #13945 Differential Revision: https://phabricator.haskell.org/D4129
* base: Add support for file unlockingBen Gamari2017-08-291-0/+30
| | | | | | | | Reviewers: austin, hvr Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3875
* Prefer #if defined to #ifdefBen Gamari2017-04-283-7/+7
| | | | Our new CPP linter enforces this.
* Fix compilation for !HAVE_FLOCKHerbert Valerio Riedel2017-04-231-0/+4
|
* base: update comment to match the change from e134af01Andrzej Rybczak2017-04-211-3/+2
| | | | | | | | | | Reviewers: austin, hvr, bgamari Reviewed By: bgamari Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3484
* base: Fix offset initialization of Windows hLock implementationBen Gamari2017-04-211-3/+2
| | | | | | | | | | | | | | | The previous implementation swapped the buffer size with the byte to be set, essentially resulting in an uninitialized buffer. Test Plan: Validate on Windows Reviewers: austin, hvr Subscribers: rwbarton, thomie GHC Trac Issues: #13599 Differential Revision: https://phabricator.haskell.org/D3478
* Decrease locked region size on Windows to fix ERROR_LOCK_INVALID_RANGEAndrzej Rybczak2017-03-151-4/+4
| | | | | | | | Reviewers: austin, hvr, bgamari Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3345
* Fix windows build broken by D3080 (0d86aa5904e5a06c93632357122e57e4e118fd2a)Tamar Christina2017-02-281-1/+0
|
* Add support for concurrent package db access and updatesAndrzej Rybczak2017-02-262-13/+180
| | | | | | | | | | Trac issues: #13194 Reviewers: austin, hvr, erikd, bgamari, dfeuer, duncan Subscribers: DemiMarie, dfeuer, thomie Differential Revision: https://phabricator.haskell.org/D3090
* bufWrite: Save extra syscall when data fills handle buffer completely.Niklas Hambüchen2017-02-111-4/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The bug is that the check `if (size - w > count)` should be `if (size - w >= count)` instead (`>=` instead of `>`), because we can do the write all fine if it fits exactly. This allows us to do 1 instead of 2 write syscalls the case it fits. An example of when this matters is when an application writes output in chunks that are a fraction of the handle buffer size. For example, assume the buffer size is 8 KB, and the application writes four 2 KB chunks. Until now, this would result in 3 copies to the handle buffer, but the 4th one would not be allowed in by `size - w > count` (because `size - w == count` is the case), so we'd end up with a write syscall of only 6 KB data instead of 8 KB, thus creating more syscalls overall. Implementing this fix (switching to `size - w >= count`), we also have to flush the buffer if we fill it completely. If we made only the changes described so far, that would have the unintended side effect that writes of the size equal to the handle buffer size (`count == size`) suddenly also go to the handle buffer first: The data would first be copied to the handle buffer, and then immediately get flushed to the underlying FD. We don't want that extra `memcpy`, because it'd be unnecessary: The point of handle buffering is to coalesce smaller writes, and there are no smaller writes in this case. For example, if you specify 8 KB buffers (which menas you want your data to be written out in 8 KB blocks), and you get data that's already 8 KB in size, you can write that out as an 8 KB straight away, zero-copy fashion. For this reason, adding to the handle buffer now got an additional condition `count < size`. That way, writes equal to the buffer size go straight to the FD, as they did before this commit. Reviewers: simonmar, austin, hvr, bgamari Reviewed By: simonmar Subscribers: mpickering, thomie Differential Revision: https://phabricator.haskell.org/D3117
* Fix: hPutBuf issues unnecessary empty write syscalls for large writes (#13246)Niklas Hambüchen2017-02-111-5/+8
| | | | | | | | | | | | | | | | | Until now, any `hPutBuf` that wrote `>= the handle buffer size` would trigger an unnecessary `write("")` system call before the actual write system call. This is fixed by making sure that we never flush an empty handle buffer: Only flush `when (w > 0)`. Reviewers: simonmar, austin, hvr, bgamari Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D3119
* Add @since annotations to base instancesSeraphime Kirkovski2016-06-061-0/+3
| | | | | | | | | | | | | | | | | | Add @since annotations to instances in `base`. Test Plan: * ./validate # some commets shouldn't break the build * review the annotations for absurdities. Reviewers: ekmett, goldfire, RyanGlScott, austin, hvr, bgamari Reviewed By: RyanGlScott, hvr, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2277 GHC Trac Issues: #11767
* Use catchException in a few more placesBen Gamari2016-03-111-1/+1
| | | | | | | | | | | | | | These are cases in the standard library that may benefit from the strictness signature of catchException and where we know that the action won't bottom. Test Plan: Validate, carefully consider changed callsites Reviewers: austin, hvr Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1972
* Fix docstring GHC.IO.Handle.FD.openFileBLockingThomas Miedema2016-01-211-3/+3
| | | | Fixes #4248.
* Allow CallStacks to be frozenEric Seidel2015-12-233-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This introduces "freezing," an operation which prevents further locations from being appended to a CallStack. Library authors may want to prevent CallStacks from exposing implementation details, as a matter of hygiene. For example, in ``` head [] = error "head: empty list" ghci> head [] *** Exception: head: empty list CallStack (from implicit params): error, called at ... ``` including the call-site of `error` in `head` is not strictly necessary as the error message already specifies clearly where the error came from. So we add a function `freezeCallStack` that wraps an existing CallStack, preventing further call-sites from being pushed onto it. In other words, ``` pushCallStack callSite (freezeCallStack callStack) = freezeCallStack callStack ``` Now we can define `head` to not produce a CallStack at all ``` head [] = let ?callStack = freezeCallStack emptyCallStack in error "head: empty list" ghci> head [] *** Exception: head: empty list CallStack (from implicit params): error, called at ... ``` --- 1. We add the `freezeCallStack` and `emptyCallStack` and update the definition of `CallStack` to support this functionality. 2. We add `errorWithoutStackTrace`, a variant of `error` that does not produce a stack trace, using this feature. I think this is a sensible wrapper function to provide in case users want it. 3. We replace uses of `error` in base with `errorWithoutStackTrace`. The rationale is that base does not export any functions that use CallStacks (except for `error` and `undefined`) so there's no way for the stack traces (from Implicit CallStacks) to include user-defined functions. They'll only contain the call to `error` itself. As base already has a good habit of providing useful error messages that name the triggering function, the stack trace really just adds noise to the error. (I don't have a strong opinion on whether we should include this third commit, but the change was very mechanical so I thought I'd include it anyway in case there's interest) 4. Updates tests in `array` and `stm` submodules Test Plan: ./validate, new test is T11049 Reviewers: simonpj, nomeata, goldfire, austin, hvr, bgamari Reviewed By: simonpj Subscribers: thomie Projects: #ghc Differential Revision: https://phabricator.haskell.org/D1628 GHC Trac Issues: #11049
* IO Handles: update comments [skip ci]Thomas Miedema2015-12-172-6/+10
| | | | | | | * hSetEcho, hGetEcho and hIsTerminalDevice are part of the Haskell2010 report (but not Haskell98) * there are great `Note`s in GHC.IO.Handle.Types. Link to them.
* Start using `-W` instead of `-f(no-)warn` in some placesHerbert Valerio Riedel2015-12-162-4/+4
| | | | | | | | | | | | | | | | | | This replaces some occurences of `-f(no-)warn` with the new `-W`-aliases introduced via 2206fa8cdb120932 / #11218, in cases which are guaranteed to be invoked with recent enough GHC (i.e. the stage1+ GHC). After this commit, mostly the compiler and the testsuite remain using `-f(wo-)warn...` because the compiler needs to be bootstrappable with older GHCs, while for the testsuite it's convenient to be able to quickly compare the behavior to older GHCs (which may not support the new flags yet). The compiler-part can be updated to use the new flags once GHC 8.3 development starts. Reviewed By: quchen Differential Revision: https://phabricator.haskell.org/D1637
* Mention "handle is semi-closed" in error messagesThomas Miedema2015-12-151-5/+9
| | | | | | | | | | | Semi-closedness is mentioned in the Haskell report, so lets not hide it from users. Reviewers: austin, hvr, bgamari Reviewed By: bgamari Differential Revision: https://phabricator.haskell.org/D1624
* base: drop redundant Typeable derivingsHerbert Valerio Riedel2015-03-071-4/+0
| | | | | | | | | | | Thanks to #9858 `Typeable` doesn't need to be explicitly derived anymore. This also makes `AutoDeriveTypeable` redundant, as well as some imports of `Typeable` (removal of whose may be beneficial to #9707). This commit removes several such now redundant use-sites in `base`. Reviewed By: austin, ekmett Differential Revision: https://phabricator.haskell.org/D712
* Convert `/Since: .../` to new `@since ...` syntaxHerbert Valerio Riedel2014-12-161-1/+1
| | | | | | Starting with Haddock 2.16 there's a new built-in support for since-annotations Note: This exposes a bug in the `@since` implementation (see e.g. `Data.Bits`)
* Update Foreign.* for Safe Haskell now that they're safe by defaultDavid Terei2014-11-211-1/+1
|
* Fix #9236 Error on read from closed handleDavid Feuer2014-10-291-1/+4
| | | | | | | | | | | | | | | | | Summary: Fixes #9236. My testing indicates that this does *not* lead to problems with broken pipes and such, but further testing is required. It found a bug in haddock; I've submitted a pull request upstream. Reviewers: ekmett, austin Reviewed By: ekmett, austin Subscribers: rwbarton, thomie, carter, simonmar Differential Revision: https://phabricator.haskell.org/D327 GHC Trac Issues: #9236
* `M-x delete-trailing-whitespace` & `M-x untabify`Herbert Valerio Riedel2014-09-243-73/+73
| | | | ...several modules in `base` recently touched by me
* Move `when` to GHC.BaseHerbert Valerio Riedel2014-09-182-2/+0
| | | | | | | | | This allows several modules to avoid importing Control.Monad and thus break import cycles that manifest themselves when implementing #9586 Reviewed By: austin, ekmett Differential Revision: https://phabricator.haskell.org/D222
* Move `Maybe`-typedef into GHC.BaseHerbert Valerio Riedel2014-09-161-1/+0
| | | | | | | This is preparatory work for reintroducing SPECIALISEs that were lost in d94de87252d0fe2ae97341d186b03a2fbe136b04 Differential Revision: https://phabricator.haskell.org/D214
* Replace DeriveDataTypeable by AutoDeriveTypeableHerbert Valerio Riedel2014-05-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a first step towards addressing #9111 This results in the following additional Typeable (exported) instances being generated (list was compiled by diff'ing hoogle txt output): instance Typeable CFile instance Typeable 'CFile instance Typeable CFpos instance Typeable 'CFpos instance Typeable CJmpBuf instance Typeable 'CJmpBuf instance Typeable ChItem instance Typeable QSem instance Typeable ID instance Typeable 'ID instance Typeable CONST instance Typeable Qi instance Typeable Qr instance Typeable Mp instance Typeable ConstrRep instance Typeable Fixity instance Typeable 'Prefix instance Typeable 'Infix instance Typeable Constr instance Typeable DataType instance Typeable DataRep instance Typeable Data instance Typeable HasResolution instance Typeable IsList Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Drop redundant `{-# LANGUAGE #-}` pragmasHerbert Valerio Riedel2013-09-283-4/+1
| | | | | | | | | | | | | This removes language pragmas from Haskell modules which are implicitly active with `default-language: Haskell2010`. Specifically, the following language extension pragmas are removed by this commit: - PatternGuards - ForeignFunctionInterface - EmptyDataDecls - NoBangPatterns Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Remove obsolete pre-Haddock-2 `#hide` pragmasHerbert Valerio Riedel2013-09-232-2/+0
| | | | | | | | | | | | The now obsolete (and redundant) `#hide` pragmas have been superseded by `{-# OPTIONS_HADDOCK hide #-}` pragmas which are used by most of the affected modules anyway. This commit also adds proper `{-# OPTIONS_HADDOCK hide #-}` pragmas to `GHC.Desugar` and `GHC.IO.Encoding.Iconv` which had only the ineffective `#hide` annotation. Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Add Haddock `/Since: 4.4.0.0/` comments to symbolsHerbert Valerio Riedel2013-09-221-0/+2
| | | | | | | | | | This commit retroactively adds `/Since: 4.4.0.0/` annotations to symbols newly added/exposed in `base-4.4.0.0` (as shipped with GHC 7.2.1). See also 6368362f which adds the respective annotation for symbols newly added in `base-4.7.0.0` (that goes together with GHC 7.8.1). Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Fix a commentIan Lynagh2013-06-151-1/+1
|
* Support for Windows DBCS and new SBCS with MultiByteToWideCharMax Bolingbroke2013-05-081-8/+11
| | | | | | | | | | | | | | Because MultiByteToWideChar/WideCharToMultiByte have a rather unhelpful interface, we have to use a lot of binary searching tricks to get them to match the iconv-like interface that GHC requires. Even though the resulting encodings are slow, it does at least mean that we now support all of Window's code pages. What's more, since these codecs are basically only used for console output there probably won't be a huge volume of text to deal with in the common case, so speed is less of a worry. Note that we will still use GHC's faster table-based custom codec for supported SBCSs.
* Fix #7522 by checking for empty byte buffers a little moreMax Bolingbroke2013-04-101-3/+29
| | | | Quite a few lines have changed but that is mostly comments.
* Don't just fail if hGetBufSome is used on a non-FD: fall back on the slow ↵Max Bolingbroke2013-03-241-8/+5
| | | | path instead
* typosGabor Greif2013-01-251-1/+1
|
* Make a class for asynchronous exceptions in the exception hierarchySimon Marlow2012-12-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | Right now, we only have data AsyncException = StackOverflow | HeapOverflow | ThreadKilled | ... so it is not possible to add another async exception. For instance, the Timeout exception in System.Timeout should really be an async exception. This patch adds a superclass for all async exceptions: data SomeAsyncException = forall e . Exception e => SomeAsyncException e deriving Typeable and makes the existing AsyncException and Timeout children of SomeAsyncException in the hierarchy.
* Replace Rank2Types with RankNTypesSimon Peyton Jones2012-10-311-1/+1
|
* Ensure hGetBufSome does not cause potentially blocking reads (#5843)Paolo Capriotti2012-03-271-1/+2
| | | | | | When there is data in a handle buffer, never fetch more than the available number of elements, since that can cause a blocking read on Windows.
* Go back to using private-use characters in roundtrippingMax Bolingbroke2011-11-181-8/+4
|
* Make the fileSystemEncoding/localeEncoding/foreignEncoding mutableMax Bolingbroke2011-11-181-6/+9
|
* Update base for latest Safe Haskell.David Terei2011-10-254-0/+5
|
* tweak unpack/unpack_nl to generate better Core (#5536)Simon Marlow2011-10-131-6/+24
|
* Improve performance of the unpack loopMax Bolingbroke2011-10-111-3/+10
|
* Fix #5436 by using 'recover' on handle EOFMax Bolingbroke2011-09-231-32/+36
|
* Fix build on WindowsIan Lynagh2011-06-201-1/+1
|
* SafeHaskell: Added SafeHaskell to baseDavid Terei2011-06-185-12/+13
|
* Use Unicode private-use characters for roundtrippingMax Bolingbroke2011-05-181-4/+5
| | | | | | | | | This replaces the previous scheme (which used lone surrogates). The reason is that there is Haskell software in the wild (i.e. the text package) that chokes on Char values that do not represent Unicode characters. This new approach will not work correctly if the reserved private-use characters are actually encountered in the input, but we expect this to be rare.
* Big patch to improve Unicode support in GHC. Validated on OS X and Windows, thisMax Bolingbroke2011-05-141-5/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | patch series fixes #5061, #1414, #3309, #3308, #3307, #4006 and #4855. The major changes are: 1) Make Foreign.C.String.*CString use the locale encoding This change follows the FFI specification in Haskell 98, which has never actually been implemented before. The functions exported from Foreign.C.String are partially-applied versions of those from GHC.Foreign, which allows the user to supply their own TextEncoding. We also introduce foreignEncoding as the name of the text encoding that follows the FFI appendix in that it transliterates encoding errors. 2) I also changed the code so that mkTextEncoding always tries the native-Haskell decoders in preference to those from iconv, even on non-Windows. The motivation here is simply that it is better for compatibility if we do this, and those are the ones you get for the utf* and latin1* predefined TextEncodings anyway. 3) Implement surrogate-byte error handling mode for TextEncoding This implements PEP383-like behaviour so that we are able to roundtrip byte strings through Strings without loss of information. The withFilePath function now uses this encoding to get to/from CStrings, so any code that uses that will get the right PEP383 behaviour automatically. 4) Implement three other coding failure modes: ignore, throw error, transliterate These mimic the behaviour of the GNU Iconv extensions.
* Change debug prints in readTextDevice' to refer to right functionMax Bolingbroke2011-04-031-2/+2
|
* fix Haddock errorSimon Marlow2011-03-291-1/+1
|
* Add GHC.IO.Handle.FD.openFileBlocking (#4248)Simon Marlow2011-03-291-9/+21
| | | | like openFile, but opens the file without O_NONBLOCK