mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-09-04 21:05:44 +00:00
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:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user