svn commit: samba r2424 - in branches/SAMBA_4_0/source: build/pidl scripting/swig

tpot at samba.org tpot at samba.org
Mon Sep 20 00:55:53 GMT 2004


Author: tpot
Date: 2004-09-20 00:55:53 +0000 (Mon, 20 Sep 2004)
New Revision: 2424

WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source&rev=2424&nolog=1

Log:
Refactor handling of non-OK NTSTATUS returns to be more swiggish.

Modified:
   branches/SAMBA_4_0/source/build/pidl/swig.pm
   branches/SAMBA_4_0/source/scripting/swig/dcerpc.i


Changeset:
Modified: branches/SAMBA_4_0/source/build/pidl/swig.pm
===================================================================
--- branches/SAMBA_4_0/source/build/pidl/swig.pm	2004-09-19 23:34:20 UTC (rev 2423)
+++ branches/SAMBA_4_0/source/build/pidl/swig.pm	2004-09-20 00:55:53 UTC (rev 2424)
@@ -241,7 +241,7 @@
 
     $result .= "\tif (!PyDict_Check(obj)) {\n";
     $result .= "\t\tPyErr_Format(PyExc_TypeError, \"Expecting dict value for key '%s'\", name);\n";
-    $result .= "\t\treturn NULL;\n";
+    $result .= "\t\t\treturn NULL;\n";
     $result .= "\t}\n\n";
 
     $result .= "\ts = talloc(mem_ctx, sizeof(struct $fn->{NAME}));\n\n";
@@ -282,8 +282,7 @@
     $result .= "\tTALLOC_CTX *mem_ctx = talloc_init(\"typemap(int) $fn->{NAME}\");\n\n";
     $result .= "\t\$1 = $fn->{NAME}_ptr_from_python(mem_ctx, \$input, \"<function params>\");\n\n";
 
-    $result .= "\tif (PyErr_Occurred())\n";
-    $result .= "\t\t\treturn NULL;\n\n";
+    $result .= "\tif (PyErr_Occurred()) return NULL;\n\n";
 
     $result .= "}\n\n";
 
@@ -291,18 +290,8 @@
 
     $result .= "%typemap(argout) struct $fn->{NAME} * {\n";
     $result .= "\tTALLOC_CTX *mem_ctx = talloc_init(\"typemap(argout) $fn->{NAME}\");\n\n";
-    $result .= "\tlong status = PyLong_AsLong(resultobj);\n";
-    $result .= "\tPyObject *dict;\n";
-    $result .= "\n";
-
-    $result .= "\tif (status != 0) {\n";
-    $result .= "\t\tset_ntstatus_exception(status);\n";
-    $result .= "\t\treturn NULL;\n";
-    $result .= "\t}\n";
-    $result .= "\n";
-    $result .= "\tdict = $fn->{NAME}_ptr_to_python(mem_ctx, \$1);\n";
-
-    $result .= "\tresultobj = dict;\n";
+    $result .= "\tresultobj = $fn->{NAME}_ptr_to_python(mem_ctx, \$1);\n\n";
+    $result .= "\ttalloc_free(mem_ctx);\n";
     $result .= "}\n\n";
 
     # Function definitions
@@ -337,8 +326,7 @@
     $result .= "\t\treturn NULL;\n";
     $result .= "\t}\n\n";
 
-    $result .= "\tif (obj == Py_None) {\n";
-    $result .= "\t\treturn NULL;\n";
+    $result .= "\tif (obj == Py_None) return NULL;\n";
     $result .= "\t}\n\n";
 
     $result .= "\tif (!PyDict_Check(obj)) {\n";
@@ -575,8 +563,7 @@
 
     # Generate interface
 
-    $result = "/* Auto-generated by pidl */\n\n";
-    $result = "/* Tastes like -*- C -*- */\n\n";
+    $result .= "/* Auto-generated by pidl. Tastes like -*- C -*-. */\n\n";
 
     foreach my $x (@{$idl}) {
 	$result .= ParseHeader($x) if ($x->{TYPE} eq "INTERFACE");

Modified: branches/SAMBA_4_0/source/scripting/swig/dcerpc.i
===================================================================
--- branches/SAMBA_4_0/source/scripting/swig/dcerpc.i	2004-09-19 23:34:20 UTC (rev 2423)
+++ branches/SAMBA_4_0/source/scripting/swig/dcerpc.i	2004-09-20 00:55:53 UTC (rev 2424)
@@ -285,6 +285,16 @@
                              const char *username,
                              const char *password);
 
+/* Run this test after each wrapped function */
+
+%exception {
+	$action
+	if (!NT_STATUS_IS_OK(result)) {
+		set_ntstatus_exception(NT_STATUS_V(result));
+		return NULL;
+	}
+}
+
 %include "librpc/gen_ndr/misc.i"
 %include "librpc/gen_ndr/lsa.i"
 %include "librpc/gen_ndr/samr.i"



More information about the samba-cvs mailing list