<div dir="ltr">Thanks Herbert! This is exactly the kind of data point I was looking for. Good to know.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 8, 2018 at 12:42 PM, Herbert Valerio Riedel <span dir="ltr"><<a href="mailto:hvriedel@gmail.com" target="_blank">hvriedel@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<span class=""><br>
On 2018-03-08 at 09:19:29 -0500, Andrew Martin wrote:<br>
> Some of the bytes in the word will have garbage in them. However, this<br>
> could always be masked out with a bit mask (you have to know the platform<br>
> endianness for this to work right).<br>
><br>
> Is this safe? I doubt think this could ever cause a segfault but I<br>
> wanted to check.<br>
<br>
</span>Due to historical reasons, this is indeed safe. the underlying<br>
`StgArrBytes` structure must be word-aligned in size, otherwise bad<br>
things are likely to happen.<br>
<br>
I've seem some code in the wild which relies on that, and as data-point,<br>
I myself exploit that property in some operations (including the masking<br>
and endianness-aware handling you refer to) of 'text-short'[1] which is<br>
optimised for UTF8-based strings (<shameless-plug>and which besides<br>
being a practically useful library having its place in the<br>
text/bytearray landscape[2], text-short also serves as an incubation<br>
area for optimisation ideas and code of which some may end up in one way<br>
or another in the text-utf8 project[3]</shameless-plug>).<br>
<br>
<br>
 [1]: <a href="https://hackage.haskell.org/package/text-short" rel="noreferrer" target="_blank">https://hackage.haskell.org/<wbr>package/text-short</a><br>
<br>
 [2]: <a href="https://markkarpov.com/post/short-bs-and-text.html" rel="noreferrer" target="_blank">https://markkarpov.com/post/<wbr>short-bs-and-text.html</a><br>
<br>
 [3]: <a href="https://hackage.haskell.org/text-utf8" rel="noreferrer" target="_blank">https://hackage.haskell.org/<wbr>text-utf8</a><br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
-- hvr<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">-Andrew Thaddeus Martin</div>
</div>