diff --git a/swig/idaapi.i b/swig/idaapi.i index 3793b33..8df161f 100644 --- a/swig/idaapi.i +++ b/swig/idaapi.i @@ -43,6 +43,9 @@ #include "xref.hpp" %} +// Do not create separate wrappers for default arguments +%feature("compactdefaultargs"); + #ifdef __EA64__ %constant ea_t BADADDR = 0xFFFFFFFFFFFFFFFF; %constant sel_t BADSEL = 0xFFFFFFFFFFFFFFFF; @@ -78,6 +81,7 @@ typedef long long longlong; // Convert all of these %cstring_output_maxstr_none(char *buf, size_t bufsize); %binary_output_or_none(void *buf, size_t bufsize); +%binary_output_with_size(void *buf, size_t *bufsize); // Accept single Python string for const void * + size input arguments // For example: put_many_bytes() and patch_many_bytes() @@ -97,9 +101,6 @@ typedef long long longlong; %pointer_class(sval_t, sval_pointer); %pointer_class(sel_t, sel_pointer); -// Do not create separate wrappers for default arguments -%feature("compactdefaultargs"); - %include "ida.i" %include "idd.i" %include "idp.i" diff --git a/swig/typeconv.i b/swig/typeconv.i index b09c7de..f3b3419 100644 --- a/swig/typeconv.i +++ b/swig/typeconv.i @@ -112,6 +112,39 @@ } %enddef +%define %binary_output_with_size(TYPEMAP, SIZE) +%typemap (default) SIZE { + size_t ressize = MAXSPECSIZE; + $1 = &ressize; +} +%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) + { + resultobj = PyString_FromStringAndSize((char *)$1, *$2); + } + 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)) {