pidl/python: Fix more warnings in the generated code.
authorJelmer Vernooij <jelmer@samba.org>
Sun, 13 Jan 2008 14:29:56 +0000 (15:29 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Mon, 14 Jan 2008 18:53:04 +0000 (19:53 +0100)
source/pidl/lib/Parse/Pidl/Samba4/Python.pm
source/pidl/pidl

index d0a5bbd7e3f18d551b1c64b89d138ae4bc81ada7..fc5480b661fa73b87b68e8d37c71020a678ba438 100644 (file)
@@ -89,37 +89,39 @@ sub EnumAndBitmapConsts($$$)
        }
 }
 
        }
 }
 
-sub FromUnionToPythonFunction($$)
+sub FromUnionToPythonFunction($$$)
 {
 {
-       my ($self, $type) = @_;
+       my ($self, $type, $name) = @_;
 
        #FIXME
 
        $self->pidl("return NULL;");
 }
 
 
        #FIXME
 
        $self->pidl("return NULL;");
 }
 
-sub FromStructToPythonFunction($$)
+sub FromStructToPythonFunction($$$)
 {
 {
-       my ($self, $type) = @_;
+       my ($self, $type, $name) = @_;
 
 
-       #FIXME
-       $self->pidl("return NULL;");
+       $self->pidl("$type->{NAME}\_Object *ret;");
+       $self->pidl("ret = PyObject_New($type->{NAME}\_Object, &$type->{NAME}\_ObjectType);");
+       $self->pidl("ret->object = talloc_reference(NULL, $name);");
+       $self->pidl("return (PyObject *) ret;");
 }
 
 }
 
-sub FromPythonToUnionFunction($$)
+sub FromPythonToUnionFunction($$$$)
 {
 {
-       my ($self, $type) = @_;
+       my ($self, $type, $mem_ctx, $name) = @_;
 
        #FIXME
        $self->pidl("return NULL;");
 }
 
 
        #FIXME
        $self->pidl("return NULL;");
 }
 
-sub FromPythonToStructFunction($$)
+sub FromPythonToStructFunction($$$$)
 {
 {
-       my ($self, $type) = @_;
+       my ($self, $type, $mem_ctx, $name) = @_;
 
 
-       #FIXME
-       $self->pidl("return NULL;");
+       $self->pidl("$type->{NAME}\_Object *py_object = ($type->{NAME}_Object *)$name;");
+       $self->pidl("return talloc_reference($mem_ctx, py_object->object);");
 }
 
 sub PythonStruct($$$$)
 }
 
 sub PythonStruct($$$$)
@@ -222,7 +224,7 @@ sub PythonFunction($$$)
        $self->pidl("$iface\_InterfaceObject *iface = ($iface\_InterfaceObject *)self;");
        $self->pidl("NTSTATUS status;");
        $self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);");
        $self->pidl("$iface\_InterfaceObject *iface = ($iface\_InterfaceObject *)self;");
        $self->pidl("NTSTATUS status;");
        $self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);");
-       $self->pidl("struct dcerpc_$fn->{NAME} r;");
+       $self->pidl("struct $fn->{NAME} r;");
        $self->pidl("PyObject *result;");
        my $result_size = 0;
 
        $self->pidl("PyObject *result;");
        my $result_size = 0;
 
@@ -234,11 +236,13 @@ sub PythonFunction($$$)
                        $result_size++;
                }
        }
                        $result_size++;
                }
        }
+       if ($result_size > 0) {
+               $self->pidl("");
+               $self->pidl("ZERO_STRUCT(r.out);");
+       }
        if ($fn->{RETURN_TYPE}) {
                $result_size++;
        }
        if ($fn->{RETURN_TYPE}) {
                $result_size++;
        }
-       $self->pidl("");
-       $self->pidl("ZERO_STRUCT(r.out);");
 
        foreach my $e (@{$fn->{ELEMENTS}}) {
                if (grep(/in/,@{$e->{DIRECTION}})) {
 
        foreach my $e (@{$fn->{ELEMENTS}}) {
                if (grep(/in/,@{$e->{DIRECTION}})) {
@@ -322,8 +326,8 @@ sub PythonType($$$)
                $self->pidl("PyObject *py_import_$d->{NAME}(" .mapTypeName($d) . " *in)");
                $self->pidl("{");
                $self->indent;
                $self->pidl("PyObject *py_import_$d->{NAME}(" .mapTypeName($d) . " *in)");
                $self->pidl("{");
                $self->indent;
-               $self->FromStructToPythonFunction($d) if ($actual_ctype->{TYPE} eq "STRUCT");
-               $self->FromUnionToPythonFunction($d) if ($actual_ctype->{TYPE} eq "UNION");
+               $self->FromStructToPythonFunction($d, "in") if ($actual_ctype->{TYPE} eq "STRUCT");
+               $self->FromUnionToPythonFunction($d, "in") if ($actual_ctype->{TYPE} eq "UNION");
                $self->deindent;
                $self->pidl("}");
                $self->pidl("");
                $self->deindent;
                $self->pidl("}");
                $self->pidl("");
@@ -331,8 +335,8 @@ sub PythonType($$$)
                $self->pidl(mapTypeName($d) . " *py_export_$d->{NAME}(TALLOC_CTX *mem_ctx, PyObject *in)");
                $self->pidl("{");
                $self->indent;
                $self->pidl(mapTypeName($d) . " *py_export_$d->{NAME}(TALLOC_CTX *mem_ctx, PyObject *in)");
                $self->pidl("{");
                $self->indent;
-               $self->FromPythonToStructFunction($d) if ($actual_ctype->{TYPE} eq "STRUCT");
-               $self->FromPythonToUnionFunction($d) if ($actual_ctype->{TYPE} eq "UNION");
+               $self->FromPythonToStructFunction($d, "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "STRUCT");
+               $self->FromPythonToUnionFunction($d, "mem_ctx", "in") if ($actual_ctype->{TYPE} eq "UNION");
                $self->deindent;
                $self->pidl("}");
                $self->pidl("");
                $self->deindent;
                $self->pidl("}");
                $self->pidl("");
@@ -414,8 +418,8 @@ sub Interface($$$)
        $self->pidl("PyObject_HEAD_INIT(NULL) 0,");
        $self->pidl(".tp_name = \"$interface->{NAME}\",");
        $self->pidl(".tp_basicsize = sizeof($interface->{NAME}_InterfaceObject),");
        $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_dealloc = (destructor)interface_$interface->{NAME}_dealloc,");
+       $self->pidl(".tp_getattr = (getattrfunc)interface_$interface->{NAME}_getattr,");
        $self->deindent;
        $self->pidl("};");
 
        $self->deindent;
        $self->pidl("};");
 
@@ -567,9 +571,9 @@ sub ConvertObjectToPython($$$)
        die("unknown type ".mapTypeName($ctype) . ": $cvar");
 }
 
        die("unknown type ".mapTypeName($ctype) . ": $cvar");
 }
 
-sub Parse($$$$)
+sub Parse($$$$$)
 {
 {
-    my($self,$basename,$ndr,$hdr) = @_;
+    my($self,$basename,$ndr,$ndr_hdr,$hdr) = @_;
     
     my $py_hdr = $hdr;
     $py_hdr =~ s/ndr_([^\/]+)$/py_$1/g;
     
     my $py_hdr = $hdr;
     $py_hdr =~ s/ndr_([^\/]+)$/py_$1/g;
@@ -582,6 +586,7 @@ sub Parse($$$$)
 #include <Python.h>
 #include \"librpc/rpc/dcerpc.h\"
 #include \"$hdr\"
 #include <Python.h>
 #include \"librpc/rpc/dcerpc.h\"
 #include \"$hdr\"
+#include \"$ndr_hdr\"
 #include \"$py_hdr\"
 
 ");
 #include \"$py_hdr\"
 
 ");
index 500b4dcbfcae888aebe16a43bfc700f59d3f0619..4dfd57dc20a7c17083bbbfe78ef9ffb2c89c7275 100755 (executable)
@@ -671,7 +671,8 @@ sub process_file($)
        if (defined($opt_python)) {
                require Parse::Pidl::Samba4::Python;
                my $generator = new Parse::Pidl::Samba4::Python(); 
        if (defined($opt_python)) {
                require Parse::Pidl::Samba4::Python;
                my $generator = new Parse::Pidl::Samba4::Python(); 
-               my ($hdr,$prsr) = $generator->Parse($basename, $ndr, $h_filename);
+               my ($hdr,$prsr) = $generator->Parse($basename, $ndr, 
+                                       "$outputdir/ndr_$basename\_c.h", $h_filename);
                FileSave("$outputdir/py_$basename.c", $prsr);
                FileSave("$outputdir/py_$basename.h", $hdr);
        }
                FileSave("$outputdir/py_$basename.c", $prsr);
                FileSave("$outputdir/py_$basename.h", $hdr);
        }