svn commit: samba r5072 - in branches/SAMBA_4_0/source/build/pidl: .

tpot at samba.org tpot at samba.org
Sat Jan 29 00:19:24 GMT 2005


Author: tpot
Date: 2005-01-29 00:19:23 +0000 (Sat, 29 Jan 2005)
New Revision: 5072

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=5072

Log:
oDecrease the amount of autogenerated code (sorry tridge) and use swig's
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)

Modified:
   branches/SAMBA_4_0/source/build/pidl/swig.pm


Changeset:
Modified: branches/SAMBA_4_0/source/build/pidl/swig.pm
===================================================================
--- branches/SAMBA_4_0/source/build/pidl/swig.pm	2005-01-28 23:57:03 UTC (rev 5071)
+++ branches/SAMBA_4_0/source/build/pidl/swig.pm	2005-01-29 00:19:23 UTC (rev 5072)
@@ -257,68 +257,6 @@
     $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 @@
 
     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 @@
     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;



More information about the samba-cvs mailing list