Skip to content

Commit 623b71d

Browse files
committed
fixup! Callback updates
1 parent bd1e760 commit 623b71d

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

platform/Callback.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ struct CallbackBase {
139139
// Dynamically dispatched operations
140140
const struct ops {
141141
void (*call)(); // type-erased function pointer
142-
void (*copy)(CallbackBase *, const CallbackBase *);
143-
void (*dtor)(CallbackBase *);
142+
void (*copy)(store &, const store &);
143+
void (*dtor)(store &);
144144
} *_ops;
145145

146146
// Control
@@ -203,7 +203,7 @@ struct CallbackBase {
203203
{
204204
_ops = other._ops;
205205
if (_ops) {
206-
_ops->copy(this, &other);
206+
_ops->copy(_storage, other._storage);
207207
}
208208
}
209209
#else
@@ -220,37 +220,36 @@ struct CallbackBase {
220220
{
221221
#if MBED_CONF_PLATFORM_CALLBACK_NONTRIVIAL
222222
if (_ops) {
223-
_ops->dtor(this);
223+
_ops->dtor(_storage);
224224
}
225225
#endif
226226
}
227227

228228
#if MBED_CONF_PLATFORM_CALLBACK_NONTRIVIAL
229229
// Copy construct F into storage
230230
template <typename F>
231-
static void target_copy(CallbackBase *d, const CallbackBase *p)
231+
static void target_copy(store &d, const store &p)
232232
{
233-
const F &f = reinterpret_cast<const F &>(p->_storage);
234-
new (&d->_storage) F(f);
233+
const F &f = reinterpret_cast<const F &>(p);
234+
new (&d) F(f);
235235
}
236236

237237
// Destroy F in storage
238238
template <typename F>
239-
static void target_dtor(CallbackBase *p)
239+
static void target_dtor(store &p)
240240
{
241241
F &f = reinterpret_cast<F &>(p);
242242
f.~F();
243243
}
244244

245245
// Trivial copy construction into storage
246-
static void trivial_target_copy(CallbackBase *d, const CallbackBase *p) noexcept
246+
static void trivial_target_copy(store &d, const store &p) noexcept
247247
{
248-
//d->_storage = p->_storage;
249-
std::memcpy(&d->_storage, &p->_storage, sizeof d->_storage);
248+
std::memcpy(&d, &p, sizeof d);
250249
}
251250

252251
// Trivial destruction in storage
253-
static void trivial_target_dtor(CallbackBase *p) noexcept
252+
static void trivial_target_dtor(store &p) noexcept
254253
{
255254
}
256255
#endif

0 commit comments

Comments
 (0)