@@ -139,8 +139,8 @@ struct CallbackBase {
139
139
// Dynamically dispatched operations
140
140
const struct ops {
141
141
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 & );
144
144
} *_ops;
145
145
146
146
// Control
@@ -203,7 +203,7 @@ struct CallbackBase {
203
203
{
204
204
_ops = other._ops ;
205
205
if (_ops) {
206
- _ops->copy (this , & other);
206
+ _ops->copy (_storage, other. _storage );
207
207
}
208
208
}
209
209
#else
@@ -220,37 +220,36 @@ struct CallbackBase {
220
220
{
221
221
#if MBED_CONF_PLATFORM_CALLBACK_NONTRIVIAL
222
222
if (_ops) {
223
- _ops->dtor (this );
223
+ _ops->dtor (_storage );
224
224
}
225
225
#endif
226
226
}
227
227
228
228
#if MBED_CONF_PLATFORM_CALLBACK_NONTRIVIAL
229
229
// Copy construct F into storage
230
230
template <typename F>
231
- static void target_copy (CallbackBase * d, const CallbackBase * p)
231
+ static void target_copy (store & d, const store & p)
232
232
{
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);
235
235
}
236
236
237
237
// Destroy F in storage
238
238
template <typename F>
239
- static void target_dtor (CallbackBase * p)
239
+ static void target_dtor (store & p)
240
240
{
241
241
F &f = reinterpret_cast <F &>(p);
242
242
f.~F ();
243
243
}
244
244
245
245
// 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
247
247
{
248
- // d->_storage = p->_storage;
249
- std::memcpy (&d->_storage , &p->_storage , sizeof d->_storage );
248
+ std::memcpy (&d, &p, sizeof d);
250
249
}
251
250
252
251
// Trivial destruction in storage
253
- static void trivial_target_dtor (CallbackBase * p) noexcept
252
+ static void trivial_target_dtor (store & p) noexcept
254
253
{
255
254
}
256
255
#endif
0 commit comments