From d909237a85356272be3425ab80688d52d3c1cbae Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 18 Feb 2005 21:49:11 +0000 Subject: r5449: More array handling cleanups. This should make the code more readable. (Output C and header files have not changed, just internal pidl changes) (This used to be commit b86b299197f2c3b314d0fc33c0139bd19ef637f2) --- source4/build/pidl/ndr.pm | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/source4/build/pidl/ndr.pm b/source4/build/pidl/ndr.pm index f5be5563b5..ce760c2d71 100644 --- a/source4/build/pidl/ndr.pm +++ b/source4/build/pidl/ndr.pm @@ -110,7 +110,8 @@ sub is_fixed_array($) sub is_conformant_array($) { my $e = shift; - return defined($e->{CONFORMANT_SIZE}); + return 1 if (util::has_property($e, "size_is")); + return 0; } # return 1 if this is a inline array @@ -132,6 +133,17 @@ sub is_varying_array($) return 0; } +sub is_surrounding_array($) +{ + my $e = shift; + + return ($e->{POINTERS} == 0 + and defined $e->{ARRAY_LEN} + and $e->{ARRAY_LEN} eq "*" + and $e == $e->{PARENT}->{ELEMENTS}[-1] + and $e->{PARENT}->{TYPE} ne "FUNCTION"); +} + sub array_type($) { my $e = shift; @@ -430,14 +442,15 @@ sub ParseArrayPush($$$) my $size = ParseExpr($e, util::array_size($e), $var_prefix); - if (is_conformant_array($e) ) { + if (is_surrounding_array($e)) { # the conformant size has already been pushed } elsif (!is_inline_array($e)) { # we need to emit the array size pidl "NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, $size));"; } - if (my $length = util::has_property($e, "length_is")) { + if (is_varying_array($e)) { + my $length = util::has_property($e, "length_is"); $length = ParseExpr($e, $length, $var_prefix); pidl "NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));"; pidl "NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, $length));"; @@ -478,8 +491,8 @@ sub CheckArraySizes($$) my $e = shift; my $var_prefix = shift; - if (!is_conformant_array($e) && - util::has_property($e, "size_is")) { + if (!is_surrounding_array($e) && + is_conformant_array($e)) { my $size = ParseExpr($e, util::array_size($e), $var_prefix); pidl "if ($var_prefix$e->{NAME}) {"; indent; @@ -489,14 +502,15 @@ sub CheckArraySizes($$) pidl "}"; } - if (my $length = util::has_property($e, "length_is")) { + if (is_varying_array($e)) { + my $length = util::has_property($e, "length_is"); $length = ParseExpr($e, $length, $var_prefix); pidl "if ($var_prefix$e->{NAME}) {"; indent; check_null_pointer($length); pidl "NDR_CHECK(ndr_check_array_length(ndr, (void*)&$var_prefix$e->{NAME}, $length));"; deindent; - pidl "}"; + pidl "}" } } @@ -513,7 +527,7 @@ sub ParseArrayPull($$$) # if this is a conformant array then we use that size to allocate, and make sure # we allocate enough to pull the elements - if (is_conformant_array($e)) { + if (is_conformant_array($e) and is_surrounding_array($e)) { $alloc_size = $e->{CONFORMANT_SIZE}; check_null_pointer($size); pidl "if ($size > $alloc_size) {"; @@ -964,7 +978,7 @@ sub ParseStructPush($) # the wire before the structure (and even before the structure # alignment) my $e = $struct->{ELEMENTS}[-1]; - if (defined $e->{ARRAY_LEN} && $e->{ARRAY_LEN} eq "*") { + if (is_conformant_array($e) and is_surrounding_array($e)) { my $size = ParseExpr($e, util::array_size($e), "r->"); $e->{CONFORMANT_SIZE} = $size; check_null_pointer($size); @@ -1228,7 +1242,7 @@ sub ParseStructPull($) # the wire before the structure (and even before the structure # alignment) my $e = $struct->{ELEMENTS}[-1]; - if (defined $e->{ARRAY_LEN} && $e->{ARRAY_LEN} eq "*") { + if (is_conformant_array($e) and is_surrounding_array($e)) { $conform_e = $e; } @@ -1238,7 +1252,6 @@ sub ParseStructPull($) } if (defined $conform_e) { - $conform_e = $e; pidl "uint32_t _conformant_size;"; $conform_e->{CONFORMANT_SIZE} = "_conformant_size"; } -- cgit