pidl:Samba4/NDR/Parser: add support for 'ms_union' style aligment
[samba.git] / pidl / lib / Parse / Pidl / Samba4 / NDR / Parser.pm
index 5802f9b39309b32f268cf56ccffbf8434e22ad5c..69c13866250f6d997da62a32e7a36d1e6a50fc4a 100644 (file)
@@ -1688,16 +1688,21 @@ sub ParseUnionPushPrimitives($$$$)
 
        $self->pidl("uint32_t level = ndr_push_get_switch_value($ndr, $varname);");
 
-       if (defined($e->{ALIGN})) {
-               $self->pidl("NDR_CHECK(ndr_push_union_align($ndr, $e->{ALIGN}));");
-       }
-
        if (defined($e->{SWITCH_TYPE})) {
+               if (defined($e->{ALIGN})) {
+                       $self->pidl("NDR_CHECK(ndr_push_union_align($ndr, $e->{ALIGN}));");
+               }
+
                $self->pidl("NDR_CHECK(ndr_push_$e->{SWITCH_TYPE}($ndr, NDR_SCALARS, level));");
        }
 
        if (defined($e->{ALIGN})) {
-               $self->pidl("NDR_CHECK(ndr_push_union_align($ndr, $e->{ALIGN}));");
+               if ($e->{IS_MS_UNION}) {
+                       $self->pidl("/* ms_union is always aligned to the largest union arm*/");
+                       $self->pidl("NDR_CHECK(ndr_push_align($ndr, $e->{ALIGN}));");
+               } else {
+                       $self->pidl("NDR_CHECK(ndr_push_union_align($ndr, $e->{ALIGN}));");
+               }
        }
 
        $self->pidl("switch (level) {");
@@ -1837,11 +1842,12 @@ sub ParseUnionPullPrimitives($$$$$)
        my ($self,$e,$ndr,$varname,$switch_type) = @_;
        my $have_default = 0;
 
-       if (defined($e->{ALIGN})) {
-               $self->pidl("NDR_CHECK(ndr_pull_union_align($ndr, $e->{ALIGN}));");
-       }
 
        if (defined($switch_type)) {
+               if (defined($e->{ALIGN})) {
+                       $self->pidl("NDR_CHECK(ndr_pull_union_align($ndr, $e->{ALIGN}));");
+               }
+
                $self->pidl("NDR_CHECK(ndr_pull_$switch_type($ndr, NDR_SCALARS, &_level));");
                $self->pidl("if (_level != level) {"); 
                $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_BAD_SWITCH, \"Bad switch value %u for $varname at \%s\", _level, __location__);");
@@ -1849,7 +1855,12 @@ sub ParseUnionPullPrimitives($$$$$)
        }
 
        if (defined($e->{ALIGN})) {
-               $self->pidl("NDR_CHECK(ndr_pull_union_align($ndr, $e->{ALIGN}));");
+               if ($e->{IS_MS_UNION}) {
+                       $self->pidl("/* ms_union is always aligned to the largest union arm*/");
+                       $self->pidl("NDR_CHECK(ndr_push_align($ndr, $e->{ALIGN}));");
+               } else {
+                       $self->pidl("NDR_CHECK(ndr_pull_union_align($ndr, $e->{ALIGN}));");
+               }
        }
 
        $self->pidl("switch (level) {");