gallium: fix reference counting functions to be strict-aliasing compliant