Skip to content

Commit

Permalink
pidl/NDR/Parser: use helper variables for array size and length
Browse files Browse the repository at this point in the history
metze
(cherry picked from commit d84758a)
  • Loading branch information
metze-samba authored and kseeger committed Apr 10, 2012
1 parent 785e164 commit 4932437
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -1538,12 +1540,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};");
Expand Down Expand Up @@ -1626,7 +1634,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);
}

Expand Down Expand Up @@ -1939,7 +1947,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;
}

Expand Down Expand Up @@ -2211,7 +2219,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 = ();
Expand Down

0 comments on commit 4932437

Please sign in to comment.