aboutsummaryrefslogtreecommitdiffstats
path: root/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-09-24 21:51:46 -0700
committerGuy Harris <guy@alum.mit.edu>2017-09-25 04:52:41 +0000
commitfd81dea208b42a0aa174810e82f2d0fe24d0251e (patch)
tree9b50625cb621af310f58354ae676fc8c815ebca0 /tools/pidl/lib/Parse/Pidl/Samba4/Python.pm
parent1dd1a13e9f2a6c3ebd51c883bac5a8c2e1eeb4d3 (diff)
pidl:Python: split out a PythonElementGetSet() helper function
Pick up a change from Samba: commit a546124f10d1e2bee29bc06c0b8754257d2bdc23 Author: Stefan Metzmacher <metze@samba.org> Date: Mon Sep 12 09:20:04 2016 +0200 pidl:Python: split out a PythonElementGetSet() helper function Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Change-Id: Ica8b699189b69833abfa6049dd3c4e489788ce54 Reviewed-on: https://code.wireshark.org/review/23715 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'tools/pidl/lib/Parse/Pidl/Samba4/Python.pm')
-rw-r--r--tools/pidl/lib/Parse/Pidl/Samba4/Python.pm64
1 files changed, 35 insertions, 29 deletions
diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm b/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 0ae2733..cab51d1 100644
--- a/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -192,6 +192,40 @@ sub FromPythonToUnionFunction($$$$$)
$self->pidl("return ret;");
}
+sub PythonElementGetSet($$$$$$) {
+ my ($self, $name, $cname, $ename, $e, $env) = @_;
+
+ my $varname = "object->$ename";
+ $self->pidl("static PyObject *py_$name\_get_$e->{NAME}(PyObject *obj, void *closure)");
+ $self->pidl("{");
+ $self->indent;
+ $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(obj);");
+ $self->pidl("PyObject *py_$e->{NAME};");
+ $self->ConvertObjectToPython("pytalloc_get_mem_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}", "return NULL;");
+ $self->pidl("return py_$e->{NAME};");
+ $self->deindent;
+ $self->pidl("}");
+ $self->pidl("");
+
+ $self->pidl("static int py_$name\_set_$e->{NAME}(PyObject *py_obj, PyObject *value, void *closure)");
+ $self->pidl("{");
+ $self->indent;
+ $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(py_obj);");
+ my $mem_ctx = "pytalloc_get_mem_ctx(py_obj)";
+ my $l = $e->{LEVELS}[0];
+ my $nl = GetNextLevel($e, $l);
+ if ($l->{TYPE} eq "POINTER" and
+ not ($nl->{TYPE} eq "ARRAY" and ($nl->{IS_FIXED} or is_charset_array($e, $nl))) and
+ not ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE}))) {
+ $self->pidl("talloc_unlink($mem_ctx, discard_const($varname));");
+ }
+ $self->ConvertObjectFromPython($env, $mem_ctx, $e, "value", $varname, "return -1;");
+ $self->pidl("return 0;");
+ $self->deindent;
+ $self->pidl("}");
+ $self->pidl("");
+}
+
sub PythonStruct($$$$$$)
{
my ($self, $modulename, $prettyname, $name, $cname, $d) = @_;
@@ -204,35 +238,7 @@ sub PythonStruct($$$$$$)
if ($#{$d->{ELEMENTS}} > -1) {
foreach my $e (@{$d->{ELEMENTS}}) {
- my $varname = "object->$e->{NAME}";
- $self->pidl("static PyObject *py_$name\_get_$e->{NAME}(PyObject *obj, void *closure)");
- $self->pidl("{");
- $self->indent;
- $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(obj);");
- $self->pidl("PyObject *py_$e->{NAME};");
- $self->ConvertObjectToPython("pytalloc_get_mem_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}", "return NULL;");
- $self->pidl("return py_$e->{NAME};");
- $self->deindent;
- $self->pidl("}");
- $self->pidl("");
-
- $self->pidl("static int py_$name\_set_$e->{NAME}(PyObject *py_obj, PyObject *value, void *closure)");
- $self->pidl("{");
- $self->indent;
- $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(py_obj);");
- my $mem_ctx = "pytalloc_get_mem_ctx(py_obj)";
- my $l = $e->{LEVELS}[0];
- my $nl = GetNextLevel($e, $l);
- if ($l->{TYPE} eq "POINTER" and
- not ($nl->{TYPE} eq "ARRAY" and ($nl->{IS_FIXED} or is_charset_array($e, $nl))) and
- not ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE}))) {
- $self->pidl("talloc_unlink($mem_ctx, discard_const($varname));");
- }
- $self->ConvertObjectFromPython($env, $mem_ctx, $e, "value", $varname, "return -1;");
- $self->pidl("return 0;");
- $self->deindent;
- $self->pidl("}");
- $self->pidl("");
+ $self->PythonElementGetSet($name, $cname, $e->{NAME}, $e, $env);
}
$getsetters = "py_$name\_getsetters";