r7187: fix alignment of unions
authorStefan Metzmacher <metze@samba.org>
Thu, 2 Jun 2005 05:17:08 +0000 (05:17 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:17:24 +0000 (13:17 -0500)
metze
(This used to be commit b9e50a47f165ba120cd99f2a2b25256b6420681b)

source4/build/pidl/ndr.pm
source4/build/pidl/ndr_parser.pm

index 69e65c0697cc861c6e29f8f06756a9aff46afe60..b41d130011696bb35fd5ef4b9fae0e5ebd364300 100644 (file)
@@ -273,7 +273,8 @@ sub ParseElement($)
                NAME => $e->{NAME},
                TYPE => $e->{TYPE},
                PROPERTIES => $e->{PROPERTIES},
-               LEVELS => GetElementLevelTable($e)
+               LEVELS => GetElementLevelTable($e),
+               ALIGN => align_type($e->{TYPE})
        };
 }
 
index dcc17b29847e842af6882c425af4d66a24904509..60000430419af74be4f7e8a18b3ea0673c9a6a07 100644 (file)
@@ -1542,14 +1542,6 @@ sub ParseUnionPush($$)
                pidl "NDR_CHECK(ndr_push_$e->{SWITCH_TYPE}(ndr, NDR_SCALARS, level));";
        }
 
-       pidl "NDR_CHECK(ndr_push_align(ndr, $e->{ALIGN}));";
-
-       if (defined($e->{PROPERTIES}{relative_base})) {
-               # set the current offset as base for relative pointers
-               # and store it based on the toplevel struct/union
-               pidl "NDR_CHECK(ndr_push_setup_relative_base_offset1(ndr, r, ndr->offset));";
-       }
-
        pidl "switch (level) {";
        indent;
        foreach my $el (@{$e->{ELEMENTS}}) {
@@ -1560,6 +1552,12 @@ sub ParseUnionPush($$)
 
                if ($el->{TYPE} ne "EMPTY") {
                        indent;
+                       if (defined($e->{PROPERTIES}{relative_base})) {
+                               pidl "NDR_CHECK(ndr_push_align(ndr, $el->{ALIGN}));";
+                               # set the current offset as base for relative pointers
+                               # and store it based on the toplevel struct/union
+                               pidl "NDR_CHECK(ndr_push_setup_relative_base_offset1(ndr, r, ndr->offset));";
+                       }
                        DeclareArrayVariables($el);
                        ParseElementPush($el, "ndr", "r->", {}, 1, 0);
                        deindent;
@@ -1683,14 +1681,6 @@ sub ParseUnionPull($$)
                pidl "}";
        }
 
-       pidl "NDR_CHECK(ndr_pull_align(ndr, $e->{ALIGN}));";
-
-       if (defined($e->{PROPERTIES}{relative_base})) {
-               # set the current offset as base for relative pointers
-               # and store it based on the toplevel struct/union
-               pidl "NDR_CHECK(ndr_pull_setup_relative_base_offset1(ndr, r, ndr->offset));";
-       }
-
        pidl "switch (level) {";
        indent;
        foreach my $el (@{$e->{ELEMENTS}}) {
@@ -1703,6 +1693,12 @@ sub ParseUnionPull($$)
                        indent;
                        DeclarePtrVariables($el);
                        DeclareArrayVariables($el);
+                       if (defined($e->{PROPERTIES}{relative_base})) {
+                               pidl "NDR_CHECK(ndr_pull_align(ndr, $el->{ALIGN}));";
+                               # set the current offset as base for relative pointers
+                               # and store it based on the toplevel struct/union
+                               pidl "NDR_CHECK(ndr_pull_setup_relative_base_offset1(ndr, r, ndr->offset));";
+                       }
                        ParseElementPull($el, "ndr", "r->", {}, 1, 0);
                        deindent;
                }