From 265db07b35e3e9b4e3bbc8e69b9a610592fdf7e0 Mon Sep 17 00:00:00 2001 From: "gergely.erdelyi" Date: Sun, 29 Mar 2009 16:54:13 +0000 Subject: [PATCH] Added type definition binary_output_or_none to accept void * output buffers with size --- swig/typeconv.i | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/swig/typeconv.i b/swig/typeconv.i index f054895..b09c7de 100644 --- a/swig/typeconv.i +++ b/swig/typeconv.i @@ -80,6 +80,38 @@ } %enddef +%define %binary_output_or_none(TYPEMAP, SIZE) +%typemap (default) SIZE { + $1 = MAXSPECSIZE; +} +%typemap(in,numinputs=0) (TYPEMAP, SIZE) { +#ifdef __cplusplus + $1 = (char *) new char[MAXSPECSIZE+1]; +#else + $1 = (char *) malloc(MAXSPECSIZE+1); +#endif +} +%typemap(out) ssize_t { + /* REMOVING ssize_t return value in $symname */ +} +%typemap(argout) (TYPEMAP,SIZE) { + if (result > 0) + { + resultobj = PyString_FromStringAndSize((char *)$1, result); + } + else + { + Py_INCREF(Py_None); + resultobj = Py_None; + } +#ifdef __cplusplus + delete [] (char *)$1; +#else + free((char *)$1); +#endif +} +%enddef + // Check that the argument is a callable Python object %typemap(in) PyObject *pyfunc { if (!PyCallable_Check($input)) {