Skip to content
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

Support bytestring 0.10.12.0 #41

Merged
merged 4 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions .github/workflows/packcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
PACKCHECK_COMMAND: ${{ matrix.command }} ${{ matrix.pack_options }}

runs-on: ${{ matrix.runner }}
continue-on-error: ${{ matrix.ignore_error }}
strategy:
fail-fast: false
matrix:
Expand All @@ -97,77 +98,87 @@ jobs:
runner: ubuntu-latest
cabal-version: 3.8.1.0
pack_options: >-
CABAL_PROJECT=cabal.project.d/master-Werror
CABAL_PROJECT=cabal.project.d/master
ignore_error: false

- name: 9.6.2
- name: 9.6.2+Werror
ghc_version: 9.6.2
command: cabal-v2
runner: ubuntu-latest
cabal-version: 3.8.1.0
pack_options: >-
CABAL_PROJECT=cabal.project.d/master-Werror
ignore_error: true

- name: 9.4.4
- name: 9.4.4+streamly-core-0.2.0
ghc_version: 9.4.4
command: cabal-v2
runner: ubuntu-latest
cabal-version: 3.8.1.0
pack_options: >-
CABAL_PROJECT=cabal.project.d/streamly-core-0.2.0
ignore_error: false

- name: 9.2.7
- name: 9.2.7+streamly-core-0.1.0
ghc_version: 9.2.7
command: cabal-v2
runner: ubuntu-latest
cabal-version: 3.6.2.0
pack_options: >-
CABAL_PROJECT=cabal.project.d/streamly-core-0.1.0
ignore_error: false

- name: 9.0.1
ghc_version: 9.0.1
command: cabal-v2
runner: ubuntu-latest
cabal-version: 3.2
pack_options: >-
CABAL_PROJECT=cabal.project.d/master-Werror
CABAL_PROJECT=cabal.project.d/master
ignore_error: false

- name: 8.10.7
- name: 8.10.7+bytestring-0.10.12
ghc_version: 8.10.7
command: cabal-v2
runner: ubuntu-latest
cabal-version: 3.2
pack_options: >-
CABAL_PROJECT=cabal.project.d/master-Werror
CABAL_PROJECT=cabal.project.d/bytestring-0.10.12
ignore_error: false

- name: 8.10.7+stack
command: stack
runner: ubuntu-latest
pack_options: >-
STACK_YAML=stack.yaml
ignore_error: false

- name: 8.10.7+macOS
ghc_version: 8.10.7
command: cabal-v2
runner: macos-latest
cabal_version: 3.4
pack_options: >-
CABAL_PROJECT=cabal.project.d/master-Werror
CABAL_PROJECT=cabal.project.d/master
ignore_error: false

- name: 8.8.4
ghc_version: 8.8.4
command: cabal-v2
runner: ubuntu-latest
cabal-version: 3.2
pack_options: >-
CABAL_PROJECT=cabal.project.d/master-Werror
CABAL_PROJECT=cabal.project.d/master
ignore_error: false

- name: 8.6.5
ghc_version: 8.6.5
command: cabal-v2
runner: ubuntu-latest
cabal-version: 3.2
pack_options: >-
CABAL_PROJECT=cabal.project.d/master-Werror
CABAL_PROJECT=cabal.project.d/master
ignore_error: false

- name: hlint
ghc_version: 8.8.4
Expand All @@ -177,6 +188,7 @@ jobs:
HLINT_OPTIONS="lint"
HLINT_TARGETS="src"
cabal-version: 3.2
ignore_error: false

steps:
- uses: actions/checkout@v2
Expand Down
8 changes: 8 additions & 0 deletions cabal.project.d/bytestring-0.10.12
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
packages: streamly-bytestring.cabal

constraints:
bytestring == 0.10.12.0
, streamly-core == 0.2.0.*

allow-newer:
deepseq
24 changes: 19 additions & 5 deletions src/Streamly/External/ByteString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
import qualified Streamly.Data.Array as Array
import qualified Streamly.Internal.Data.Unfold as Unfold (fold, mkUnfoldrM)

#if !(MIN_VERSION_bytestring(0,11,0))
import GHC.ForeignPtr (plusForeignPtr)
#endif

#if MIN_VERSION_streamly_core(0,2,0)
import Streamly.Internal.Data.Array (Array(..))
import Streamly.Internal.Data.MutByteArray (MutByteArray(..))
Expand All @@ -62,6 +66,14 @@
#define MUT_BYTE_ARRAY MutableByteArray
#endif

#if MIN_VERSION_bytestring(0,11,0)
#define CONSTRUCTOR(a, b, c) BS a c
#define WHEN_0_10_12(x)
#else
#define CONSTRUCTOR(a, b, c) PS a b c
#define WHEN_0_10_12(x) x
#endif

{-# INLINE mutableByteArrayContents# #-}
mutableByteArrayContents# :: MutableByteArray# RealWorld -> Addr#
mutableByteArrayContents# marr# = byteArrayContents# (unsafeCoerce# marr#)
Expand All @@ -79,14 +91,16 @@
-- there is a copy involved.
{-# INLINE toArray #-}
toArray :: ByteString -> Array Word8
toArray (BS (ForeignPtr addr# _) _)
toArray (CONSTRUCTOR((ForeignPtr addr# _), _, _))
| Ptr addr# == nullPtr = Array MutBA.nil 0 0

Check warning on line 95 in src/Streamly/External/ByteString.hs

View workflow job for this annotation

GitHub Actions / 9.8.1

In the use of ‘nil’

Check warning on line 95 in src/Streamly/External/ByteString.hs

View workflow job for this annotation

GitHub Actions / 9.8.1

In the use of ‘nil’

Check failure on line 95 in src/Streamly/External/ByteString.hs

View workflow job for this annotation

GitHub Actions / 9.6.2+Werror

In the use of ‘nil’

Check warning on line 95 in src/Streamly/External/ByteString.hs

View workflow job for this annotation

GitHub Actions / 9.0.1

In the use of ‘nil’

Check warning on line 95 in src/Streamly/External/ByteString.hs

View workflow job for this annotation

GitHub Actions / 9.0.1

In the use of ‘nil’

Check warning on line 95 in src/Streamly/External/ByteString.hs

View workflow job for this annotation

GitHub Actions / 8.10.7+macOS

In the use of ‘nil’

Check warning on line 95 in src/Streamly/External/ByteString.hs

View workflow job for this annotation

GitHub Actions / 8.10.7+macOS

In the use of ‘nil’

Check warning on line 95 in src/Streamly/External/ByteString.hs

View workflow job for this annotation

GitHub Actions / 8.8.4

In the use of ‘nil’

Check warning on line 95 in src/Streamly/External/ByteString.hs

View workflow job for this annotation

GitHub Actions / 8.8.4

In the use of ‘nil’

Check warning on line 95 in src/Streamly/External/ByteString.hs

View workflow job for this annotation

GitHub Actions / 8.6.5

In the use of ‘nil’

Check warning on line 95 in src/Streamly/External/ByteString.hs

View workflow job for this annotation

GitHub Actions / 8.6.5

In the use of ‘nil’

Check warning on line 95 in src/Streamly/External/ByteString.hs

View workflow job for this annotation

GitHub Actions / hlint

In the use of ‘nil’

Check warning on line 95 in src/Streamly/External/ByteString.hs

View workflow job for this annotation

GitHub Actions / hlint

In the use of ‘nil’
toArray (BS (ForeignPtr addr# (PlainPtr marr#)) len) =
toArray (CONSTRUCTOR((ForeignPtr addr# (PlainPtr marr#)), off0, len)) =
let off = I# (addr# `minusAddr#` mutableByteArrayContents# marr#)
WHEN_0_10_12(+ off0)
in Array (MUT_BYTE_ARRAY marr#) off (off + len)
toArray (BS fptr len) =
toArray (CONSTRUCTOR(fptr, off, len)) =
unsafeInlineIO
$ withForeignPtr fptr $ Unfold.fold (Array.writeN len) generator
$ withForeignPtr (fptr WHEN_0_10_12(`plusForeignPtr` off))
$ Unfold.fold (Array.writeN len) generator

where

Expand All @@ -101,7 +115,7 @@
fromArray :: Array Word8 -> ByteString
fromArray (Array {..})
| aLen == 0 = mempty
| otherwise = BS (makeForeignPtr arrContents arrStart) aLen
| otherwise = CONSTRUCTOR((makeForeignPtr arrContents arrStart), 0, aLen)

where

Expand Down
5 changes: 3 additions & 2 deletions streamly-bytestring.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ library
ghc-options: -Wall -O2
build-depends:
base >=4.7 && <5
, bytestring == 0.11.0.*
, bytestring == 0.10.12.*
|| == 0.11.0.*
|| == 0.11.1.*
|| == 0.11.2.*
-- bytestring-0.11.3.0 causes panics and other issues on
Expand All @@ -47,7 +48,7 @@ library
|| == 0.11.4.*
|| == 0.11.5.*
|| == 0.12.0.*
, streamly-core >= 0.1.0 && < 0.2.2
, streamly-core >= 0.1.0 && < 0.2.3
default-language: Haskell2010

test-suite sb-test
Expand Down
Loading