Skip to content

Commit b3bd56f

Browse files
committed
TemporaryCallback has to be strictly reserved for input arguments, or else it may crash.
1 parent 035562a commit b3bd56f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Source/DFPSR/base/TemporaryCallback.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ namespace dsr {
3333
// Either pass a lambda allocated on the stack or declare a new lambda for the implicit constructor.
3434
// Use as an input argument to high level functions when the function will not be saved for later.
3535
// Do not save a TemporaryCallback for later, because then it will refer to stack memory that is no longer available.
36-
// If TemporaryCallback outlives a lambda's closure allocated as a nameless structure on the stack, .
36+
// If TemporaryCallback outlives a lambda's closure allocated as a nameless structure on the stack, the stack memory will be deallocated before use.
37+
// If you store the callback then it is safer to use StorableCallback, because deleting the copy constructor can not prevent all memory errors.
3738
template<typename T>
3839
class TemporaryCallback;
3940
template<typename RESULT, typename... ARGS>

Source/test/tests/ListTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
#include "../testTools.h"
33
#include "../../DFPSR/collection/List.h"
4-
#include "../../DFPSR/base/TemporaryCallback.h"
4+
#include "../../DFPSR/base/StorableCallback.h"
55

66
static void targetByReference(List<int32_t> &target, int32_t value) {
77
target.push(value);
@@ -50,7 +50,7 @@ START_TEST(List)
5050
ASSERT_EQUAL(integers.length(), 2);
5151
ASSERT_EQUAL(integers[0], 5);
5252
ASSERT_EQUAL(integers[1], 86);
53-
TemporaryCallback<void(int32_t value)> method([&integers](int32_t value) {
53+
StorableCallback<void(int32_t value)> method([&integers](int32_t value) {
5454
integers.push(value);
5555
});
5656
method(24);

0 commit comments

Comments
 (0)