From 5db62a16ff9b784c11c704b8083da9bf6e736f08 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 8 Apr 2008 14:19:26 +0200 Subject: Array lengths can be obtained from Python objects so remove them from the Python API. (This used to be commit 652810ff46c6db9034e930d0fb018a02ee385f15) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index c04324e992..5d514c5f09 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -272,7 +272,21 @@ sub PythonFunctionBody($$$) my $signature = "S.$prettyname("; + my %metadata_args = (); + + sub get_var($) { my $x = shift; $x =~ s/\*//g; return $x; } + + # Determine arguments that are metadata for other arguments (size_is/length_is) + foreach my $e (@{$fn->{ELEMENTS}}) { + if (has_property($e, "length_is")) { + $metadata_args{get_var($e->{PROPERTIES}->{length_is})} = $e->{NAME}; + } elsif (has_property($e, "size_is")) { + $metadata_args{get_var($e->{PROPERTIES}->{size_is})} = $e->{NAME}; + } + } + foreach my $e (@{$fn->{ELEMENTS}}) { + next if ($metadata_args{$e->{NAME}}); $self->pidl("PyObject *py_$e->{NAME};"); if (grep(/out/,@{$e->{DIRECTION}})) { $result_size++; @@ -307,7 +321,16 @@ sub PythonFunctionBody($$$) } foreach my $e (@{$fn->{ELEMENTS}}) { - if (grep(/in/,@{$e->{DIRECTION}})) { + next unless (grep(/in/,@{$e->{DIRECTION}})); + if ($metadata_args{$e->{NAME}}) { + my $val = "PyList_Size(py_".$metadata_args{$e->{NAME}}.")"; + if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { + $self->pidl("r->in.$e->{NAME} = talloc_ptrtype(mem_ctx, r->in.$e->{NAME});"); + $self->pidl("*r->in.$e->{NAME} = $val;"); + } else { + $self->pidl("r->in.$e->{NAME} = PyList_Size(py_".$metadata_args{$e->{NAME}}.");"); + } + } else { $self->ConvertObjectFromPython($env, "mem_ctx", $e, "py_$e->{NAME}", "r->in.$e->{NAME}", "talloc_free(mem_ctx); return NULL;"); } } @@ -325,6 +348,7 @@ sub PythonFunctionBody($$$) } foreach my $e (@{$fn->{ELEMENTS}}) { + next if ($metadata_args{$e->{NAME}}); my $py_name = "py_$e->{NAME}"; if (grep(/out/,@{$e->{DIRECTION}})) { $self->ConvertObjectToPython("r", $env, $e, "r->out.$e->{NAME}", $py_name); -- cgit