summaryrefslogtreecommitdiff
path: root/docs/users_guide
diff options
context:
space:
mode:
authornineonine <mail4chemik@gmail.com>2022-11-10 21:03:11 -0800
committerMatthew Pickering <matthewtpickering@gmail.com>2023-01-27 16:12:13 +0000
commit1d6f42895641555e18a2e4cdc664759b6d00dac4 (patch)
treeab93abbc0ceb37714a3bbaebfe206f36a3b951a8 /docs/users_guide
parentb95dab8b0807533de258e5fe985822ae393f5fef (diff)
downloadhaskell-wip/T22043.tar.gz
CApiFFI: add ConstPtr for encoding const-qualified pointer return typeswip/T22043
Previously, when using `capi` calling convention in foreign declarations, code generator failed to handle const-cualified pointer return types. This resulted in CC toolchain throwing `-Wincompatible-pointer-types-discards-qualifiers` warning. `Foreign.C.Types.ConstPtr` newtype was introduced to handle these cases - special treatment was put in place to generate appropritetly qualified C wrapper that no longer triggers the above mentioned warning. Fixes #22043.
Diffstat (limited to 'docs/users_guide')
-rw-r--r--docs/users_guide/9.6.1-notes.rst3
-rw-r--r--docs/users_guide/exts/ffi.rst12
2 files changed, 15 insertions, 0 deletions
diff --git a/docs/users_guide/9.6.1-notes.rst b/docs/users_guide/9.6.1-notes.rst
index e78972a919..f0961348f3 100644
--- a/docs/users_guide/9.6.1-notes.rst
+++ b/docs/users_guide/9.6.1-notes.rst
@@ -167,6 +167,9 @@ Runtime system
``ghc`` library
~~~~~~~~~~~~~~~
+- Add `Foreign.C.Types.ConstPtr` was added to encode ``const``-qualified pointer return
+ types in foreign declarations when using ``CApiFFI`` extension.
+
``ghc-heap`` library
~~~~~~~~~~~~~~~~~~~~
diff --git a/docs/users_guide/exts/ffi.rst b/docs/users_guide/exts/ffi.rst
index b490ac662d..37d96a0a68 100644
--- a/docs/users_guide/exts/ffi.rst
+++ b/docs/users_guide/exts/ffi.rst
@@ -437,6 +437,18 @@ specified. The syntax looks like: ::
data {-# CTYPE "unistd.h" "useconds_t" #-} T = ...
newtype {-# CTYPE "useconds_t" #-} T = ...
+In case foreign declarations contain ``const``-qualified pointer return
+type, ``ConstPtr`` from :base-ref:`Foreign.C.ConstPtr` may be used to
+encode this, e.g. ::
+
+ foreign import capi "header.h f" f :: CInt -> ConstPtr CInt
+
+which corresponds to
+
+.. code-block:: c
+
+ const *int f(int);
+
``hs_thread_done()``
~~~~~~~~~~~~~~~~~~~~