This is initial (and partial/incomplete) implementation of T51804.
Some notes about current patch:
I) Compared to T51804, also added new handling of freeing (since things like 'not in Main', 'not user-refcounting' etc. also are crucial to be correctly handled by freeing code.
II) It is not finished! This is first step, laying out new API and general behavior. Lots of work remains to get master-ready patch, mostly monkey-coding in copy area.
III) It aims at not breaking anything (obviously), also for current branches. To do so, it mostly defines *new* functions, and avoids changing signature/behavior of existing ones in most cases. That's why we have some duplicated code/functionnality, goal is to get rid of deprecated functions later, as smoothly as possible for everybody.
IV) Biggest changes (and most noisy ones) will be in copy code, since right now most of it always assumes to always increment usercount of used IDs. Not sure if we want to double all those functions with _ex versions taking flag optionsparameter, or to directly modify existing ones? The former would ensure we do not break any existing branch, the later would avoid adding too much new functions...