r20836: Use real type name, to fix compilation with -WC++-compat
authorJelmer Vernooij <jelmer@samba.org>
Tue, 16 Jan 2007 17:45:33 +0000 (17:45 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:43:38 +0000 (14:43 -0500)
(This used to be commit 10ca65bd78d27c425ae0347930fd2c9a92fe345c)

source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm

index f8ff4582752cfc6fd93dabe70209dfb16a0102ad..97cbc8b0ab7230e2e7e28d40c0b1a933a240ca39 100644 (file)
@@ -8,9 +8,9 @@ package Parse::Pidl::Samba3::ServerNDR;
 
 use strict;
 use Parse::Pidl qw(warning fatal);
-use Parse::Pidl::Typelist qw(hasType getType mapType scalar_is_reference);
-use Parse::Pidl::Util qw(has_property ParseExpr is_constant);
-use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred);
+use Parse::Pidl::Typelist qw(mapType scalar_is_reference);
+use Parse::Pidl::Util qw(ParseExpr has_property is_constant);
+use Parse::Pidl::NDR qw(GetNextLevel);
 use Parse::Pidl::Samba4 qw(DeclLong);
 
 use vars qw($VERSION);
@@ -25,21 +25,59 @@ sub pidl($) { $res .= $tabs.(shift)."\n"; }
 sub pidl_hdr($) { $res_hdr .= (shift)."\n"; }
 sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; }
 
+sub DeclLevel($$) 
+{
+       sub DeclLevel($$);
+       my ($e, $l) = @_;
+
+       my $ret = "";
+
+       if (has_property($e, "charset")) {
+               $ret.="const char";
+       } else {
+               $ret.=mapType($e->{TYPE});
+       }
+
+       my $numstar = $e->{ORIGINAL}->{POINTERS};
+       if ($numstar >= 1) {
+               $numstar-- if scalar_is_reference($e->{TYPE});
+       }
+       foreach (@{$e->{ORIGINAL}->{ARRAY_LEN}})
+       {
+               next if is_constant($_) and 
+                       not has_property($e, "charset");
+               $numstar++;
+       }
+       $numstar -= $l;
+       die ("Too few pointers") if $numstar < 0;
+       if ($numstar > 0) 
+       {
+               $ret.=" ";
+               $ret.="*" foreach (1..$numstar);
+       }
+
+       return $ret;
+}
+
 sub AllocOutVar($$$$)
 {
        my ($e, $mem_ctx, $name, $env) = @_;
 
        my $l = $e->{LEVELS}[0];
+       my $nl = $l;
 
        if ($l->{TYPE} eq "POINTER") {
-               $l = GetNextLevel($e, $l);
+               $nl = GetNextLevel($e, $l);
        }
 
        if ($l->{TYPE} eq "ARRAY") {
                my $size = ParseExpr($l->{SIZE_IS}, $env, $e);
-               pidl "$name = talloc_zero_size($mem_ctx, sizeof(*$name) * $size);";
+               pidl "$name = talloc_zero_array($mem_ctx, " . DeclLevel($e, 1) . ", $size);";
+       } elsif ($l->{TYPE} eq "POINTER" and $nl->{TYPE} eq "ARRAY") {
+               my $size = ParseExpr($nl->{SIZE_IS}, $env, $e);
+               pidl "$name = talloc_zero_array($mem_ctx, " . DeclLevel($e, 1) . ", $size);";
        } else {
-               pidl "$name = talloc_zero_size($mem_ctx, sizeof(*$name));";
+               pidl "$name = talloc_zero($mem_ctx, " . DeclLevel($e, 1) . ");";
        }
 
        pidl "if ($name == NULL) {";
@@ -101,7 +139,8 @@ sub ParseFunction($$)
                my @dir = @{$_->{DIRECTION}};
                if (grep(/in/, @dir) and grep(/out/, @dir)) {
                        pidl "r.out.$_->{NAME} = r.in.$_->{NAME};";
-               } elsif (grep(/out/, @dir)) {
+               } elsif (grep(/out/, @dir) and not 
+                                has_property($_, "represent_as")) {
                        AllocOutVar($_, "mem_ctx", "r.out.$_->{NAME}", \%env);
                }
                if (grep(/in/, @dir)) { $ret .= ", r.in.$_->{NAME}"; }