genius257 / DllStructEx

Extended DllStruct for AutoIt3
MIT License
2 stars 1 forks source link

byte alignment/padding issue #15

Closed genius257 closed 2 years ago

genius257 commented 3 years ago

byte alignment/padding is wrong for items within an nested struct and union. The solutions are not pretty at this stage, but a simple version would be to act, when first element type is requested, and solve the ptr offset from the top and down, via DLLStruct get ptr and using the transpiled struct strings, with the first element from the solved struct/union on the selected element branch. finding and replacing the bytes allocated with the solved, appropriate type is easy, thanks to everything relevant, having a name and the predictable format of the transpiled struct.

This does mean the current version of this UDF is unreliable, when working with unions and nested structs.

genius257 commented 3 years ago

I am currently doing a lot of headwork, for preparing the best approach, with as little waste of my spare time to code as possible.

genius257 commented 2 years ago

So after looking into it, it seems to be troublesome for this library to calculate the expected padding between declarations. special cases like align may change behavior of a nested struct type and keeping track of that would require rewriting a lot of code. There are also missing information, like what the struct;...endstruct; case does. It tells us it should be used for c++ nested structures, but not why. In my tests it seems to do nothing with alignment, and i haven't persuaded myself to ask on the forum.

The best fix i can see is that nested structs should internally resolve to the normal structure string instead of a byte array (due to it causing the padding to break). Finally the nested struct used internally should have all members stripped of their name and the first element should receive the expected identifier for the nested struct ref.

This will solve the problem for most things, except unions. From what i can gather c++ unions still have byte alignment/padding done for each case. This will mean the solution here is an iterative approach where each case needs to save their expected alignment for later use in code. I expect unions to take a while to solve.