On Wed Aug 2 15:35:54 2023 +0000, Jacek Caban wrote:
When unlink will be initiated by CC, you can't assume that there are no more refs, only that CC expects that after unlinking there will be no more refs. Since we don't control value's destructor, the object should be in a consistent state while calling it. For all we know it may call `get_nodeValue`. In practice we don't care what exactly we do in such an obscure case, but returning a dispatch that we don't own ref to is never right. We could instead have a helper like `unlink_variant` which would just do something like `if(V_VT(v) == VT_DISPATCH && V_DISPATCH(v)) unlink_ref(&V_DISPATCH(v));` and leave `VariantClear` for the destructor.
In that case, `unlink_ref` isn't going to work either because it NULLs it out, and that would return a NULL VT_DISPATCH in get_nodeValue, which is not exactly ideal, unless I'm missing something?
Probably it would need to be something like: ```c if(V_VT(v) != VT_DISPATCH) { VariantClear(v); return; } V_VT(v) = VT_EMPTY; if(V_DISPATCH(v)) IDispatch_Release(V_DISPATCH(v)); ``` Basically like VariantClear, except it puts VT_EMPTY first before releasing, what do you think?
Actually in this case I should do same with VT_UNKNOWN.