Returning const arrays forces a copy

* This doesn't cover all cases but helps with 'pythonic' cases where a list
  returned from a function should be expected to be mutable. Modifying direct
  'members' can still modify through const.
This commit is contained in:
baldurk
2026-08-13 17:46:43 +01:00
parent 0bab6e4059
commit c95a69c8a1
5 changed files with 28 additions and 6 deletions
+2 -2
View File
@@ -155,8 +155,8 @@ public:
ResultDetails GetFatalError() override { return m_Replay.GetFatalError(); }
rdcstr GetCaptureFilename() override { return m_CaptureFile; }
CaptureModifications GetCaptureModifications() override { return m_CaptureMods; }
const FrameDescription &FrameInfo() override { return m_FrameInfo; }
const APIProperties &APIProps() override { return m_APIProps; }
FrameDescription FrameInfo() override { return m_FrameInfo; }
APIProperties APIProps() override { return m_APIProps; }
rdcarray<ShaderEncoding> CustomShaderEncodings() override { return m_CustomEncodings; }
rdcarray<ShaderSourcePrefix> CustomShaderSourcePrefixes() override { return m_CustomPrefixes; }
rdcarray<ShaderEncoding> TargetShaderEncodings() override { return m_TargetEncodings; }
+2 -2
View File
@@ -2166,14 +2166,14 @@ the UI which aren't reflected in the capture file on disk.
:return: The frame information.
:rtype: renderdoc.FrameDescription
)");
virtual const FrameDescription &FrameInfo() = 0;
virtual FrameDescription FrameInfo() = 0;
DOCUMENT(R"(Retrieve the :class:`~renderdoc.APIProperties` for the currently loaded capture.
:return: The API properties.
:rtype: renderdoc.APIProperties
)");
virtual const APIProperties &APIProps() = 0;
virtual APIProperties APIProps() = 0;
DOCUMENT(R"(Retrieve the list of :class:`~renderdoc.ShaderEncoding` that are available for
building target shaders for the currently loaded capture. See
@@ -328,6 +328,10 @@ void ARRAY_INSTANTIATION_CHECK_NAME(typeName)(typeName<innerType> *);
%typemap(ret) typeName & { ARRAY_INSTANTIATION_CHECK_NAME(typeName)($1); }
%typemap(ret) typeName { ARRAY_INSTANTIATION_CHECK_NAME(typeName)(&$1); }
%typemap(out) typeName const & {
$result = ConvertToPy(indirect($1));
}
%enddef
%define NON_TEMPLATE_ARRAY_INSTANTIATE(typeName)
+18
View File
@@ -98,6 +98,13 @@ VA_IGNORE_REST_OF_FILE
PyDateTime_IMPORT;
%}
%typemap(out) const SWIGTYPE & {
static_assert(false, "Const ref types must be explicitly allowed, to ensure proper copy semantics. " \
"Consider returning by copy if reasonable, or explicitly set up copy typemap.");
//$ltype owned = new std::remove_pointer<$ltype>::type(indirect($1));
//$result = SWIG_NewPointerObj(SWIG_as_voidptr(owned), $descriptor, SWIG_POINTER_OWN | 0 );
}
%include "pyconversion.i"
// typemaps for windowing data
@@ -232,6 +239,17 @@ VA_IGNORE_REST_OF_FILE
$1.assign(*$input);
}
// this is fine to return directly as it offers no mutable members
%typemap(out) const PipeState & {
$result = SWIG_NewPointerObj(SWIG_as_voidptr($1), $descriptor, 0 );
}
// this is returned directly due to the size of the data contained in the type.
// it's mostly "pythonic" to have an object returned that is considered mutable
%typemap(out) const SDFile & {
$result = SWIG_NewPointerObj(SWIG_as_voidptr($1), $descriptor, 0 );
}
%typemap(ret) const ActionDescription * {
// for ActionDescription pointers don't apply parent tracking, since these are preserved
// in other ways and the linked-list nature of walking them can produce absurdly long