pidl/NDR/Parser: use helper variables for array size and length
authorStefan Metzmacher <metze@samba.org>
Thu, 15 Mar 2012 12:13:20 +0000 (13:13 +0100)
committerKarolin Seeger <kseeger@samba.org>
Sat, 7 Apr 2012 13:58:54 +0000 (15:58 +0200)
metze

pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm

index ff1f0c105349cc99f2b142bb1c805cd11ca98766..a98ec6ec812aaede36d8caf06bf1afd56f1c7214 100644 (file)
@@ -332,7 +332,8 @@ sub ParseArrayPullGetSize($$$$$$)
                        check_fully_dereferenced($e, $env));
        }
 
-       my $array_size = $size;
+       $self->pidl("size_$e->{NAME}_$l->{LEVEL_INDEX} = $size;");
+       my $array_size = "size_$e->{NAME}_$l->{LEVEL_INDEX}";
 
        return $array_size;
 }
@@ -350,7 +351,8 @@ sub ParseArrayPullGetLength($$$$$$;$)
        my $array_length = $array_size;
        if ($l->{IS_VARYING}) {
                my $length = "ndr_get_array_length($ndr, " . get_pointer_to($var_name) .")";
-               $array_length = $length;
+               $self->pidl("length_$e->{NAME}_$l->{LEVEL_INDEX} = $length;");
+               $array_length = "length_$e->{NAME}_$l->{LEVEL_INDEX}";
        }
 
        return $array_length;
@@ -1540,12 +1542,18 @@ sub DeclarePtrVariables($$)
        }
 }
 
-sub DeclareArrayVariables($$)
+sub DeclareArrayVariables($$;$)
 {
-       my ($self,$e) = @_;
+       my ($self,$e,$pull) = @_;
 
        foreach my $l (@{$e->{LEVELS}}) {
                next if ($l->{TYPE} ne "ARRAY");
+               if (defined($pull)) {
+                       $self->pidl("uint32_t size_$e->{NAME}_$l->{LEVEL_INDEX} = 0;");
+                       if ($l->{IS_VARYING}) {
+                               $self->pidl("uint32_t length_$e->{NAME}_$l->{LEVEL_INDEX} = 0;");
+                       }
+               }
                next if has_fast_array($e,$l);
                next if is_charset_array($e,$l);
                $self->pidl("uint32_t cntr_$e->{NAME}_$l->{LEVEL_INDEX};");
@@ -1630,7 +1638,7 @@ sub ParseStructPull($$$$)
        # declare any internal pointers we need
        foreach my $e (@{$struct->{ELEMENTS}}) {
                $self->DeclarePtrVariables($e);
-               $self->DeclareArrayVariables($e);
+               $self->DeclareArrayVariables($e, "pull");
                $self->DeclareMemCtxVariables($e);
        }
 
@@ -1951,7 +1959,7 @@ sub ParseUnionPull($$$$)
                next if ($double_cases{"$el->{NAME}"});
                $self->DeclareMemCtxVariables($el);
                $self->DeclarePtrVariables($el);
-               $self->DeclareArrayVariables($el);
+               $self->DeclareArrayVariables($el, "pull");
                $double_cases{"$el->{NAME}"} = 1;
        }
 
@@ -2223,7 +2231,7 @@ sub ParseFunctionPull($$)
        # declare any internal pointers we need
        foreach my $e (@{$fn->{ELEMENTS}}) { 
                $self->DeclarePtrVariables($e);
-               $self->DeclareArrayVariables($e);
+               $self->DeclareArrayVariables($e, "pull");
        }
 
        my %double_cases = ();