From 0a3a76fe969fc56a033af1745374b90fd4aff6c7 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 6 Sep 2004 11:01:10 +0000 Subject: r2235: When creating exception data, use Py_BuildValue instead of doing it all by hand. Use $symname to name TALLOC_CTX's created in wrapper function. Also, make sure to free context afterwards. Set the DCERPC_NDR_REF_ALLOC flag in the dcerpc_pipe struct to save use lots of initialisation. (This used to be commit 5fead63618b5ee76cadc4719d933ea9cee7538b5) --- source4/scripting/swig/dcerpc.i | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/source4/scripting/swig/dcerpc.i b/source4/scripting/swig/dcerpc.i index c843ec3c36..afa968a640 100644 --- a/source4/scripting/swig/dcerpc.i +++ b/source4/scripting/swig/dcerpc.i @@ -41,11 +41,8 @@ PyObject *ntstatus_exception; void set_ntstatus_exception(int status) { - PyObject *obj = PyTuple_New(2); - - PyTuple_SetItem(obj, 0, PyInt_FromLong(status)); - PyTuple_SetItem(obj, 1, - PyString_FromString(nt_errstr(NT_STATUS(status)))); + PyObject *obj = Py_BuildValue("(i,s)", status, + nt_errstr(NT_STATUS(status))); PyErr_SetObject(ntstatus_exception, obj); } @@ -86,15 +83,30 @@ uint32 get_uint32_property(PyObject *dict, char *key) } %typemap(in, numinputs=0) TALLOC_CTX * { - $1 = talloc_init("foo"); + $1 = talloc_init("$symname"); +} + +%typemap(freearg) TALLOC_CTX * { + talloc_free($1); } %typemap(argout) struct dcerpc_pipe ** { long status = PyLong_AsLong(resultobj); + + /* Throw exception if result was not OK */ + if (status != 0) { set_ntstatus_exception(status); return NULL; } + + /* Set REF_ALLOC flag so we don't have to do too much extra + mucking around with ref variables in ndr unmarshalling. */ + + (*$1)->flags |= DCERPC_NDR_REF_ALLOC; + + /* Return swig handle on dcerpc_pipe */ + resultobj = SWIG_NewPointerObj(*$1, SWIGTYPE_p_dcerpc_pipe, 0); } -- cgit