aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-09-24 21:46:05 -0700
committerGuy Harris <guy@alum.mit.edu>2017-09-25 04:46:58 +0000
commit1373f619f9772d30d6aef104a0d7063f660195b1 (patch)
treec4fd735a9594b2e1e4876a366475f4c657486248
parentaff94cf8f52057b76ce57736e0f64d29e06ceecc (diff)
pidl:Python: provide the abstract syntax as <module>.<interface>_abstract_syntax
Pick up change from Samba: commit 3a0ce3e41d9fdab58273c239955862b03396ea19 Author: Stefan Metzmacher <metze@samba.org> Date: Sun Sep 25 00:48:29 2016 +0200 pidl:Python: provide the abstract syntax as <module>.<interface>_abstract_syntax The <module>.abstract_syntax alias is only kept as legacy for the first interface in a module. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Change-Id: Ie6d3d48ea3012bd328eb20e2e6693928fe24ead8 Reviewed-on: https://code.wireshark.org/review/23711 Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--tools/pidl/lib/Parse/Pidl/Samba4/Python.pm46
1 files changed, 34 insertions, 12 deletions
diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm b/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm
index e72c725440..fe7b2a01cd 100644
--- a/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -24,7 +24,9 @@ sub new($) {
my ($class) = @_;
my $self = { res => "", res_hdr => "", tabs => "",
constants => [], constants_uniq => {},
- module_methods => [], module_objects => [], ready_types => [],
+ module_methods => [],
+ module_objects => [], module_objects_uniq => {},
+ ready_types => [],
module_imports => [], module_imports_uniq => {},
type_imports => [], type_imports_uniq => {},
patch_type_calls => [], prereadycode => [],
@@ -657,7 +659,7 @@ sub PythonType($$$$)
$typeobject = $self->PythonStruct($modulename, $fn_name, $d->{NAME}, mapTypeName($d), $d->{DATA});
}
- $self->register_module_typeobject($fn_name, $typeobject);
+ $self->register_module_typeobject($fn_name, $typeobject, $d->{ORIGINAL});
}
if ($d->{TYPE} eq "ENUM" or $d->{TYPE} eq "BITMAP") {
@@ -797,7 +799,7 @@ sub Interface($$$)
$self->pidl("");
- $self->register_module_typeobject($interface->{NAME}, "&$if_typename");
+ $self->register_module_typeobject($interface->{NAME}, "&$if_typename", $interface->{ORIGINAL});
my $dcerpc_typename = $self->import_type_variable("samba.dcerpc.base", "ClientConnection");
$self->register_module_prereadycode(["$if_typename.tp_base = $dcerpc_typename;", ""]);
$self->register_module_postreadycode(["if (!PyInterface_AddNdrRpcMethods(&$if_typename, py_ndr_$interface->{NAME}\_methods))", "\treturn;", ""]);
@@ -812,7 +814,7 @@ sub Interface($$$)
$self->pidl("");
- my $signature = "\"abstract_syntax()\\n\"";
+ my $signature = "\"$interface->{NAME}_abstract_syntax()\\n\"";
my $docstring = $self->DocString($interface, $interface->{NAME}."_syntax");
@@ -827,7 +829,7 @@ sub Interface($$$)
$self->pidl("static PyTypeObject $syntax_typename = {");
$self->indent;
$self->pidl("PyObject_HEAD_INIT(NULL) 0,");
- $self->pidl(".tp_name = \"$basename.$interface->{NAME}\",");
+ $self->pidl(".tp_name = \"$basename.$interface->{NAME}_abstract_syntax\",");
$self->pidl(".tp_doc = $docstring,");
$self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,");
$self->pidl(".tp_new = syntax_$interface->{NAME}_new,");
@@ -836,7 +838,12 @@ sub Interface($$$)
$self->pidl("");
- $self->register_module_typeobject("abstract_syntax", "&$syntax_typename");
+ $self->register_module_typeobject("$interface->{NAME}_abstract_syntax", "&$syntax_typename", $interface->{ORIGINAL});
+ if (not defined($self->existing_module_object("abstract_syntax"))) {
+ # Only the first syntax gets registered with the legacy
+ # "abstract_syntax" name
+ $self->register_module_typeobject("abstract_syntax", "&$syntax_typename", $interface->{ORIGINAL});
+ }
my $ndr_typename = $self->import_type_variable("samba.dcerpc.misc", "ndr_syntax_id");
$self->register_module_prereadycode(["$syntax_typename.tp_base = $ndr_typename;",
"$syntax_typename.tp_basicsize = pytalloc_BaseObject_size();",
@@ -853,11 +860,11 @@ sub register_module_method($$$$$)
push (@{$self->{module_methods}}, [$fn_name, $pyfn_name, $flags, $doc])
}
-sub register_module_typeobject($$$)
+sub register_module_typeobject($$$$)
{
- my ($self, $name, $py_name) = @_;
+ my ($self, $name, $py_name, $location) = @_;
- $self->register_module_object($name, "(PyObject *)(void *)$py_name");
+ $self->register_module_object($name, "(PyObject *)(void *)$py_name", $location);
$self->check_ready_type($py_name);
@@ -946,11 +953,26 @@ sub register_module_postreadycode($$)
push (@{$self->{postreadycode}}, @$code);
}
-sub register_module_object($$$)
+sub existing_module_object($$)
+{
+ my ($self, $name) = @_;
+
+ if (defined($self->{module_object_uniq}->{$name})) {
+ return $self->{module_object_uniq}->{$name};
+ }
+
+ return undef;
+}
+
+sub register_module_object($$$$)
{
- my ($self, $name, $py_name) = @_;
+ my ($self, $name, $py_name, $location) = @_;
+
+ my $existing = $self->existing_module_object($name);
+ fatal($location, "module_object($name, $py_name) registered twice! $existing.") if defined($existing);
- push (@{$self->{module_objects}}, [$name, $py_name])
+ push (@{$self->{module_objects}}, [$name, $py_name]);
+ $self->{module_object_uniq}->{$name} = $py_name;
}
sub assign($$$)