pidl/ejs: Fix bug that filled in the body for types without body.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 12 Jan 2008 22:38:05 +0000 (23:38 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 12 Jan 2008 22:38:05 +0000 (23:38 +0100)
(This used to be commit 4f4dfa6042178c157a09df61d72a42af7aa5c67b)

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

index fa0c97961c738f32b0eae0fd9288b68fd1926b01..24270340b9e0a661f58b963f112a089e57e80269 100644 (file)
@@ -11,7 +11,7 @@ use Exporter;
 @EXPORT_OK = qw(check_null_pointer fn_declare TypeFunctionName);
 
 use strict;
-use Parse::Pidl::Typelist;
+use Parse::Pidl::Typelist qw(typeHasBody);
 use Parse::Pidl::CUtil qw(get_pointer_to get_value_of);
 use Parse::Pidl::Util qw(has_property ParseExpr);
 use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel);
@@ -274,6 +274,7 @@ sub EjsUnionPull($$$)
 sub EjsEnumConstant($$)
 {
        my ($self, $d) = @_;
+       return unless (defined($d->{ELEMENTS}));
        my $v = 0;
        foreach my $e (@{$d->{ELEMENTS}}) {
                my $el = $e;
@@ -572,6 +573,7 @@ sub EjsEnumPush($$$)
 sub EjsBitmapPush($$$)
 {
        my ($self, $d, $varname) = @_;
+       return unless (defined($d->{ELEMENTS}));
        my $type_fn = $d->{BASE_TYPE};
        # put the bitmap elements in the constants array
        foreach my $e (@{$d->{ELEMENTS}}) {
@@ -710,6 +712,7 @@ sub EjsInterface($$$)
        $self->pidl_hdr("\n");
 
        foreach my $d (@{$interface->{TYPES}}) {
+               next unless (typeHasBody($d));
                ($needed->{TypeFunctionName("ejs_push", $d)}) && $self->EjsTypePushFunction($d, $d->{NAME});
                ($needed->{TypeFunctionName("ejs_pull", $d)}) && $self->EjsTypePullFunction($d, $d->{NAME});
        }
@@ -823,8 +826,9 @@ sub NeededType($$$)
 
        NeededType($t->{DATA}, $needed, $req) if ($t->{TYPE} eq "TYPEDEF");
 
-       return if (($t->{TYPE} ne "STRUCT") and 
-                          ($t->{TYPE} ne "UNION"));
+       return unless (($t->{TYPE} eq "STRUCT") or ($t->{TYPE} eq "UNION"));
+
+       return unless(typeHasBody($t));
 
        foreach (@{$t->{ELEMENTS}}) {
                next if (has_property($_, "subcontext")); #FIXME: Support subcontexts
index cfd16c7b409dfd18dbf4698c3b44f34922c5f00f..451e899ffbcf066ef7234880dfefb6d373598e80 100644 (file)
@@ -2543,7 +2543,8 @@ sub ParseInterface($$$)
 
        # Typedefs
        foreach my $d (@{$interface->{TYPES}}) {
-               next unless typeHasBody($d);
+               next unless(typeHasBody($d));
+
                ($needed->{TypeFunctionName("ndr_push", $d)}) && $self->ParseTypePushFunction($d, "r");
                ($needed->{TypeFunctionName("ndr_pull", $d)}) && $self->ParseTypePullFunction($d, "r");
                ($needed->{TypeFunctionName("ndr_print", $d)}) && $self->ParseTypePrintFunction($d, "r");
index d14c374740a87ac9259a73bb1fa1a68175f48620..93f772ef41fc1518b53215e6ca624c9a981db6d6 100755 (executable)
@@ -4,7 +4,7 @@
 # Published under the GNU General Public License
 use strict;
 
-use Test::More tests => 65 * 2 + 5;
+use Test::More tests => 65 * 2 + 6;
 use FindBin qw($RealBin);
 use lib "$RealBin";
 use Util qw(test_errors);
@@ -143,6 +143,13 @@ $x = Parse::Pidl::IDL::parse_string("interface foo { typedef struct {} y; }", "<
 
 is_deeply($x, 
         [ { 'FILE' => '<foo>', 'NAME' => 'foo', 'DATA' => [ 
-                { 'FILE' => '<foo>', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => {
-                        TYPE => 'STRUCT', ELEMENTS => [] } } ], 
+                { 'FILE' => '<foo>', 'LINE' => 0, 'NAME' => 'y', 'TYPE' => 'TYPEDEF', DATA => { TYPE => 'STRUCT', ELEMENTS => [] } } ], 
+                'TYPE' => 'INTERFACE', 'LINE' => 0 } ]); 
+
+# A typedef of a bitmap with no body
+$x = Parse::Pidl::IDL::parse_string("interface foo { typedef bitmap x y; }", "<foo>");
+
+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 } ]);