<div dir="auto">I forgot about that addition. In that case we would just need the lifted wrapper</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 20, 2021, 17:01 Viktor Dukhovni <<a href="mailto:ietf-dane@dukhovni.org">ietf-dane@dukhovni.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, Jan 20, 2021 at 09:54:30AM -0800, chessai wrote:<br>
<br>
> I've wanted the following before:<br>
> <br>
> foreign import ccall unsafe "strlen"<br>
> cstringLength# :: Addr# -> Int#<br>
> <br>
> cstringLength :: CString -> Int<br>
> cstringLength (Ptr s) = I# (cstringLength# s)<br>
> <br>
> A natural place for this seems to be Foreign.C.String.<br>
<br>
Why a new FFI call, rather than `cstringLength#` from ghc-prim: GHC.CString<br>
(as of GHC 9.0.1):<br>
<br>
9.0.1-notes.rst: ``ghc-prim`` library<br>
9.0.1-notes.rst: ~~~~~~~~~~~~~~~~~~~~<br>
9.0.1-notes.rst: <br>
9.0.1-notes.rst: - Add a known-key ``cstringLength#`` to ``GHC.CString`` that is eligible<br>
9.0.1-notes.rst: for constant folding by a built-in rule.<br>
<br>
ghc-prim/changelog.md: - Add known-key `cstringLength#` to `GHC.CString`. This is just the<br>
ghc-prim/changelog.md: C function `strlen`, but a built-in rewrite rule allows GHC to<br>
ghc-prim/changelog.md: compute the result at compile time when the argument is known.<br>
<br>
CString.hs: -- | Compute the length of a NUL-terminated string. This address<br>
CString.hs: -- must refer to immutable memory. GHC includes a built-in rule for<br>
CString.hs: -- constant folding when the argument is a statically-known literal.<br>
CString.hs: -- That is, a core-to-core pass reduces the expression<br>
CString.hs: -- @cstringLength# "hello"#@ to the constant @5#@.<br>
CString.hs: cstringLength# :: Addr# -> Int#<br>
CString.hs: {-# INLINE[0] cstringLength# #-}<br>
CString.hs: cstringLength# = c_strlen<br>
<br>
Which is in turn re-exported by GHC.Exts:<br>
<br>
GHC/Exts.hs: -- * CString<br>
GHC/Exts.hs: unpackCString#,<br>
GHC/Exts.hs: unpackAppendCString#,<br>
GHC/Exts.hs: unpackFoldrCString#,<br>
GHC/Exts.hs: unpackCStringUtf8#,<br>
GHC/Exts.hs: unpackNBytes#,<br>
GHC/Exts.hs: cstringLength#,<br>
<br>
It is perhaps somewhat disappointing that the cstringLength#<br>
optimisations for `bytestring` (in master) aren't included in the<br>
`bytestring` version in 9.0.1.<br>
<br>
-- <br>
Viktor.<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank" rel="noreferrer">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>