diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2008-01-13 15:51:15 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2008-01-14 19:53:04 +0100 |
commit | ce874c0b898eee3dfa8439424350579bf974e98f (patch) | |
tree | 8d1f1984e8d200710f29658d4c73e64552e83ac1 /source4/pidl/lib/Parse | |
parent | c660845737f454713f60f01d015125b053435b2c (diff) | |
download | samba-ce874c0b898eee3dfa8439424350579bf974e98f.tar.gz samba-ce874c0b898eee3dfa8439424350579bf974e98f.tar.bz2 samba-ce874c0b898eee3dfa8439424350579bf974e98f.zip |
pidl/python: Convert unions.
(This used to be commit e9037d0f5d222efd4ca04a0f8ce5c39cb3bb6997)
Diffstat (limited to 'source4/pidl/lib/Parse')
-rw-r--r-- | source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 57 |
1 files changed, 43 insertions, 14 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index fc5480b661..8720421088 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -91,36 +91,65 @@ sub EnumAndBitmapConsts($$$) sub FromUnionToPythonFunction($$$) { - my ($self, $type, $name) = @_; + my ($self, $type, $switch, $name) = @_; - #FIXME + $self->pidl("switch ($switch) {"); + $self->indent; + + foreach my $e (@{$type->{ELEMENTS}}) { + my $conv = $self->ConvertObjectToPython($e->{TYPE}, "$name->$e->{NAME}"); + if (defined($e->{CASE})) { + $self->pidl("$e->{CASE}: return $conv;"); + } else { + $self->pidl("default: return $conv;"); + } + } + $self->deindent; + $self->pidl("}"); + + $self->pidl("PyErr_SetString(PyExc_TypeError, \"unknown union level\");"); $self->pidl("return NULL;"); } sub FromStructToPythonFunction($$$) { - my ($self, $type, $name) = @_; + my ($self, $type, $typename, $name) = @_; - $self->pidl("$type->{NAME}\_Object *ret;"); - $self->pidl("ret = PyObject_New($type->{NAME}\_Object, &$type->{NAME}\_ObjectType);"); + $self->pidl("$typename\_Object *ret;"); + $self->pidl("ret = PyObject_New($typename\_Object, &$typename\_ObjectType);"); $self->pidl("ret->object = talloc_reference(NULL, $name);"); $self->pidl("return (PyObject *) ret;"); } sub FromPythonToUnionFunction($$$$) { - my ($self, $type, $mem_ctx, $name) = @_; + my ($self, $type, $switch, $mem_ctx, $name) = @_; - #FIXME + $self->pidl("switch ($switch) {"); + $self->indent; + + foreach my $e (@{$type->{ELEMENTS}}) { + my $conv = $self->ConvertObjectFromPython($e->{TYPE}, "$name"); + if (defined($e->{CASE})) { + $self->pidl("$e->{CASE}: return $conv;"); + } else { + $self->pidl("default: return $conv;"); + } + } + + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("PyErr_SetString(PyExc_TypeError, \"invalid union level value\");"); $self->pidl("return NULL;"); } -sub FromPythonToStructFunction($$$$) +sub FromPythonToStructFunction($$$$$) { - my ($self, $type, $mem_ctx, $name) = @_; + my ($self, $type, $typename, $mem_ctx, $name) = @_; - $self->pidl("$type->{NAME}\_Object *py_object = ($type->{NAME}_Object *)$name;"); + $self->pidl("$typename\_Object *py_object = ($typename\_Object *)$name;"); $self->pidl("return talloc_reference($mem_ctx, py_object->object);"); } @@ -326,8 +355,8 @@ sub PythonType($$$) $self->pidl("PyObject *py_import_$d->{NAME}(" .mapTypeName($d) . " *in)"); $self->pidl("{"); $self->indent; - $self->FromStructToPythonFunction($d, "in") if ($actual_ctype->{TYPE} eq "STRUCT"); - $self->FromUnionToPythonFunction($d, "in") if ($actual_ctype->{TYPE} eq "UNION"); + $self->FromStructToPythonFunction($actual_ctype, $d->{NAME}, "in") if ($actual_ctype->{TYPE} eq "STRUCT"); + $self->FromUnionToPythonFunction($actual_ctype, "level", "in") if ($actual_ctype->{TYPE} eq "UNION"); $self->deindent; $self->pidl("}"); $self->pidl(""); @@ -335,8 +364,8 @@ sub PythonType($$$) $self->pidl(mapTypeName($d) . " *py_export_$d->{NAME}(TALLOC_CTX *mem_ctx, PyObject *in)"); $self->pidl("{"); $self->indent; - $self->FromPythonToStructFunction($d, "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "STRUCT"); - $self->FromPythonToUnionFunction($d, "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "UNION"); + $self->FromPythonToStructFunction($actual_ctype, $d->{NAME}, "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "STRUCT"); + $self->FromPythonToUnionFunction($actual_ctype, "level", "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "UNION"); $self->deindent; $self->pidl("}"); $self->pidl(""); |