From 935031309ac2f7a174c39caef5bc7b3d2f2508e2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 3 Jan 2008 21:57:44 -0600 Subject: r26659: pidl/python: Support string constants and handle modules. (This used to be commit 885e5980d7d7fbafdcf308b8ba6f2560c5b467ec) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 45 ++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (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 68e35a8532..7c2c2c06c6 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -49,6 +49,38 @@ sub deindent($) $self->{tabs} = substr($self->{tabs}, 0, -1); } +sub Import +{ + my $self = shift; + my @imports = @_; + foreach (@imports) { + s/\.idl\"$//; + s/^\"//; + $self->pidl_hdr("#include \"librpc/gen_ndr/py_$_\.h\"\n"); + } +} + +sub Const($$) +{ + my ($self, $const) = @_; + $self->{constants}->{$const->{NAME}} = [$const->{DATA}->{TYPE}, $const->{VALUE}]; +} + +sub Interface($$) +{ + my($self,$interface) = @_; + + $self->pidl_hdr("#ifndef _HEADER_PYTHON_$interface->{NAME}\n"); + $self->pidl_hdr("#define _HEADER_PYTHON_$interface->{NAME}\n\n"); + + $self->pidl_hdr("\n"); + + $self->Const($_) foreach (@{$interface->{CONSTS}}); + + $self->pidl_hdr("\n"); + $self->pidl_hdr("#endif /* _HEADER_NDR_$interface->{NAME} */\n"); +} + sub Parse($$$$) { my($self,$basename,$ndr,$hdr) = @_; @@ -66,6 +98,11 @@ sub Parse($$$$) #include \"$py_hdr\" "); + + foreach my $x (@$ndr) { + ($x->{TYPE} eq "INTERFACE") && $self->Interface($x); + ($x->{TYPE} eq "IMPORT") && $self->Import(@{$x->{PATHS}}); + } $self->pidl("static PyMethodDef $basename\_methods[] = {"); $self->indent; @@ -78,9 +115,13 @@ sub Parse($$$$) $self->pidl("void init$basename(void)"); $self->pidl("{"); $self->indent; - $self->pidl("PyObject *m;"); + $self->pidl("PyObject *m, *d;"); $self->pidl("m = Py_InitModule((char *)\"$basename\", $basename\_methods);"); - # FIXME + $self->pidl("d = PyModule_GetDict(m);"); + foreach (keys %{$self->{constants}}) { + # FIXME: Handle non-string constants + $self->pidl("PyDict_SetItemString(d, \"$_\", PyString_FromString(" . $self->{constants}->{$_}->[1] . "));"); + } $self->deindent; $self->pidl("}"); return ($self->{res_hdr}, $self->{res}); -- cgit