diff options
-rw-r--r-- | source4/librpc/config.mk | 5 | ||||
-rw-r--r-- | source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 83 | ||||
-rw-r--r-- | source4/scripting/python/modules.c | 3 |
3 files changed, 44 insertions, 47 deletions
diff --git a/source4/librpc/config.mk b/source4/librpc/config.mk index ab94770d46..03977e8263 100644 --- a/source4/librpc/config.mk +++ b/source4/librpc/config.mk @@ -606,6 +606,9 @@ PRIVATE_DEPENDENCIES = RPC_NDR_WINREG python_misc [PYTHON::python_dcerpc_misc] OBJ_FILES = gen_ndr/py_misc.o -[PYTHON::python_dcerpc_initshutdown] +[PYTHON::python_initshutdown] OBJ_FILES = gen_ndr/py_initshutdown.o PRIVATE_DEPENDENCIES = RPC_NDR_INITSHUTDOWN + +[PYTHON::python_epmapper] +OBJ_FILES = gen_ndr/py_epmapper.o diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 9f6a7847b1..0d5237022a 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -102,11 +102,7 @@ sub FromUnionToPythonFunction($$$$) $self->indent; foreach my $e (@{$type->{ELEMENTS}}) { - if (defined($e->{CASE})) { - $self->pidl("$e->{CASE}:"); - } else { - $self->pidl("default:"); - } + $self->pidl("$e->{CASE}:"); $self->indent; @@ -141,12 +137,8 @@ sub FromPythonToUnionFunction($$$$$) $self->indent; foreach my $e (@{$type->{ELEMENTS}}) { - if (defined($e->{CASE})) { - $self->pidl("$e->{CASE}:"); - } else { - $has_default = 1; - $self->pidl("default:"); - } + $self->pidl("$e->{CASE}:"); + if ($e->{CASE} eq "default") { $has_default = 1; } $self->indent; if ($e->{NAME}) { $self->ConvertObjectFromPython({}, $mem_ctx, $e, $name, "ret->$e->{NAME}", "talloc_free(ret); return NULL;"); @@ -182,16 +174,18 @@ sub PythonStruct($$$$) $self->pidl("static PyObject *py_$name\_getattr(PyObject *obj, char *name)"); $self->pidl("{"); $self->indent; - $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->indent; - $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("}"); + 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->indent; + $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;"); @@ -202,19 +196,21 @@ sub PythonStruct($$$$) $self->pidl("static int py_$name\_setattr(PyObject *py_obj, char *name, PyObject *value)"); $self->pidl("{"); $self->indent; - $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->indent; - if ($e->{ORIGINAL}->{POINTERS} > 0) { - $self->pidl("talloc_free($varname);"); + 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->indent; + if ($e->{ORIGINAL}->{POINTERS} > 0) { + $self->pidl("talloc_free($varname);"); + } + $self->ConvertObjectFromPython($env, $mem_ctx, $e, "value", $varname, "return -1;"); + $self->pidl("return 0;"); + $self->deindent; + $self->pidl("}"); } - $self->ConvertObjectFromPython($env, $mem_ctx, $e, "value", $varname, "return -1;"); - $self->pidl("return 0;"); - $self->deindent; - $self->pidl("}"); } $self->pidl("PyErr_SetString(PyExc_AttributeError, \"no such attribute\");"); $self->pidl("return -1;"); @@ -591,7 +587,7 @@ sub assign($$$) { my ($self, $dest, $src) = @_; if ($dest =~ /^\&/) { - $self->pidl("memcpy($dest, $src, sizeof(*$dest));"); + $self->pidl("memcpy($dest, $src, sizeof(" . get_value_of($dest) . "));"); } else { $self->pidl("$dest = $src;"); } @@ -605,11 +601,6 @@ sub ConvertObjectFromPythonData($$$$$$) $ctype = resolveType($ctype); - if (ref($ctype) ne "HASH") { - $self->pidl("$target = FIXME($cvar);"); - return; - } - my $actual_ctype = $ctype; if ($ctype->{TYPE} eq "TYPEDEF") { $actual_ctype = $ctype->{DATA}; @@ -641,7 +632,7 @@ sub ConvertObjectFromPythonData($$$$$$) } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "ipv4address") { - $self->pidl("$target = FIXME($cvar);"); + $self->pidl("$target = PyString_AsString($cvar);"); return; } @@ -657,7 +648,7 @@ sub ConvertObjectFromPythonData($$$$$$) } if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "string_array") { - $self->pidl("$target = FIXME($cvar);"); + $self->pidl("$target = PyCObject_AsVoidPtr($cvar);"); return; } @@ -725,9 +716,9 @@ sub ConvertObjectFromPythonLevel($$$$$$$$) } elsif ($l->{TYPE} eq "SWITCH") { $var_name = get_pointer_to($var_name); my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e); - $self->pidl("$var_name = py_export_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $py_var);"); + $self->assign($var_name, "py_export_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $py_var)"); } elsif ($l->{TYPE} eq "SUBCONTEXT") { - $self->pidl("#error Subcontext not yet supported"); + $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, GetNextLevel($e, $l), $var_name, $fail); } else { die("unknown level type $l->{TYPE}"); } @@ -753,7 +744,7 @@ sub ConvertScalarToPython($$$) } if ($ctypename eq "DATA_BLOB") { - return "PyString_FromStringAndSize($cvar->data, $cvar->length)"; + return "PyString_FromStringAndSize((char *)($cvar).data, ($cvar).length)"; } if ($ctypename eq "NTSTATUS") { @@ -770,7 +761,7 @@ sub ConvertScalarToPython($$$) # Not yet supported if ($ctypename eq "string_array") { return "PyCObject_FromVoidPtr($cvar)"; } - if ($ctypename eq "ipv4address") { return "PyCObject_FromVoidPtr($cvar)"; } + if ($ctypename eq "ipv4address") { return "PyString_FromString($cvar)"; } if ($ctypename eq "pointer") { return "PyCObject_FromVoidPtr($cvar, talloc_free)"; } @@ -867,7 +858,7 @@ sub ConvertObjectToPythonLevel($$$$$) my $conv = $self->ConvertObjectToPythonData($mem_ctx, $l->{DATA_TYPE}, $var_name); $self->pidl("$py_var = $conv;"); } elsif ($l->{TYPE} eq "SUBCONTEXT") { - $self->pidl("FIXME"); + $self->ConvertObjectToPythonLevel($mem_ctx, $env, $e, GetNextLevel($e, $l), $var_name, $py_var); } else { die("Unknown level type $l->{TYPE} $var_name"); } diff --git a/source4/scripting/python/modules.c b/source4/scripting/python/modules.c index 5e53aadb94..d8a5fdeeae 100644 --- a/source4/scripting/python/modules.c +++ b/source4/scripting/python/modules.c @@ -36,6 +36,9 @@ extern void inituuid(void); extern void init_net(void); extern void initecho(void); extern void initwinreg(void); +extern void initepmapper(void); +extern void initinitshutdown(void); +static void initdcerpc_misc(void) {} static struct _inittab py_modules[] = { STATIC_LIBPYTHON_MODULES }; |