@@ -20948,13 +20948,23 @@ void flecs_type_info_mark_in_use(
2094820948#endif
2094920949
2095020950void flecs_default_ctor(
20951- void *ptr,
20952- int32_t count,
20951+ void *ptr,
20952+ int32_t count,
2095320953 const ecs_type_info_t *ti)
2095420954{
2095520955 ecs_os_memset(ptr, 0, ti->size * count);
2095620956}
2095720957
20958+ void flecs_default_move(
20959+ void *dst_ptr,
20960+ void *src_ptr,
20961+ int32_t count,
20962+ const ecs_type_info_t *ti)
20963+ {
20964+ ecs_os_memcpy(dst_ptr, src_ptr, ti->size * count);
20965+ ecs_os_memset(src_ptr, 0, ti->size * count);
20966+ }
20967+
2095820968bool flecs_type_info_ctor(
2095920969 void *ptr,
2096020970 int32_t count,
@@ -21152,14 +21162,6 @@ void flecs_default_move_ctor_w_dtor(void *dst_ptr, void *src_ptr,
2115221162 cl->dtor(src_ptr, count, ti);
2115321163}
2115421164
21155- static
21156- void flecs_default_move(void *dst_ptr, void *src_ptr,
21157- int32_t count, const ecs_type_info_t *ti)
21158- {
21159- const ecs_type_hooks_t *cl = &ti->hooks;
21160- cl->move(dst_ptr, src_ptr, count, ti);
21161- }
21162-
2116321165static
2116421166void flecs_default_dtor(void *dst_ptr, void *src_ptr,
2116521167 int32_t count, const ecs_type_info_t *ti)
@@ -21424,7 +21426,21 @@ void ecs_set_hooks_id(
2142421426 * ease of use, if no constructor is specified, set a default one that
2142521427 * initializes the component to 0. */
2142621428 if (!h->ctor && (h->dtor || h->copy || h->move)) {
21427- ti->hooks.ctor = flecs_default_ctor;
21429+ ti->hooks.ctor = flecs_default_ctor;
21430+ }
21431+
21432+ /* If only ctor and dtor are set, default move to flecs_default_move which
21433+ * memcpys src to dst and zeros src. This avoids invoking the dtor on the
21434+ * source after a move. Skip when ctor/dtor/move are flagged illegal: in
21435+ * those cases h->ctor / h->dtor may point to illegal stubs and pairing
21436+ * them with a move is not meaningful. */
21437+ if (h->ctor && h->dtor && !h->move && !h->copy && !h->copy_ctor &&
21438+ !h->move_ctor && !h->move_dtor && !h->ctor_move_dtor &&
21439+ !(flags & (ECS_TYPE_HOOK_MOVE_ILLEGAL |
21440+ ECS_TYPE_HOOK_CTOR_ILLEGAL |
21441+ ECS_TYPE_HOOK_DTOR_ILLEGAL)))
21442+ {
21443+ ti->hooks.move = flecs_default_move;
2142821444 }
2142921445
2143021446 /* Set default copy ctor, move ctor and merge */
@@ -21435,14 +21451,14 @@ void ecs_set_hooks_id(
2143521451 }
2143621452
2143721453 if (!h->move_ctor && !(flags & ECS_TYPE_HOOK_MOVE_CTOR_ILLEGAL)) {
21438- if (h-> move) {
21454+ if (ti->hooks. move) {
2143921455 ti->hooks.move_ctor = flecs_default_move_ctor;
2144021456 }
2144121457 }
2144221458
2144321459 if (!h->ctor_move_dtor) {
2144421460 ecs_flags32_t illegal_check = 0;
21445- if (h-> move) {
21461+ if (ti->hooks. move) {
2144621462 illegal_check |= ECS_TYPE_HOOK_MOVE_ILLEGAL;
2144721463 if (h->dtor) {
2144821464 illegal_check |= ECS_TYPE_HOOK_DTOR_ILLEGAL;
@@ -21482,13 +21498,13 @@ void ecs_set_hooks_id(
2148221498
2148321499 if (!h->move_dtor) {
2148421500 ecs_flags32_t illegal_check = 0;
21485- if (h-> move) {
21501+ if (ti->hooks. move) {
2148621502 illegal_check |= ECS_TYPE_HOOK_MOVE_ILLEGAL;
2148721503 if (h->dtor) {
2148821504 illegal_check |= ECS_TYPE_HOOK_DTOR_ILLEGAL;
2148921505 ti->hooks.move_dtor = flecs_default_move_w_dtor;
2149021506 } else {
21491- ti->hooks.move_dtor = flecs_default_move ;
21507+ ti->hooks.move_dtor = ti->hooks.move ;
2149221508 }
2149321509 } else {
2149421510 if (h->dtor) {
0 commit comments