Add QCoro::connect helper function#125
Conversation
78ab629 to
4c5fdd1
Compare
|
@danvratil Do you know why the memory leak only occurs in certain configurations? Or is there simply no asan on apple clang and msvc? |
danvratil
left a comment
There was a problem hiding this comment.
Hi,
thanks for the patch, it's a good feature!
I did only rough review, I'll help you with the Asan issue after the weekend when I'm back at my computer. Reading Asan reports on the phone screen is really hard 😅
|
Regarding Asan, It is off on Windows right now, but should be enabled on Apple, so it's weird that apple-clang and regular clang detections would differ. I'll investigate later. Edit: I see now that the failing matrix is more complex...hmmm |
9eb1ed8 to
b00dae4
Compare
|
Looks like the leaked memory is the coroutine frame - whether it leaks or not depends heavily on the coroutine code generated by the compiler, which is why the matrix is failing in this pattern. Looks like GCC is affected in all versions, clang-11 and apple-clang (== clang-12) are fine, clang-14 and -dev are affected, likely due to some change in the codegen since clang-12. Anyway, the real cause for the memory leak is either a bug in QCoro, or a bug in compiler, consider this testcase: QCoro::Task<> testTaskConnectOK_coro(QCoro::TestContext) {
auto task = timer(1000ms);
bool called = false;
auto context = std::make_unique<QObject>();
QCoro::connect(task, context.get(), [&]() {
qDebug() << "Task done in connect()";
called = true;
});
qDebug() << "Task ready?" << task.isReady();
co_await task;
qDebug() << "Task resumed, ready=" << task.isReady();
QTest::qWait(2000);
}And the output from running this testcase: Somehow, It could be a bug in compilers, but I before I go down that rabbit hole, I want to make sure it's not a bug in QCoro where the |
|
After some assembly debugging and re-reading of the C++ standard, I found that, as I suspected, it's a QCoro bug related to the same coroutine being awaited twice: the When the code reaches the This is obviously a bug in QCoro, probably from back when I still had no idea what I was doing :-) I'll create a dedicated test scenario for this and let you know when it's fixed. |
|
Hi @jbbgameich, could you please rebase your PR on current |
b00dae4 to
e4a6674
Compare
|
Seems to work fine now, thanks for the fixes! |
This adds a function that is a bit more similar to QObject::connect. It's main feature is that it can take a context object, and thus can be used to interface between coroutines code and synchronous code, for example in list models.
e4a6674 to
711039d
Compare
This adds a function that is a bit more similar to QObject::connect. It's main feature is that it can take a context object, and thus can be used to interface between coroutines code and synchronous code, for example in list models.