pidl: Avoid accidently filling in empty body for types without body.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 12 Jan 2008 23:05:24 +0000 (00:05 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 12 Jan 2008 23:05:24 +0000 (00:05 +0100)
(This used to be commit 1fe5c1ad07c574dc094f59f728025dfcafa0cf22)

source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
source4/pidl/lib/Parse/Pidl/Typelist.pm
source4/pidl/tests/ndr.pl
source4/pidl/tests/parse_idl.pl

index 451e899ffbcf066ef7234880dfefb6d373598e80..8eb2f9ad1555686b0956973f1bae7a9542042f94 100644 (file)
@@ -2688,6 +2688,7 @@ sub NeededType($$$)
        NeededType($t->{DATA}, $needed, $req) if ($t->{TYPE} eq "TYPEDEF");
 
        if ($t->{TYPE} eq "STRUCT" or $t->{TYPE} eq "UNION") {
+               return unless defined($t->{ELEMENTS});
                for my $e (@{$t->{ELEMENTS}}) {
                        $e->{PARENT} = $t;
                        if (has_property($e, "compression")) { 
index aad0cf426c8e4a4ede8a92e4d7615d47cc248897..e54ef11b8831f307d8a63f774f13b54ff28f5da7 100644 (file)
@@ -135,7 +135,9 @@ sub is_scalar($)
        sub is_scalar($);
        my $type = shift;
 
-       return 1 if (ref($type) eq "HASH" and $type->{TYPE} eq "SCALAR");
+       return 1 if (ref($type) eq "HASH" and 
+               ($type->{TYPE} eq "SCALAR" or $type->{TYPE} eq "ENUM" or 
+                $type->{TYPE} eq "BITMAP"));
 
        if (my $dt = getType($type)) {
                return is_scalar($dt->{DATA}) if ($dt->{TYPE} eq "TYPEDEF");
@@ -149,7 +151,7 @@ sub is_scalar($)
 sub scalar_is_reference($)
 {
        my $name = shift;
-       
+
        return 1 if (grep(/^$name$/, @reference_scalars));
        return 0;
 }
index ba7fef361b7b25f0af67311587c150436cda0c6b..7fcc7ef40e66e536005aab8e8af0cc0a6178bbe4 100755 (executable)
@@ -4,7 +4,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 39;
+use Test::More tests => 40;
 use FindBin qw($RealBin);
 use lib "$RealBin";
 use Util;
@@ -279,3 +279,5 @@ ok(can_contain_deferred({ TYPE => "STRUCT",
 ok(not defined(ParseType({TYPE => "ENUM", NAME => "foo" }, "ref")->{ELEMENTS}));
 # Make sure the elements for a bitmap without body aren't filled in
 ok(not defined(ParseType({TYPE => "BITMAP", NAME => "foo" }, "ref")->{ELEMENTS}));
+# Make sure the elements for a union without body aren't filled in
+ok(not defined(ParseType({TYPE => "UNION", NAME => "foo" }, "ref")->{ELEMENTS}));
index 93f772ef41fc1518b53215e6ca624c9a981db6d6..9d43ddccc7ae3457e7f3e687737fbc98be0a880c 100755 (executable)
@@ -4,7 +4,7 @@
 # Published under the GNU General Public License
 use strict;
 
-use Test::More tests => 65 * 2 + 6;
+use Test::More tests => 65 * 2 + 7;
 use FindBin qw($RealBin);
 use lib "$RealBin";
 use Util qw(test_errors);
@@ -153,3 +153,12 @@ is_deeply($x,
         [ { 'FILE' => '<foo>', 'NAME' => 'foo', 'DATA' => [ 
                 { 'FILE' => '<foo>', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { TYPE => 'BITMAP', NAME => 'x' } } ], 
                 'TYPE' => 'INTERFACE', 'LINE' => 0 } ]); 
+
+
+# A typedef of a union with no body
+$x = Parse::Pidl::IDL::parse_string("interface foo { typedef union x y; }", "<foo>");
+
+is_deeply($x, 
+        [ { 'FILE' => '<foo>', 'NAME' => 'foo', 'DATA' => [ 
+                { 'FILE' => '<foo>', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { TYPE => 'UNION', NAME => 'x' } } ], 
+                'TYPE' => 'INTERFACE', 'LINE' => 0 } ]);