eval/typval_encode: Dump empty dictionary before checking for refcycle

Otherwise copyID will stay forever on empty dictionaries.
This commit is contained in:
ZyX 2017-01-06 23:32:04 +03:00
parent 10c6e68db6
commit 1052009b37

View File

@ -703,6 +703,10 @@ typval_encode_stop_converting_one_item:
dict_T *const dict = pt == NULL ? NULL : pt->pt_dict;
if (dict != NULL) {
TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, dict->dv_hashtab.ht_used);
if (dict->dv_hashtab.ht_used == 0) {
TYPVAL_ENCODE_CONV_EMPTY_DICT(NULL, pt->pt_dict);
continue;
}
const int te_csr_ret = _TYPVAL_ENCODE_CHECK_SELF_REFERENCE(
TYPVAL_ENCODE_FIRST_ARG_NAME,
dict, &dict->dv_copyID, &mpstack, copyID, kMPConvDict,
@ -714,9 +718,6 @@ typval_encode_stop_converting_one_item:
continue;
}
}
if (dict->dv_hashtab.ht_used == 0) {
TYPVAL_ENCODE_CONV_EMPTY_DICT(NULL, pt->pt_dict);
} else {
TYPVAL_ENCODE_CONV_DICT_START(NULL, pt->pt_dict,
dict->dv_hashtab.ht_used);
_mp_push(mpstack, ((MPConvStackVal) {
@ -731,7 +732,6 @@ typval_encode_stop_converting_one_item:
},
},
}));
}
} else {
TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, -1);
}