From f5e6534ee7934c12eb19dca307f1732d73c86ec5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 6 Apr 2008 00:42:27 +0200 Subject: Fix authservice count. (This used to be commit 761536a5e4dd3dbfacf1576d7092827cdeda897b) --- source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index a959dc84f6..9fb5a6a597 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -2248,7 +2248,7 @@ sub FunctionTable($$) $self->pidl(""); $self->pidl("static const struct ndr_interface_string_array $interface->{NAME}\_authservices = {"); - $self->pidl("\t.count\t= $endpoint_count,"); + $self->pidl("\t.count\t= $authservice_count,"); $self->pidl("\t.names\t= $interface->{NAME}\_authservice_strings"); $self->pidl("};"); $self->pidl(""); -- cgit From c30f9add8cc5b060b73381f53671ecd01c31cdd8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 6 Apr 2008 00:57:14 +0200 Subject: Add test for authservice struct. (This used to be commit da8b8364b06a79a10d4ebdc0e451463b3105730e) --- source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm | 37 ++++++++++++++---------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index 9fb5a6a597..0d1806a0fa 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -2190,6 +2190,26 @@ sub ParseFunctionPull($$) $self->pidl(""); } +sub AuthServiceStruct($$$) +{ + my ($self, $ifacename, $authservice) = @_; + my @a = split /,/, $authservice; + my $authservice_count = $#a + 1; + + $self->pidl("static const char * const $ifacename\_authservice_strings[] = {"); + foreach my $ap (@a) { + $self->pidl("\t$ap, "); + } + $self->pidl("};"); + $self->pidl(""); + + $self->pidl("static const struct ndr_interface_string_array $ifacename\_authservices = {"); + $self->pidl("\t.count\t= $authservice_count,"); + $self->pidl("\t.names\t= $ifacename\_authservice_strings"); + $self->pidl("};"); + $self->pidl(""); +} + ##################################################################### # produce a function call table sub FunctionTable($$) @@ -2237,21 +2257,8 @@ sub FunctionTable($$) $interface->{PROPERTIES}->{authservice} = "\"host\""; } - my @a = split /,/, $interface->{PROPERTIES}->{authservice}; - my $authservice_count = $#a + 1; - - $self->pidl("static const char * const $interface->{NAME}\_authservice_strings[] = {"); - foreach my $ap (@a) { - $self->pidl("\t$ap, "); - } - $self->pidl("};"); - $self->pidl(""); - - $self->pidl("static const struct ndr_interface_string_array $interface->{NAME}\_authservices = {"); - $self->pidl("\t.count\t= $authservice_count,"); - $self->pidl("\t.names\t= $interface->{NAME}\_authservice_strings"); - $self->pidl("};"); - $self->pidl(""); + $self->AuthServiceStruct($interface->{NAME}, + $interface->{PROPERTIES}->{authservice}); $self->pidl("\nconst struct ndr_interface_table ndr_table_$interface->{NAME} = {"); $self->pidl("\t.name\t\t= \"$interface->{NAME}\","); -- cgit From f07ded6d8921a4a2572d07af2b10aede0b4ce0cb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 7 Apr 2008 23:21:38 +0200 Subject: Add simple docstring for Python modules. (This used to be commit 57c7b4e896116f06b39e0040ad386c561d76bd3d) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 2475925377..6d51d8ec56 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -929,7 +929,7 @@ sub Parse($$$$$) $self->pidl("{"); $self->indent; $self->pidl("PyObject *m;"); - $self->pidl("m = Py_InitModule(\"$basename\", $basename\_methods);"); + $self->pidl("m = Py_InitModule3(\"$basename\", $basename\_methods, \"$basename DCE/RPC interface\");"); foreach my $name (keys %{$self->{constants}}) { my $py_obj; my ($ctype, $cvar) = @{$self->{constants}->{$name}}; -- cgit From a057c7369ae756f67aed107613dec69008c0e78f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 8 Apr 2008 00:10:24 +0200 Subject: Set docstrings from helpstring attribute where possible. (This used to be commit 07f52ca51c008a6b80fed5b03935e1c3241d08d5) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 52 ++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 14 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 6d51d8ec56..26ef6ae0c9 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -226,6 +226,7 @@ sub PythonStruct($$$$) $self->pidl_hdr("#define $name\_Check(op) PyObject_TypeCheck(op, &$name\_Type)\n"); $self->pidl_hdr("#define $name\_CheckExact(op) ((op)->ob_type == &$name\_Type)\n"); $self->pidl_hdr("\n"); + my $docstring = $self->DocString($d, $name); $self->pidl("PyTypeObject $name\_Type = {"); $self->indent; $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); @@ -235,6 +236,7 @@ sub PythonStruct($$$$) $self->pidl(".tp_getattr = py_$name\_getattr,"); $self->pidl(".tp_setattr = py_$name\_setattr,"); $self->pidl(".tp_repr = py_talloc_default_repr,"); + $self->pidl(".tp_doc = $docstring,"); $self->deindent; $self->pidl("};"); @@ -250,14 +252,18 @@ sub PythonStruct($$$$) $self->pidl("}"); $self->pidl(""); - return $py_fnname; + return ($py_fnname, "NULL"); } sub PythonFunction($$$) { my ($self, $fn, $iface) = @_; - $self->pidl("static PyObject *py_$fn->{NAME}(PyObject *self, PyObject *args, PyObject *kwargs)"); + my $docstring = $self->DocString($fn, $fn->{NAME}); + + my $fnname = "py_$fn->{NAME}"; + + $self->pidl("static PyObject *$fnname(PyObject *self, PyObject *args, PyObject *kwargs)"); $self->pidl("{"); $self->indent; $self->pidl("$iface\_InterfaceObject *iface = ($iface\_InterfaceObject *)self;"); @@ -347,6 +353,8 @@ sub PythonFunction($$$) $self->deindent; $self->pidl("}"); $self->pidl(""); + + return ($fnname, $docstring); } sub handle_werror($$$$) @@ -387,11 +395,11 @@ sub PythonType($$$) } if ($actual_ctype->{TYPE} eq "STRUCT") { - my $py_fnname; + my ($py_fnname, $py_fndocstring); if ($d->{TYPE} eq "STRUCT") { - $py_fnname = $self->PythonStruct($d->{NAME}, mapTypeName($d), $d); + ($py_fnname, $py_fndocstring) = $self->PythonStruct($d->{NAME}, mapTypeName($d), $d); } else { - $py_fnname = $self->PythonStruct($d->{NAME}, mapTypeName($d), $d->{DATA}); + ($py_fnname, $py_fndocstring) = $self->PythonStruct($d->{NAME}, mapTypeName($d), $d->{DATA}); } my $fn_name = $d->{NAME}; @@ -399,7 +407,7 @@ sub PythonType($$$) $fn_name =~ s/^$interface->{NAME}_//; $fn_name =~ s/^$basename\_//; - $self->register_module_method($fn_name, $py_fnname, "METH_NOARGS", "NULL"); + $self->register_module_method($fn_name, $py_fnname, "METH_NOARGS", $py_fndocstring); } if ($d->{TYPE} eq "ENUM" or $d->{TYPE} eq "BITMAP") { @@ -429,6 +437,18 @@ sub PythonType($$$) } } +sub DocString($$$) +{ + my ($self, $d, $name) = @_; + if (has_property($d, "helpstring")) { + my $docstring = "py_doc_$name"; + $self->pidl("static const char ".$docstring."[] = ".has_property($d, "helpstring").";"); + return $docstring; + } + + return "NULL"; +} + sub Interface($$$) { my($self,$interface,$basename) = @_; @@ -457,25 +477,27 @@ sub Interface($$$) $self->pidl(""); + my @fns = (); + foreach my $d (@{$interface->{FUNCTIONS}}) { next if not defined($d->{OPNUM}); next if has_property($d, "nopython"); - $self->PythonFunction($d, $interface->{NAME}); + my ($fnname, $fndocstring) = $self->PythonFunction($d, $interface->{NAME}); + + push (@fns, [$fnname, $fndocstring]); } $self->pidl("static PyMethodDef interface_$interface->{NAME}\_methods[] = {"); $self->indent; - foreach my $d (@{$interface->{FUNCTIONS}}) { - next if not defined($d->{OPNUM}); - next if has_property($d, "nopython"); - - my $fn_name = $d->{NAME}; + foreach my $d (@fns) { + my ($c_fn, $docstring) = @$d; + my $fn_name = $c_fn; $fn_name =~ s/^$interface->{NAME}_//; $fn_name =~ s/^$basename\_//; - $self->pidl("{ \"$fn_name\", (PyCFunction)py_$d->{NAME}, METH_VARARGS|METH_KEYWORDS, NULL },"); + $self->pidl("{ \"$fn_name\", (PyCFunction)$c_fn, METH_VARARGS|METH_KEYWORDS, $docstring },"); } $self->pidl("{ NULL, NULL, 0, NULL }"); $self->deindent; @@ -501,6 +523,7 @@ sub Interface($$$) $self->pidl(""); + my $docstring = $self->DocString($interface, $interface->{NAME}); $self->pidl("PyTypeObject $interface->{NAME}_InterfaceType = {"); $self->indent; $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); @@ -508,12 +531,13 @@ sub Interface($$$) $self->pidl(".tp_basicsize = sizeof($interface->{NAME}_InterfaceObject),"); $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,"); $self->pidl(".tp_getattr = interface_$interface->{NAME}_getattr,"); + $self->pidl(".tp_doc = $docstring,"); $self->deindent; $self->pidl("};"); $self->pidl(""); - $self->register_module_method($interface->{NAME}, "interface_$interface->{NAME}", "METH_VARARGS|METH_KEYWORDS", "NULL"); + $self->register_module_method($interface->{NAME}, "interface_$interface->{NAME}", "METH_VARARGS|METH_KEYWORDS", "\"$interface->{NAME}(binding, lp_ctx, credentials)\\nConnect to the $interface->{NAME} interface\""); $self->pidl("static PyObject *interface_$interface->{NAME}(PyObject *self, PyObject *args, PyObject *kwargs)"); $self->pidl("{"); $self->indent; -- cgit From a3bfabefd71c88a651ae153ce6482313d7f9e405 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 8 Apr 2008 00:13:09 +0200 Subject: Set tp_flags for Python types. (This used to be commit f214206a36d8822e485f6f076c9f3f0bfc1e1df4) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 26ef6ae0c9..2191bc0fbb 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -237,6 +237,7 @@ sub PythonStruct($$$$) $self->pidl(".tp_setattr = py_$name\_setattr,"); $self->pidl(".tp_repr = py_talloc_default_repr,"); $self->pidl(".tp_doc = $docstring,"); + $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT,"); $self->deindent; $self->pidl("};"); @@ -532,6 +533,7 @@ sub Interface($$$) $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,"); $self->pidl(".tp_getattr = interface_$interface->{NAME}_getattr,"); $self->pidl(".tp_doc = $docstring,"); + $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT,"); $self->deindent; $self->pidl("};"); -- cgit From 6f02fdea23b97204db3f1ac7a266cbde657371ff Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 8 Apr 2008 00:59:27 +0200 Subject: Register types rather than constructors, display structs as classes. (This used to be commit aad07f482544107dbeb4c3c468ce7dd78c151849) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 159 ++++++++++++++++----------- 1 file changed, 96 insertions(+), 63 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 2191bc0fbb..efec2cae1f 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -21,7 +21,7 @@ $VERSION = '0.01'; sub new($) { my ($class) = @_; my $self = { res => "", res_hdr => "", tabs => "", constants => {}, - module_methods => []}; + module_methods => [], module_objects => [], module_types => []}; bless($self, $class); } @@ -163,9 +163,9 @@ sub FromPythonToUnionFunction($$$$$) $self->pidl("return ret;"); } -sub PythonStruct($$$$) +sub PythonStruct($$$$$$) { - my ($self, $name, $cname, $d) = @_; + my ($self, $modulename, $prettyname, $name, $cname, $d) = @_; my $env = GenerateStructEnv($d, "object"); @@ -222,38 +222,40 @@ sub PythonStruct($$$$) $self->pidl("}"); $self->pidl(""); + $self->pidl("static PyObject *py_$name\_new(PyTypeObject *self, PyObject *args, PyObject *kwargs)"); + $self->pidl("{"); + $self->indent; + $self->pidl("$cname *ret = talloc_zero(NULL, $cname);"); + $self->pidl("return py_talloc_import(&$name\_Type, ret);"); + $self->deindent; + $self->pidl("}"); + + $self->pidl(""); + $self->pidl_hdr("PyAPI_DATA(PyTypeObject) $name\_Type;\n"); $self->pidl_hdr("#define $name\_Check(op) PyObject_TypeCheck(op, &$name\_Type)\n"); $self->pidl_hdr("#define $name\_CheckExact(op) ((op)->ob_type == &$name\_Type)\n"); $self->pidl_hdr("\n"); my $docstring = $self->DocString($d, $name); - $self->pidl("PyTypeObject $name\_Type = {"); + my $typeobject = "$name\_Type"; + $self->pidl("PyTypeObject $typeobject = {"); $self->indent; $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); - $self->pidl(".tp_name = \"$name\","); + $self->pidl(".tp_name = \"$modulename.$prettyname\","); $self->pidl(".tp_basicsize = sizeof(py_talloc_Object),"); $self->pidl(".tp_dealloc = py_talloc_dealloc,"); $self->pidl(".tp_getattr = py_$name\_getattr,"); $self->pidl(".tp_setattr = py_$name\_setattr,"); $self->pidl(".tp_repr = py_talloc_default_repr,"); $self->pidl(".tp_doc = $docstring,"); - $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT,"); + $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,"); + $self->pidl(".tp_new = py_$name\_new,"); $self->deindent; $self->pidl("};"); $self->pidl(""); - my $py_fnname = "py_$name"; - $self->pidl("static PyObject *$py_fnname(PyObject *self, PyObject *args)"); - $self->pidl("{"); - $self->indent; - $self->pidl("$cname *ret = talloc_zero(NULL, $cname);"); - $self->pidl("return py_talloc_import(&$name\_Type, ret);"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); - - return ($py_fnname, "NULL"); + return "&$typeobject"; } sub PythonFunction($$$) @@ -386,9 +388,9 @@ sub handle_ntstatus($$$$) $self->pidl(""); } -sub PythonType($$$) +sub PythonType($$$$) { - my ($self, $d, $interface, $basename) = @_; + my ($self, $modulename, $d, $interface, $basename) = @_; my $actual_ctype = $d; if ($actual_ctype->{TYPE} eq "TYPEDEF") { @@ -396,19 +398,20 @@ sub PythonType($$$) } if ($actual_ctype->{TYPE} eq "STRUCT") { - my ($py_fnname, $py_fndocstring); - if ($d->{TYPE} eq "STRUCT") { - ($py_fnname, $py_fndocstring) = $self->PythonStruct($d->{NAME}, mapTypeName($d), $d); - } else { - ($py_fnname, $py_fndocstring) = $self->PythonStruct($d->{NAME}, mapTypeName($d), $d->{DATA}); - } - + my $typeobject; my $fn_name = $d->{NAME}; $fn_name =~ s/^$interface->{NAME}_//; $fn_name =~ s/^$basename\_//; - $self->register_module_method($fn_name, $py_fnname, "METH_NOARGS", $py_fndocstring); + + if ($d->{TYPE} eq "STRUCT") { + $typeobject = $self->PythonStruct($modulename, $fn_name, $d->{NAME}, mapTypeName($d), $d); + } else { + $typeobject = $self->PythonStruct($modulename, $fn_name, $d->{NAME}, mapTypeName($d), $d->{DATA}); + } + + $self->register_module_typeobject($fn_name, $typeobject); } if ($d->{TYPE} eq "ENUM" or $d->{TYPE} eq "BITMAP") { @@ -464,7 +467,7 @@ sub Interface($$$) foreach my $d (@{$interface->{TYPES}}) { next if has_property($d, "nopython"); - $self->PythonType($d, $interface, $basename); + $self->PythonType($basename, $d, $interface, $basename); } if (defined $interface->{PROPERTIES}->{uuid}) { @@ -486,19 +489,19 @@ sub Interface($$$) my ($fnname, $fndocstring) = $self->PythonFunction($d, $interface->{NAME}); - push (@fns, [$fnname, $fndocstring]); + my $prettyname = $d->{NAME}; + + $prettyname =~ s/^$interface->{NAME}_//; + $prettyname =~ s/^$basename\_//; + + push (@fns, [$fnname, $prettyname, $fndocstring]); } $self->pidl("static PyMethodDef interface_$interface->{NAME}\_methods[] = {"); $self->indent; foreach my $d (@fns) { - my ($c_fn, $docstring) = @$d; - my $fn_name = $c_fn; - - $fn_name =~ s/^$interface->{NAME}_//; - $fn_name =~ s/^$basename\_//; - - $self->pidl("{ \"$fn_name\", (PyCFunction)$c_fn, METH_VARARGS|METH_KEYWORDS, $docstring },"); + my ($c_fn, $prettyname, $docstring) = @$d; + $self->pidl("{ \"$prettyname\", (PyCFunction)$c_fn, METH_VARARGS|METH_KEYWORDS, $docstring },"); } $self->pidl("{ NULL, NULL, 0, NULL }"); $self->deindent; @@ -515,32 +518,7 @@ sub Interface($$$) $self->pidl("}"); $self->pidl(""); - $self->pidl("static PyObject *interface_$interface->{NAME}_getattr(PyObject *obj, char *name)"); - $self->pidl("{"); - $self->indent; - $self->pidl("return Py_FindMethod(interface_$interface->{NAME}\_methods, obj, name);"); - $self->deindent; - $self->pidl("}"); - - $self->pidl(""); - - my $docstring = $self->DocString($interface, $interface->{NAME}); - $self->pidl("PyTypeObject $interface->{NAME}_InterfaceType = {"); - $self->indent; - $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); - $self->pidl(".tp_name = \"$interface->{NAME}\","); - $self->pidl(".tp_basicsize = sizeof($interface->{NAME}_InterfaceObject),"); - $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,"); - $self->pidl(".tp_getattr = interface_$interface->{NAME}_getattr,"); - $self->pidl(".tp_doc = $docstring,"); - $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT,"); - $self->deindent; - $self->pidl("};"); - - $self->pidl(""); - - $self->register_module_method($interface->{NAME}, "interface_$interface->{NAME}", "METH_VARARGS|METH_KEYWORDS", "\"$interface->{NAME}(binding, lp_ctx, credentials)\\nConnect to the $interface->{NAME} interface\""); - $self->pidl("static PyObject *interface_$interface->{NAME}(PyObject *self, PyObject *args, PyObject *kwargs)"); + $self->pidl("static PyObject *interface_$interface->{NAME}_new(PyTypeObject *self, PyObject *args, PyObject *kwargs)"); $self->pidl("{"); $self->indent; $self->pidl("$interface->{NAME}_InterfaceObject *ret;"); @@ -600,6 +578,25 @@ sub Interface($$$) $self->pidl("}"); $self->pidl(""); + + + my $docstring = $self->DocString($interface, $interface->{NAME}); + $self->pidl("PyTypeObject $interface->{NAME}_InterfaceType = {"); + $self->indent; + $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); + $self->pidl(".tp_name = \"$basename.$interface->{NAME}\","); + $self->pidl(".tp_basicsize = sizeof($interface->{NAME}_InterfaceObject),"); + $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,"); + $self->pidl(".tp_methods = interface_$interface->{NAME}_methods,"); + $self->pidl(".tp_doc = $docstring,"); + $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,"); + $self->pidl(".tp_new = interface_$interface->{NAME}_new,"); + $self->deindent; + $self->pidl("};"); + + $self->pidl(""); + + $self->register_module_typeobject($interface->{NAME}, "&$interface->{NAME}_InterfaceType"); } $self->pidl_hdr("\n"); @@ -613,6 +610,22 @@ sub register_module_method($$$$$) push (@{$self->{module_methods}}, [$fn_name, $pyfn_name, $flags, $doc]) } +sub register_module_typeobject($$$) +{ + my ($self, $name, $py_name) = @_; + + $self->register_module_object($name, "(PyObject *)$py_name"); + + push (@{$self->{module_types}}, [$name, $py_name]) +} + +sub register_module_object($$$) +{ + my ($self, $name, $py_name) = @_; + + push (@{$self->{module_objects}}, [$name, $py_name]) +} + sub assign($$$) { my ($self, $dest, $src) = @_; @@ -955,7 +968,20 @@ sub Parse($$$$$) $self->pidl("{"); $self->indent; $self->pidl("PyObject *m;"); - $self->pidl("m = Py_InitModule3(\"$basename\", $basename\_methods, \"$basename DCE/RPC interface\");"); + $self->pidl(""); + + foreach (@{$self->{module_types}}) { + my ($object_name, $c_name) = @$_; + $self->pidl("if (PyType_Ready($c_name) < 0)"); + $self->pidl("\treturn;"); + } + + $self->pidl(""); + + $self->pidl("m = Py_InitModule3(\"$basename\", $basename\_methods, \"$basename DCE/RPC\");"); + $self->pidl("if (m == NULL)"); + $self->pidl("\treturn;"); + $self->pidl(""); foreach my $name (keys %{$self->{constants}}) { my $py_obj; my ($ctype, $cvar) = @{$self->{constants}->{$name}}; @@ -969,6 +995,13 @@ sub Parse($$$$$) $self->pidl("PyModule_AddObject(m, \"$name\", $py_obj);"); } + + foreach (@{$self->{module_objects}}) { + my ($object_name, $c_name) = @$_; + $self->pidl("Py_INCREF($c_name);"); + $self->pidl("PyModule_AddObject(m, \"$object_name\", $c_name);"); + } + $self->deindent; $self->pidl("}"); return ($self->{res_hdr}, $self->{res}); -- cgit From a5d51180baf302ff109b9985b74d7a60b21ee73c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 8 Apr 2008 01:23:19 +0200 Subject: Add function signature to docstrings in python. (This used to be commit 61f331e9748bf5b3a1120ef19f93790facf9f64c) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 34 +++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index efec2cae1f..3043430b68 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -260,7 +260,7 @@ sub PythonStruct($$$$$$) sub PythonFunction($$$) { - my ($self, $fn, $iface) = @_; + my ($self, $fn, $iface, $prettyname) = @_; my $docstring = $self->DocString($fn, $fn->{NAME}); @@ -282,6 +282,8 @@ sub PythonFunction($$$) my $args_string = ""; my $args_names = ""; + my $signature = "S.$prettyname("; + foreach my $e (@{$fn->{ELEMENTS}}) { $self->pidl("PyObject *py_$e->{NAME};"); if (grep(/out/,@{$e->{DIRECTION}})) { @@ -291,8 +293,14 @@ sub PythonFunction($$$) $args_format .= "O"; $args_string .= ", &py_$e->{NAME}"; $args_names .= "\"$e->{NAME}\", "; + $signature .= "$e->{NAME}, "; } } + if (substr($signature, -2) eq ", ") { + $signature = substr($signature, 0, -2); + } + $signature.= ") -> "; + $self->pidl("const char *kwnames[] = {"); $self->indent; $self->pidl($args_names . "NULL"); @@ -323,6 +331,9 @@ sub PythonFunction($$$) if ($result_size > 1) { $self->pidl("result = PyTuple_New($result_size);"); + $signature .= "("; + } elsif ($result_size == 0) { + $signature .= "None"; } foreach my $e (@{$fn->{ELEMENTS}}) { @@ -332,8 +343,10 @@ sub PythonFunction($$$) if ($result_size > 1) { $self->pidl("PyTuple_SetItem(result, $i, $py_name);"); $i++; + $signature .= "$e->{NAME}, "; } else { $self->pidl("result = $py_name;"); + $signature .= "result"; } } } @@ -346,17 +359,32 @@ sub PythonFunction($$$) my $conv = $self->ConvertObjectToPythonData("r", $fn->{RETURN_TYPE}, "r->out.result"); if ($result_size > 1) { $self->pidl("PyTuple_SetItem(result, $i, $conv);"); + $signature .= "result"; } else { $self->pidl("result = $conv;"); + $signature .= "result"; } } + if (substr($signature, -2) eq ", ") { + $signature = substr($signature, 0, -2); + } + if ($result_size > 1) { + $signature .= ")"; + } + $self->pidl("talloc_free(mem_ctx);"); $self->pidl("return result;"); $self->deindent; $self->pidl("}"); $self->pidl(""); + if ($docstring eq "NULL") { + $docstring = "\"$signature\""; + } else { + $docstring = "\"$signature\\n\\n\"$docstring"; + } + return ($fnname, $docstring); } @@ -487,13 +515,13 @@ sub Interface($$$) next if not defined($d->{OPNUM}); next if has_property($d, "nopython"); - my ($fnname, $fndocstring) = $self->PythonFunction($d, $interface->{NAME}); - my $prettyname = $d->{NAME}; $prettyname =~ s/^$interface->{NAME}_//; $prettyname =~ s/^$basename\_//; + my ($fnname, $fndocstring) = $self->PythonFunction($d, $interface->{NAME}, $prettyname); + push (@fns, [$fnname, $prettyname, $fndocstring]); } -- cgit From 0bea00f481ffa0fd20457fbe4c448bfac93940b5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 8 Apr 2008 01:42:27 +0200 Subject: use builtin getset stuff rather than custom getattr/setattr implementation. (This used to be commit bb59f3084ff8ff99e5bd72abfaadcbb68110f9fa) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 51 +++++++++++++--------------- 1 file changed, 23 insertions(+), 28 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 3043430b68..bd124e79e5 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -171,38 +171,27 @@ sub PythonStruct($$$$$$) $self->pidl(""); - $self->pidl("static PyObject *py_$name\_getattr(PyObject *obj, char *name)"); - $self->pidl("{"); - $self->indent; + my $getsetters = "NULL"; + if ($#{$d->{ELEMENTS}} > -1) { - $self->pidl("$cname *object = py_talloc_get_ptr(obj);"); foreach my $e (@{$d->{ELEMENTS}}) { - $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); my $varname = "object->$e->{NAME}"; + $self->pidl("static PyObject *py_$name\_get_$e->{NAME}(PyObject *obj, void *closure)"); + $self->pidl("{"); $self->indent; + $self->pidl("$cname *object = py_talloc_get_ptr(obj);"); $self->pidl("PyObject *py_$e->{NAME};"); $self->ConvertObjectToPython("py_talloc_get_mem_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}"); $self->pidl("return py_$e->{NAME};"); $self->deindent; $self->pidl("}"); - } - } - $self->pidl("PyErr_SetString(PyExc_AttributeError, \"no such attribute\");"); - $self->pidl("return NULL;"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); + $self->pidl(""); - $self->pidl("static int py_$name\_setattr(PyObject *py_obj, char *name, PyObject *value)"); - $self->pidl("{"); - $self->indent; - if ($#{$d->{ELEMENTS}} > -1) { - $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); - my $mem_ctx = "py_talloc_get_mem_ctx(py_obj)"; - foreach my $e (@{$d->{ELEMENTS}}) { - $self->pidl("if (!strcmp(name, \"$e->{NAME}\")) {"); - my $varname = "object->$e->{NAME}"; + $self->pidl("static int py_$name\_set_$e->{NAME}(PyObject *py_obj, PyObject *value, void *closure)"); + $self->pidl("{"); $self->indent; + $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); + my $mem_ctx = "py_talloc_get_mem_ctx(py_obj)"; my $l = $e->{LEVELS}[0]; my $nl = GetNextLevel($e, $l); if ($l->{TYPE} eq "POINTER" and @@ -214,13 +203,20 @@ sub PythonStruct($$$$$$) $self->pidl("return 0;"); $self->deindent; $self->pidl("}"); + $self->pidl(""); + } + + $getsetters = "py_$name\_getsetters"; + $self->pidl("static PyGetSetDef ".$getsetters."[] = {"); + $self->indent; + foreach my $e (@{$d->{ELEMENTS}}) { + $self->pidl("{ discard_const_p(char, \"$e->{NAME}\"), py_$name\_get_$e->{NAME}, py_$name\_set_$e->{NAME} },"); } + $self->pidl("{ NULL }"); + $self->deindent; + $self->pidl("};"); + $self->pidl(""); } - $self->pidl("PyErr_SetString(PyExc_AttributeError, \"no such attribute\");"); - $self->pidl("return -1;"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); $self->pidl("static PyObject *py_$name\_new(PyTypeObject *self, PyObject *args, PyObject *kwargs)"); $self->pidl("{"); @@ -244,8 +240,7 @@ sub PythonStruct($$$$$$) $self->pidl(".tp_name = \"$modulename.$prettyname\","); $self->pidl(".tp_basicsize = sizeof(py_talloc_Object),"); $self->pidl(".tp_dealloc = py_talloc_dealloc,"); - $self->pidl(".tp_getattr = py_$name\_getattr,"); - $self->pidl(".tp_setattr = py_$name\_setattr,"); + $self->pidl(".tp_getset = $getsetters,"); $self->pidl(".tp_repr = py_talloc_default_repr,"); $self->pidl(".tp_doc = $docstring,"); $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,"); -- cgit From b99d24419f9934ab5467f11a5f59d34618686c91 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 8 Apr 2008 02:08:31 +0200 Subject: Add signature of connect function to docstrings. (This used to be commit 51441376d37de01f7f4bd795947fc2c46c38e3f1) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index bd124e79e5..40c0cd51cb 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -232,7 +232,7 @@ sub PythonStruct($$$$$$) $self->pidl_hdr("#define $name\_Check(op) PyObject_TypeCheck(op, &$name\_Type)\n"); $self->pidl_hdr("#define $name\_CheckExact(op) ((op)->ob_type == &$name\_Type)\n"); $self->pidl_hdr("\n"); - my $docstring = $self->DocString($d, $name); + my $docstring = ($self->DocString($d, $name) or "NULL"); my $typeobject = "$name\_Type"; $self->pidl("PyTypeObject $typeobject = {"); $self->indent; @@ -374,10 +374,10 @@ sub PythonFunction($$$) $self->pidl("}"); $self->pidl(""); - if ($docstring eq "NULL") { - $docstring = "\"$signature\""; - } else { + if ($docstring) { $docstring = "\"$signature\\n\\n\"$docstring"; + } else { + $docstring = "\"$signature\""; } return ($fnname, $docstring); @@ -468,12 +468,12 @@ sub DocString($$$) { my ($self, $d, $name) = @_; if (has_property($d, "helpstring")) { - my $docstring = "py_doc_$name"; - $self->pidl("static const char ".$docstring."[] = ".has_property($d, "helpstring").";"); + my $docstring = uc("py_doc_$name"); + $self->pidl("#define $docstring ".has_property($d, "helpstring")); return $docstring; } - return "NULL"; + return undef; } sub Interface($$$) @@ -602,8 +602,21 @@ sub Interface($$$) $self->pidl(""); + my $signature = +"\"$interface->{NAME}(binding, lp_ctx=None, credentials=None) -> Connection to DCE/RPC interface.\\n\" +\"\\n\" +\"binding should be a DCE/RPC binding string (for example: ncacn_ip_tcp:127.0.0.1)\\n\" +\"lp_ctx should be a path to a smb.conf file or a param.LoadParm object\\n\" +\"credentials should be a credentials.Credentials object.\\n\\n\""; my $docstring = $self->DocString($interface, $interface->{NAME}); + + if ($docstring) { + $docstring = "$signature$docstring"; + } else { + $docstring = $signature; + } + $self->pidl("PyTypeObject $interface->{NAME}_InterfaceType = {"); $self->indent; $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); -- cgit From ab27e718fd88dde3c8ad716042f5c37a8e4ecab3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 8 Apr 2008 02:57:59 +0200 Subject: Support [todo] attribute on functions. (This used to be commit a3e22bbcea27580c31d44dfaae04c9eef83389d4) --- source4/pidl/lib/Parse/Pidl/NDR.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/NDR.pm b/source4/pidl/lib/Parse/Pidl/NDR.pm index 86ed1a8d10..33e5ad3196 100644 --- a/source4/pidl/lib/Parse/Pidl/NDR.pm +++ b/source4/pidl/lib/Parse/Pidl/NDR.pm @@ -866,6 +866,7 @@ my %property_list = ( "nosize" => ["FUNCTION", "TYPEDEF"], "noprint" => ["FUNCTION", "TYPEDEF"], "noejs" => ["FUNCTION", "TYPEDEF"], + "todo" => ["FUNCTION"], # union "switch_is" => ["ELEMENT"], -- cgit From e5aa9f7e8dbb5b66a5ce25f50ed67dfcae7a1809 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 8 Apr 2008 02:58:18 +0200 Subject: Raise NotImplementedError from functions that don't have complete IDL. (This used to be commit 685aab0c99c87386fee64c07d8b68c75652713c6) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 43 +++++++++++++++++++--------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 40c0cd51cb..c04324e992 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -253,17 +253,10 @@ sub PythonStruct($$$$$$) return "&$typeobject"; } -sub PythonFunction($$$) +sub PythonFunctionBody($$$) { my ($self, $fn, $iface, $prettyname) = @_; - my $docstring = $self->DocString($fn, $fn->{NAME}); - - my $fnname = "py_$fn->{NAME}"; - - $self->pidl("static PyObject *$fnname(PyObject *self, PyObject *args, PyObject *kwargs)"); - $self->pidl("{"); - $self->indent; $self->pidl("$iface\_InterfaceObject *iface = ($iface\_InterfaceObject *)self;"); $self->pidl("NTSTATUS status;"); $self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);"); @@ -370,16 +363,38 @@ sub PythonFunction($$$) $self->pidl("talloc_free(mem_ctx);"); $self->pidl("return result;"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); - if ($docstring) { - $docstring = "\"$signature\\n\\n\"$docstring"; + return $signature; +} + +sub PythonFunction($$$) +{ + my ($self, $fn, $iface, $prettyname) = @_; + + my $fnname = "py_$fn->{NAME}"; + my $docstring = $self->DocString($fn, $fn->{NAME}); + + $self->pidl("static PyObject *$fnname(PyObject *self, PyObject *args, PyObject *kwargs)"); + $self->pidl("{"); + $self->indent; + if (has_property($fn, "todo")) { + $self->pidl("PyErr_SetString(PyExc_NotImplementedError, \"No marshalling code available yet for $prettyname\");"); + $self->pidl("return NULL;"); + unless ($docstring) { $docstring = "NULL"; } } else { - $docstring = "\"$signature\""; + my $signature = $self->PythonFunctionBody($fn, $iface, $prettyname); + + if ($docstring) { + $docstring = "\"$signature\\n\\n\"$docstring"; + } else { + $docstring = "\"$signature\""; + } } + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + return ($fnname, $docstring); } -- cgit From 5db62a16ff9b784c11c704b8083da9bf6e736f08 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 8 Apr 2008 14:19:26 +0200 Subject: Array lengths can be obtained from Python objects so remove them from the Python API. (This used to be commit 652810ff46c6db9034e930d0fb018a02ee385f15) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index c04324e992..5d514c5f09 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -272,7 +272,21 @@ sub PythonFunctionBody($$$) my $signature = "S.$prettyname("; + my %metadata_args = (); + + sub get_var($) { my $x = shift; $x =~ s/\*//g; return $x; } + + # Determine arguments that are metadata for other arguments (size_is/length_is) + foreach my $e (@{$fn->{ELEMENTS}}) { + if (has_property($e, "length_is")) { + $metadata_args{get_var($e->{PROPERTIES}->{length_is})} = $e->{NAME}; + } elsif (has_property($e, "size_is")) { + $metadata_args{get_var($e->{PROPERTIES}->{size_is})} = $e->{NAME}; + } + } + foreach my $e (@{$fn->{ELEMENTS}}) { + next if ($metadata_args{$e->{NAME}}); $self->pidl("PyObject *py_$e->{NAME};"); if (grep(/out/,@{$e->{DIRECTION}})) { $result_size++; @@ -307,7 +321,16 @@ sub PythonFunctionBody($$$) } foreach my $e (@{$fn->{ELEMENTS}}) { - if (grep(/in/,@{$e->{DIRECTION}})) { + next unless (grep(/in/,@{$e->{DIRECTION}})); + if ($metadata_args{$e->{NAME}}) { + my $val = "PyList_Size(py_".$metadata_args{$e->{NAME}}.")"; + if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { + $self->pidl("r->in.$e->{NAME} = talloc_ptrtype(mem_ctx, r->in.$e->{NAME});"); + $self->pidl("*r->in.$e->{NAME} = $val;"); + } else { + $self->pidl("r->in.$e->{NAME} = PyList_Size(py_".$metadata_args{$e->{NAME}}.");"); + } + } else { $self->ConvertObjectFromPython($env, "mem_ctx", $e, "py_$e->{NAME}", "r->in.$e->{NAME}", "talloc_free(mem_ctx); return NULL;"); } } @@ -325,6 +348,7 @@ sub PythonFunctionBody($$$) } foreach my $e (@{$fn->{ELEMENTS}}) { + next if ($metadata_args{$e->{NAME}}); my $py_name = "py_$e->{NAME}"; if (grep(/out/,@{$e->{DIRECTION}})) { $self->ConvertObjectToPython("r", $env, $e, "r->out.$e->{NAME}", $py_name); -- cgit From 90c8841beff1fe8c492670811aacd3b92e296912 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 8 Apr 2008 14:56:09 +0200 Subject: Fix bug handling size arguments in a direction without actual data. (This used to be commit 169d505e9e2285aedc21547e44986b8b841b8e37) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 33 ++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 5d514c5f09..2ab61e3246 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -272,21 +272,28 @@ sub PythonFunctionBody($$$) my $signature = "S.$prettyname("; - my %metadata_args = (); + my $metadata_args = { in => {}, out => {} }; sub get_var($) { my $x = shift; $x =~ s/\*//g; return $x; } # Determine arguments that are metadata for other arguments (size_is/length_is) foreach my $e (@{$fn->{ELEMENTS}}) { - if (has_property($e, "length_is")) { - $metadata_args{get_var($e->{PROPERTIES}->{length_is})} = $e->{NAME}; - } elsif (has_property($e, "size_is")) { - $metadata_args{get_var($e->{PROPERTIES}->{size_is})} = $e->{NAME}; + foreach my $dir (@{$e->{DIRECTION}}) { + my $main = undef; + if (has_property($e, "length_is")) { + $main = get_var($e->{PROPERTIES}->{length_is}); + } elsif (has_property($e, "size_is")) { + $main = get_var($e->{PROPERTIES}->{size_is}); + } + if ($main) { + $metadata_args->{$dir}->{$main} = $e->{NAME}; + } } } foreach my $e (@{$fn->{ELEMENTS}}) { - next if ($metadata_args{$e->{NAME}}); + next if (($metadata_args->{in}->{$e->{NAME}} and grep(/in/, @{$e->{DIRECTION}})) or + ($metadata_args->{out}->{$e->{NAME}}) and grep(/out/, @{$e->{DIRECTION}})); $self->pidl("PyObject *py_$e->{NAME};"); if (grep(/out/,@{$e->{DIRECTION}})) { $result_size++; @@ -315,23 +322,27 @@ sub PythonFunctionBody($$$) $self->pidl("return NULL;"); $self->deindent; $self->pidl("}"); + $self->pidl(""); if ($fn->{RETURN_TYPE}) { $result_size++ unless ($fn->{RETURN_TYPE} eq "WERROR" or $fn->{RETURN_TYPE} eq "NTSTATUS"); } + my $fail = "talloc_free(mem_ctx); return NULL;"; foreach my $e (@{$fn->{ELEMENTS}}) { next unless (grep(/in/,@{$e->{DIRECTION}})); - if ($metadata_args{$e->{NAME}}) { - my $val = "PyList_Size(py_".$metadata_args{$e->{NAME}}.")"; + if ($metadata_args->{in}->{$e->{NAME}}) { + my $py_var = "py_".$metadata_args->{in}->{$e->{NAME}}; + $self->pidl("PY_CHECK_TYPE(PyList, $py_var, $fail);"); + my $val = "PyList_Size($py_var)"; if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { $self->pidl("r->in.$e->{NAME} = talloc_ptrtype(mem_ctx, r->in.$e->{NAME});"); $self->pidl("*r->in.$e->{NAME} = $val;"); } else { - $self->pidl("r->in.$e->{NAME} = PyList_Size(py_".$metadata_args{$e->{NAME}}.");"); + $self->pidl("r->in.$e->{NAME} = $val;"); } } else { - $self->ConvertObjectFromPython($env, "mem_ctx", $e, "py_$e->{NAME}", "r->in.$e->{NAME}", "talloc_free(mem_ctx); return NULL;"); + $self->ConvertObjectFromPython($env, "mem_ctx", $e, "py_$e->{NAME}", "r->in.$e->{NAME}", $fail); } } $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, r);"); @@ -348,7 +359,7 @@ sub PythonFunctionBody($$$) } foreach my $e (@{$fn->{ELEMENTS}}) { - next if ($metadata_args{$e->{NAME}}); + next if ($metadata_args->{out}->{$e->{NAME}}); my $py_name = "py_$e->{NAME}"; if (grep(/out/,@{$e->{DIRECTION}})) { $self->ConvertObjectToPython("r", $env, $e, "r->out.$e->{NAME}", $py_name); -- cgit From 66b529029a6d15d9d2f8cac8f863de618509a95e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 8 Apr 2008 15:18:24 +0200 Subject: Clearer names for singleton return types. (This used to be commit 19d0560464304f79224a946278105edafb285453) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 2ab61e3246..acaea99f6d 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -369,7 +369,7 @@ sub PythonFunctionBody($$$) $signature .= "$e->{NAME}, "; } else { $self->pidl("result = $py_name;"); - $signature .= "result"; + $signature .= $e->{NAME}; } } } @@ -382,11 +382,10 @@ sub PythonFunctionBody($$$) my $conv = $self->ConvertObjectToPythonData("r", $fn->{RETURN_TYPE}, "r->out.result"); if ($result_size > 1) { $self->pidl("PyTuple_SetItem(result, $i, $conv);"); - $signature .= "result"; } else { $self->pidl("result = $conv;"); - $signature .= "result"; } + $signature .= "result"; } if (substr($signature, -2) eq ", ") { -- cgit From fd52fe86169ddc0adda2d1cd97215c58d06f93c4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 15 Apr 2008 14:32:13 +0200 Subject: Fix pointers when pushing strings to python during pidl generation. (This used to be commit ca72187b3e71a037780d42a57e46b60e75f724f6) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index acaea99f6d..2d12da358c 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -952,16 +952,15 @@ sub ConvertObjectToPythonLevel($$$$$) $self->pidl("}"); } } elsif ($l->{TYPE} eq "ARRAY") { - if (is_charset_array($e, $l)) { + my $pl = GetPrevLevel($e, $l); + if ($pl && $pl->{TYPE} eq "POINTER") { $var_name = get_pointer_to($var_name); + } + + if (is_charset_array($e, $l)) { # FIXME: Use Unix charset setting rather than utf-8 $self->pidl("$py_var = PyUnicode_Decode($var_name, strlen($var_name), \"utf-8\", \"ignore\");"); } else { - my $pl = GetPrevLevel($e, $l); - if ($pl && $pl->{TYPE} eq "POINTER") { - $var_name = get_pointer_to($var_name); - } - die("No SIZE_IS for array $var_name") unless (defined($l->{SIZE_IS})); my $length = $l->{SIZE_IS}; if (defined($l->{LENGTH_IS})) { -- cgit From 7bb2ebb884c35676a6cf03efe6ecc15b3e232a43 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 15 Apr 2008 16:00:07 +0200 Subject: Fix size to memcpy call in generated Samba 3 client code. Reported-By: vl (This used to be commit a28807569d0cf32968bacdc0bd88197b19fbae49) --- source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 65 ++++++++++++++----------- 1 file changed, 36 insertions(+), 29 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index 7a2575b897..87ed29b54e 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -9,7 +9,7 @@ package Parse::Pidl::Samba3::ClientNDR; use Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(ParseFunction $res $res_hdr); +@EXPORT_OK = qw(ParseFunction $res $res_hdr ParseOutputArgument); use strict; use Parse::Pidl qw(fatal warning); @@ -73,6 +73,40 @@ sub HeaderProperties($$) } } +sub ParseOutputArgument($$$) +{ + my ($self, $fn, $e) = @_; + my $level = 0; + + fatal($e->{ORIGINAL}, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY"); + + if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { + $level = 1; + if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") { + $self->pidl("if ($e->{NAME} && r.out.$e->{NAME}) {"); + $self->indent; + } + } + + if ($e->{LEVELS}[$level]->{TYPE} eq "ARRAY") { + # This is a call to GenerateFunctionInEnv intentionally. + # Since the data is being copied into a user-provided data + # structure, the user should be able to know the size beforehand + # to allocate a structure of the right size. + my $env = GenerateFunctionInEnv($fn, "r."); + my $size_is = ParseExpr($e->{LEVELS}[$level]->{SIZE_IS}, $env, $e->{ORIGINAL}); + $self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is * sizeof(*$e->{NAME}));"); + } else { + $self->pidl("*$e->{NAME} = *r.out.$e->{NAME};"); + } + + if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { + if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") { + $self->deindent; + $self->pidl("}"); + } + } +} sub ParseFunction($$$) { @@ -147,36 +181,9 @@ sub ParseFunction($$$) $self->pidl("/* Return variables */"); foreach my $e (@{$fn->{ELEMENTS}}) { next unless (grep(/out/, @{$e->{DIRECTION}})); - my $level = 0; - fatal($e->{ORIGINAL}, "[out] argument is not a pointer or array") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER" and $e->{LEVELS}[0]->{TYPE} ne "ARRAY"); - - if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { - $level = 1; - if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") { - $self->pidl("if ($e->{NAME} && r.out.$e->{NAME}) {"); - $self->indent; - } - } + $self->ParseOutputArgument($fn, $e); - if ($e->{LEVELS}[$level]->{TYPE} eq "ARRAY") { - # This is a call to GenerateFunctionInEnv intentionally. - # Since the data is being copied into a user-provided data - # structure, the user should be able to know the size beforehand - # to allocate a structure of the right size. - my $env = GenerateFunctionInEnv($fn, "r."); - my $size_is = ParseExpr($e->{LEVELS}[$level]->{SIZE_IS}, $env, $e->{ORIGINAL}); - $self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is);"); - } else { - $self->pidl("*$e->{NAME} = *r.out.$e->{NAME};"); - } - - if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { - if ($e->{LEVELS}[0]->{POINTER_TYPE} ne "ref") { - $self->deindent; - $self->pidl("}"); - } - } } $self->pidl(""); -- cgit From d49f94621bd1d18437d5846d61b84054f35d39e4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 16 Apr 2008 17:21:48 +0200 Subject: Provide stubs when the [todo] attribute is set. (This used to be commit 356a5d24747bb5e1ef9774c690a5ec386a4a165e) --- source4/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm | 54 ++++++++++++++++++------ 1 file changed, 41 insertions(+), 13 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm index e9c158e933..f8209be654 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm @@ -7,6 +7,7 @@ package Parse::Pidl::Samba4::NDR::Client; use Parse::Pidl::Samba4 qw(choose_header is_intree); +use Parse::Pidl::Util qw(has_property); use vars qw($VERSION); $VERSION = '0.01'; @@ -15,30 +16,45 @@ use strict; my($res,$res_hdr); -##################################################################### -# parse a function -sub ParseFunction($$) +sub ParseFunctionSend($$$) { - my ($interface, $fn) = @_; - my $name = $fn->{NAME}; + my ($interface, $fn, $name) = @_; my $uname = uc $name; - $res_hdr .= "\nstruct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r); -NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r); -"; + my $proto = "struct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)"; - $res .= " -struct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r) -{ + $res_hdr .= "\n$proto;\n"; + + $res .= "$proto\n{\n"; + + if (has_property($fn, "todo")) { + $res .= "\treturn NULL;\n"; + } else { + $res .= " if (p->conn->flags & DCERPC_DEBUG_PRINT_IN) { NDR_PRINT_IN_DEBUG($name, r); } return dcerpc_ndr_request_send(p, NULL, &ndr_table_$interface->{NAME}, NDR_$uname, mem_ctx, r); +"; + } + + $res .= "}\n\n"; } -NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r) +sub ParseFunctionSync($$$) { + my ($interface, $fn, $name) = @_; + + my $proto = "NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)"; + + $res_hdr .= "\n$proto;\n"; + $res .= "$proto\n{\n"; + + if (has_property($fn, "todo")) { + $res .= "\treturn NT_STATUS_NOT_IMPLEMENTED;\n"; + } else { + $res .= " struct rpc_request *req; NTSTATUS status; @@ -58,8 +74,20 @@ NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name * $res .= " return status; -} "; + } + + $res .= "}\n\n"; +} + +##################################################################### +# parse a function +sub ParseFunction($$) +{ + my ($interface, $fn) = @_; + + ParseFunctionSend($interface, $fn, $fn->{NAME}); + ParseFunctionSync($interface, $fn, $fn->{NAME}); } my %done; -- cgit From db30ff4bea11f6612bd68c934ba31387ad99cefc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 21 Apr 2008 17:59:08 +0200 Subject: Load default smb.conf file if none was specified explicitly. (This used to be commit 8fa23fac516dbf4c8245c1d009e81f02a6341775) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 2d12da358c..e344589f8e 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -597,7 +597,7 @@ sub Interface($$$) $self->pidl("const char *binding_string;"); $self->pidl("struct cli_credentials *credentials;"); $self->pidl("struct loadparm_context *lp_ctx = NULL;"); - $self->pidl("PyObject *py_lp_ctx = NULL, *py_credentials = Py_None;"); + $self->pidl("PyObject *py_lp_ctx = Py_None, *py_credentials = Py_None;"); $self->pidl("TALLOC_CTX *mem_ctx = NULL;"); $self->pidl("NTSTATUS status;"); $self->pidl(""); @@ -609,14 +609,12 @@ sub Interface($$$) $self->pidl("extern struct loadparm_context *lp_from_py_object(PyObject *py_obj);"); $self->pidl("extern struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj);"); $self->pidl(""); - $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"sO|O:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials)) {"); + $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s|OO:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials)) {"); $self->indent; $self->pidl("return NULL;"); $self->deindent; $self->pidl("}"); $self->pidl(""); - $self->pidl("if (py_lp_ctx != NULL) {"); - $self->indent; $self->pidl("lp_ctx = lp_from_py_object(py_lp_ctx);"); $self->pidl("if (lp_ctx == NULL) {"); $self->indent; @@ -624,8 +622,6 @@ sub Interface($$$) $self->pidl("return NULL;"); $self->deindent; $self->pidl("}"); - $self->deindent; - $self->pidl("}"); $self->pidl(""); $self->pidl("credentials = cli_credentials_from_py_object(py_credentials);"); -- cgit From f1b76952c035ca6341e67d0ef1a14b655c4652a2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 22 Apr 2008 22:33:34 +0200 Subject: Fix event context initialization for Python bindings. (This used to be commit 132efc779ede27898765320a13bdde0b5256102b) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index e344589f8e..884ee1d822 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -599,6 +599,7 @@ sub Interface($$$) $self->pidl("struct loadparm_context *lp_ctx = NULL;"); $self->pidl("PyObject *py_lp_ctx = Py_None, *py_credentials = Py_None;"); $self->pidl("TALLOC_CTX *mem_ctx = NULL;"); + $self->pidl("struct event_context *event_ctx;"); $self->pidl("NTSTATUS status;"); $self->pidl(""); $self->pidl("const char *kwnames[] = {"); @@ -634,9 +635,11 @@ sub Interface($$$) $self->pidl("ret = PyObject_New($interface->{NAME}_InterfaceObject, &$interface->{NAME}_InterfaceType);"); $self->pidl(""); + $self->pidl("event_ctx = event_context_init(mem_ctx);"); + $self->pidl(""); $self->pidl("status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, "); - $self->pidl(" &ndr_table_$interface->{NAME}, credentials, NULL, lp_ctx);"); + $self->pidl(" &ndr_table_$interface->{NAME}, credentials, event_ctx, lp_ctx);"); $self->handle_ntstatus("status", "NULL", "mem_ctx"); $self->pidl("ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC;"); @@ -1020,6 +1023,7 @@ sub Parse($$$$$) #include \"librpc/rpc/dcerpc.h\" #include \"scripting/python/pytalloc.h\" #include \"scripting/python/pyrpc.h\" +#include \"lib/events/events.h\" #include \"$hdr\" #include \"$ndr_hdr\" #include \"$py_hdr\" -- cgit From a9c96b2e7b9d7d894b194d520e4925e772ca0247 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 13:00:04 +0200 Subject: Fix indentation. (This used to be commit 5c3d4fce06ae07663632cc50d9703ddbc728c737) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 884ee1d822..88f2daa3b8 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -203,7 +203,7 @@ sub PythonStruct($$$$$$) $self->pidl("return 0;"); $self->deindent; $self->pidl("}"); - $self->pidl(""); + $self->pidl(""); } $getsetters = "py_$name\_getsetters"; @@ -253,6 +253,20 @@ sub PythonStruct($$$$$$) return "&$typeobject"; } +sub get_metadata_var($) +{ + my ($e) = @_; + sub get_var($) { my $x = shift; $x =~ s/\*//g; return $x; } + + if (has_property($e, "length_is")) { + return get_var($e->{PROPERTIES}->{length_is}); + } elsif (has_property($e, "size_is")) { + return get_var($e->{PROPERTIES}->{size_is}); + } + + return undef; +} + sub PythonFunctionBody($$$) { my ($self, $fn, $iface, $prettyname) = @_; @@ -274,17 +288,10 @@ sub PythonFunctionBody($$$) my $metadata_args = { in => {}, out => {} }; - sub get_var($) { my $x = shift; $x =~ s/\*//g; return $x; } - # Determine arguments that are metadata for other arguments (size_is/length_is) foreach my $e (@{$fn->{ELEMENTS}}) { foreach my $dir (@{$e->{DIRECTION}}) { - my $main = undef; - if (has_property($e, "length_is")) { - $main = get_var($e->{PROPERTIES}->{length_is}); - } elsif (has_property($e, "size_is")) { - $main = get_var($e->{PROPERTIES}->{size_is}); - } + my $main = get_metadata_var($e); if ($main) { $metadata_args->{$dir}->{$main} = $e->{NAME}; } -- cgit From 97cac27b334350f4452a7fe60658f533d851bbb9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 12:45:05 +0200 Subject: Fix syntax for return type in DCE/RPC interface python bindings. (This used to be commit 40652801fce937b37a43d37db9892821572cd6fd) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 88f2daa3b8..440b1bff97 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -658,7 +658,7 @@ sub Interface($$$) $self->pidl(""); my $signature = -"\"$interface->{NAME}(binding, lp_ctx=None, credentials=None) -> Connection to DCE/RPC interface.\\n\" +"\"$interface->{NAME}(binding, lp_ctx=None, credentials=None) -> connection\\n\" \"\\n\" \"binding should be a DCE/RPC binding string (for example: ncacn_ip_tcp:127.0.0.1)\\n\" \"lp_ctx should be a path to a smb.conf file or a param.LoadParm object\\n\" -- cgit