* If, during the entry freeing, a destructor happens to add
* a new weak backref, then sv_add_backref will look in both
* places (magic in HvAUX) for the AV, but will create a new
- * AV in HvAUX if it can't find one. So at the end of the
- * iteration we have to allow for this. */
+ * AV in HvAUX if it can't find one (if it finds it in magic,
+ * it moves it back into HvAUX. So at the end of the iteration
+ * we have to allow for this. */
+
if (iter->xhv_backreferences) {
if (SvTYPE(iter->xhv_backreferences) == SVt_PVAV) {
* store it directly in the HvAUX or mg_obj slot, avoiding the need to
* allocate an AV. (Whether the slot holds an AV tells us whether this is
* active.)
+ *
+ * If an HV's backref is stored in magic, it is moved back to HvAUX.
*/
/* A discussion about the backreferences array and its refcount:
if (SvTYPE(tsv) == SVt_PVHV && SvOOK(tsv)) {
svp = (SV**)Perl_hv_backreferences_p(aTHX_ MUTABLE_HV(tsv));
- /* We mustn't attempt to "fix up" the hash here by moving the
- backreference array back to the hv_aux structure, as that is stored
- in the main HvARRAY(), and hfreentries assumes that no-one
- reallocates HvARRAY() while it is running. */
}
if (!svp || !*svp) {
MAGIC *const mg