Re: Need help with creating a GUI window on Linux using libxcb.so XCB API
- Posted by mattlewis (admin) Jul 03, 2013
- 1487 views
Side note: I know Matt's been working on struct support for 4.1. Any chance that could make its way to returning structs-by-value via c_func/c_proc? This would help with a few other libraries as well.
We'd have to understand how compilers handle this. I've never looked to see what they do in those cases, but I agree that it would be extremely useful.
Matt
My understanding was that structs, when returned (passed by value) from a C function, will be passed on the stack. So, a struct made up of 5 elements, each being a 32bit int, will take up 20 bytes of stack space. Likewise, a struct made up of a single element, an array of bytes, with the array having a length of 12, will take up 3 dwords of stack space.
I was thinking that, in these cases, we could somehow encode the length of the struct in the return type, and return a sequence of bytes to be reconstructed by the caller.
We'd have to figure out how to get that stuff off the stack. Yuck. And I suspect it will work differently on different architectures. Double yuck. Especially considering the semi-hardcoded way we call stuff on x86-64 (and ARM? I can't recall of the top of my head).
I would rather return a sequence containing the data as it would appear if you peeked it as a memstruct.
Matt