New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
long in struct causes incorrect align on 32-bit linux (BridJ) #320
Comments
I'm guessing the problem is somewhere around lines 603-608 of StructIO.java:
Possibly this needs to check Platform.isLinux(), and whether the field is a double or not, and whether the platform is 32-bits, and align to 4-bytes if: isLInux() && isDouble() && is32Bits() ? |
Note that this issue does not exist in 64-bit (understandable since linux double aligns on 8-byte in 64-bit). It is specific to 32-bit linux. |
Hi Olivier, Did you have any thoughts on this? I have the same problem and wrote a Customizer to correct it: public class ScoreAlignmentCustomizer extends DefaultCustomizer {
@Override
public void beforeLayout(StructIO io, List<AggregatedFieldDesc> aggregatedFields) {
for (AggregatedFieldDesc field : aggregatedFields) {
if (field.fields.get(0).toString().contains("score")) {
if (Platform.isLinux() && !Platform.is64Bits()) {
field.alignment = 4;
} else {
field.alignment = 8;
}
}
}
}
} However it results in an "Unaligned pointer access" exception from BridJ. I enabled SUPPORTS_UNALIGNED_ACCESS for all platforms in bridj.hpp and it now all works correctly but obviously I'm concerned about the impact of enabling SUPPORTS_UNALIGNED_ACCESS under Linux and also the inelegance of the customizer. I would be happy to try and update the code in StructIO and generate a pull request to avoid the Customizer but that will still result in the Unaligned error. Any help would be greatly appreciated. |
… added BRIDJ_ALIGN_DOUBLE / bridj.alignDouble option (issue #320)
Hi @hughperkins , @ESTW , This should be fixed in the next release (0.6.2), which I'm unfortunately taking an unusually long time to perform (I'm still waiting for the renewal of my code signing certificates to publish to Maven Central :-S). Will let you know here when it's available, in the meanwhile please build from sources. Cheers |
Hi @ochafik Thanks, that's great. I have tested it and it has resolved the need for the Customizer however with the latest source it still results in the "Unaligned pointer access !" error i.e.
This appears to work by defining SUPPORTS_UNALIGNED_ACCESS in BridJ/src/main/cpp/bridj/bridj.hpp for Linux however I'm not sure if that's the right solution? Thanks again. |
Ouch, sorry about that one! Pointer-related code must indeed let this half-alignment pass through properly. |
Sorry about the huge delay! |
Great, thanks Olivier. I'll give it a run through this week and let you On Sun, Jun 9, 2013 at 8:18 PM, Olivier Chafik notifications@github.comwrote:
|
long in struct causes incorrect align on 32-bit linux
if I pass this struct in to a method:
which method looks like:
... then the first 2 doubles print correctly, whereas the third one is garbage.
I think that this is because the 'long' field causes incorrect alignment/padding for subsequent fields.
Environment: ubuntu linux 12.04, 32-bit
Note that this is still unsolved in bridj-0.6.2-20120618.225518-13.jar snapshot
Note that adding one additional long before the last double causes the last double to display correctly.
What I think is happening:
( http://en.wikipedia.org/wiki/Data_structure_alignment: "A double (eight bytes) will be 8-byte aligned on Windows and 4-byte aligned on Linux (8-byte with -malign-double compile time option)." )
The text was updated successfully, but these errors were encountered: