os-string 2.0.6 → 2.0.7
raw patch · 6 files changed
+40/−13 lines, 6 filesdep ~base
Dependency ranges changed: base
Files
- System/OsString/Common.hs +5/−5
- System/OsString/Encoding/Internal.hs +3/−2
- System/OsString/Internal/Exception.hs +20/−0
- changelog.md +4/−0
- os-string.cabal +3/−2
- tests/encoding/EncodingSpec.hs +5/−4
System/OsString/Common.hs view
@@ -143,7 +143,7 @@ where -+import System.OsString.Internal.Exception import System.OsString.Internal.Types ( #ifdef WINDOWS WindowsString(..), WindowsChar(..)@@ -236,7 +236,7 @@ -> String -> Either EncodingException PLATFORM_STRING encodeWith enc str = unsafePerformIO $ do- r <- try @SomeException $ GHC.withCStringLen enc str $ \cstr -> WindowsString <$> BS8.packCStringLen cstr+ r <- trySafe @SomeException $ GHC.withCStringLen enc str $ \cstr -> WindowsString <$> BS8.packCStringLen cstr evaluate $ force $ first (flip EncodingError Nothing . displayException) r #else -- | Encode a 'String' with the specified encoding.@@ -244,7 +244,7 @@ -> String -> Either EncodingException PLATFORM_STRING encodeWith enc str = unsafePerformIO $ do- r <- try @SomeException $ GHC.withCStringLen enc str $ \cstr -> PosixString <$> BSP.packCStringLen cstr+ r <- trySafe @SomeException $ GHC.withCStringLen enc str $ \cstr -> PosixString <$> BSP.packCStringLen cstr evaluate $ force $ first (flip EncodingError Nothing . displayException) r #endif @@ -340,7 +340,7 @@ -> PLATFORM_STRING -> Either EncodingException String decodeWith winEnc (WindowsString ba) = unsafePerformIO $ do- r <- try @SomeException $ BS8.useAsCStringLen ba $ \fp -> GHC.peekCStringLen winEnc fp+ r <- trySafe @SomeException $ BS8.useAsCStringLen ba $ \fp -> GHC.peekCStringLen winEnc fp evaluate $ force $ first (flip EncodingError Nothing . displayException) r #else -- | Decode a 'PosixString' with the specified encoding.@@ -350,7 +350,7 @@ -> PLATFORM_STRING -> Either EncodingException String decodeWith unixEnc (PosixString ba) = unsafePerformIO $ do- r <- try @SomeException $ BSP.useAsCStringLen ba $ \fp -> GHC.peekCStringLen unixEnc fp+ r <- trySafe @SomeException $ BSP.useAsCStringLen ba $ \fp -> GHC.peekCStringLen unixEnc fp evaluate $ force $ first (flip EncodingError Nothing . displayException) r #endif
System/OsString/Encoding/Internal.hs view
@@ -10,6 +10,7 @@ import qualified System.OsString.Data.ByteString.Short as BS8 import qualified System.OsString.Data.ByteString.Short.Word16 as BS16+import System.OsString.Internal.Exception import GHC.Base import GHC.Real@@ -282,13 +283,13 @@ -- | Decode with the given 'TextEncoding'. decodeWithTE :: TextEncoding -> BS8.ShortByteString -> Either EncodingException String decodeWithTE enc ba = unsafePerformIO $ do- r <- try @SomeException $ BS8.useAsCStringLen ba $ \fp -> GHC.peekCStringLen enc fp+ r <- trySafe @SomeException $ BS8.useAsCStringLen ba $ \fp -> GHC.peekCStringLen enc fp evaluate $ force $ first (flip EncodingError Nothing . displayException) r -- | Encode with the given 'TextEncoding'. encodeWithTE :: TextEncoding -> String -> Either EncodingException BS8.ShortByteString encodeWithTE enc str = unsafePerformIO $ do- r <- try @SomeException $ GHC.withCStringLen enc str $ \cstr -> BS8.packCStringLen cstr+ r <- trySafe @SomeException $ GHC.withCStringLen enc str $ \cstr -> BS8.packCStringLen cstr evaluate $ force $ first (flip EncodingError Nothing . displayException) r -- -----------------------------------------------------------------------------
+ System/OsString/Internal/Exception.hs view
@@ -0,0 +1,20 @@+module System.OsString.Internal.Exception where++import Control.Exception ( catch, fromException, toException, throwIO, Exception, SomeAsyncException(..) )++-- | Like 'try', but rethrows async exceptions.+trySafe :: Exception e => IO a -> IO (Either e a)+trySafe ioA = catch action eHandler+ where+ action = do+ v <- ioA+ return (Right v)+ eHandler e+ | isAsyncException e = throwIO e+ | otherwise = return (Left e)++isAsyncException :: Exception e => e -> Bool+isAsyncException e =+ case fromException (toException e) of+ Just (SomeAsyncException _) -> True+ Nothing -> False
changelog.md view
@@ -1,5 +1,9 @@ # Changelog for [`os-string` package](http://hackage.haskell.org/package/os-string) +## 2.0.7 *Nov 2024*++* don't catch asynchronous exceptions during encoding/decoding wrt [#22](https://github.com/haskell/os-string/issues/22)+ ## 2.0.6 *Jun 2024* * add `fromString` on windows
os-string.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: os-string-version: 2.0.6+version: 2.0.7 -- NOTE: Don't forget to update ./changelog.md license: BSD-3-Clause@@ -50,6 +50,7 @@ System.OsString.Encoding.Internal System.OsString System.OsString.Internal+ System.OsString.Internal.Exception System.OsString.Internal.Types System.OsString.Posix System.OsString.Windows@@ -63,7 +64,7 @@ default-language: Haskell2010 build-depends:- , base >=4.12.0.0 && <4.21+ , base >=4.12.0.0 && <4.22 , bytestring >=0.11.3.0 , deepseq , exceptions
tests/encoding/EncodingSpec.hs view
@@ -14,6 +14,7 @@ import Data.Either ( isRight ) import qualified System.OsString.Data.ByteString.Short as BS8 import qualified System.OsString.Data.ByteString.Short.Word16 as BS16+import System.OsString.Internal.Exception import System.OsString.Encoding.Internal import GHC.IO (unsafePerformIO) import GHC.IO.Encoding ( setFileSystemEncoding )@@ -154,21 +155,21 @@ decodeP' :: BS8.ShortByteString -> Either String String decodeP' ba = unsafePerformIO $ do- r <- try @SomeException $ decodeWithBasePosix ba+ r <- trySafe @SomeException $ decodeWithBasePosix ba evaluate $ force $ first displayException r encodeP' :: String -> Either String BS8.ShortByteString encodeP' str = unsafePerformIO $ do- r <- try @SomeException $ encodeWithBasePosix str+ r <- trySafe @SomeException $ encodeWithBasePosix str evaluate $ force $ first displayException r decodeW' :: BS16.ShortByteString -> Either String String decodeW' ba = unsafePerformIO $ do- r <- try @SomeException $ decodeWithBaseWindows ba+ r <- trySafe @SomeException $ decodeWithBaseWindows ba evaluate $ force $ first displayException r encodeW' :: String -> Either String BS8.ShortByteString encodeW' str = unsafePerformIO $ do- r <- try @SomeException $ encodeWithBaseWindows str+ r <- trySafe @SomeException $ encodeWithBaseWindows str evaluate $ force $ first displayException r