summaryrefslogtreecommitdiff
path: root/source4/pidl/lib
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2006-09-14 13:37:17 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:18:42 -0500
commitf78ff444e68aa45674310e5c679b8caef69e35c9 (patch)
tree0fb70c7797dc0914996854e077d7c126845762ec /source4/pidl/lib
parentdf08af841881d331285a56f76a826ebd19b426b8 (diff)
downloadsamba-f78ff444e68aa45674310e5c679b8caef69e35c9.tar.gz
samba-f78ff444e68aa45674310e5c679b8caef69e35c9.tar.bz2
samba-f78ff444e68aa45674310e5c679b8caef69e35c9.zip
r18524: Pre-allocate out arguments.
(This used to be commit 0ee42669d3a5ec062ec14ecda94342b0df519964)
Diffstat (limited to 'source4/pidl/lib')
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm33
1 files changed, 33 insertions, 0 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm
index dea3a32607..4d3dba2e0e 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm
@@ -26,6 +26,30 @@ sub fatal($$) { my ($e,$s) = @_; die("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LI
sub warning($$) { my ($e,$s) = @_; warn("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); }
sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; }
+sub AllocOutVar($$$$)
+{
+ my ($e, $mem_ctx, $name, $env) = @_;
+
+ my $l = $e->{LEVELS}[0];
+
+ if ($l->{TYPE} eq "POINTER") {
+ $l = GetNextLevel($e, $l);
+ }
+
+ if ($l->{TYPE} eq "ARRAY") {
+ my $size = ParseExpr($l->{SIZE_IS}, $env);
+ pidl "$name = talloc_array_size($mem_ctx, sizeof(*$name), $size);";
+ } else {
+ pidl "$name = talloc_size($mem_ctx, sizeof(*$name));";
+ }
+
+ pidl "if ($name == NULL) {";
+ pidl "\ttalloc_free(mem_ctx);";
+ pidl "\treturn False;";
+ pidl "}";
+ pidl "";
+}
+
sub ParseFunction($$)
{
my ($if,$fn) = @_;
@@ -56,12 +80,21 @@ sub ParseFunction($$)
pidl "\treturn False;";
pidl "}";
pidl "";
+
+ my %env = ();
+ foreach (@{$fn->{ELEMENTS}}) {
+ next unless (grep (/in/, @{$_->{DIRECTION}}));
+ $env{$_->{NAME}} = "r.in.$_->{NAME}";
+ }
+
my $proto = "_$fn->{NAME}(pipes_struct *p";
my $ret = "_$fn->{NAME}(p";
foreach (@{$fn->{ELEMENTS}}) {
my @dir = @{$_->{DIRECTION}};
if (grep(/in/, @dir) and grep(/out/, @dir)) {
pidl "r.out.$_->{NAME} = r.in.$_->{NAME};";
+ } elsif (grep(/out/, @dir)) {
+ AllocOutVar($_, "mem_ctx", "r.out.$_->{NAME}", \%env);
}
if (grep(/in/, @dir)) { $ret .= ", r.in.$_->{NAME}"; }
else { $ret .= ", r.out.$_->{NAME}"; }