iOS: Replace variable length array in event dispatcher with QVarLengthArray

This does mean that if a custom stack size has been requested which
is larger than the default size, we'll end up with a custom stack
on the heap instead of on the existing stack.

I don't remember exactly why we opted for our custom stack to live
on the stack in the fist place. The commit message for the change
that introduced it (59601e06d96edb5661a3dd91341d74e16dc6b229) does
mention garbage collection as once use-case, but iOS hasn't used
GC itself, and a GC's mark-and-sweep would have to include the heap
in any case.

However, for compatibility we keep the custom stack on the stack
if we can, as we pass the default stack size to QVarLengthArray,
which covers 99,9999% of apps use anyways (GitHub shows no hits
for the QtRunLoopIntegrationStackSize override that would trigger
a heap-allocated custom stack).

In testing on both simulator and device a custom stack size that
results in a heap-allocated custom stack does work, so we should
be good in either case.

Fixes: QTBUG-135609
Pick-to: 6.9 6.8
Change-Id: I86251da005ebca8a1cad5cabd2835e83486b3f8e
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Tor Arne Vestbø 2025-04-04 10:57:07 +02:00 committed by Volker Hilsheimer
parent fffe4f32dd
commit be93c06758

View File

@ -188,17 +188,16 @@ extern "C" int qt_main_wrapper(int argc, char *argv[])
s_isQtApplication = true; s_isQtApplication = true;
@autoreleasepool { @autoreleasepool {
size_t defaultStackSize = 512 * kBytesPerKiloByte; // Same as secondary threads constexpr size_t defaultStackSize = 512 * kBytesPerKiloByte; // Same as secondary threads
uint requestedStackSize = qMax(0, infoPlistValue(@"QtRunLoopIntegrationStackSize", defaultStackSize)); uint requestedStackSize = qMax(0, infoPlistValue(@"QtRunLoopIntegrationStackSize", defaultStackSize));
if (infoPlistValue(@"QtRunLoopIntegrationDisableSeparateStack", false)) if (infoPlistValue(@"QtRunLoopIntegrationDisableSeparateStack", false))
requestedStackSize = 0; requestedStackSize = 0;
char reservedStack[Stack::computeSize(requestedStackSize)]; QVarLengthArray<uchar, defaultStackSize> reservedStack(Stack::computeSize(requestedStackSize));
if (reservedStack.size() > 0) {
if (sizeof(reservedStack) > 0) { userMainStack.adopt(reservedStack.data(), reservedStack.size());
userMainStack.adopt(reservedStack, sizeof(reservedStack));
if (infoPlistValue(@"QtRunLoopIntegrationDebugStackUsage", false)) { if (infoPlistValue(@"QtRunLoopIntegrationDebugStackUsage", false)) {
debugStackUsage = true; debugStackUsage = true;