@mflatt user mrm on IRC asked yesterday if there were any explanation of how linklets work. Do you have something within hyperlink’s reach ? I had a quick look at your racket7 repo, but didn’t see any obvious pointers.
@georges-duperon I guess this is as close as it gets to web-accessible: https://github.com/racket/racket7/blob/master/pkgs/racket-doc/scribblings/reference/linklet.scrbl
@mflatt Thanks! I had explicitly searched for files containing “linklet” in the repo, and somehow managed to miss that one :slightly_smiling_face:
Does anyone know how to ‘collapse’ the padding in two cstructs in the FFI?
Like, I have a struct with a lot of fields, and in the middle, I have for a list size, followed by a pointer to that list.
I want to make a ctype that will give me a safe list given those two values.
And I can do that in another cstruct, but because the padding is now larger, it messes up the offsets for the rest of the struct.
So, is there any way I can insert a cstruct into another cstruct such that it takes the paddings of the element in the inner cstruct?
Either way, thank you.
@leif You be able to achieve the effect you want by declaring #:alignment
Okay cool. In which cstruct?
Like, it seems like I’d need to set it in the outer one, and then manually calculate the allignment for the rest of the struct, is tht correct @mflatt ?
I was thinking that you’d set it for the inner one
Oh, okay. In that case the docs kind of confused me what it does. As I thought you attached it to specific fields?
(I mean, I know you can attach it to the whole struct, but in this case, I only want one field to be alligned differently.)
Oh, I see what you mean, #:alignment 1
worked, thank you @mflatt
@zenspider has joined the channel
@mflatt Actually, after thinking about it a bit more, I don’t think #:alignment 1
would work, or any ‘alignment’ on the inside struct would be good enough.
Because this is going to be context sensitive on the placement of the outside struct and its alignment.
Like, if I had: struct{
char prefix,
char count,
void *data
}
, I would want it to be compacted (on 32-bit x86 for simplicity) as: [prefix][count][padding][padding][padding][data][data][data][data]
(Where I have specified each byte in [...]
)
But when I do #:alignment 1
on the inner struct, the layout is going to be:
[prefix][count][data][data][data][data]
which removes the padding.
Any thoughts @mflatt ?
@leif I think you’d have to add the padding back manually in that case. There’s not much in between “do the default thing” and “let me control layout completely”.
@mflatt Ah fair. Well thank you.