[Bf-blender-cvs] [a27772c] master: Fix makesdna not checking alignment for a non-native platform
Sergey Sharybin
noreply at git.blender.org
Mon May 9 09:55:13 CEST 2016
Commit: a27772cd661839b0194acb782fdf8beab19b000d
Author: Sergey Sharybin
Date: Mon May 9 09:53:50 2016 +0200
Branches: master
https://developer.blender.org/rBa27772cd661839b0194acb782fdf8beab19b000d
Fix makesdna not checking alignment for a non-native platform
This was causing alignment issues which were only visible on a platform
of particular bitness, so it was easy to break stuff for 32bit when
working on 64bit platform and vice versa.
===================================================================
M source/blender/makesdna/DNA_gpencil_types.h
M source/blender/makesdna/intern/makesdna.c
===================================================================
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 43d4201..41f53f9 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -80,7 +80,7 @@ typedef struct bGPDstroke {
bGPDtriangle *triangles;/* tesselated triangles for GP Fill */
int tot_triangles; /* number of triangles in array */
- short pad2[2]; /* avoid compiler align error */
+ int pad1, *pad2;
double inittime; /* Init time of stroke */
} bGPDstroke;
diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c
index 651794d..fc94a8d 100644
--- a/source/blender/makesdna/intern/makesdna.c
+++ b/source/blender/makesdna/intern/makesdna.c
@@ -720,6 +720,28 @@ static int arraysize(const char *str)
return mul;
}
+static bool check_field_alignment(int firststruct, int structtype, int type, int len,
+ const char *name, const char *detail)
+{
+ bool result = true;
+ if (type < firststruct && typelens_native[type] > 4 && (len % 8)) {
+ fprintf(stderr, "Align 8 error (%s) in struct: %s %s (add %d padding bytes)\n",
+ detail, types[structtype], name, len % 8);
+ result = false;
+ }
+ if (typelens_native[type] > 3 && (len % 4) ) {
+ fprintf(stderr, "Align 4 error (%s) in struct: %s %s (add %d padding bytes)\n",
+ detail, types[structtype], name, len % 4);
+ result = false;
+ }
+ if (typelens_native[type] == 2 && (len % 2) ) {
+ fprintf(stderr, "Align 2 error (%s) in struct: %s %s (add %d padding bytes)\n",
+ detail, types[structtype], name, len % 2);
+ result = false;
+ }
+ return result;
+}
+
static int calculate_structlens(int firststruct)
{
int unknown = nr_structs, lastunknown;
@@ -815,20 +837,11 @@ static int calculate_structlens(int firststruct)
}
}
- /* 2-4-8 aligned/ */
- if (type < firststruct && typelens_native[type] > 4 && (len_native % 8)) {
- fprintf(stderr, "Align 8 error in struct: %s %s (add %d padding bytes)\n",
- types[structtype], cp, len_native % 8);
- dna_error = 1;
- }
- if (typelens_native[type] > 3 && (len_native % 4) ) {
- fprintf(stderr, "Align 4 error in struct: %s %s (add %d padding bytes)\n",
- types[structtype], cp, len_native % 4);
+ /* Check 2-4-8 aligned. */
+ if (!check_field_alignment(firststruct, structtype, type, len_32, cp, "32 bit")) {
dna_error = 1;
}
- else if (typelens_native[type] == 2 && (len_native % 2) ) {
- fprintf(stderr, "Align 2 error in struct: %s %s (add %d padding bytes)\n",
- types[structtype], cp, len_native % 2);
+ if (!check_field_alignment(firststruct, structtype, type, len_64, cp, "64 bit")) {
dna_error = 1;
}
More information about the Bf-blender-cvs
mailing list