diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2008-01-03 21:57:44 -0600 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2008-01-03 16:03:01 -0600 |
commit | 935031309ac2f7a174c39caef5bc7b3d2f2508e2 (patch) | |
tree | 835f128df0722c0601d83b9e82886f50f0b8ed3b | |
parent | 1548d8d2be2a1012549f626d504070272bb51c9e (diff) | |
download | samba-935031309ac2f7a174c39caef5bc7b3d2f2508e2.tar.gz samba-935031309ac2f7a174c39caef5bc7b3d2f2508e2.tar.bz2 samba-935031309ac2f7a174c39caef5bc7b3d2f2508e2.zip |
r26659: pidl/python: Support string constants and handle modules.
(This used to be commit 885e5980d7d7fbafdcf308b8ba6f2560c5b467ec)
-rw-r--r-- | source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 45 |
1 files changed, 43 insertions, 2 deletions
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}); |