legacy: Ensure generated GType names are valid
Legacy classes accept names that aren't valid GType names. Usually this is something the programmer can take into account, however sometimes a parent class isn't under their control and can therefore change unexpectedly (gnome-shell extensions are a primary example).
Handle this case gracefully by replacing any invalid characters with underscores.
This came up in gnome-shell!153 (merged).