From a0a0756b9db6a41a5a8103a25815f3a397953ad1 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Mon, 23 Sep 2019 06:42:47 +0000 Subject: [PATCH] changed moo_shallowcopy() to exclude the hash field when copying --- moo/lib/gc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/moo/lib/gc.c b/moo/lib/gc.c index 04c7c83..a9c3f35 100644 --- a/moo/lib/gc.c +++ b/moo/lib/gc.c @@ -1133,8 +1133,12 @@ moo_oop_t moo_shallowcopy (moo_t* moo, moo_oop_t oop) return MOO_NULL; } -/* TODO: exclude trailer and hash space? exclde hash space at least? */ total_bytes = MOO_SIZEOF(moo_obj_t) + moo_getobjpayloadbytes(moo, oop); + if (MOO_OBJ_GET_FLAGS_HASH(oop)) + { + /* exclude the hash value field from copying */ + total_bytes -= MOO_SIZEOF(moo_oow_t); + } moo_pushvolat (moo, &oop); z = (moo_oop_t)moo_allocbytes(moo, total_bytes); @@ -1142,6 +1146,7 @@ moo_oop_t moo_shallowcopy (moo_t* moo, moo_oop_t oop) MOO_MEMCPY (z, oop, total_bytes); MOO_OBJ_SET_FLAGS_RDONLY (z, 0); /* a copied object is not read-only */ + MOO_OBJ_SET_FLAGS_HASH (z, 0); /* no hash field */ return z; }