diff --git a/qrenderdoc/Code/pyrenderdoc/pyconversion.h b/qrenderdoc/Code/pyrenderdoc/pyconversion.h index a57e40230..e1383c5b5 100644 --- a/qrenderdoc/Code/pyrenderdoc/pyconversion.h +++ b/qrenderdoc/Code/pyrenderdoc/pyconversion.h @@ -305,6 +305,48 @@ struct TypeConversion, false> } }; +// specialisation for array +template <> +struct TypeConversion, false> +{ + // we add some extra parameters so the typemaps for array can use these to get + // nicer failure error messages out with the index that failed + static int ConvertFromPy(PyObject *in, rdctype::array &out, int *failIdx) + { + if(!PyBytes_Check(in)) + return SWIG_TypeError; + + Py_ssize_t len = PyBytes_Size(in); + + out.create((int)len); + memcpy(&out[0], PyBytes_AsString(in), out.count); + + return SWIG_OK; + } + + static int ConvertFromPy(PyObject *in, rdctype::array &out) + { + return ConvertFromPy(in, out, NULL); + } + + static PyObject *ConvertToPyInPlace(PyObject *self, PyObject *list, + const rdctype::array &in, int *failIdx) + { + // can't modify bytes objects + return NULL; + } + + static PyObject *ConvertToPy(PyObject *self, const rdctype::array &in, int *failIdx) + { + return PyBytes_FromStringAndSize((const char *)in.elems, (Py_ssize_t)in.count); + } + + static PyObject *ConvertToPy(PyObject *self, const rdctype::array &in) + { + return ConvertToPy(self, in, NULL); + } +}; + // specialisation for array template struct TypeConversion, false>