Skip to content

Commit

Permalink
Prepare 0.1.0.3 release.
Browse files Browse the repository at this point in the history
Reformatted.
Use new .github workflows.
Updated package metadata.
  • Loading branch information
brianjosephmckeon authored Mar 5, 2024
1 parent 7765d13 commit 215ed62
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 74 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@byteverse/l3c
11 changes: 11 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: build
on:
pull_request:
branches:
- "*"

jobs:
call-workflow:
uses: byteverse/.github/.github/workflows/build-matrix.yaml@main
with:
cabal-file: primitive-addr.cabal
10 changes: 10 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: release
on:
push:
tags:
- "*"

jobs:
call-workflow:
uses: byteverse/.github/.github/workflows/release.yaml@main
secrets: inherit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode/
dist
dist-*
cabal-dev
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for primitive-addr

## 0.1.0.3 -- 2024-03-05

* Update package metadata.

## 0.1.0.2 -- 2019-07-18

* Allow building with `primitive-0.6.4.0`.
Expand All @@ -10,4 +14,4 @@

## 0.1.0.0 -- 2019-05-17

* First version. Released on an unsuspecting world.
* First version.
2 changes: 0 additions & 2 deletions Setup.hs

This file was deleted.

15 changes: 0 additions & 15 deletions build

This file was deleted.

51 changes: 51 additions & 0 deletions fourmolu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Number of spaces per indentation step
indentation: 2

# Max line length for automatic line breaking
column-limit: 200

# Styling of arrows in type signatures (choices: trailing, leading, or leading-args)
function-arrows: trailing

# How to place commas in multi-line lists, records, etc. (choices: leading or trailing)
comma-style: leading

# Styling of import/export lists (choices: leading, trailing, or diff-friendly)
import-export-style: leading

# Whether to full-indent or half-indent 'where' bindings past the preceding body
indent-wheres: false

# Whether to leave a space before an opening record brace
record-brace-space: true

# Number of spaces between top-level declarations
newlines-between-decls: 1

# How to print Haddock comments (choices: single-line, multi-line, or multi-line-compact)
haddock-style: multi-line

# How to print module docstring
haddock-style-module: null

# Styling of let blocks (choices: auto, inline, newline, or mixed)
let-style: auto

# How to align the 'in' keyword with respect to the 'let' keyword (choices: left-align, right-align, or no-space)
in-style: right-align

# Whether to put parentheses around a single constraint (choices: auto, always, or never)
single-constraint-parens: always

# Output Unicode syntax (choices: detect, always, or never)
unicode: never

# Give the programmer more choice on where to insert blank lines
respectful: true

# Fixity information for operators
fixities: []

# Module reexports Fourmolu should know about
reexports: []

45 changes: 27 additions & 18 deletions primitive-addr.cabal
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
cabal-version: 2.2
name: primitive-addr
version: 0.1.0.2
synopsis: Addresses to unmanaged memory
cabal-version: 3.0
name: primitive-addr
version: 0.1.0.3
synopsis: Addresses to unmanaged memory
description:
This library provides the `Data.Primitive.Addr` module
that was a part of the `primitive` library before `primitive-0.7.0.0`.
homepage: https://github.com/andrewthad/primitive-addr
bug-reports: https://github.com/andrewthad/primitive-addr/issues
license: BSD-3-Clause
license-file: LICENSE
author: Andrew Martin
maintainer: [email protected]
copyright: 2019 Andrew Martin
category: Data
extra-source-files: CHANGELOG.md

homepage: https://github.com/byteverse/primitive-addr
bug-reports: https://github.com/byteverse/primitive-addr/issues
license: BSD-3-Clause
license-file: LICENSE
author: Andrew Martin
maintainer: [email protected]
copyright: 2019 Andrew Martin
category: Data
extra-doc-files: CHANGELOG.md
tested-with: GHC ==9.4.8 || ==9.6.3 || ==9.8.1

common build-settings
default-language: Haskell2010
ghc-options: -Wall -Wunused-packages
build-depends: base >=4.17.2.1 && <5

library
import: build-settings
hs-source-dirs: src
exposed-modules: Data.Primitive.Addr
build-depends:
, base >=4.5.1.0 && <5
, primitive >=0.6.4 && <0.10
hs-source-dirs: src
default-language: Haskell2010
build-depends: primitive >=0.6.4 && <0.10

source-repository head
type: git
location: git://github.com/byteverse/primitive-addr.git
91 changes: 53 additions & 38 deletions src/Data/Primitive/Addr.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{-# language CPP #-}
{-# language MagicHash #-}
{-# language UnboxedTuples #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}

{- FOURMOLU_DISABLE -}
-- | Primitive operations on machine addresses.
module Data.Primitive.Addr
( -- * Types
Expand All @@ -25,15 +26,15 @@ module Data.Primitive.Addr
-- * Conversion
, addrToInt
) where
{- FOURMOLU_ENABLE -}

import Numeric (showHex)
import Control.Monad.Primitive
import Data.Primitive.Types (Prim(..))
import Data.Primitive.ByteArray
import Data.Primitive.Types (Prim (..))
import Numeric (showHex)

import GHC.Exts
import GHC.Ptr
import Foreign.Marshal.Utils
import GHC.Exts

#if __GLASGOW_HASKELL__ < 708
toBool# :: Bool -> Bool
Expand Down Expand Up @@ -71,44 +72,53 @@ infixl 7 `remAddr`
plusAddr :: Addr -> Int -> Addr
plusAddr (Addr a#) (I# i#) = Addr (plusAddr# a# i#)

-- | Distance in bytes between two addresses. The result is only valid if the
-- difference fits in an 'Int'.
{- | Distance in bytes between two addresses. The result is only valid if the
difference fits in an 'Int'.
-}
minusAddr :: Addr -> Addr -> Int
minusAddr (Addr a#) (Addr b#) = I# (minusAddr# a# b#)

-- | The remainder of the address and the integer.
remAddr :: Addr -> Int -> Int
remAddr (Addr a#) (I# i#) = I# (remAddr# a# i#)

-- | Read a value from a memory position given by an address and an offset.
-- The memory block the address refers to must be immutable. The offset is in
-- elements of type @a@ rather than in bytes.
indexOffAddr :: Prim a => Addr -> Int -> a
{- | Read a value from a memory position given by an address and an offset.
The memory block the address refers to must be immutable. The offset is in
elements of type @a@ rather than in bytes.
-}
indexOffAddr :: (Prim a) => Addr -> Int -> a
{-# INLINE indexOffAddr #-}
indexOffAddr (Addr addr#) (I# i#) = indexOffAddr# addr# i#

-- | Read a value from a memory position given by an address and an offset.
-- The offset is in elements of type @a@ rather than in bytes.
{- | Read a value from a memory position given by an address and an offset.
The offset is in elements of type @a@ rather than in bytes.
-}
readOffAddr :: (Prim a, PrimMonad m) => Addr -> Int -> m a
{-# INLINE readOffAddr #-}
readOffAddr (Addr addr#) (I# i#) = primitive (readOffAddr# addr# i#)

-- | Write a value to a memory position given by an address and an offset.
-- The offset is in elements of type @a@ rather than in bytes.
{- | Write a value to a memory position given by an address and an offset.
The offset is in elements of type @a@ rather than in bytes.
-}
writeOffAddr :: (Prim a, PrimMonad m) => Addr -> Int -> a -> m ()
{-# INLINE writeOffAddr #-}
writeOffAddr (Addr addr#) (I# i#) x = primitive_ (writeOffAddr# addr# i# x)

-- | Copy the given number of bytes from the second 'Addr' to the first. The
-- areas may not overlap.
copyAddr :: PrimMonad m
=> Addr -- ^ destination address
-> Addr -- ^ source address
-> Int -- ^ number of bytes
-> m ()
{- | Copy the given number of bytes from the second 'Addr' to the first. The
areas may not overlap.
-}
copyAddr ::
(PrimMonad m) =>
-- | destination address
Addr ->
-- | source address
Addr ->
-- | number of bytes
Int ->
m ()
{-# INLINE copyAddr #-}
copyAddr (Addr dst#) (Addr src#) n
= unsafePrimToPrim $ copyBytes (Ptr dst#) (Ptr src#) n
copyAddr (Addr dst#) (Addr src#) n =
unsafePrimToPrim $ copyBytes (Ptr dst#) (Ptr src#) n

#if __GLASGOW_HASKELL__ >= 708
-- | Copy the given number of bytes from the 'Addr' to the 'MutableByteArray'.
Expand All @@ -125,19 +135,25 @@ copyAddrToByteArray (MutableByteArray marr) (I# off) (Addr addr) (I# len) =
primitive_ $ copyAddrToByteArray# addr marr off len
#endif

-- | Copy the given number of bytes from the second 'Addr' to the first. The
-- areas may overlap.
moveAddr :: PrimMonad m
=> Addr -- ^ destination address
-> Addr -- ^ source address
-> Int -- ^ number of bytes
-> m ()
{- | Copy the given number of bytes from the second 'Addr' to the first. The
areas may overlap.
-}
moveAddr ::
(PrimMonad m) =>
-- | destination address
Addr ->
-- | source address
Addr ->
-- | number of bytes
Int ->
m ()
{-# INLINE moveAddr #-}
moveAddr (Addr dst#) (Addr src#) n
= unsafePrimToPrim $ moveBytes (Ptr dst#) (Ptr src#) n
moveAddr (Addr dst#) (Addr src#) n =
unsafePrimToPrim $ moveBytes (Ptr dst#) (Ptr src#) n

-- | Fill a memory block of with the given value. The length is in
-- elements of type @a@ rather than in bytes.
{- | Fill a memory block of with the given value. The length is in
elements of type @a@ rather than in bytes.
-}
setAddr :: (Prim a, PrimMonad m) => Addr -> Int -> a -> m ()
{-# INLINE setAddr #-}
setAddr (Addr addr#) (I# n#) x = primitive_ (setOffAddr# addr# 0# n# x)
Expand All @@ -146,4 +162,3 @@ setAddr (Addr addr#) (I# n#) x = primitive_ (setOffAddr# addr# 0# n# x)
addrToInt :: Addr -> Int
{-# INLINE addrToInt #-}
addrToInt (Addr addr#) = I# (addr2Int# addr#)

0 comments on commit 215ed62

Please sign in to comment.