r5072: oDecrease the amount of autogenerated code (sorry tridge) and use swig's
authorTim Potter <tpot@samba.org>
Sat, 29 Jan 2005 00:19:23 +0000 (00:19 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:09:19 +0000 (13:09 -0500)
structure mapping features instead of doing it all ourselves.

This basically works, but has broken all the existing checked in Python
code.

Sample:

pipe = dcerpc.pipe_connect(binding,
        dcerpc.DCERPC_SAMR_UUID, int(dcerpc.DCERPC_SAMR_VERSION),
        domain, username, password)

r = dcerpc.samr_Connect2()
r.data_in.system_name = 'foo'
r.data_in.access_mask = 0x02000000

result = dcerpc.dcerpc_samr_Connect2(pipe, r)

source/build/pidl/swig.pm

index afb6364721ac5220a12bfc73b4bf074455f876e3..68d67b4879ad943fbb91cace0217aafedb8a2664 100644 (file)
@@ -257,68 +257,6 @@ sub ParseFunction($)
     $result .= IdlDump::DumpFunction($fn);
     $result .= "*/\n\n";
 
-    # Generate function to convert Python dict to structure pointer
-
-    $result .= "/* Convert Python dict to struct $fn->{NAME}.in */\n\n";
-
-    $result .= "struct $fn->{NAME} *$fn->{NAME}_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj, char *name)\n";
-    $result .= "{\n";
-
-    $result .= "\tstruct $fn->{NAME} *s;\n\n";
-
-    $result .= "\tif (!PyDict_Check(obj)) {\n";
-    $result .= "\t\tPyErr_Format(PyExc_TypeError, \"Expecting dict value for key '%s'\", name);\n";
-    $result .= "\t\t\treturn NULL;\n";
-    $result .= "\t}\n\n";
-
-    $result .= "\ts = talloc_p(mem_ctx, struct $fn->{NAME});\n\n";
-
-    # Remove this when all elements are initialised
-    $result .= "\tmemset(s, 0, sizeof(struct $fn->{NAME}));\n\n";
-
-    foreach my $e (@{$fn->{DATA}}) {
-       if (util::has_property($e, "in")) {
-           if (util::has_property($e, "ref")) {
-               $result .= "\tif (PyDict_GetItemString(obj, \"$e->{NAME}\") == Py_None) {\n";
-               $result .= "\t\tPyErr_Format(PyExc_ValueError, \"Key '$e->{NAME}' cannot be None\");\n";
-               $result .= "\t\treturn NULL;\n";
-               $result .= "\t}\n";
-           }
-           $result .= FieldFromPython($e, "in.") ;
-       }
-    }
-
-    $result .= "\n";
-    $result .= "\treturn s;\n";
-    $result .= "}\n\n";
-
-    # Generate function to convert structure pointer to Python dict
-
-    $result .= "/* Convert struct $fn->{NAME}.out to Python dict */\n\n";
-
-    $result .= "PyObject *$fn->{NAME}_ptr_to_python(TALLOC_CTX *mem_ctx, struct $fn->{NAME} *s";
-
-    foreach my $e (@{$fn->{DATA}}) {
-       if (isunion($e->{TYPE})) {
-           $result .= ", int $e->{NAME}_switch_is";
-       }
-    }
-    $result .= ")\n";
-
-    $result .= "{\n";
-
-    $result .= "\tPyObject *obj = PyDict_New();\n\n";
-
-    foreach my $e (@{$fn->{DATA}}) {
-       $result .= FieldToPython($e, "out.") if util::has_property($e, "out")
-    }
-
-    $result .= "\n";
-    $result .= "\treturn obj;\n";
-    $result .= "}\n\n";
-
-    $result .= "%}\n\n";
-
     # Input typemap
 
     $result .= "%typemap(in) struct $fn->{NAME} * {\n";
@@ -689,7 +627,6 @@ sub ParseInheritedData($)
 
     foreach my $e (@{$data}) {
        $result .= ParseFunction($e) if $e->{TYPE} eq "FUNCTION";
-       $result .= ParseTypedef($e) if $e->{TYPE} eq "TYPEDEF";
     }
 
     return $result;
@@ -744,4 +681,66 @@ sub Parse($)
     return $result;
 }
 
+sub pidl($)
+{
+       print OUT shift;
+}
+
+#####################################################################
+# rewrite autogenerated header file
+sub RewriteHeader($$$)
+{
+    my($idl) = shift;
+    my($input) = shift;
+    my($output) = shift;
+
+    open(IN, "<$input") || die "can't open $input for reading";
+    open(OUT, ">$output") || die "can't open $output for writing";    
+
+    pidl "%{\n";
+    pidl "#define data_in in\n";
+    pidl "#define data_out out\n";
+    pidl "%}\n\n";
+   
+    while(<IN>) {
+
+       # Copy structure definitions
+
+       if (/^struct .*? {$/ .. /^\};$/) {
+           s/\} (in|out);/\} data_$1;/; # "in" is a Python keyword
+           pidl $_;
+           next;
+       }
+
+       # Copy dcerpc functions
+
+       pidl $_ if /^NTSTATUS dcerpc_.*?\(struct dcerpc_pipe/;
+
+       # Copy interface definitions
+
+        pidl $_ 
+           if /^\#define DCERPC_.*?_UUID/ or /^\#define DCERPC_.*?_VERSION/;
+    }
+
+    close(OUT);   
+}
+
+#####################################################################
+# rewrite autogenerated header file
+sub RewriteC($$$)
+{
+    my($idl) = shift;
+    my($input) = shift;
+    my($output) = shift;
+
+    open(IN, "<$input") || die "can't open $input for reading";
+    open(OUT, ">>$output") || die "can't open $output for writing";    
+   
+    while(<IN>) {
+    }
+
+    close(OUT);   
+}
+
+
 1;