New version. Same code as v2, but comments improved to explain the reasoning, with reference to README's buffer access rules. I'm planning to push this soon if there are no objections.
pgsql-hackers by date:
Соглашаюсь с условиями обработки персональных данных