Author: jelmer Date: 2008-01-04 03:44:32 +0000 (Fri, 04 Jan 2008) New Revision: 26661
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=26661 Log: pidl/python: More generic handling of NTSTATUS, add stubs for types. Modified: branches/SAMBA_4_0/ branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/Python.pm Changeset: Property changes on: branches/SAMBA_4_0 ___________________________________________________________________ Name: bzr:revision-info ...skipped... Name: bzr:revision-id:v3-trunk0 ...skipped... Modified: branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/Python.pm =================================================================== --- branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/Python.pm 2008-01-03 23:58:38 UTC (rev 26660) +++ branches/SAMBA_4_0/source/pidl/lib/Parse/Pidl/Samba4/Python.pm 2008-01-04 03:44:32 UTC (rev 26661) @@ -84,23 +84,48 @@ { my ($self, $type) = @_; + $self->pidl("static PyObject *py_$type->{NAME}(PyObject *self, PyObject *args)"); + $self->pidl("{"); + $self->indent; #FIXME + + $self->pidl("return Py_None;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); } -sub PythonFunction($$) +sub PythonFunction($$$) { - my ($self, $fn) = @_; + my ($self, $fn, $iface) = @_; $self->pidl("static PyObject *py_$fn->{NAME}(PyObject *self, PyObject *args)"); $self->pidl("{"); $self->indent; + $self->pidl("$iface\_InterfaceObject *iface = ($iface\_InterfaceObject *)self;"); + $self->pidl("NTSTATUS status;"); + $self->pidl(""); # FIXME + $self->handle_ntstatus("status", "NULL"); $self->pidl("return Py_None;"); $self->deindent; $self->pidl("}"); $self->pidl(""); } +sub handle_ntstatus($$$) +{ + my ($self, $var, $retval) = @_; + + $self->pidl("if (NT_STATUS_IS_ERR($var)) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_RuntimeError, nt_errstr($var));"); + $self->pidl("return $retval;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); +} + sub Interface($$) { my($self,$interface) = @_; @@ -155,7 +180,7 @@ $self->pidl("static void interface_$interface->{NAME}_dealloc(PyObject* self)"); $self->pidl("{"); $self->indent; - $self->pidl("$interface->{NAME}_InterfaceObject *interface;"); + $self->pidl("$interface->{NAME}_InterfaceObject *interface = ($interface->{NAME}_InterfaceObject *)self;"); $self->pidl("talloc_free(interface->pipe);"); $self->pidl("PyObject_Del(self);"); $self->deindent; @@ -199,13 +224,7 @@ $self->pidl("status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, "); $self->pidl(" &ndr_table_$interface->{NAME}, credentials, NULL, lp_ctx);"); - $self->pidl("if (NT_STATUS_IS_ERR(status)) {"); - $self->indent; - $self->pidl("PyErr_SetString(PyExc_RuntimeError, nt_errstr(status));"); - $self->pidl("return NULL;"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); + $self->handle_ntstatus("status", "NULL"); $self->pidl("return (PyObject *)ret;"); $self->deindent; @@ -246,6 +265,18 @@ foreach my $x (@$ndr) { next if ($x->{TYPE} ne "INTERFACE"); $self->pidl("{ (char *)\"$x->{NAME}\", (PyCFunction)interface_$x->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },"); + + foreach my $d (@{$x->{TYPES}}) { + next if has_property($d, "nopython"); + next if ($d->{TYPE} eq "ENUM" or $d->{TYPE} eq "BITMAP"); + + my $fn_name = $d->{NAME}; + + $fn_name =~ s/^$x->{NAME}_//; + $fn_name =~ s/^$basename\_//; + + $self->pidl("{ (char *)\"$fn_name\", (PyCFunction)py_$d->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },"); + } } $self->pidl("{ NULL, NULL, 0, NULL }");