{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE Trustworthy #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  Foreign.C.ConstPtr
-- Copyright   :  (c) GHC Developers
-- License     :  BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer  :  ffi@haskell.org
-- Stability   :  provisional
-- Portability :  portable
--
-- This module provides typed @const@ pointers to foreign data. It is part
-- of the Foreign Function Interface (FFI).
--
-----------------------------------------------------------------------------

module Foreign.C.ConstPtr (
    ConstPtr(..)
) where

import GHC.Base
import GHC.Ptr
import GHC.Show

-- | A pointer with the C @const@ qualifier. For instance, an argument of type
-- @ConstPtr CInt@ would be marshalled as @const int*@.
--
-- While @const@-ness generally does not matter for @ccall@ imports (since
-- @const@ and non-@const@ pointers typically have equivalent calling
-- conventions), it does matter for @capi@ imports. See GHC #22043.
--
-- @since 4.18.0.0
--
type ConstPtr :: Type -> Type
type role ConstPtr phantom
newtype ConstPtr a = ConstPtr { forall a. ConstPtr a -> Ptr a
unConstPtr :: Ptr a }
    deriving (ConstPtr a -> ConstPtr a -> Bool
(ConstPtr a -> ConstPtr a -> Bool)
-> (ConstPtr a -> ConstPtr a -> Bool) -> Eq (ConstPtr a)
forall a. ConstPtr a -> ConstPtr a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. ConstPtr a -> ConstPtr a -> Bool
== :: ConstPtr a -> ConstPtr a -> Bool
$c/= :: forall a. ConstPtr a -> ConstPtr a -> Bool
/= :: ConstPtr a -> ConstPtr a -> Bool
Eq, Eq (ConstPtr a)
Eq (ConstPtr a) =>
(ConstPtr a -> ConstPtr a -> Ordering)
-> (ConstPtr a -> ConstPtr a -> Bool)
-> (ConstPtr a -> ConstPtr a -> Bool)
-> (ConstPtr a -> ConstPtr a -> Bool)
-> (ConstPtr a -> ConstPtr a -> Bool)
-> (ConstPtr a -> ConstPtr a -> ConstPtr a)
-> (ConstPtr a -> ConstPtr a -> ConstPtr a)
-> Ord (ConstPtr a)
ConstPtr a -> ConstPtr a -> Bool
ConstPtr a -> ConstPtr a -> Ordering
ConstPtr a -> ConstPtr a -> ConstPtr a
forall a. Eq (ConstPtr a)
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. ConstPtr a -> ConstPtr a -> Bool
forall a. ConstPtr a -> ConstPtr a -> Ordering
forall a. ConstPtr a -> ConstPtr a -> ConstPtr a
$ccompare :: forall a. ConstPtr a -> ConstPtr a -> Ordering
compare :: ConstPtr a -> ConstPtr a -> Ordering
$c< :: forall a. ConstPtr a -> ConstPtr a -> Bool
< :: ConstPtr a -> ConstPtr a -> Bool
$c<= :: forall a. ConstPtr a -> ConstPtr a -> Bool
<= :: ConstPtr a -> ConstPtr a -> Bool
$c> :: forall a. ConstPtr a -> ConstPtr a -> Bool
> :: ConstPtr a -> ConstPtr a -> Bool
$c>= :: forall a. ConstPtr a -> ConstPtr a -> Bool
>= :: ConstPtr a -> ConstPtr a -> Bool
$cmax :: forall a. ConstPtr a -> ConstPtr a -> ConstPtr a
max :: ConstPtr a -> ConstPtr a -> ConstPtr a
$cmin :: forall a. ConstPtr a -> ConstPtr a -> ConstPtr a
min :: ConstPtr a -> ConstPtr a -> ConstPtr a
Ord)

-- doesn't use record syntax
instance Show (ConstPtr a) where
    showsPrec :: Int -> ConstPtr a -> ShowS
showsPrec Int
d (ConstPtr Ptr a
p) = Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"ConstPtr " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Ptr a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Ptr a
p