Skip to content

Commit c74c3d3

Browse files
committed
Improve ResourceId repr/str handling, and add an int() handling
1 parent 09ba0b4 commit c74c3d3

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

qrenderdoc/Code/pyrenderdoc/renderdoc.i

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,44 @@ CONTAINER_TYPEMAPS(rdctype::array)
7171

7272
// add __str__ functions
7373
%feature("python:tp_str") ResourceId "resid_str";
74+
%feature("python:tp_repr") ResourceId "resid_str";
75+
%feature("python:nb_int") ResourceId "resid_int";
7476

7577
%wrapper %{
7678
static PyObject *resid_str(PyObject *resid)
7779
{
78-
return PyUnicode_FromFormat("<ResourceId %S>", PyObject_GetAttrString(resid, "id"));
80+
void *resptr = NULL;
81+
unsigned long long *id = NULL;
82+
int res = SWIG_ConvertPtr(resid, &resptr, SWIGTYPE_p_ResourceId, 0);
83+
if (!SWIG_IsOK(res)) {
84+
SWIG_exception_fail(SWIG_ArgError(res), "in method 'ResourceId.str', ResourceId is not correct type");
85+
}
86+
87+
// cast as unsigned long long
88+
id = (unsigned long long *)resptr;
89+
static_assert(sizeof(unsigned long long) == sizeof(ResourceId), "Wrong size");
90+
91+
return PyUnicode_FromFormat("<ResourceId %llu>", *id);
92+
fail:
93+
return NULL;
94+
}
95+
96+
static PyObject *resid_int(PyObject *resid)
97+
{
98+
void *resptr = NULL;
99+
unsigned long long *id = NULL;
100+
int res = SWIG_ConvertPtr(resid, &resptr, SWIGTYPE_p_ResourceId, 0);
101+
if (!SWIG_IsOK(res)) {
102+
SWIG_exception_fail(SWIG_ArgError(res), "in method 'ResourceId.str', ResourceId is not correct type");
103+
}
104+
105+
// cast as unsigned long long
106+
id = (unsigned long long *)resptr;
107+
static_assert(sizeof(unsigned long long) == sizeof(ResourceId), "Wrong size");
108+
109+
return PyLong_FromUnsignedLongLong(*id);
110+
fail:
111+
return NULL;
79112
}
80113
%}
81114

0 commit comments

Comments
 (0)