On Python >= 3.7, `tb_next` is directly assignable. On PyPy, use
transparent proxies only if support is enabled. For cpython < 3.7, use
ctypes to set `tb_next`. Rewrite the ctypes code to use `py_object` and
`pythonapi.Py_IncRef`, which seems to avoid crashing on debug builds.
On Python 3, a rewritten `TemplateSyntaxError` would retain the frames
from the compiler functions for some reason. Clear these so the template
source is the last thing in the traceback.