summaryrefslogtreecommitdiff
path: root/docs/users_guide
diff options
context:
space:
mode:
authorRyanGlScott <ryan.gl.scott@gmail.com>2015-12-19 11:09:52 +0100
committerThomas Miedema <thomasmiedema@gmail.com>2015-12-19 11:09:59 +0100
commit2cc5b607df27e702541985f7c4c987806c4ec2a1 (patch)
tree2ab126c6dccef992bf689a336a3aed6590a7d052 /docs/users_guide
parentb2670fc47754288224b825a3308b92642ccf7e73 (diff)
downloadhaskell-2cc5b607df27e702541985f7c4c987806c4ec2a1.tar.gz
Documentation, tests for hsc2hs's new #alignment macro
Adds two tests (one for Trac #4340 and one for Trac #10272), as well as advice on how to fix your code if `hsc2hs` emits warnings with GHC 8.0 due to a redefinition of `#alignment`. (I also put the advice in the [GHC 8.0 Migration Guide](https://ghc.haskell.org/trac/ghc/wiki/Migration/8.0).) Reviewed By: thomie Differential Revision: https://phabricator.haskell.org/D1663 GHC Trac Issues: #4340, #10272
Diffstat (limited to 'docs/users_guide')
-rw-r--r--docs/users_guide/7.12.1-notes.rst26
-rw-r--r--docs/users_guide/utils.rst4
2 files changed, 30 insertions, 0 deletions
diff --git a/docs/users_guide/7.12.1-notes.rst b/docs/users_guide/7.12.1-notes.rst
index 749f7afbc1..d443a0a65e 100644
--- a/docs/users_guide/7.12.1-notes.rst
+++ b/docs/users_guide/7.12.1-notes.rst
@@ -321,6 +321,32 @@ Package system
- TODO FIXME.
+hsc2hs
+~~~~~~
+
+- ``hsc2hs`` now supports the ``#alignment`` macro, which can be used to
+ calculate the alignment of a struct in bytes. Previously, ``#alignment``
+ had to be implemented manually via a ``#let`` directive, e.g., ::
+
+ #let alignment t = "%lu", (unsigned long)offsetof(struct {char x__; t (y__); }, y__)
+
+ As a result, if you have the above directive in your code, it will now emit
+ a warning when compiled with GHC 8.0. ::
+
+ Module.hsc:24:0: warning: "hsc_alignment" redefined [enabled by default]
+ In file included from dist/build/Module_hsc_make.c:1:0:
+ /path/to/ghc/lib/template-hsc.h:88:0: note: this is the location of the previous definition
+ #define hsc_alignment(t...) \
+ ^
+
+ To make your code free of warnings on GHC 8.0 and still support earlier
+ versions, surround the directive with a pragma checking for the right GHC
+ version. ::
+
+ #if __GLASGOW_HASKELL__ < 800
+ #let alignment t = "%lu", (unsigned long)offsetof(struct {char x__; t (y__); }, y__)
+ #endif
+
Libraries
---------
diff --git a/docs/users_guide/utils.rst b/docs/users_guide/utils.rst
index 9c1237dd02..f490bfa2d8 100644
--- a/docs/users_guide/utils.rst
+++ b/docs/users_guide/utils.rst
@@ -224,6 +224,10 @@ Meanings of specific keywords:
Computes the size, in bytes, of ``struct_type``. It will have type
``Int``.
+``#alignment ⟨struct_type⟩``
+ Computes the alignment, in bytes, of ``struct_type``. It will have type
+ ``Int``.
+
``#enum ⟨type⟩, ⟨constructor⟩, ⟨value⟩, ⟨value⟩, ...``
A shortcut for multiple definitions which use ``#const``. Each
``value`` is a name of a C integer constant, e.g. enumeration value.