From a0667e11ae2c92850919a1568ca47fa83d29af6f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Feb 2005 11:09:10 +0000 Subject: r5417: Add wrapper function for typedefs hash rather then using the "our" keyword, move pointer parsing to seperate function. (This used to be commit ea872b9a2b9a51ba9f6c2842303d067e9e85d11a) --- source4/build/pidl/dump.pm | 4 +-- source4/build/pidl/header.pm | 5 +++- source4/build/pidl/ndr.pm | 63 +++++++++++++++++++++++++++++++------------- 3 files changed, 49 insertions(+), 23 deletions(-) (limited to 'source4') diff --git a/source4/build/pidl/dump.pm b/source4/build/pidl/dump.pm index 00a57b10b4..9e896cd256 100644 --- a/source4/build/pidl/dump.pm +++ b/source4/build/pidl/dump.pm @@ -47,10 +47,8 @@ sub DumpElement($) ($res .= DumpProperties($element->{PROPERTIES})); $res .= DumpType($element->{TYPE}); $res .= " "; - if ($element->{POINTERS}) { - for (my($i)=0; $i < $element->{POINTERS}; $i++) { + for my $i (1..$element->{POINTERS}) { $res .= "*"; - } } $res .= "$element->{NAME}"; (defined $element->{ARRAY_LEN}) && ($res .= "[$element->{ARRAY_LEN}]"); diff --git a/source4/build/pidl/header.pm b/source4/build/pidl/header.pm index c49f60ce8b..00321fef93 100644 --- a/source4/build/pidl/header.pm +++ b/source4/build/pidl/header.pm @@ -185,7 +185,10 @@ sub HeaderType($$$) return; } - my $dt = $NdrParser::typedefs{$e->{TYPE}}->{DATA}; + my $dt; + if (my $t = NdrParser::get_typedef($e->{TYPE})) { + $dt = $t->{DATA}; + } if ($data =~ "string") { pidl "const char *"; diff --git a/source4/build/pidl/ndr.pm b/source4/build/pidl/ndr.pm index 81a909c472..961f32e333 100644 --- a/source4/build/pidl/ndr.pm +++ b/source4/build/pidl/ndr.pm @@ -11,8 +11,14 @@ use strict; use needed; # list of known types -our %typedefs; -our %typefamily; +my %typedefs; +my %typefamily; + +sub get_typedef($) +{ + my $n = shift; + return $typedefs{$n}; +} sub RegisterPrimitives() { @@ -534,7 +540,7 @@ sub ParseElementPushScalar($$$) } elsif (util::is_inline_array($e)) { ParseArrayPush($e, "r->", "NDR_SCALARS"); } elsif (need_wire_pointer($e)) { - pidl "NDR_CHECK(ndr_push_unique_ptr(ndr, $var_prefix$e->{NAME}));"; + ParseElementPushPtr($e, $var_prefix, $ndr_flags); } elsif (need_alloc($e)) { # no scalar component } elsif (my $switch = util::has_property($e, "switch_is")) { @@ -548,6 +554,18 @@ sub ParseElementPushScalar($$$) end_flags($e); } +##################################################################### +# parse a pointer in a struct element or function +sub ParseElementPushPtr($$$) +{ + my $e = shift; + my $var_prefix = shift; + my $ndr_flags = shift; + + pidl "NDR_CHECK(ndr_push_unique_ptr(ndr, $var_prefix$e->{NAME}));"; +} + + ##################################################################### # print scalars in a structure element sub ParseElementPrintScalar($$) @@ -710,19 +728,7 @@ sub ParseElementPullScalar($$$) if (util::is_inline_array($e)) { ParseArrayPull($e, "r->", "NDR_SCALARS"); } elsif (need_wire_pointer($e)) { - pidl "NDR_CHECK(ndr_pull_unique_ptr(ndr, &_ptr_$e->{NAME}));"; - pidl "if (_ptr_$e->{NAME}) {"; - indent; - pidl "NDR_ALLOC(ndr, $var_prefix$e->{NAME});"; - if (util::has_property($e, "relative")) { - pidl "NDR_CHECK(ndr_pull_relative_ptr1(ndr, $var_prefix$e->{NAME}, _ptr_$e->{NAME}));"; - } - deindent; - pidl "} else {"; - indent; - pidl "$var_prefix$e->{NAME} = NULL;"; - deindent; - pidl "}"; + ParseElementPullPtr($e, $var_prefix, $ndr_flags); } elsif (need_alloc($e)) { # no scalar component } elsif (my $switch = util::has_property($e, "switch_is")) { @@ -735,15 +741,34 @@ sub ParseElementPullScalar($$$) if (my $range = util::has_property($e, "range")) { my ($low, $high) = split(/ /, $range, 2); pidl "if ($var_prefix$e->{NAME} < $low || $var_prefix$e->{NAME} > $high) {"; - indent; - pidl "return ndr_pull_error(ndr, NDR_ERR_RANGE, \"value out of range\");"; - deindent; + pidl "\treturn ndr_pull_error(ndr, NDR_ERR_RANGE, \"value out of range\");"; pidl "}"; } end_flags($e); } +##################################################################### +# parse a pointer in a struct element or function +sub ParseElementPullPtr($$$) +{ + my($e) = shift; + my($var_prefix) = shift; + my($ndr_flags) = shift; + + pidl "NDR_CHECK(ndr_pull_unique_ptr(ndr, &_ptr_$e->{NAME}));"; + pidl "if (_ptr_$e->{NAME}) {"; + indent; + pidl "NDR_ALLOC(ndr, $var_prefix$e->{NAME});"; + if (util::has_property($e, "relative")) { + pidl "NDR_CHECK(ndr_pull_relative_ptr1(ndr, $var_prefix$e->{NAME}, _ptr_$e->{NAME}));"; + } + deindent; + pidl "} else {"; + pidl "\t$var_prefix$e->{NAME} = NULL;"; + pidl "}"; +} + ##################################################################### # parse buffers in a structure element sub ParseElementPushBuffer($$$) -- cgit