Preserve value references across arena relocation during array copies

This commit is contained in:
2026-10-27 07:39:19 +01:00
parent f74af13f98
commit b1605b0e82
2 changed files with 42 additions and 10 deletions
+14 -2
View File
@@ -261,6 +261,8 @@ static sxi32 HashmapGrowBucket(ph7_hashmap *pMap) {
*/
static sxi32 HashmapInsertIntKey(ph7_hashmap *pMap, sxi64 iKey, ph7_value *pValue, sxu32 nRefIdx) {
ph7_hashmap_node *pNode;
sxu32 nValue = pValue ? pValue->nIdx : SXU32_HIGH;
sxi32 bArena = pValue && SySetAt(&pMap->pVm->aMemObj, nValue) == pValue;
sxu32 nIdx;
sxu32 nHash;
sxi32 rc;
@@ -271,11 +273,15 @@ static sxi32 HashmapInsertIntKey(ph7_hashmap *pMap, sxi64 iKey, ph7_value *pValu
if(pObj == 0) {
return SXERR_MEM;
}
nIdx = pObj->nIdx;
if(pValue) {
/* Reserve may move the source slot as well as the new destination. */
if(bArena) {
pValue = (ph7_value *)SySetAt(&pMap->pVm->aMemObj, nValue);
}
/* Duplicate the value */
PH7_MemObjStore(pValue, pObj);
}
nIdx = pObj->nIdx;
/* Hash the key */
nHash = pMap->xIntHash(iKey);
/* Allocate a new int node */
@@ -302,6 +308,8 @@ static sxi32 HashmapInsertIntKey(ph7_hashmap *pMap, sxi64 iKey, ph7_value *pValu
*/
static sxi32 HashmapInsertBlobKey(ph7_hashmap *pMap, const void *pKey, sxu32 nKeyLen, ph7_value *pValue, sxu32 nRefIdx) {
ph7_hashmap_node *pNode;
sxu32 nValue = pValue ? pValue->nIdx : SXU32_HIGH;
sxi32 bArena = pValue && SySetAt(&pMap->pVm->aMemObj, nValue) == pValue;
sxu32 nHash;
sxu32 nIdx;
sxi32 rc;
@@ -312,11 +320,15 @@ static sxi32 HashmapInsertBlobKey(ph7_hashmap *pMap, const void *pKey, sxu32 nKe
if(pObj == 0) {
return SXERR_MEM;
}
nIdx = pObj->nIdx;
if(pValue) {
/* Reserve may move the source slot as well as the new destination. */
if(bArena) {
pValue = (ph7_value *)SySetAt(&pMap->pVm->aMemObj, nValue);
}
/* Duplicate the value */
PH7_MemObjStore(pValue, pObj);
}
nIdx = pObj->nIdx;
/* Hash the key */
nHash = pMap->xBlobHash(pKey, nKeyLen);
/* Allocate a new blob node */