diff options
Diffstat (limited to 'source4/pidl')
-rw-r--r-- | source4/pidl/lib/Parse/Pidl/NDR.pm | 44 | ||||
-rwxr-xr-x | source4/pidl/tests/ndr.pl | 32 |
2 files changed, 63 insertions, 13 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/NDR.pm b/source4/pidl/lib/Parse/Pidl/NDR.pm index e9c4b59358..e950591cb7 100644 --- a/source4/pidl/lib/Parse/Pidl/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/NDR.pm @@ -392,6 +392,18 @@ sub ParseStruct($$) my @elements = (); my $surrounding = undef; + return { + TYPE => "STRUCT", + NAME => $struct->{NAME}, + SURROUNDING_ELEMENT => undef, + ELEMENTS => undef, + PROPERTIES => $struct->{PROPERTIES}, + ORIGINAL => $struct, + ALIGN => undef + } unless defined($struct->{ELEMENTS}); + + CheckPointerTypes($struct, $pointer_default); + foreach my $x (@{$struct->{ELEMENTS}}) { my $e = ParseElement($x, $pointer_default); @@ -433,12 +445,23 @@ sub ParseUnion($$) { my ($e, $pointer_default) = @_; my @elements = (); + my $hasdefault = 0; my $switch_type = has_property($e, "switch_type"); unless (defined($switch_type)) { $switch_type = "uint32"; } - if (has_property($e, "nodiscriminant")) { $switch_type = undef; } - - my $hasdefault = 0; + + return { + TYPE => "UNION", + NAME => $e->{NAME}, + SWITCH_TYPE => $switch_type, + ELEMENTS => undef, + PROPERTIES => $e->{PROPERTIES}, + HAS_DEFAULT => $hasdefault, + ORIGINAL => $e + } unless defined($e->{ELEMENTS}); + + CheckPointerTypes($e, $pointer_default); + foreach my $x (@{$e->{ELEMENTS}}) { my $t; @@ -501,11 +524,6 @@ sub ParseType($$) { my ($d, $pointer_default) = @_; - if ($d->{TYPE} eq "STRUCT" or $d->{TYPE} eq "UNION") { - return $d if (not defined($d->{ELEMENTS})); - CheckPointerTypes($d, $pointer_default); - } - my $data = { STRUCT => \&ParseStruct, UNION => \&ParseUnion, @@ -589,6 +607,8 @@ sub CheckPointerTypes($$) { my ($s,$default) = @_; + return unless defined($s->{ELEMENTS}); + foreach my $e (@{$s->{ELEMENTS}}) { if ($e->{POINTERS} and not defined(pointer_type($e))) { $e->{PROPERTIES}->{$default} = 1; @@ -1005,6 +1025,8 @@ sub ValidStruct($) ValidProperties($struct, "STRUCT"); + return unless defined($struct->{ELEMENTS}); + foreach my $e (@{$struct->{ELEMENTS}}) { $e->{PARENT} = $struct; ValidElement($e); @@ -1022,7 +1044,9 @@ sub ValidUnion($) if (has_property($union->{PARENT}, "nodiscriminant") and has_property($union->{PARENT}, "switch_type")) { fatal($union->{PARENT}, $union->{PARENT}->{NAME} . ": switch_type() on union without discriminant"); } - + + return unless defined($union->{ELEMENTS}); + foreach my $e (@{$union->{ELEMENTS}}) { $e->{PARENT} = $union; @@ -1129,7 +1153,7 @@ sub ValidInterface($) $d->{TYPE} eq "STRUCT" or $d->{TYPE} eq "UNION" or $d->{TYPE} eq "ENUM" or - $d->{TYPE} eq "BITMAP") && ValidType($d); + $d->{TYPE} eq "BITMAP") && ValidType($d); } } diff --git a/source4/pidl/tests/ndr.pl b/source4/pidl/tests/ndr.pl index 8245f768e8..043d2b9905 100755 --- a/source4/pidl/tests/ndr.pl +++ b/source4/pidl/tests/ndr.pl @@ -4,7 +4,7 @@ use strict; use warnings; -use Test::More tests => 26; +use Test::More tests => 27; use FindBin qw($RealBin); use lib "$RealBin"; use Util; @@ -225,5 +225,31 @@ is(mapToScalar({TYPE => "BITMAP", PROPERTIES => { bitmap64bit => 1 } }), "hyper"); is(mapToScalar({TYPE => "TYPEDEF", DATA => {TYPE => "ENUM", PARENT => { PROPERTIES => { enum8bit => 1 } } }}), "uint8"); -is_deeply(ParseType({TYPE => "STRUCT", NAME => "foo" }, "ref"), - {TYPE => "STRUCT", NAME => "foo" }); +my $t; +$t = { + TYPE => "STRUCT", + NAME => "foo", + SURROUNDING_ELEMENT => undef, + ELEMENTS => undef, + PROPERTIES => undef, + ORIGINAL => { + TYPE => "STRUCT", + NAME => "foo" + }, + ALIGN => undef +}; +is_deeply(ParseType($t->{ORIGINAL}, "ref"), $t); + +$t = { + TYPE => "UNION", + NAME => "foo", + SWITCH_TYPE => "uint32", + ELEMENTS => undef, + PROPERTIES => undef, + HAS_DEFAULT => 0, + ORIGINAL => { + TYPE => "UNION", + NAME => "foo" + } +}; +is_deeply(ParseType($t->{ORIGINAL}, "ref"), $t); |