diff --git a/qrenderdoc/Code/pyrenderdoc/pyconversion.h b/qrenderdoc/Code/pyrenderdoc/pyconversion.h index e5677da7c..7ba113183 100644 --- a/qrenderdoc/Code/pyrenderdoc/pyconversion.h +++ b/qrenderdoc/Code/pyrenderdoc/pyconversion.h @@ -44,7 +44,7 @@ struct TypeConversion return cached_type_info; } - static int Convert(PyObject *in, T &out) + static int ConvertFromPy(PyObject *in, T &out) { swig_type_info *type_info = GetTypeInfo(); if(type_info == NULL) @@ -58,14 +58,14 @@ struct TypeConversion return res; } - static PyObject *Convert(const T &in) + static PyObject *ConvertToPy(PyObject *self, const T &in) { swig_type_info *type_info = GetTypeInfo(); if(type_info == NULL) return NULL; T *pyCopy = new T(in); - return SWIG_InternalNewPointerObj((void *)pyCopy, type_info, SWIG_BUILTIN_INIT); + return SWIG_NewPointerObj((void *)pyCopy, type_info, SWIG_BUILTIN_INIT); } }; @@ -87,7 +87,7 @@ struct TypeConversion return cached_type_info; } - static int Convert(PyObject *in, Opaque *&out) + static int ConvertFromPy(PyObject *in, Opaque *&out) { swig_type_info *type_info = GetTypeInfo(); if(type_info == NULL) @@ -101,7 +101,7 @@ struct TypeConversion return res; } - static PyObject *Convert(const Opaque *&in) + static PyObject *ConvertToPy(PyObject *self, const Opaque *&in) { swig_type_info *type_info = GetTypeInfo(); if(type_info == NULL) @@ -110,14 +110,17 @@ struct TypeConversion return SWIG_InternalNewPointerObj((void *)in, type_info, 0); } - static PyObject *Convert(Opaque *in) { return Convert((const Opaque *&)in); } + static PyObject *ConvertToPy(PyObject *self, Opaque *in) + { + return ConvertToPy(self, (const Opaque *&)in); + } }; // specialisations for basic types template <> struct TypeConversion { - static int Convert(PyObject *in, uint8_t &out) + static int ConvertFromPy(PyObject *in, uint8_t &out) { if(!PyLong_Check(in)) return SWIG_TypeError; @@ -132,13 +135,16 @@ struct TypeConversion return SWIG_OK; } - static PyObject *Convert(const uint8_t &in) { return PyLong_FromUnsignedLong(in); } + static PyObject *ConvertToPy(PyObject *self, const uint8_t &in) + { + return PyLong_FromUnsignedLong(in); + } }; template <> struct TypeConversion { - static int Convert(PyObject *in, uint32_t &out) + static int ConvertFromPy(PyObject *in, uint32_t &out) { if(!PyLong_Check(in)) return SWIG_TypeError; @@ -151,13 +157,16 @@ struct TypeConversion return SWIG_OK; } - static PyObject *Convert(const uint32_t &in) { return PyLong_FromUnsignedLong(in); } + static PyObject *ConvertToPy(PyObject *self, const uint32_t &in) + { + return PyLong_FromUnsignedLong(in); + } }; template <> struct TypeConversion { - static int Convert(PyObject *in, int32_t &out) + static int ConvertFromPy(PyObject *in, int32_t &out) { if(!PyLong_Check(in)) return SWIG_TypeError; @@ -170,13 +179,13 @@ struct TypeConversion return SWIG_OK; } - static PyObject *Convert(const int32_t &in) { return PyLong_FromLong(in); } + static PyObject *ConvertToPy(PyObject *self, const int32_t &in) { return PyLong_FromLong(in); } }; template <> struct TypeConversion { - static int Convert(PyObject *in, uint64_t &out) + static int ConvertFromPy(PyObject *in, uint64_t &out) { if(!PyLong_Check(in)) return SWIG_TypeError; @@ -189,13 +198,16 @@ struct TypeConversion return SWIG_OK; } - static PyObject *Convert(const uint64_t &in) { return PyLong_FromUnsignedLongLong(in); } + static PyObject *ConvertToPy(PyObject *self, const uint64_t &in) + { + return PyLong_FromUnsignedLongLong(in); + } }; template <> struct TypeConversion { - static int Convert(PyObject *in, float &out) + static int ConvertFromPy(PyObject *in, float &out) { if(!PyFloat_Check(in)) return SWIG_TypeError; @@ -208,13 +220,13 @@ struct TypeConversion return SWIG_OK; } - static PyObject *Convert(const float &in) { return PyFloat_FromDouble(in); } + static PyObject *ConvertToPy(PyObject *self, const float &in) { return PyFloat_FromDouble(in); } }; template <> struct TypeConversion { - static int Convert(PyObject *in, double &out) + static int ConvertFromPy(PyObject *in, double &out) { if(!PyFloat_Check(in)) return SWIG_TypeError; @@ -227,7 +239,7 @@ struct TypeConversion return SWIG_OK; } - static PyObject *Convert(const double &in) { return PyFloat_FromDouble(in); } + static PyObject *ConvertToPy(PyObject *self, const double &in) { return PyFloat_FromDouble(in); } }; // partial specialisation for enums, we just convert as their underlying type, @@ -237,22 +249,25 @@ struct TypeConversion { typedef typename std::underlying_type::type etype; - static int Convert(PyObject *in, T &out) + static int ConvertFromPy(PyObject *in, T &out) { etype int_out = 0; - int ret = TypeConversion::Convert(in, int_out); + int ret = TypeConversion::ConvertFromPy(in, int_out); out = T(int_out); return ret; } - static PyObject *Convert(const T &in) { return TypeConversion::Convert(etype(in)); } + static PyObject *ConvertToPy(PyObject *self, const T &in) + { + return TypeConversion::ConvertToPy(self, etype(in)); + } }; // specialisation for pair template struct TypeConversion, false> { - static int Convert(PyObject *in, rdctype::pair &out) + static int ConvertFromPy(PyObject *in, rdctype::pair &out) { if(!PyTuple_Check(in)) return SWIG_TypeError; @@ -262,20 +277,20 @@ struct TypeConversion, false> if(size != 2) return SWIG_TypeError; - int ret = TypeConversion::Convert(PyTuple_GetItem(in, 0), out.first); + int ret = TypeConversion::ConvertFromPy(PyTuple_GetItem(in, 0), out.first); if(SWIG_IsOK(ret)) - ret = TypeConversion::Convert(PyTuple_GetItem(in, 1), out.second); + ret = TypeConversion::ConvertFromPy(PyTuple_GetItem(in, 1), out.second); return ret; } - static PyObject *Convert(const rdctype::pair &in) + static PyObject *ConvertToPy(PyObject *self, const rdctype::pair &in) { - PyObject *first = TypeConversion::Convert(in.first); + PyObject *first = TypeConversion::ConvertToPy(self, in.first); if(!first) return NULL; - PyObject *second = TypeConversion::Convert(in.second); + PyObject *second = TypeConversion::ConvertToPy(self, in.second); if(!second) return NULL; @@ -296,7 +311,7 @@ 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 Convert(PyObject *in, rdctype::array &out, int *failIdx) + static int ConvertFromPy(PyObject *in, rdctype::array &out, int *failIdx) { if(!PyList_Check(in)) return SWIG_TypeError; @@ -305,7 +320,7 @@ struct TypeConversion, false> for(int i = 0; i < out.count; i++) { - int ret = TypeConversion::Convert(PyList_GetItem(in, i), out.elems[i]); + int ret = TypeConversion::ConvertFromPy(PyList_GetItem(in, i), out.elems[i]); if(!SWIG_IsOK(ret)) { if(failIdx) @@ -317,12 +332,16 @@ struct TypeConversion, false> return SWIG_OK; } - static int Convert(PyObject *in, rdctype::array &out) { return Convert(in, out, NULL); } - static PyObject *ConvertInPlace(PyObject *list, const rdctype::array &in, int *failIdx) + 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) { for(int i = 0; i < in.count; i++) { - PyObject *elem = TypeConversion::Convert(in.elems[i]); + PyObject *elem = TypeConversion::ConvertToPy(self, in.elems[i]); if(elem) { @@ -340,13 +359,13 @@ struct TypeConversion, false> return list; } - static PyObject *Convert(const rdctype::array &in, int *failIdx) + static PyObject *ConvertToPy(PyObject *self, const rdctype::array &in, int *failIdx) { PyObject *list = PyList_New(0); if(!list) return NULL; - PyObject *ret = ConvertInPlace(list, in, failIdx); + PyObject *ret = ConvertToPyInPlace(self, list, in, failIdx); // if a failure happened, don't leak the list we created if(!ret) @@ -355,7 +374,10 @@ struct TypeConversion, false> return ret; } - static PyObject *Convert(const rdctype::array &in) { return Convert(in, NULL); } + static PyObject *ConvertToPy(PyObject *self, const rdctype::array &in) + { + return ConvertToPy(self, in, NULL); + } }; // specialisation for string @@ -374,7 +396,7 @@ struct TypeConversion return cached_type_info; } - static int Convert(PyObject *in, rdctype::str &out) + static int ConvertFromPy(PyObject *in, rdctype::str &out) { if(PyUnicode_Check(in)) { @@ -417,22 +439,22 @@ struct TypeConversion return res; } - static PyObject *Convert(const rdctype::str &in) + static PyObject *ConvertToPy(PyObject *self, const rdctype::str &in) { return PyUnicode_FromStringAndSize(in.elems, in.count); } }; // free functions forward to struct template -int Convert(PyObject *in, T &out) +int ConvertFromPy(PyObject *in, T &out) { - return TypeConversion::Convert(in, out); + return TypeConversion::ConvertFromPy(in, out); } template -PyObject *Convert(const T &in) +PyObject *ConvertToPy(PyObject *self, const T &in) { - return TypeConversion::Convert(in); + return TypeConversion::ConvertToPy(self, in); } template @@ -440,7 +462,7 @@ inline T get_return(const char *funcname, PyObject *result, bool &failflag) { T val = T(); - int res = Convert(result, val); + int res = ConvertToPy(result, val); if(!SWIG_IsOK(res)) { @@ -464,23 +486,23 @@ inline void get_return(const char *funcname, PyObject *result, bool &failflag) template struct varfunc { - varfunc(const char *funcname, paramTypes... params) + varfunc(PyObject *self, const char *funcname, paramTypes... params) { args = PyTuple_New(sizeof...(paramTypes)); currentarg = 0; using expand_type = int[]; - (void)expand_type{0, (push_arg(funcname, params), 0)...}; + (void)expand_type{0, (push_arg(self, funcname, params), 0)...}; } template - void push_arg(const char *funcname, const T &arg) + void push_arg(PyObject *self, const char *funcname, const T &arg) { if(!args) return; - PyObject *obj = Convert(arg); + PyObject *obj = ConvertToPy(self, arg); if(!obj) { @@ -520,10 +542,10 @@ struct varfunc }; template -funcType ConvertFunc(const char *funcname, PyObject *func, bool &failflag) +funcType ConvertFunc(PyObject *self, const char *funcname, PyObject *func, bool &failflag) { - return [funcname, func, &failflag](auto... param) { - varfunc f(funcname, param...); + return [self, funcname, func, &failflag](auto... param) { + varfunc f(self, funcname, param...); return f.call(funcname, func, failflag); }; } diff --git a/qrenderdoc/Code/pyrenderdoc/renderdoc.i b/qrenderdoc/Code/pyrenderdoc/renderdoc.i index 2ad561f81..063d3da49 100644 --- a/qrenderdoc/Code/pyrenderdoc/renderdoc.i +++ b/qrenderdoc/Code/pyrenderdoc/renderdoc.i @@ -219,7 +219,7 @@ %typemap(in, fragment="tempalloc,pyconvert") SimpleType (BaseType temp) { tempset($1, &temp); - int res = Convert($input, indirect($1)); + int res = ConvertFromPy($input, indirect($1)); if(!SWIG_IsOK(res)) { SWIG_exception_fail(SWIG_ArgError(res), "in method '$symname' argument $argnum of type '$1_basetype'"); @@ -227,7 +227,7 @@ } %typemap(out, fragment="tempalloc,pyconvert") SimpleType { - $result = Convert(indirect($1)); + $result = ConvertToPy(self, indirect($1)); } %enddef @@ -252,7 +252,7 @@ SIMPLE_TYPEMAPS_VARIANT(SimpleType, SimpleType &) tempalloc($1, tempmem); int failIdx = 0; - int res = TypeConversion::type>::Convert($input, indirect($1), &failIdx); + int res = TypeConversion::type>::ConvertFromPy($input, indirect($1), &failIdx); if(!SWIG_IsOK(res)) { @@ -280,7 +280,7 @@ SIMPLE_TYPEMAPS_VARIANT(SimpleType, SimpleType &) // overwrite with array contents int failIdx = 0; - PyObject *res = TypeConversion::type>::ConvertInPlace($input, indirect($1), &failIdx); + PyObject *res = TypeConversion::type>::ConvertToPyInPlace(self, $input, indirect($1), &failIdx); if(!res) { @@ -291,7 +291,7 @@ SIMPLE_TYPEMAPS_VARIANT(SimpleType, SimpleType &) %typemap(out, fragment="tempalloc,pyconvert") ContainerType { int failIdx = 0; - $result = TypeConversion::type>::Convert(indirect($1), &failIdx); + $result = TypeConversion::type>::ConvertToPy(self, indirect($1), &failIdx); if(!$result) { snprintf(convert_error, sizeof(convert_error)-1, "in method '$symname' returning type '$1_basetype', encoding element %d", failIdx); @@ -308,7 +308,7 @@ CONTAINER_TYPEMAPS(rdctype::arr) %typemap(in, fragment="pyconvert") std::function { PyObject *func = $input; failed$argnum = false; - $1 = ConvertFunc<$1_ltype>("$symname", func, failed$argnum); + $1 = ConvertFunc<$1_ltype>(self, "$symname", func, failed$argnum); } %typemap(argout) std::function (bool failed) {