mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-05 01:20:42 +00:00
9db71b803a
* Previously we would convert from python to C++ arrays immediately by copying, and vice-versa convert TO python immediately by creating a new python list by copying. * This however behaves rather poorly in common situations, e.g.: > foo.bar.append(5) Would not append 5 to foo.bar, but copy foo.bar to a temporary, append 5 to it, then destroy it leaving foo.bar untouched. * Instead we leave the C++ array type as a pointer for as long as we can and instead implement the python sequence API as extensions/slots that work in-place on the original array.
43 lines
1.3 KiB
OpenEdge ABL
43 lines
1.3 KiB
OpenEdge ABL
|
|
// add some useful builtin functions for ResourceId
|
|
%feature("python:tp_str") ResourceId "resid_str";
|
|
%feature("python:tp_repr") ResourceId "resid_str";
|
|
%feature("python:nb_int") ResourceId "resid_int";
|
|
|
|
%wrapper %{
|
|
static PyObject *resid_str(PyObject *resid)
|
|
{
|
|
void *resptr = NULL;
|
|
unsigned long long *id = NULL;
|
|
int res = SWIG_ConvertPtr(resid, &resptr, SWIGTYPE_p_ResourceId, 0);
|
|
if (!SWIG_IsOK(res)) {
|
|
SWIG_exception_fail(SWIG_ArgError(res), "in method 'ResourceId.str', ResourceId is not correct type");
|
|
}
|
|
|
|
// cast as unsigned long long
|
|
id = (unsigned long long *)resptr;
|
|
static_assert(sizeof(unsigned long long) == sizeof(ResourceId), "Wrong size");
|
|
|
|
return PyUnicode_FromFormat("<ResourceId %llu>", *id);
|
|
fail:
|
|
return NULL;
|
|
}
|
|
|
|
static PyObject *resid_int(PyObject *resid)
|
|
{
|
|
void *resptr = NULL;
|
|
unsigned long long *id = NULL;
|
|
int res = SWIG_ConvertPtr(resid, &resptr, SWIGTYPE_p_ResourceId, 0);
|
|
if (!SWIG_IsOK(res)) {
|
|
SWIG_exception_fail(SWIG_ArgError(res), "in method 'ResourceId.str', ResourceId is not correct type");
|
|
}
|
|
|
|
// cast as unsigned long long
|
|
id = (unsigned long long *)resptr;
|
|
static_assert(sizeof(unsigned long long) == sizeof(ResourceId), "Wrong size");
|
|
|
|
return PyLong_FromUnsignedLongLong(*id);
|
|
fail:
|
|
return NULL;
|
|
}
|
|
%} |