<div dir="auto">Can you do that? I know with the UnliftedFFI you can use ByteArray# and if you have something like uint8_t*, it will make sure that the pointer lines up with the payload of the ByteArray#. You could always just wrap it in Data.Primitive.ByteArray.ByteArray, no? That is to say, I don't think GHC can do what you're asking.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 10, 2019, 4:10 PM Shao, Cheng <<a href="mailto:cheng.shao@tweag.io">cheng.shao@tweag.io</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Yes, and specifically, the lifted ByteArray type as described in the<br>
comments, not the unlifted ByteArray# type.<br>
<br>
On Fri, Oct 11, 2019 at 4:00 AM Csaba Hruska <<a href="mailto:csaba.hruska@gmail.com" target="_blank" rel="noreferrer">csaba.hruska@gmail.com</a>> wrote:<br>
><br>
> Sorry, maybe I got it wrong. Are you asking if is there any package that passes ByteArrays via FFI?<br>
><br>
> On Thu, Oct 10, 2019 at 8:54 PM Csaba Hruska <<a href="mailto:csaba.hruska@gmail.com" target="_blank" rel="noreferrer">csaba.hruska@gmail.com</a>> wrote:<br>
>><br>
>> It's a primitive type.<br>
>> <a href="https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/prelude/primops.txt.pp#L1388" rel="noreferrer noreferrer" target="_blank">https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/prelude/primops.txt.pp#L1388</a><br>
>> <a href="https://gitlab.haskell.org/ghc/ghc/wikis/commentary/prim-ops" rel="noreferrer noreferrer" target="_blank">https://gitlab.haskell.org/ghc/ghc/wikis/commentary/prim-ops</a><br>
>><br>
>> Cheers,<br>
>> Csaba<br>
>><br>
>> On Thu, Oct 10, 2019 at 8:16 PM Shao, Cheng <<a href="mailto:cheng.shao@tweag.io" target="_blank" rel="noreferrer">cheng.shao@tweag.io</a>> wrote:<br>
>>><br>
>>> Hello devs,<br>
>>><br>
>>> I've been trying to figure out how to pass lifted types as foreign<br>
>>> types, then encountered the following code in the `DsCCall` module<br>
>>> (<a href="https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/deSugar/DsCCall.hs#L172" rel="noreferrer noreferrer" target="_blank">https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/deSugar/DsCCall.hs#L172</a>):<br>
>>><br>
>>> ```<br>
>>>   -- Byte-arrays, both mutable and otherwise; hack warning<br>
>>>   -- We're looking for values of type ByteArray, MutableByteArray<br>
>>>   --    data ByteArray          ix = ByteArray        ix ix ByteArray#<br>
>>>   --    data MutableByteArray s ix = MutableByteArray ix ix<br>
>>> (MutableByteArray# s)<br>
>>>   | is_product_type &&<br>
>>>     data_con_arity == 3 &&<br>
>>>     isJust maybe_arg3_tycon &&<br>
>>>     (arg3_tycon ==  byteArrayPrimTyCon ||<br>
>>>      arg3_tycon ==  mutableByteArrayPrimTyCon)<br>
>>>   = do case_bndr <- newSysLocalDs arg_ty<br>
>>>        vars@[_l_var, _r_var, arr_cts_var] <- newSysLocalsDs data_con_arg_tys<br>
>>>        return (Var arr_cts_var,<br>
>>>                \ body -> Case arg case_bndr (exprType body) [(DataAlt<br>
>>> data_con,vars,body)]<br>
>>>               )<br>
>>> ```<br>
>>><br>
>>> It seems we allow a "ByteArray" type as a foreign import argument, if<br>
>>> the third field of the datacon is a ByteArray# or MutableByteArray#.<br>
>>> But I can't find such a ByteArray type definition in today's common<br>
>>> packages. What's the rationale for this piece of code?<br>
>>><br>
>>> Cheers,<br>
>>> Cheng<br>
>>> _______________________________________________<br>
>>> ghc-devs mailing list<br>
>>> <a href="mailto:ghc-devs@haskell.org" target="_blank" rel="noreferrer">ghc-devs@haskell.org</a><br>
>>> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank" rel="noreferrer">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
</blockquote></div>