src: centralize class wrap/unwrap

While almost all cases were handled by simple WRAP/UNWRAP macros, this
extends those to cover all known occurrences.


This started as a patch to use external array data to store class instances, but didn't offer enough performance gains to justify the change. So instead this is just the cleanup that occurred during the creation of the previous patch.