r24493: - it turns out that
authorStefan Metzmacher <metze@samba.org>
Thu, 16 Aug 2007 14:42:22 +0000 (14:42 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 20:02:01 +0000 (15:02 -0500)
  foreach my $e (@{$union->{ELEMENTS}}) {
  changes $union->{ELEMENTS} from undef into an empty array.
  this removes the difference between
  struct foo { }; and struct foo;
  So we need to explicit return before.
- we should return the same element for layout for
  structs and unions with no elements.
- fix the testsuite to match

metze
(This used to be commit 5f1f50cd27e3702b79a19dbe1079498cbfc4842b)

source4/pidl/lib/Parse/Pidl/NDR.pm
source4/pidl/tests/ndr.pl

index e9c4b59358dfef44be75d092eac0a60fc068bafe..e950591cb7989d8512b6239ce1d0924722b4a809 100644 (file)
@@ -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);
        }
 
 }
index 8245f768e8463a1d86487567bf430187631ca05a..043d2b9905caa9597248c050985d263725a1f31f 100755 (executable)
@@ -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);