summaryrefslogtreecommitdiff
path: root/pidl/lib/Parse/Pidl
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2010-11-30 23:06:32 +0100
committerJelmer Vernooij <jelmer@samba.org>2010-12-01 01:48:24 +0100
commitba2110d19060c4d84656917eb6be7b78afc6df6b (patch)
treeff66a56b0cd41a770cff66807c2ce6421cd2cdb4 /pidl/lib/Parse/Pidl
parent36bdb3b9af271a8dcde23d40737117d7ce5daef8 (diff)
downloadsamba-ba2110d19060c4d84656917eb6be7b78afc6df6b.tar.gz
samba-ba2110d19060c4d84656917eb6be7b78afc6df6b.tar.bz2
samba-ba2110d19060c4d84656917eb6be7b78afc6df6b.zip
pidl: Allow more flexibility importing modules using convenience function.
Diffstat (limited to 'pidl/lib/Parse/Pidl')
-rw-r--r--pidl/lib/Parse/Pidl/Samba4/Python.pm16
1 files changed, 9 insertions, 7 deletions
diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm
index b0b8e53f44..ebd2a66af3 100644
--- a/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -24,7 +24,7 @@ sub new($) {
my ($class) = @_;
my $self = { res => "", res_hdr => "", tabs => "", constants => {},
module_methods => [], module_objects => [], ready_types => [],
- module_imports => [], type_imports => {},
+ module_imports => {}, type_imports => {},
patch_type_calls => [], prereadycode => [],
postreadycode => []};
bless($self, $class);
@@ -756,7 +756,7 @@ sub register_module_import($$)
{
my ($self, $basename) = @_;
- push (@{$self->{module_imports}}, $basename) unless (grep(/^$basename$/,@{$self->{module_imports}}));
+ $self->{module_imports}->{"dep_$basename"} = "samba.dcerpc.$basename";
}
sub import_type_variable($$$)
@@ -1294,14 +1294,16 @@ sub Parse($$$$$)
$self->pidl("{");
$self->indent;
$self->pidl("PyObject *m;");
- foreach (@{$self->{module_imports}}) {
- $self->pidl("PyObject *dep_$_;");
+ foreach (keys %{$self->{module_imports}}) {
+ $self->pidl("PyObject *$_;");
}
$self->pidl("");
- foreach (@{$self->{module_imports}}) {
- $self->pidl("dep_$_ = PyImport_ImportModule(\"samba.dcerpc.$_\");");
- $self->pidl("if (dep_$_ == NULL)");
+ foreach (keys %{$self->{module_imports}}) {
+ my $var_name = $_;
+ my $module_path = $self->{module_imports}->{$var_name};
+ $self->pidl("$var_name = PyImport_ImportModule(\"$module_path\");");
+ $self->pidl("if ($var_name == NULL)");
$self->pidl("\treturn;");
$self->pidl("");
}