Author: tpot Date: 2004-10-15 07:17:51 +0000 (Fri, 15 Oct 2004) New Revision: 2986
WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source&rev=2986&nolog=1 Log: Add correct value to dict when generating wrapper for functions that return WERROR values. Clean up WERROR vs NTSTATUS handling a bit. Modified: branches/SAMBA_4_0/source/build/pidl/swig.pm branches/SAMBA_4_0/source/scripting/swig/dcerpc.i branches/SAMBA_4_0/source/scripting/swig/samba.i Changeset: Modified: branches/SAMBA_4_0/source/build/pidl/swig.pm =================================================================== --- branches/SAMBA_4_0/source/build/pidl/swig.pm 2004-10-15 06:41:35 UTC (rev 2985) +++ branches/SAMBA_4_0/source/build/pidl/swig.pm 2004-10-15 07:17:51 UTC (rev 2986) @@ -341,7 +341,11 @@ $result .= ");\n\n"; - $result .= "\tPyDict_SetItemString(temp, \"result\", resultobj);\n"; + if ($fn->{RETURN_TYPE} eq "NTSTATUS") { + $result .= "\tPyDict_SetItemString(temp, \"result\", resultobj);\n"; + } else { + $result .= "\tPyDict_SetItemString(temp, \"result\", PyLong_FromLong(W_ERROR_V(arg3->out.result)));\n"; + } $result .= "\tresultobj = temp;\n"; $result .= "\ttalloc_free(mem_ctx);\n"; @@ -350,7 +354,7 @@ # Function definitions $result .= "%rename($fn->{NAME}) dcerpc_$fn->{NAME};\n"; - $result .= "$fn->{RETURN_TYPE} dcerpc_$fn->{NAME}(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $fn->{NAME} *r);\n\n"; + $result .= "NTSTATUS dcerpc_$fn->{NAME}(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $fn->{NAME} *r);\n\n"; return $result; } @@ -443,6 +447,19 @@ $result .= "\treturn obj;\n"; $result .= "}\n"; + # Generate function to convert DATA_BLOB to Python dict + + if (util::has_property($s, "public")) { + $result .= "/* Convert DATA_BLOB to python dict of struct $s->{NAME} */\n\n"; + + $result .= "NTSTATUS DATA_BLOB_to_python_$s->{NAME}(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, PyObject **obj)\n"; + $result .= "{\n"; + $result .= "\tstruct $s->{NAME} s;\n"; + $result .= "\tNTSTATUS result = ndr_pull_struct_blob(blob, mem_ctx, &s, ndr_pull_$s->{NAME});\n\n"; + $result .= "\treturn NT_STATUS_OK;\n"; + $result .= "}\n"; + } + $result .= "\n%}\n\n"; return $result; Modified: branches/SAMBA_4_0/source/scripting/swig/dcerpc.i =================================================================== --- branches/SAMBA_4_0/source/scripting/swig/dcerpc.i 2004-10-15 06:41:35 UTC (rev 2985) +++ branches/SAMBA_4_0/source/scripting/swig/dcerpc.i 2004-10-15 07:17:51 UTC (rev 2986) @@ -352,6 +352,7 @@ %exception { $action + if (NT_STATUS_IS_ERR(result)) { set_ntstatus_exception(NT_STATUS_V(result)); return NULL; @@ -365,10 +366,14 @@ %exception { $action + if (NT_STATUS_IS_ERR(result)) { set_ntstatus_exception(NT_STATUS_V(result)); return NULL; } + + /* Emulate NT_STATUS_IS_ERR() */ + if (!W_ERROR_IS_OK(arg3->out.result) && !(W_ERROR_EQUAL(arg3->out.result, WERR_INSUFFICIENT_BUFFER))) { set_werror_exception(W_ERROR_V(arg3->out.result)); @@ -379,4 +384,7 @@ %include "librpc/gen_ndr/winreg.i" %include "librpc/gen_ndr/spoolss.i" +/* The status codes must be included last otherwise the automatically + generated .i files get confused. This is kind of yucky. */ + %include "status_codes.i" Modified: branches/SAMBA_4_0/source/scripting/swig/samba.i =================================================================== --- branches/SAMBA_4_0/source/scripting/swig/samba.i 2004-10-15 06:41:35 UTC (rev 2985) +++ branches/SAMBA_4_0/source/scripting/swig/samba.i 2004-10-15 07:17:51 UTC (rev 2986) @@ -32,10 +32,6 @@ $1 = (uint32_t)PyInt_AsLong($input); } -/* For the moment treat NTSTATUS as an integer */ - -#define WERROR NTSTATUS - %typemap(out) NTSTATUS { $result = PyInt_FromLong(NT_STATUS_V($1)); }