The branch, master has been updated
       via  9fe4b69 pidl:Samba4/NDR/Parser: add support for 'ms_union' style 
aligment
       via  6124148 pidl:Samba4/NDR/Parser: only do the switch type alignment 
when we have a switch type
       via  76f2ddf pidl:NDR: add support for 'ms_union' property.
       via  5ae04bc midltests: add invalid/midltests_pipe_struct_union_01.idl
      from  6696fd1 Ensure we send the direct levelII oplock break to the 
correct fid.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 9fe4b695feefb2a94559ce978048fb8a2189f5ab
Author: Stefan Metzmacher <me...@samba.org>
Date:   Mon Jan 31 14:09:02 2011 +0100

    pidl:Samba4/NDR/Parser: add support for 'ms_union' style aligment
    
    metze
    
    Autobuild-User: Stefan Metzmacher <me...@samba.org>
    Autobuild-Date: Tue Feb  1 12:13:45 CET 2011 on sn-devel-104

commit 6124148d66d90064ebe3fa2ecb2c6588705495a0
Author: Stefan Metzmacher <me...@samba.org>
Date:   Mon Jan 31 14:05:52 2011 +0100

    pidl:Samba4/NDR/Parser: only do the switch type alignment when we have a 
switch type
    
    This doesn't change the logic, it just doesn't call the same aligment 
function
    twice.
    
    metze

commit 76f2ddf5a9cef9e8253b11dec1304d51e47eda54
Author: Stefan Metzmacher <me...@samba.org>
Date:   Mon Jan 31 13:23:08 2011 +0100

    pidl:NDR: add support for 'ms_union' property.
    
    metze

commit 5ae04bca01b974672fcc3c68acf3fc9bab61ba05
Author: Stefan Metzmacher <me...@samba.org>
Date:   Tue Feb 1 09:59:59 2011 +0100

    midltests: add invalid/midltests_pipe_struct_union_01.idl
    
    pipes with unions are not supported by midl,
    so we don't need to implement them in pidl:-)
    
    metze

-----------------------------------------------------------------------

Summary of changes:
 pidl/lib/Parse/Pidl/NDR.pm                         |   61 ++++++-----
 pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm           |   29 ++++--
 pidl/tests/ndr.pl                                  |   39 ++++----
 .../midltests_pipe_struct_union_01.idl}            |  115 +++++++++++---------
 .../invalid/midltests_pipe_struct_union_01.txt     |   17 +++
 5 files changed, 152 insertions(+), 109 deletions(-)
 copy testprogs/win32/midltests/{todo/midltests-pipe-04-struct.idl => 
invalid/midltests_pipe_struct_union_01.idl} (96%)
 create mode 100644 
testprogs/win32/midltests/invalid/midltests_pipe_struct_union_01.txt


Changeset truncated at 500 lines:

diff --git a/pidl/lib/Parse/Pidl/NDR.pm b/pidl/lib/Parse/Pidl/NDR.pm
index 21b7568..3edb9b7 100644
--- a/pidl/lib/Parse/Pidl/NDR.pm
+++ b/pidl/lib/Parse/Pidl/NDR.pm
@@ -81,9 +81,9 @@ my $scalar_alignment = {
        'dnsp_string' => 1
 };
 
-sub GetElementLevelTable($$)
+sub GetElementLevelTable($$$)
 {
-       my ($e, $pointer_default) = @_;
+       my ($e, $pointer_default, $ms_union) = @_;
 
        my $order = [];
        my $is_deferred = 0;
@@ -307,9 +307,9 @@ sub GetElementLevelTable($$)
        return $order;
 }
 
-sub GetTypedefLevelTable($$$)
+sub GetTypedefLevelTable($$$$)
 {
-       my ($e, $data, $pointer_default) = @_;
+       my ($e, $data, $pointer_default, $ms_union) = @_;
 
        my $order = [];
 
@@ -432,30 +432,30 @@ sub align_type($)
        die("Unknown data type type $dt->{TYPE}");
 }
 
-sub ParseElement($$)
+sub ParseElement($$$)
 {
-       my ($e, $pointer_default) = @_;
+       my ($e, $pointer_default, $ms_union) = @_;
 
        $e->{TYPE} = expandAlias($e->{TYPE});
 
        if (ref($e->{TYPE}) eq "HASH") {
-               $e->{TYPE} = ParseType($e->{TYPE}, $pointer_default);
+               $e->{TYPE} = ParseType($e->{TYPE}, $pointer_default, $ms_union);
        }
 
        return {
                NAME => $e->{NAME},
                TYPE => $e->{TYPE},
                PROPERTIES => $e->{PROPERTIES},
-               LEVELS => GetElementLevelTable($e, $pointer_default),
+               LEVELS => GetElementLevelTable($e, $pointer_default, $ms_union),
                REPRESENTATION_TYPE => ($e->{PROPERTIES}->{represent_as} or 
$e->{TYPE}),
                ALIGN => align_type($e->{TYPE}),
                ORIGINAL => $e
        };
 }
 
-sub ParseStruct($$)
+sub ParseStruct($$$)
 {
-       my ($struct, $pointer_default) = @_;
+       my ($struct, $pointer_default, $ms_union) = @_;
        my @elements = ();
        my $surrounding = undef;
 
@@ -473,7 +473,7 @@ sub ParseStruct($$)
 
        foreach my $x (@{$struct->{ELEMENTS}}) 
        {
-               my $e = ParseElement($x, $pointer_default);
+               my $e = ParseElement($x, $pointer_default, $ms_union);
                if ($x != $struct->{ELEMENTS}[-1] and 
                        $e->{LEVELS}[0]->{IS_SURROUNDING}) {
                        fatal($x, "conformant member not at end of struct");
@@ -510,8 +510,10 @@ sub ParseStruct($$)
 
 sub ParseUnion($$)
 {
-       my ($e, $pointer_default) = @_;
+       my ($e, $pointer_default, $ms_union) = @_;
        my @elements = ();
+       my $is_ms_union = $ms_union;
+       $is_ms_union = 1 if has_property($e, "ms_union");
        my $hasdefault = 0;
        my $switch_type = has_property($e, "switch_type");
        unless (defined($switch_type)) { $switch_type = "uint32"; }
@@ -524,6 +526,7 @@ sub ParseUnion($$)
                ELEMENTS => undef,
                PROPERTIES => $e->{PROPERTIES},
                HAS_DEFAULT => $hasdefault,
+               IS_MS_UNION => $is_ms_union,
                ORIGINAL => $e,
                ALIGN => undef
        } unless defined($e->{ELEMENTS});
@@ -536,7 +539,7 @@ sub ParseUnion($$)
                if ($x->{TYPE} eq "EMPTY") {
                        $t = { TYPE => "EMPTY" };
                } else {
-                       $t = ParseElement($x, $pointer_default);
+                       $t = ParseElement($x, $pointer_default, $ms_union);
                }
                if (has_property($x, "default")) {
                        $t->{CASE} = "default";
@@ -561,6 +564,7 @@ sub ParseUnion($$)
                ELEMENTS => \@elements,
                PROPERTIES => $e->{PROPERTIES},
                HAS_DEFAULT => $hasdefault,
+               IS_MS_UNION => $is_ms_union,
                ORIGINAL => $e,
                ALIGN => $align
        };
@@ -568,7 +572,7 @@ sub ParseUnion($$)
 
 sub ParseEnum($$)
 {
-       my ($e, $pointer_default) = @_;
+       my ($e, $pointer_default, $ms_union) = @_;
 
        return {
                TYPE => "ENUM",
@@ -580,9 +584,9 @@ sub ParseEnum($$)
        };
 }
 
-sub ParseBitmap($$)
+sub ParseBitmap($$$)
 {
-       my ($e, $pointer_default) = @_;
+       my ($e, $pointer_default, $ms_union) = @_;
 
        return {
                TYPE => "BITMAP",
@@ -594,9 +598,9 @@ sub ParseBitmap($$)
        };
 }
 
-sub ParseType($$)
+sub ParseType($$$)
 {
-       my ($d, $pointer_default) = @_;
+       my ($d, $pointer_default, $ms_union) = @_;
 
        my $data = {
                STRUCT => \&ParseStruct,
@@ -604,14 +608,14 @@ sub ParseType($$)
                ENUM => \&ParseEnum,
                BITMAP => \&ParseBitmap,
                TYPEDEF => \&ParseTypedef,
-       }->{$d->{TYPE}}->($d, $pointer_default);
+       }->{$d->{TYPE}}->($d, $pointer_default, $ms_union);
 
        return $data;
 }
 
 sub ParseTypedef($$)
 {
-       my ($d, $pointer_default) = @_;
+       my ($d, $pointer_default, $ms_union) = @_;
 
        my $data;
 
@@ -621,7 +625,7 @@ sub ParseTypedef($$)
                        $d->{PROPERTIES} = $d->{DATA}->{PROPERTIES};
                }
 
-               $data = ParseType($d->{DATA}, $pointer_default);
+               $data = ParseType($d->{DATA}, $pointer_default, $ms_union);
                $data->{ALIGN} = align_type($d->{NAME});
        } else {
                $data = getType($d->{DATA});
@@ -631,7 +635,7 @@ sub ParseTypedef($$)
                NAME => $d->{NAME},
                TYPE => $d->{TYPE},
                PROPERTIES => $d->{PROPERTIES},
-               LEVELS => GetTypedefLevelTable($d, $data, $pointer_default),
+               LEVELS => GetTypedefLevelTable($d, $data, $pointer_default, 
$ms_union),
                DATA => $data,
                ORIGINAL => $d
        };
@@ -644,9 +648,9 @@ sub ParseConst($$)
        return $d;
 }
 
-sub ParseFunction($$$)
+sub ParseFunction($$$$)
 {
-       my ($ndr,$d,$opnum) = @_;
+       my ($ndr,$d,$opnum,$ms_union) = @_;
        my @elements = ();
        my $rettype = undef;
        my $thisopnum = undef;
@@ -659,7 +663,7 @@ sub ParseFunction($$$)
        }
 
        foreach my $x (@{$d->{ELEMENTS}}) {
-               my $e = ParseElement($x, $ndr->{PROPERTIES}->{pointer_default});
+               my $e = ParseElement($x, $ndr->{PROPERTIES}->{pointer_default}, 
$ms_union);
                push (@{$e->{DIRECTION}}, "in") if (has_property($x, "in"));
                push (@{$e->{DIRECTION}}, "out") if (has_property($x, "out"));
 
@@ -720,6 +724,8 @@ sub ParseInterface($)
        my @endpoints;
        my $opnum = 0;
        my $version;
+       my $ms_union = 0;
+       $ms_union = 1 if has_property($idl, "ms_union");
 
        if (not has_property($idl, "pointer_default")) {
                # MIDL defaults to "ptr" in DCE compatible mode (/osf)
@@ -729,11 +735,11 @@ sub ParseInterface($)
 
        foreach my $d (@{$idl->{DATA}}) {
                if ($d->{TYPE} eq "FUNCTION") {
-                       push (@functions, ParseFunction($idl, $d, \$opnum));
+                       push (@functions, ParseFunction($idl, $d, \$opnum, 
$ms_union));
                } elsif ($d->{TYPE} eq "CONST") {
                        push (@consts, ParseConst($idl, $d));
                } else {
-                       push (@types, ParseType($d, 
$idl->{PROPERTIES}->{pointer_default}));
+                       push (@types, ParseType($d, 
$idl->{PROPERTIES}->{pointer_default}, $ms_union));
                        FindNestedTypes(\@types, $d);
                }
        }
@@ -935,6 +941,7 @@ my %property_list = (
        "switch_is"             => ["ELEMENT"],
        "switch_type"           => ["ELEMENT", "UNION"],
        "nodiscriminant"        => ["UNION"],
+       "ms_union"              => ["INTERFACE", "UNION"],
        "case"                  => ["ELEMENT"],
        "default"               => ["ELEMENT"],
 
diff --git a/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm 
b/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
index 5802f9b..69c1386 100644
--- a/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
@@ -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) {");
diff --git a/pidl/tests/ndr.pl b/pidl/tests/ndr.pl
index 9c30189..b6fd489 100755
--- a/pidl/tests/ndr.pl
+++ b/pidl/tests/ndr.pl
@@ -22,7 +22,7 @@ my $e = {
        'PARENT' => { TYPE => 'STRUCT' },
        'LINE' => 42 };
 
-is_deeply(GetElementLevelTable($e, "unique"), [
+is_deeply(GetElementLevelTable($e, "unique", 0), [
        {
                'IS_DEFERRED' => 0,
                'LEVEL_INDEX' => 0,
@@ -33,7 +33,7 @@ is_deeply(GetElementLevelTable($e, "unique"), [
        }
 ]);
 
-my $ne = ParseElement($e, "unique");
+my $ne = ParseElement($e, "unique", 0);
 is($ne->{ORIGINAL}, $e);
 is($ne->{NAME}, "v");
 is($ne->{ALIGN}, 1);
@@ -60,7 +60,7 @@ $e = {
        'TYPE' => 'uint8',
        'LINE' => 42 };
 
-is_deeply(GetElementLevelTable($e, "unique"), [
+is_deeply(GetElementLevelTable($e, "unique", 0), [
        {
                LEVEL_INDEX => 0,
                IS_DEFERRED => 0,
@@ -90,7 +90,7 @@ $e = {
        'PARENT' => { TYPE => 'STRUCT' },
        'LINE' => 42 };
 
-is_deeply(GetElementLevelTable($e, "unique"), [
+is_deeply(GetElementLevelTable($e, "unique", 0), [
        {
                LEVEL_INDEX => 0,
                IS_DEFERRED => 0,
@@ -128,7 +128,7 @@ $e = {
        'PARENT' => { TYPE => 'STRUCT' },
        'LINE' => 42 };
 
-is_deeply(GetElementLevelTable($e, "unique"), [
+is_deeply(GetElementLevelTable($e, "unique", 0), [
        {
                LEVEL_INDEX => 0,
                IS_DEFERRED => 0,
@@ -158,7 +158,7 @@ $e = {
        'PARENT' => { TYPE => 'STRUCT' },
        'LINE' => 42 };
 
-is_deeply(GetElementLevelTable($e, "unique"), [
+is_deeply(GetElementLevelTable($e, "unique", 0), [
        {
                LEVEL_INDEX => 0,
                IS_DEFERRED => 0,
@@ -204,7 +204,7 @@ $e = {
        'PARENT' => { TYPE => 'STRUCT' },
        'LINE' => 42 };
 
-is_deeply(GetElementLevelTable($e, "ref"), [
+is_deeply(GetElementLevelTable($e, "ref", 0), [
        {
                LEVEL_INDEX => 0,
                IS_DEFERRED => 0,
@@ -250,7 +250,7 @@ $e = {
        'PARENT' => { TYPE => 'FUNCTION' },
        'LINE' => 42 };
 
-is_deeply(GetElementLevelTable($e, "unique"), [
+is_deeply(GetElementLevelTable($e, "unique", 0), [
        {
                LEVEL_INDEX => 0,
                IS_DEFERRED => 0,
@@ -280,7 +280,7 @@ $e = {
        'PARENT' => { TYPE => 'FUNCTION' },
        'LINE' => 42 };
 
-is_deeply(GetElementLevelTable($e, "unique"), [
+is_deeply(GetElementLevelTable($e, "unique", 0), [
        {
                LEVEL_INDEX => 0,
                IS_DEFERRED => 0,
@@ -326,7 +326,7 @@ $e = {
        'PARENT' => { TYPE => 'FUNCTION' },
        'LINE' => 42 };
 
-is_deeply(GetElementLevelTable($e, "unique"), [
+is_deeply(GetElementLevelTable($e, "unique", 0), [
        {
                LEVEL_INDEX => 0,
                IS_DEFERRED => 0,
@@ -372,7 +372,7 @@ $e = {
        'PARENT' => { TYPE => 'FUNCTION' },
        'LINE' => 42 };
 
-is_deeply(GetElementLevelTable($e, "ref"), [
+is_deeply(GetElementLevelTable($e, "ref", 0), [
        {
                LEVEL_INDEX => 0,
                IS_DEFERRED => 0,
@@ -418,7 +418,7 @@ $e = {
        'PARENT' => { TYPE => 'FUNCTION' },
        'LINE' => 42 };
 
-is_deeply(GetElementLevelTable($e, "ref"), [
+is_deeply(GetElementLevelTable($e, "ref", 0), [
        {
                LEVEL_INDEX => 0,
                IS_DEFERRED => 0,
@@ -463,7 +463,7 @@ $e = {
        'PARENT' => { TYPE => 'STRUCT' },
        'LINE' => 42 };
 
-$ne = ParseElement($e, undef);
+$ne = ParseElement($e, undef, 0);
 is($ne->{REPRESENTATION_TYPE}, "bar");
 
 # representation_type
@@ -476,7 +476,7 @@ $e = {
        'PARENT' => { TYPE => 'STRUCT' },
        'LINE' => 42 };
 
-$ne = ParseElement($e, undef);
+$ne = ParseElement($e, undef, 0);
 is($ne->{REPRESENTATION_TYPE}, "uint8");
 
 is(align_type("hyper"), 8);
@@ -521,7 +521,7 @@ $t = {
        },
        ALIGN => undef
 };
-is_deeply(ParseType($t->{ORIGINAL}, "ref"), $t); 
+is_deeply(ParseType($t->{ORIGINAL}, "ref", 0), $t);
 
 $t = {
        TYPE => "UNION",
@@ -530,13 +530,14 @@ $t = {
        ELEMENTS => undef,
        PROPERTIES => undef,
        HAS_DEFAULT => 0,
+       IS_MS_UNION => 0,
        ORIGINAL => {
                TYPE => "UNION",
                NAME => "foo"
        },
        ALIGN => undef
 };
-is_deeply(ParseType($t->{ORIGINAL}, "ref"), $t); 
+is_deeply(ParseType($t->{ORIGINAL}, "ref", 0), $t);
 
 ok(not can_contain_deferred("uint32"));
 ok(can_contain_deferred("some_unknown_type"));
@@ -553,8 +554,8 @@ ok(not can_contain_deferred({ TYPE => "TYPEDEF",
 ok(can_contain_deferred({ TYPE => "STRUCT", 
                ELEMENTS => [ { TYPE => "someunknowntype" } ]}));
 # Make sure the elements for a enum without body aren't filled in
-ok(not defined(ParseType({TYPE => "ENUM", NAME => "foo" }, 
"ref")->{ELEMENTS}));
+ok(not defined(ParseType({TYPE => "ENUM", NAME => "foo" }, "ref", 
0)->{ELEMENTS}));
 # Make sure the elements for a bitmap without body aren't filled in
-ok(not defined(ParseType({TYPE => "BITMAP", NAME => "foo" }, 
"ref")->{ELEMENTS}));
+ok(not defined(ParseType({TYPE => "BITMAP", NAME => "foo" }, "ref", 
0)->{ELEMENTS}));
 # Make sure the elements for a union without body aren't filled in
-ok(not defined(ParseType({TYPE => "UNION", NAME => "foo" }, 
"ref")->{ELEMENTS}));
+ok(not defined(ParseType({TYPE => "UNION", NAME => "foo" }, "ref", 
0)->{ELEMENTS}));
diff --git a/testprogs/win32/midltests/todo/midltests-pipe-04-struct.idl 
b/testprogs/win32/midltests/invalid/midltests_pipe_struct_union_01.idl
similarity index 96%
copy from testprogs/win32/midltests/todo/midltests-pipe-04-struct.idl
copy to testprogs/win32/midltests/invalid/midltests_pipe_struct_union_01.idl
index 07921b8..517806b 100644
--- a/testprogs/win32/midltests/todo/midltests-pipe-04-struct.idl
+++ b/testprogs/win32/midltests/invalid/midltests_pipe_struct_union_01.idl
@@ -11,6 +11,13 @@ interface midltests
        typedef struct {
                long l;
                short s;
+               [switch_is(l)] union {
+                       [case(0)];
+                       [case(1)] char c;
+                       [case(2)] short s;
+                       [case(4)] long l;
+                       [case(8)] hyper h;
+               } u;
        } structtype;
        typedef pipe structtype pipe_structtype;
 
@@ -21,8 +28,8 @@ interface midltests
 
        long midltests_fn(
                [out,ref] struct msg *out1,
-               [out] pipe_structtype outp,
-               [in] pipe_structtype inp,
+               [out,ref] pipe_structtype *outp,
+               [in,ref] pipe_structtype *inp,
                [in] struct msg in1
        );
 
@@ -31,58 +38,58 @@ interface midltests
 }
 
 #elif MIDLTESTS_C_CODE
-
-struct pipe_char_state {
-       const char *name;
-       unsigned long count;
-       unsigned long sleep;


-- 
Samba Shared Repository

Reply via email to